MOBILE-2795 notifications: Show user avatars

main
Pau Ferrer Ocaña 2019-01-08 11:23:47 +01:00
parent 9f2d0a40aa
commit 74cbeb403a
2 changed files with 21 additions and 11 deletions

View File

@ -44,9 +44,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 +61,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,7 +152,8 @@ 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);
return this.formatNotificationsData(notifications).then(() => {
if (this.appProvider.isDesktop() && toDisplay && !read && limitFrom === 0) { if (this.appProvider.isDesktop() && toDisplay && !read && limitFrom === 0) {
// Store the last received notification. Don't block the user for this. // Store the last received notification. Don't block the user for this.
this.emulatorHelper.storeLastReceivedNotification( this.emulatorHelper.storeLastReceivedNotification(
@ -153,6 +161,7 @@ export class AddonNotificationsProvider {
} }
return notifications; return notifications;
});
} else { } else {
return Promise.reject(null); return Promise.reject(null);
} }

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>