MOBILE-3868 user: Fix problems when using site home ID in profile

main
Dani Palou 2021-09-30 12:39:36 +02:00
parent 4bb336b049
commit 59d3a761a4
3 changed files with 31406 additions and 78 deletions

31435
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -39,9 +39,14 @@ export class AddonBadgesUserBadgesPage implements AfterViewInit, OnDestroy {
@ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent; @ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent;
constructor() { constructor() {
const courseId = CoreNavigator.getRouteNumberParam('courseId') ?? 0; // Use 0 for site badges. let courseId = CoreNavigator.getRouteNumberParam('courseId') ?? 0; // Use 0 for site badges.
const userId = CoreNavigator.getRouteNumberParam('userId') ?? CoreSites.getCurrentSiteUserId(); const userId = CoreNavigator.getRouteNumberParam('userId') ?? CoreSites.getCurrentSiteUserId();
if (courseId === CoreSites.getCurrentSiteHomeId()) {
// Use courseId 0 for site home, otherwise the site doesn't return site badges.
courseId = 0;
}
this.badges = new AddonBadgesUserBadgesManager(AddonBadgesUserBadgesPage, courseId, userId); this.badges = new AddonBadgesUserBadgesManager(AddonBadgesUserBadgesPage, courseId, userId);
} }

View File

@ -44,7 +44,7 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
protected courseId?: number; protected courseId?: number;
protected userId!: number; protected userId!: number;
protected site?: CoreSite; protected site!: CoreSite;
protected obsProfileRefreshed: CoreEventObserver; protected obsProfileRefreshed: CoreEventObserver;
protected subscription?: Subscription; protected subscription?: Subscription;
@ -75,25 +75,25 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
* On init. * On init.
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.site = CoreSites.getCurrentSite(); try {
this.courseId = CoreNavigator.getRouteNumberParam('courseId'); this.site = CoreSites.getRequiredCurrentSite();
const userId = CoreNavigator.getRouteNumberParam('userId'); this.courseId = CoreNavigator.getRouteNumberParam('courseId');
this.userId = CoreNavigator.getRequiredRouteNumberParam('userId');
if (!this.site) { } catch (error) {
return; CoreDomUtils.showErrorModal(error);
}
if (userId === undefined) {
CoreDomUtils.showErrorModal('User ID not supplied');
CoreNavigator.back(); CoreNavigator.back();
return; return;
} }
this.userId = userId; if (this.courseId === this.site.getSiteHomeId()) {
// Get site profile.
this.courseId = undefined;
}
// Allow to change the profile image only in the app profile page. // Allow to change the profile image only in the app profile page.
this.canChangeProfilePicture = this.canChangeProfilePicture =
(!this.courseId || this.courseId == this.site.getSiteHomeId()) && !this.courseId &&
this.userId == this.site.getUserId() && this.userId == this.site.getUserId() &&
this.site.canUploadFiles() && this.site.canUploadFiles() &&
!CoreUser.isUpdatePictureDisabledInSite(this.site); !CoreUser.isUpdatePictureDisabledInSite(this.site);
@ -101,8 +101,12 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
try { try {
await this.fetchUser(); await this.fetchUser();
if (!this.user) {
return;
}
try { try {
await CoreUser.logView(this.userId, this.courseId, this.user!.fullname); await CoreUser.logView(this.userId, this.courseId, this.user.fullname);
} catch (error) { } catch (error) {
this.isDeleted = error?.errorcode === 'userdeleted'; this.isDeleted = error?.errorcode === 'userdeleted';
this.isEnrolled = error?.errorcode !== 'notenrolledprofile'; this.isEnrolled = error?.errorcode !== 'notenrolledprofile';
@ -211,14 +215,14 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
modal = await CoreDomUtils.showModalLoading('core.sending', true); modal = await CoreDomUtils.showModalLoading('core.sending', true);
const profileImageURL = await CoreUser.changeProfilePicture(result.itemid, this.userId, this.site!.getId()); const profileImageURL = await CoreUser.changeProfilePicture(result.itemid, this.userId, this.site.getId());
CoreEvents.trigger(CoreUserProvider.PROFILE_PICTURE_UPDATED, { CoreEvents.trigger(CoreUserProvider.PROFILE_PICTURE_UPDATED, {
userId: this.userId, userId: this.userId,
picture: profileImageURL, picture: profileImageURL,
}, this.site!.getId()); }, this.site.getId());
CoreSites.updateSiteInfo(this.site!.getId()); CoreSites.updateSiteInfo(this.site.getId());
this.refreshUser(); this.refreshUser();
} catch (error) { } catch (error) {
@ -273,7 +277,11 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
* @param handler Handler that was clicked. * @param handler Handler that was clicked.
*/ */
handlerClicked(event: Event, handler: CoreUserProfileHandlerData): void { handlerClicked(event: Event, handler: CoreUserProfileHandlerData): void {
handler.action(event, this.user!, this.courseId); if (!this.user) {
return;
}
handler.action(event, this.user, this.courseId);
} }
/** /**