MOBILE-3320 messages: Fix message tab not selected
parent
7353bfac79
commit
f9fc2d3758
|
@ -0,0 +1,44 @@
|
||||||
|
// (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 { Injectable } from '@angular/core';
|
||||||
|
import { CanActivate, UrlTree } from '@angular/router';
|
||||||
|
import { Router } from '@singletons';
|
||||||
|
import { AddonMessagesMainMenuHandlerService } from '../services/handlers/mainmenu';
|
||||||
|
import { AddonMessages } from '../services/messages';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guard to redirect to the right page based on the current Moodle site version.
|
||||||
|
*/
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class AddonMessagesIndexGuard implements CanActivate {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
canActivate(): UrlTree {
|
||||||
|
return this.guard();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if there is a pending redirect and trigger it.
|
||||||
|
*/
|
||||||
|
private guard(): UrlTree {
|
||||||
|
const enabled = AddonMessages.isGroupMessagingEnabled();
|
||||||
|
const path = `/main/${AddonMessagesMainMenuHandlerService.PAGE_NAME}/` + ( enabled ? 'group-conversations' : 'index');
|
||||||
|
|
||||||
|
return Router.parseUrl(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ import { Injector, NgModule } from '@angular/core';
|
||||||
import { Route, RouterModule, ROUTES, Routes } from '@angular/router';
|
import { Route, RouterModule, ROUTES, Routes } from '@angular/router';
|
||||||
|
|
||||||
import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
|
import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
|
||||||
|
import { AddonMessagesIndexGuard } from './guards';
|
||||||
|
|
||||||
export const AddonMessagesDiscussionRoute: Route = {
|
export const AddonMessagesDiscussionRoute: Route = {
|
||||||
path: 'discussion',
|
path: 'discussion',
|
||||||
|
@ -51,8 +52,7 @@ function buildRoutes(injector: Injector): Routes {
|
||||||
.then(m => m.AddonMessagesContactsPageModule),
|
.then(m => m.AddonMessagesContactsPageModule),
|
||||||
},
|
},
|
||||||
...buildTabMainRoutes(injector, {
|
...buildTabMainRoutes(injector, {
|
||||||
redirectTo: 'index',
|
canActivate: [AddonMessagesIndexGuard],
|
||||||
pathMatch: 'full',
|
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { CoreContentLinksAction } from '@features/contentlinks/services/contentl
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { AddonMessages } from '../messages';
|
import { AddonMessages } from '../messages';
|
||||||
|
import { AddonMessagesMainMenuHandlerService } from './mainmenu';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content links handler for messaging index.
|
* Content links handler for messaging index.
|
||||||
|
@ -37,9 +38,7 @@ export class AddonMessagesIndexLinkHandlerService extends CoreContentLinksHandle
|
||||||
getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||||
return [{
|
return [{
|
||||||
action: async (siteId): Promise<void> => {
|
action: async (siteId): Promise<void> => {
|
||||||
const pageName = await AddonMessages.getMainMessagesPagePathInSite(siteId);
|
CoreNavigator.navigateToSitePath(AddonMessagesMainMenuHandlerService.PAGE_NAME, {
|
||||||
|
|
||||||
CoreNavigator.navigateToSitePath(pageName, {
|
|
||||||
siteId,
|
siteId,
|
||||||
preferCurrentTab: false,
|
preferCurrentTab: false,
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,7 +43,7 @@ export class AddonMessagesMainMenuHandlerService implements CoreMainMenuHandler,
|
||||||
protected handler: CoreMainMenuHandlerToDisplay = {
|
protected handler: CoreMainMenuHandlerToDisplay = {
|
||||||
icon: 'fas-comments',
|
icon: 'fas-comments',
|
||||||
title: 'addon.messages.messages',
|
title: 'addon.messages.messages',
|
||||||
page: AddonMessages.getMainMessagesPagePath(),
|
page: AddonMessagesMainMenuHandlerService.PAGE_NAME,
|
||||||
class: 'addon-messages-handler',
|
class: 'addon-messages-handler',
|
||||||
showBadge: true, // Do not check isMessageCountEnabled because we'll use fallback it not enabled.
|
showBadge: true, // Do not check isMessageCountEnabled because we'll use fallback it not enabled.
|
||||||
badge: '',
|
badge: '',
|
||||||
|
@ -107,8 +107,6 @@ export class AddonMessagesMainMenuHandlerService implements CoreMainMenuHandler,
|
||||||
* @return Data needed to render the handler.
|
* @return Data needed to render the handler.
|
||||||
*/
|
*/
|
||||||
getDisplayData(): CoreMainMenuHandlerToDisplay {
|
getDisplayData(): CoreMainMenuHandlerToDisplay {
|
||||||
this.handler.page = AddonMessages.getMainMessagesPagePath();
|
|
||||||
|
|
||||||
if (this.handler.loading) {
|
if (this.handler.loading) {
|
||||||
this.refreshBadge();
|
this.refreshBadge();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { AddonMessages } from '../messages';
|
import { AddonMessages } from '../messages';
|
||||||
|
import { AddonMessagesMainMenuHandlerService } from './mainmenu';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for messaging push notifications clicks.
|
* Handler for messaging push notifications clicks.
|
||||||
|
@ -61,7 +62,6 @@ export class AddonMessagesPushClickHandlerService implements CorePushNotificatio
|
||||||
|
|
||||||
// Check if group messaging is enabled, to determine which page should be loaded.
|
// Check if group messaging is enabled, to determine which page should be loaded.
|
||||||
const enabled = await AddonMessages.isGroupMessagingEnabledInSite(notification.site);
|
const enabled = await AddonMessages.isGroupMessagingEnabledInSite(notification.site);
|
||||||
const pageName = await AddonMessages.getMainMessagesPagePathInSite(notification.site);
|
|
||||||
|
|
||||||
let nextPageParams: Params | undefined;
|
let nextPageParams: Params | undefined;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ export class AddonMessagesPushClickHandlerService implements CorePushNotificatio
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await CoreNavigator.navigateToSitePath(pageName, {
|
await CoreNavigator.navigateToSitePath(AddonMessagesMainMenuHandlerService.PAGE_NAME, {
|
||||||
siteId: notification.site,
|
siteId: notification.site,
|
||||||
preferCurrentTab: false,
|
preferCurrentTab: false,
|
||||||
nextNavigation: nextPageParams ?
|
nextNavigation: nextPageParams ?
|
||||||
|
|
|
@ -30,7 +30,6 @@ import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
|
||||||
import { CoreWSExternalWarning } from '@services/ws';
|
import { CoreWSExternalWarning } from '@services/ws';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { AddonMessagesMainMenuHandlerService } from './handlers/mainmenu';
|
|
||||||
import { AddonMessagesSyncEvents, AddonMessagesSyncProvider } from './messages-sync';
|
import { AddonMessagesSyncEvents, AddonMessagesSyncProvider } from './messages-sync';
|
||||||
|
|
||||||
const ROOT_CACHE_KEY = 'mmaMessages:';
|
const ROOT_CACHE_KEY = 'mmaMessages:';
|
||||||
|
@ -1411,29 +1410,6 @@ export class AddonMessagesProvider {
|
||||||
throw new CoreError('Error getting message preferences');
|
throw new CoreError('Error getting message preferences');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the site main messages page path for a site.
|
|
||||||
*
|
|
||||||
* @param siteId Site ID. If not defined, use current site.
|
|
||||||
* @return Main messages page path of the site.
|
|
||||||
*/
|
|
||||||
async getMainMessagesPagePathInSite(siteId?: string): Promise<string> {
|
|
||||||
const enabled = await this.isGroupMessagingEnabledInSite(siteId);
|
|
||||||
|
|
||||||
return AddonMessagesMainMenuHandlerService.PAGE_NAME + ( enabled ? '/group-conversations' : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the site main messages page path.
|
|
||||||
*
|
|
||||||
* @return Main messages page path of the site.
|
|
||||||
*/
|
|
||||||
getMainMessagesPagePath(): string {
|
|
||||||
const enabled = this.isGroupMessagingEnabled();
|
|
||||||
|
|
||||||
return AddonMessagesMainMenuHandlerService.PAGE_NAME + ( enabled ? '/group-conversations' : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get messages according to the params.
|
* Get messages according to the params.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue