MOBILE-2919 forum: Handle forum discussion notification clicks

main
Dani Palou 2019-03-14 09:25:29 +01:00
parent 6e054bf6cd
commit 8b2ed818fa
4 changed files with 57 additions and 5 deletions

View File

@ -1,4 +1,4 @@
<ion-card-header text-wrap no-padding >
<ion-card-header text-wrap no-padding id="addon-mod_forum-post-{{post.id}}">
<ion-item text-wrap>
<ion-avatar core-user-avatar [user]="post" item-start (click)="openUserProfile(post.userid)"></ion-avatar>
<h2><span [class.core-bold]="post.parent == 0"><core-format-text [text]="post.subject"></core-format-text></span></h2>

View File

@ -76,6 +76,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
cmId: number;
protected forumId: number;
protected postId: number;
protected onlineObserver: any;
protected syncObserver: any;
protected syncManualObserver: any;
@ -107,6 +108,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
this.discussionId = navParams.get('discussionId');
this.trackPosts = navParams.get('trackPosts');
this.locked = navParams.get('locked');
this.postId = navParams.get('postId');
this.isOnline = this.appProvider.isOnline();
this.onlineObserver = network.onchange().subscribe((online) => {
@ -124,7 +126,14 @@ export class AddonModForumDiscussionPage implements OnDestroy {
* View loaded.
*/
ionViewDidLoad(): void {
this.fetchPosts(true, false, true);
this.fetchPosts(true, false, true).then(() => {
if (this.postId) {
// Scroll to the post.
setTimeout(() => {
this.domUtils.scrollToElementBySelector(this.content, '#addon-mod_forum-post-' + this.postId);
});
}
});
}
/**

View File

@ -24,8 +24,10 @@ import { CoreSettingsDelegate } from '@core/settings/providers/delegate';
import { CoreCronDelegate } from '@providers/cron';
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
import { CoreSitesProvider } from '@providers/sites';
import { CoreUrlUtilsProvider } from '@providers/utils/url';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
import { AddonModForumProvider } from '@addon/mod/forum/providers/forum';
// List of providers (without handlers).
export const ADDON_NOTIFICATIONS_PROVIDERS: any[] = [
@ -50,12 +52,44 @@ export class AddonNotificationsModule {
cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone,
appProvider: CoreAppProvider, utils: CoreUtilsProvider, sitesProvider: CoreSitesProvider,
notificationsProvider: AddonNotificationsProvider, localNotifications: CoreLocalNotificationsProvider,
linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: AddonPushNotificationsDelegate) {
linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: AddonPushNotificationsDelegate,
urlUtils: CoreUrlUtilsProvider, forumProvider: AddonModForumProvider) {
mainMenuDelegate.registerHandler(mainMenuHandler);
settingsDelegate.registerHandler(settingsHandler);
cronDelegate.register(cronHandler);
const notificationClicked = (notification: any): void => {
// Temporary fix to make forum notifications work. This will be improved in next release.
if (notification.moodlecomponent == 'mod_forum' && notification.name == 'posts') {
sitesProvider.isFeatureDisabled('CoreCourseModuleDelegate_AddonModForum', notification.site).then((disabled) => {
if (disabled) {
// Forum is disabled, stop.
return;
}
const contextUrlParams = urlUtils.extractUrlParams(notification.contexturl),
pageParams: any = {
courseId: Number(notification.courseid),
discussionId: Number(contextUrlParams.d),
};
if (contextUrlParams.urlHash) {
pageParams.postId = Number(contextUrlParams.urlHash.replace('p', ''));
}
forumProvider.invalidateDiscussionPosts(pageParams.discussionId).catch(() => {
// Ignore errors.
}).then(() => {
linkHelper.goInSite(undefined, 'AddonModForumDiscussionPage', pageParams, notification.site);
});
});
} else {
goToNotifications(notification);
}
};
const goToNotifications = (notification: any): void => {
sitesProvider.isFeatureDisabled('CoreMainMenuDelegate_AddonNotifications', notification.site).then((disabled) => {
if (disabled) {
// Notifications are disabled, stop.

View File

@ -52,14 +52,23 @@ export class CoreUrlUtilsProvider {
*/
extractUrlParams(url: string): any {
const regex = /[?&]+([^=&]+)=?([^&]*)?/gi,
params = {};
params: any = {},
urlAndHash = url.split('#');
url.replace(regex, (match: string, key: string, value: string): string => {
urlAndHash[0].replace(regex, (match: string, key: string, value: string): string => {
params[key] = typeof value != 'undefined' ? value : '';
return match;
});
if (urlAndHash.length > 1) {
// Remove the URL from the array.
urlAndHash.shift();
// Add the hash as a param with a special name. Use a join in case there is more than one #.
params.urlHash = urlAndHash.join('#');
}
return params;
}