MOBILE-3320 messages: Fix message tab not selected

main
Dani Palou 2021-05-12 15:15:33 +02:00
parent 7353bfac79
commit f9fc2d3758
6 changed files with 51 additions and 34 deletions

View File

@ -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);
}
}

View File

@ -16,6 +16,7 @@ import { Injector, NgModule } from '@angular/core';
import { Route, RouterModule, ROUTES, Routes } from '@angular/router';
import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module';
import { AddonMessagesIndexGuard } from './guards';
export const AddonMessagesDiscussionRoute: Route = {
path: 'discussion',
@ -51,8 +52,7 @@ function buildRoutes(injector: Injector): Routes {
.then(m => m.AddonMessagesContactsPageModule),
},
...buildTabMainRoutes(injector, {
redirectTo: 'index',
pathMatch: 'full',
canActivate: [AddonMessagesIndexGuard],
}),
];
}

View File

@ -18,6 +18,7 @@ import { CoreContentLinksAction } from '@features/contentlinks/services/contentl
import { CoreNavigator } from '@services/navigator';
import { makeSingleton } from '@singletons';
import { AddonMessages } from '../messages';
import { AddonMessagesMainMenuHandlerService } from './mainmenu';
/**
* Content links handler for messaging index.
@ -37,9 +38,7 @@ export class AddonMessagesIndexLinkHandlerService extends CoreContentLinksHandle
getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: async (siteId): Promise<void> => {
const pageName = await AddonMessages.getMainMessagesPagePathInSite(siteId);
CoreNavigator.navigateToSitePath(pageName, {
CoreNavigator.navigateToSitePath(AddonMessagesMainMenuHandlerService.PAGE_NAME, {
siteId,
preferCurrentTab: false,
});

View File

@ -43,7 +43,7 @@ export class AddonMessagesMainMenuHandlerService implements CoreMainMenuHandler,
protected handler: CoreMainMenuHandlerToDisplay = {
icon: 'fas-comments',
title: 'addon.messages.messages',
page: AddonMessages.getMainMessagesPagePath(),
page: AddonMessagesMainMenuHandlerService.PAGE_NAME,
class: 'addon-messages-handler',
showBadge: true, // Do not check isMessageCountEnabled because we'll use fallback it not enabled.
badge: '',
@ -107,8 +107,6 @@ export class AddonMessagesMainMenuHandlerService implements CoreMainMenuHandler,
* @return Data needed to render the handler.
*/
getDisplayData(): CoreMainMenuHandlerToDisplay {
this.handler.page = AddonMessages.getMainMessagesPagePath();
if (this.handler.loading) {
this.refreshBadge();
}

View File

@ -20,6 +20,7 @@ import { CoreNavigator } from '@services/navigator';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';
import { AddonMessages } from '../messages';
import { AddonMessagesMainMenuHandlerService } from './mainmenu';
/**
* 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.
const enabled = await AddonMessages.isGroupMessagingEnabledInSite(notification.site);
const pageName = await AddonMessages.getMainMessagesPagePathInSite(notification.site);
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,
preferCurrentTab: false,
nextNavigation: nextPageParams ?

View File

@ -30,7 +30,6 @@ import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreWSExternalWarning } from '@services/ws';
import { makeSingleton } from '@singletons';
import { CoreError } from '@classes/errors/error';
import { AddonMessagesMainMenuHandlerService } from './handlers/mainmenu';
import { AddonMessagesSyncEvents, AddonMessagesSyncProvider } from './messages-sync';
const ROOT_CACHE_KEY = 'mmaMessages:';
@ -1411,29 +1410,6 @@ export class AddonMessagesProvider {
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.
*