2021-01-18 15:40:34 +00:00
|
|
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
import { APP_INITIALIZER, NgModule } from '@angular/core';
|
|
|
|
import { Routes } from '@angular/router';
|
|
|
|
|
|
|
|
import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module';
|
|
|
|
import { MESSAGES_OFFLINE_SITE_SCHEMA } from './services/database/messages';
|
|
|
|
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
|
|
|
import { CoreMainMenuDelegate } from '@features/mainmenu/services/mainmenu-delegate';
|
|
|
|
import { AddonMessagesMainMenuHandler, AddonMessagesMainMenuHandlerService } from './services/handlers/mainmenu';
|
|
|
|
import { CoreCronDelegate } from '@services/cron';
|
2021-01-21 16:27:52 +00:00
|
|
|
import { CoreSettingsDelegate } from '@features/settings/services/settings-delegate';
|
|
|
|
import { AddonMessagesSettingsHandler } from './services/handlers/settings';
|
|
|
|
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
2021-01-22 12:40:50 +00:00
|
|
|
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
|
|
|
|
import { AddonMessagesIndexLinkHandler } from './services/handlers/index-link';
|
|
|
|
import { AddonMessagesDiscussionLinkHandler } from './services/handlers/discussion-link';
|
|
|
|
import { AddonMessagesContactRequestLinkHandler } from './services/handlers/contact-request-link';
|
|
|
|
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
|
|
|
|
import { AddonMessagesPushClickHandler } from './services/handlers/push-click';
|
|
|
|
import { CoreUserDelegate } from '@features/user/services/user-delegate';
|
|
|
|
import { AddonMessagesSendMessageUserHandler } from './services/handlers/user-send-message';
|
2021-01-22 14:03:56 +00:00
|
|
|
import { Network, NgZone } from '@singletons';
|
|
|
|
import { AddonMessagesSync } from './services/messages-sync';
|
2021-01-18 15:40:34 +00:00
|
|
|
|
|
|
|
const mainMenuChildrenRoutes: Routes = [
|
|
|
|
{
|
|
|
|
path: AddonMessagesMainMenuHandlerService.PAGE_NAME,
|
|
|
|
loadChildren: () => import('./messages-lazy.module').then(m => m.AddonMessagesLazyModule),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
@NgModule({
|
|
|
|
imports: [
|
|
|
|
CoreMainMenuRoutingModule.forChild({ children: mainMenuChildrenRoutes }),
|
2021-01-21 16:27:52 +00:00
|
|
|
CoreMainMenuTabRoutingModule.forChild( mainMenuChildrenRoutes),
|
2021-01-18 15:40:34 +00:00
|
|
|
],
|
|
|
|
providers: [
|
|
|
|
{
|
|
|
|
provide: CORE_SITE_SCHEMAS,
|
|
|
|
useValue: [MESSAGES_OFFLINE_SITE_SCHEMA],
|
|
|
|
multi: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: APP_INITIALIZER,
|
|
|
|
multi: true,
|
|
|
|
deps: [],
|
|
|
|
useFactory: () => () => {
|
2021-01-22 12:40:50 +00:00
|
|
|
// Register handlers.
|
2021-01-18 15:40:34 +00:00
|
|
|
CoreMainMenuDelegate.instance.registerHandler(AddonMessagesMainMenuHandler.instance);
|
|
|
|
CoreCronDelegate.instance.register(AddonMessagesMainMenuHandler.instance);
|
2021-01-22 14:03:56 +00:00
|
|
|
CoreCronDelegate.instance.register(AddonMessagesPushClickHandler.instance);
|
2021-01-21 16:27:52 +00:00
|
|
|
CoreSettingsDelegate.instance.registerHandler(AddonMessagesSettingsHandler.instance);
|
2021-01-22 12:40:50 +00:00
|
|
|
CoreContentLinksDelegate.instance.registerHandler(AddonMessagesIndexLinkHandler.instance);
|
|
|
|
CoreContentLinksDelegate.instance.registerHandler(AddonMessagesDiscussionLinkHandler.instance);
|
|
|
|
CoreContentLinksDelegate.instance.registerHandler(AddonMessagesContactRequestLinkHandler.instance);
|
|
|
|
CorePushNotificationsDelegate.instance.registerClickHandler(AddonMessagesPushClickHandler.instance);
|
|
|
|
CoreUserDelegate.instance.registerHandler(AddonMessagesSendMessageUserHandler.instance);
|
|
|
|
|
|
|
|
// Sync some discussions when device goes online.
|
2021-01-22 14:03:56 +00:00
|
|
|
Network.instance.onConnect().subscribe(() => {
|
2021-01-22 12:40:50 +00:00
|
|
|
// Execute the callback in the Angular zone, so change detection doesn't stop working.
|
|
|
|
NgZone.instance.run(() => {
|
|
|
|
AddonMessagesSync.instance.syncAllDiscussions(undefined, true);
|
|
|
|
});
|
2021-01-22 14:03:56 +00:00
|
|
|
});
|
2021-01-18 15:40:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
})
|
2021-01-22 12:40:50 +00:00
|
|
|
export class AddonMessagesModule {}
|