Merge pull request #1710 from crazyserver/MOBILE-2795

Mobile 2795
main
Juan Leyva 2019-01-08 12:45:38 +01:00 committed by GitHub
commit 8bad2a3e67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 18 deletions

View File

@ -253,6 +253,10 @@ export class AddonModForumDiscussionPage implements OnDestroy {
const posts = offlineReplies.concat(onlinePosts); const posts = offlineReplies.concat(onlinePosts);
this.discussion = this.forumProvider.extractStartingPost(posts); this.discussion = this.forumProvider.extractStartingPost(posts);
if (!this.discussion) {
return Promise.reject('Invalid forum discussion');
}
// If sort type is nested, normal sorting is disabled and nested posts will be displayed. // If sort type is nested, normal sorting is disabled and nested posts will be displayed.
if (this.sort == 'nested') { if (this.sort == 'nested') {
// Sort first by creation date to make format tree work. // Sort first by creation date to make format tree work.

View File

@ -19,6 +19,7 @@ import { CoreSitesProvider } from '@providers/sites';
import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { CoreUserProvider } from '@core/user/providers/user'; import { CoreUserProvider } from '@core/user/providers/user';
import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper'; import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper';
import { AddonMessagesProvider } from '@addon/messages/providers/messages';
/** /**
* Service to handle notifications. * Service to handle notifications.
@ -36,7 +37,7 @@ export class AddonNotificationsProvider {
constructor(logger: CoreLoggerProvider, private appProvider: CoreAppProvider, private sitesProvider: CoreSitesProvider, constructor(logger: CoreLoggerProvider, private appProvider: CoreAppProvider, private sitesProvider: CoreSitesProvider,
private timeUtils: CoreTimeUtilsProvider, private userProvider: CoreUserProvider, private timeUtils: CoreTimeUtilsProvider, private userProvider: CoreUserProvider,
private emulatorHelper: CoreEmulatorHelperProvider) { private emulatorHelper: CoreEmulatorHelperProvider, private messageProvider: AddonMessagesProvider) {
this.logger = logger.getInstance('AddonNotificationsProvider'); this.logger = logger.getInstance('AddonNotificationsProvider');
} }
@ -44,9 +45,10 @@ export class AddonNotificationsProvider {
* Function to format notification data. * Function to format notification data.
* *
* @param {any[]} notifications List of notifications. * @param {any[]} notifications List of notifications.
* @return {Promise<any[]>} Promise resolved with notifications.
*/ */
protected formatNotificationsData(notifications: any[]): void { protected formatNotificationsData(notifications: any[]): Promise<any> {
notifications.forEach((notification) => { const promises = notifications.map((notification) => {
// Set message to show. // Set message to show.
if (notification.contexturl && notification.contexturl.indexOf('/mod/forum/') >= 0) { if (notification.contexturl && notification.contexturl.indexOf('/mod/forum/') >= 0) {
notification.mobiletext = notification.smallmessage; notification.mobiletext = notification.smallmessage;
@ -60,13 +62,19 @@ export class AddonNotificationsProvider {
} }
if (notification.useridfrom > 0) { if (notification.useridfrom > 0) {
// Try to get the profile picture of the user. // Try to get the profile picture of the user.
this.userProvider.getProfile(notification.useridfrom, notification.courseid, true).then((user) => { return this.userProvider.getProfile(notification.useridfrom, notification.courseid, true).then((user) => {
notification.profileimageurlfrom = user.profileimageurl; notification.profileimageurlfrom = user.profileimageurl;
return notification;
}).catch(() => { }).catch(() => {
// Error getting user. This can happen if device is offline or the user is deleted. // Error getting user. This can happen if device is offline or the user is deleted.
}); });
} }
return Promise.resolve(notification);
}); });
return Promise.all(promises);
} }
/** /**
@ -145,14 +153,16 @@ export class AddonNotificationsProvider {
return site.read('core_message_get_messages', data, preSets).then((response) => { return site.read('core_message_get_messages', data, preSets).then((response) => {
if (response.messages) { if (response.messages) {
const notifications = response.messages; const notifications = response.messages;
this.formatNotificationsData(notifications);
if (this.appProvider.isDesktop() && toDisplay && !read && limitFrom === 0) {
// Store the last received notification. Don't block the user for this.
this.emulatorHelper.storeLastReceivedNotification(
AddonNotificationsProvider.PUSH_SIMULATION_COMPONENT, notifications[0], siteId);
}
return notifications; return this.formatNotificationsData(notifications).then(() => {
if (this.appProvider.isDesktop() && toDisplay && !read && limitFrom === 0) {
// Store the last received notification. Don't block the user for this.
this.emulatorHelper.storeLastReceivedNotification(
AddonNotificationsProvider.PUSH_SIMULATION_COMPONENT, notifications[0], siteId);
}
return notifications;
});
} else { } else {
return Promise.reject(null); return Promise.reject(null);
} }
@ -249,18 +259,26 @@ export class AddonNotificationsProvider {
} }
/** /**
* Mark message notification as read. * Mark a single notification as read.
* *
* @param {number} notificationId ID of notification to mark as read * @param {number} notificationId ID of notification to mark as read
* @returns {Promise<any>} Resolved when done. * @returns {Promise<any>} Resolved when done.
* @since 3.5
*/ */
markNotificationRead(notificationId: number): Promise<any> { markNotificationRead(notificationId: number): Promise<any> {
const params = { const currentSite = this.sitesProvider.getCurrentSite();
messageid: notificationId,
timeread: this.timeUtils.timestamp()
};
return this.sitesProvider.getCurrentSite().write('core_message_mark_message_read', params); if (currentSite.wsAvailable('core_message_mark_notification_read')) {
const params = {
notificationid: notificationId,
timeread: this.timeUtils.timestamp()
};
return currentSite.write('core_message_mark_notification_read', params);
} else {
// Fallback for versions prior to 3.5.
return this.messageProvider.markMessageRead(notificationId);
}
} }
/** /**

View File

@ -1,3 +1,4 @@
<img src="{{profileUrl}}" [alt]="'core.pictureof' | translate:{$a: fullname}" core-external-content onError="this.src='assets/img/user-avatar.png'" role="presentation" [siteId]="siteId || null" (click)="gotoProfile($event)"> <img *ngIf="profileUrl" [src]="profileUrl" [alt]="'core.pictureof' | translate:{$a: fullname}" core-external-content onError="this.src='assets/img/user-avatar.png'" role="presentation" [siteId]="siteId || null" (click)="gotoProfile($event)">
<img *ngIf="!profileUrl" src="assets/img/user-avatar.png" [alt]="'core.pictureof' | translate:{$a: fullname}" role="presentation" (click)="gotoProfile($event)">
<span *ngIf="checkOnline && isOnline()" class="contact-status online"></span> <span *ngIf="checkOnline && isOnline()" class="contact-status online"></span>
<ng-content></ng-content> <ng-content></ng-content>