Merge pull request #1808 from dpalou/MOBILE-2919

Mobile 2919
main
Juan Leyva 2019-03-14 11:07:28 +01:00 committed by GitHub
commit 064d5747d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 8 deletions

View File

@ -109,11 +109,20 @@ export class AddonMessagesModule {
messagesProvider.invalidateDiscussionsCache(notification.site).finally(() => { messagesProvider.invalidateDiscussionsCache(notification.site).finally(() => {
// 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.
messagesProvider.isGroupMessagingEnabledInSite(notification.site).then((enabled) => { messagesProvider.isGroupMessagingEnabledInSite(notification.site).then((enabled) => {
const pageParams: any = {};
let pageName = 'AddonMessagesIndexPage'; let pageName = 'AddonMessagesIndexPage';
if (enabled) { if (enabled) {
pageName = 'AddonMessagesGroupConversationsPage'; pageName = 'AddonMessagesGroupConversationsPage';
} }
linkHelper.goInSite(undefined, pageName, undefined, notification.site);
// Check if we have enough information to open the conversation.
if (notification.convid && enabled) {
pageParams.conversationId = Number(notification.convid);
} else if (notification.userfromid) {
pageParams.discussionUserId = Number(notification.userfromid);
}
linkHelper.goInSite(undefined, pageName, pageParams, notification.site);
}); });
}); });
}); });

View File

@ -70,6 +70,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
protected siteId: string; protected siteId: string;
protected currentUserId: number; protected currentUserId: number;
protected conversationId: number; protected conversationId: number;
protected discussionUserId: number;
protected newMessagesObserver: any; protected newMessagesObserver: any;
protected pushObserver: any; protected pushObserver: any;
protected appResumeSubscription: any; protected appResumeSubscription: any;
@ -89,7 +90,9 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
this.loadingString = translate.instant('core.loading'); this.loadingString = translate.instant('core.loading');
this.siteId = sitesProvider.getCurrentSiteId(); this.siteId = sitesProvider.getCurrentSiteId();
this.currentUserId = sitesProvider.getCurrentSiteUserId(); this.currentUserId = sitesProvider.getCurrentSiteUserId();
// Conversation to load.
this.conversationId = navParams.get('conversationId') || false; this.conversationId = navParams.get('conversationId') || false;
this.discussionUserId = !this.conversationId && (navParams.get('discussionUserId') || false);
// Update conversations when new message is received. // Update conversations when new message is received.
this.newMessagesObserver = eventsProvider.on(AddonMessagesProvider.NEW_MESSAGE_EVENT, (data) => { this.newMessagesObserver = eventsProvider.on(AddonMessagesProvider.NEW_MESSAGE_EVENT, (data) => {
@ -213,9 +216,9 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
* Component loaded. * Component loaded.
*/ */
ngOnInit(): void { ngOnInit(): void {
if (this.conversationId) { if (this.conversationId || this.discussionUserId) {
// There is a discussion to load, open the discussion in a new state. // There is a discussion to load, open the discussion in a new state.
this.gotoConversation(this.conversationId); this.gotoConversation(this.conversationId, this.discussionUserId);
} }
this.fetchData().then(() => { this.fetchData().then(() => {

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-item text-wrap>
<ion-avatar core-user-avatar [user]="post" item-start (click)="openUserProfile(post.userid)"></ion-avatar> <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> <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; cmId: number;
protected forumId: number; protected forumId: number;
protected postId: number;
protected onlineObserver: any; protected onlineObserver: any;
protected syncObserver: any; protected syncObserver: any;
protected syncManualObserver: any; protected syncManualObserver: any;
@ -107,6 +108,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
this.discussionId = navParams.get('discussionId'); this.discussionId = navParams.get('discussionId');
this.trackPosts = navParams.get('trackPosts'); this.trackPosts = navParams.get('trackPosts');
this.locked = navParams.get('locked'); this.locked = navParams.get('locked');
this.postId = navParams.get('postId');
this.isOnline = this.appProvider.isOnline(); this.isOnline = this.appProvider.isOnline();
this.onlineObserver = network.onchange().subscribe((online) => { this.onlineObserver = network.onchange().subscribe((online) => {
@ -124,7 +126,14 @@ export class AddonModForumDiscussionPage implements OnDestroy {
* View loaded. * View loaded.
*/ */
ionViewDidLoad(): void { 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 { CoreCronDelegate } from '@providers/cron';
import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
import { CoreSitesProvider } from '@providers/sites'; import { CoreSitesProvider } from '@providers/sites';
import { CoreUrlUtilsProvider } from '@providers/utils/url';
import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreUtilsProvider } from '@providers/utils/utils';
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
import { AddonModForumProvider } from '@addon/mod/forum/providers/forum';
// List of providers (without handlers). // List of providers (without handlers).
export const ADDON_NOTIFICATIONS_PROVIDERS: any[] = [ export const ADDON_NOTIFICATIONS_PROVIDERS: any[] = [
@ -50,12 +52,44 @@ export class AddonNotificationsModule {
cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone, cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone,
appProvider: CoreAppProvider, utils: CoreUtilsProvider, sitesProvider: CoreSitesProvider, appProvider: CoreAppProvider, utils: CoreUtilsProvider, sitesProvider: CoreSitesProvider,
notificationsProvider: AddonNotificationsProvider, localNotifications: CoreLocalNotificationsProvider, notificationsProvider: AddonNotificationsProvider, localNotifications: CoreLocalNotificationsProvider,
linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: AddonPushNotificationsDelegate) { linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: AddonPushNotificationsDelegate,
urlUtils: CoreUrlUtilsProvider, forumProvider: AddonModForumProvider) {
mainMenuDelegate.registerHandler(mainMenuHandler); mainMenuDelegate.registerHandler(mainMenuHandler);
settingsDelegate.registerHandler(settingsHandler); settingsDelegate.registerHandler(settingsHandler);
cronDelegate.register(cronHandler); cronDelegate.register(cronHandler);
const notificationClicked = (notification: any): void => { 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) => { sitesProvider.isFeatureDisabled('CoreMainMenuDelegate_AddonNotifications', notification.site).then((disabled) => {
if (disabled) { if (disabled) {
// Notifications are disabled, stop. // Notifications are disabled, stop.

View File

@ -52,14 +52,23 @@ export class CoreUrlUtilsProvider {
*/ */
extractUrlParams(url: string): any { extractUrlParams(url: string): any {
const regex = /[?&]+([^=&]+)=?([^&]*)?/gi, 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 : ''; params[key] = typeof value != 'undefined' ? value : '';
return match; 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; return params;
} }