MOBILE-3739 chat: Implement on leave guard
parent
2f8333d516
commit
8e20e05afc
|
@ -430,6 +430,7 @@
|
||||||
"addon.mod_book.toc": "book",
|
"addon.mod_book.toc": "book",
|
||||||
"addon.mod_chat.beep": "chat",
|
"addon.mod_chat.beep": "chat",
|
||||||
"addon.mod_chat.chatreport": "chat",
|
"addon.mod_chat.chatreport": "chat",
|
||||||
|
"addon.mod_chat.confirmloss": "local_moodlemobileapp",
|
||||||
"addon.mod_chat.currentusers": "chat",
|
"addon.mod_chat.currentusers": "chat",
|
||||||
"addon.mod_chat.enterchat": "chat",
|
"addon.mod_chat.enterchat": "chat",
|
||||||
"addon.mod_chat.entermessage": "chat",
|
"addon.mod_chat.entermessage": "chat",
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { AddonModChatSessionMessagesPage } from './pages/session-messages/sessio
|
||||||
import { CoreScreen } from '@services/screen';
|
import { CoreScreen } from '@services/screen';
|
||||||
import { conditionalRoutes } from '@/app/app-routing.module';
|
import { conditionalRoutes } from '@/app/app-routing.module';
|
||||||
import { AddonModChatSessionsPage } from './pages/sessions/sessions';
|
import { AddonModChatSessionsPage } from './pages/sessions/sessions';
|
||||||
|
import { CanLeaveGuard } from '@guards/can-leave';
|
||||||
|
|
||||||
const commonRoutes: Routes = [
|
const commonRoutes: Routes = [
|
||||||
{
|
{
|
||||||
|
@ -31,6 +32,7 @@ const commonRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: ':courseId/:cmId/chat',
|
path: ':courseId/:cmId/chat',
|
||||||
component: AddonModChatChatPage,
|
component: AddonModChatChatPage,
|
||||||
|
canDeactivate: [CanLeaveGuard],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"beep": "Beep",
|
"beep": "Beep",
|
||||||
"chatreport": "Chat sessions",
|
"chatreport": "Chat sessions",
|
||||||
|
"confirmloss": "Are you sure? Chat history can be lost.",
|
||||||
"currentusers": "Current users",
|
"currentusers": "Current users",
|
||||||
"enterchat": "Click here to enter the chat now",
|
"enterchat": "Click here to enter the chat now",
|
||||||
"entermessage": "Enter your message",
|
"entermessage": "Enter your message",
|
||||||
|
@ -25,4 +26,4 @@
|
||||||
"showincompletesessions": "Show incomplete sessions",
|
"showincompletesessions": "Show incomplete sessions",
|
||||||
"talk": "Talk",
|
"talk": "Talk",
|
||||||
"viewreport": "View past chat sessions"
|
"viewreport": "View past chat sessions"
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,14 @@
|
||||||
import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core';
|
import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { CoreAnimations } from '@components/animations';
|
import { CoreAnimations } from '@components/animations';
|
||||||
import { CoreSendMessageFormComponent } from '@components/send-message-form/send-message-form';
|
import { CoreSendMessageFormComponent } from '@components/send-message-form/send-message-form';
|
||||||
|
import { CanLeave } from '@guards/can-leave';
|
||||||
import { IonContent } from '@ionic/angular';
|
import { IonContent } from '@ionic/angular';
|
||||||
import { CoreApp } from '@services/app';
|
import { CoreApp } from '@services/app';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { Network, NgZone } from '@singletons';
|
import { Network, NgZone, Translate } from '@singletons';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { AddonModChatUsersModalComponent, AddonModChatUsersModalResult } from '../../components/users-modal/users-modal';
|
import { AddonModChatUsersModalComponent, AddonModChatUsersModalResult } from '../../components/users-modal/users-modal';
|
||||||
|
@ -37,7 +38,7 @@ import { AddonModChatFormattedMessage, AddonModChatHelper } from '../../services
|
||||||
animations: [CoreAnimations.SLIDE_IN_OUT],
|
animations: [CoreAnimations.SLIDE_IN_OUT],
|
||||||
styleUrls: ['chat.scss', '../../../../messages/pages/discussion/discussion.scss'],
|
styleUrls: ['chat.scss', '../../../../messages/pages/discussion/discussion.scss'],
|
||||||
})
|
})
|
||||||
export class AddonModChatChatPage implements OnInit, OnDestroy {
|
export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave {
|
||||||
|
|
||||||
@ViewChild(IonContent) content?: IonContent;
|
@ViewChild(IonContent) content?: IonContent;
|
||||||
@ViewChild(CoreSendMessageFormComponent) sendMessageForm?: CoreSendMessageFormComponent;
|
@ViewChild(CoreSendMessageFormComponent) sendMessageForm?: CoreSendMessageFormComponent;
|
||||||
|
@ -381,6 +382,22 @@ export class AddonModChatChatPage implements OnInit, OnDestroy {
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if we can leave the page or not.
|
||||||
|
*
|
||||||
|
* @return Resolved with true if we can leave it, rejected if not.
|
||||||
|
*/
|
||||||
|
async canLeave(): Promise<boolean> {
|
||||||
|
if (! this.messages.some((message) => !message.special)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modified, confirm user wants to go back.
|
||||||
|
await CoreDomUtils.showConfirm(Translate.instant('addon.mod_chat.confirmloss'));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue