From e0f2610ad831ba28dc67f66a7d651d7a66bad9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 4 Jan 2019 11:20:45 +0100 Subject: [PATCH 1/9] MOBILE-2795 user: Update profile picture when changed --- src/components/user-avatar/user-avatar.ts | 28 ++++++++++++++++++----- src/core/user/pages/profile/profile.ts | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/components/user-avatar/user-avatar.ts b/src/components/user-avatar/user-avatar.ts index 627fb1a5b..65108f470 100644 --- a/src/components/user-avatar/user-avatar.ts +++ b/src/components/user-avatar/user-avatar.ts @@ -12,11 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input, OnInit, OnChanges, SimpleChange } from '@angular/core'; +import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChange } from '@angular/core'; import { NavController } from 'ionic-angular'; import { CoreSitesProvider } from '@providers/sites'; import { CoreAppProvider } from '@providers/app'; import { CoreUtilsProvider } from '@providers/utils/utils'; +import { CoreEventsProvider } from '@providers/events'; +import { CoreUserProvider } from '@core/user/providers/user'; /** * Component to display a "user avatar". @@ -27,7 +29,7 @@ import { CoreUtilsProvider } from '@providers/utils/utils'; selector: 'ion-avatar[core-user-avatar]', templateUrl: 'core-user-avatar.html' }) -export class CoreUserAvatarComponent implements OnInit, OnChanges { +export class CoreUserAvatarComponent implements OnInit, OnChanges, OnDestroy { @Input() user: any; // The following params will override the ones in user object. @Input() profileUrl?: string; @@ -42,10 +44,17 @@ export class CoreUserAvatarComponent implements OnInit, OnChanges { protected timetoshowusers = 300000; // Miliseconds default. protected myUser = false; protected currentUserId: number; + protected pictureObs; constructor(private navCtrl: NavController, private sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider, - private appProvider: CoreAppProvider) { + private appProvider: CoreAppProvider, eventsProvider: CoreEventsProvider) { this.currentUserId = this.sitesProvider.getCurrentSiteUserId(); + + this.pictureObs = eventsProvider.on(CoreUserProvider.PROFILE_PICTURE_UPDATED, (data) => { + if (data.userId == this.userId) { + this.profileUrl = data.picture; + } + }, this.sitesProvider.getCurrentSiteId()); } /** @@ -69,11 +78,11 @@ export class CoreUserAvatarComponent implements OnInit, OnChanges { * Set fields from user. */ protected setFields(): void { - this.profileUrl = this.profileUrl || (this.user && (this.user.profileimageurl || this.user.userprofileimageurl || + const profileUrl = this.profileUrl || (this.user && (this.user.profileimageurl || this.user.userprofileimageurl || this.user.userpictureurl || this.user.profileimageurlsmall)); - if (typeof this.profileUrl != 'string') { - this.profileUrl = ''; + if (typeof profileUrl == 'string') { + this.profileUrl = profileUrl; } this.fullname = this.fullname || (this.user && (this.user.fullname || this.user.userfullname)); @@ -117,4 +126,11 @@ export class CoreUserAvatarComponent implements OnInit, OnChanges { this.navCtrl.push('CoreUserProfilePage', { userId: this.userId, courseId: this.courseId }); } } + + /** + * Component destroyed. + */ + ngOnDestroy(): void { + this.pictureObs && this.pictureObs.off(); + } } diff --git a/src/core/user/pages/profile/profile.ts b/src/core/user/pages/profile/profile.ts index 2f9952852..a6b506f63 100644 --- a/src/core/user/pages/profile/profile.ts +++ b/src/core/user/pages/profile/profile.ts @@ -148,7 +148,7 @@ export class CoreUserProfilePage { this.eventsProvider.trigger(CoreUserProvider.PROFILE_PICTURE_UPDATED, { userId: this.userId, picture: profileImageURL - }); + }, this.site.getId()); this.sitesProvider.updateSiteInfo(this.site.getId()); this.refreshUser(); }).finally(() => { From 88ed260ed6cd91559be7baf148b16f8eff4d0d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 4 Jan 2019 11:55:57 +0100 Subject: [PATCH 2/9] MOBILE-2795 messages: Avoid flick on header avatar --- src/addon/messages/pages/discussion/discussion.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/addon/messages/pages/discussion/discussion.html b/src/addon/messages/pages/discussion/discussion.html index 8eacd2b4c..7fb8da636 100644 --- a/src/addon/messages/pages/discussion/discussion.html +++ b/src/addon/messages/pages/discussion/discussion.html @@ -1,8 +1,8 @@ - - + + From 99d97d0e96459f19fa4a6dceb3b873caa71970e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 4 Jan 2019 11:56:18 +0100 Subject: [PATCH 3/9] MOBILE-2795 app: Avoid warning when not adding platform class --- src/app/app.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 779e8e3c6..f368628ec 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -55,7 +55,7 @@ export class MoodleMobileApp implements OnInit { desktopClass += this.appProvider.isMac() ? ' platform-mac' : ''; desktopClass += this.appProvider.isLinux() ? ' platform-linux' : ''; desktopClass += this.appProvider.isWindows() ? ' platform-windows' : ''; - app.setElementClass(desktopClass, true); + desktopClass != '' ? app.setElementClass(desktopClass, true) : false; }); } From ba4a628d34c3a04ef67e63e60eb8a5344940db20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 4 Jan 2019 12:30:34 +0100 Subject: [PATCH 4/9] MOBILE-2795 feedback: Don\t show answer questions when closed --- .../mod/feedback/components/index/addon-mod-feedback-index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addon/mod/feedback/components/index/addon-mod-feedback-index.html b/src/addon/mod/feedback/components/index/addon-mod-feedback-index.html index ac5eacd51..10df6623c 100644 --- a/src/addon/mod/feedback/components/index/addon-mod-feedback-index.html +++ b/src/addon/mod/feedback/components/index/addon-mod-feedback-index.html @@ -113,7 +113,7 @@ {{ 'addon.mod_feedback.preview' | translate }} - + From 1bb6a35d8c19948308467eb1c7aceafaf634fb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 4 Jan 2019 14:23:02 +0100 Subject: [PATCH 9/9] MOBILE-2795 comments: Fix uncaught exception --- src/core/comments/pages/viewer/viewer.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/core/comments/pages/viewer/viewer.ts b/src/core/comments/pages/viewer/viewer.ts index 1ce7872a1..6652b879b 100644 --- a/src/core/comments/pages/viewer/viewer.ts +++ b/src/core/comments/pages/viewer/viewer.ts @@ -78,20 +78,16 @@ export class CoreCommentsViewerPage { // Get the user profile image. this.userProvider.getProfile(comment.userid, undefined, true).then((user) => { comment.profileimageurl = user.profileimageurl; + }).catch(() => { + // Ignore errors. }); }); }).catch((error) => { - if (error) { - if (this.component == 'assignsubmission_comments') { - this.domUtils.showAlertTranslated('core.notice', 'core.commentsnotworking'); - } else { - this.domUtils.showErrorModal(error); - } + if (error && this.component == 'assignsubmission_comments') { + this.domUtils.showAlertTranslated('core.notice', 'core.commentsnotworking'); } else { - this.domUtils.showErrorModal(this.translate.instant('core.error') + ': get_comments'); + this.domUtils.showErrorModalDefault(error, this.translate.instant('core.error') + ': get_comments'); } - - return Promise.reject(null); }); }