MOBILE-3797 user: Fix infinite requests loop
parent
7faf348042
commit
996e4db71b
|
@ -169,7 +169,7 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.userId != this.site.getUserId() || this.user.profileimageurl == this.site.getInfo()!.userpictureurl) {
|
if (this.userId != this.site.getUserId() || !this.isUserAvatarDirty()) {
|
||||||
// Not current user or hasn't changed.
|
// Not current user or hasn't changed.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
|
||||||
}, this.site.getId());
|
}, this.site.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.user.profileimageurl != this.site.getInfo()!.userpictureurl) {
|
if (this.isUserAvatarDirty()) {
|
||||||
// The image is still different, this means that the good one is the one in site info.
|
// The image is still different, this means that the good one is the one in site info.
|
||||||
await this.refreshUser();
|
await this.refreshUser();
|
||||||
} else {
|
} else {
|
||||||
|
@ -285,4 +285,41 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
|
||||||
this.obsProfileRefreshed.off();
|
this.obsProfileRefreshed.off();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the user avatar is not up to date with site info.
|
||||||
|
*
|
||||||
|
* @return Whether the user avatar differs from site info cache.
|
||||||
|
*/
|
||||||
|
private isUserAvatarDirty(): boolean {
|
||||||
|
if (!this.user || !this.site) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const courseAvatarUrl = this.normalizeAvatarUrl(this.user.profileimageurl);
|
||||||
|
const siteAvatarUrl = this.normalizeAvatarUrl(this.site.getInfo()?.userpictureurl);
|
||||||
|
|
||||||
|
return courseAvatarUrl !== siteAvatarUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize an avatar url regardless of theme.
|
||||||
|
*
|
||||||
|
* Given that the default image is the only one that can be changed per theme, any other url will stay the same. Note that
|
||||||
|
* the values returned by this function may not be valid urls, given that they are intended for string comparison.
|
||||||
|
*
|
||||||
|
* @param avatarUrl Avatar url.
|
||||||
|
* @return Normalized avatar string (may not be a valid url).
|
||||||
|
*/
|
||||||
|
private normalizeAvatarUrl(avatarUrl?: string): string {
|
||||||
|
if (!avatarUrl) {
|
||||||
|
return 'undefined';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (avatarUrl.startsWith(`${this.site?.siteUrl}/theme/image.php`)) {
|
||||||
|
return 'default';
|
||||||
|
}
|
||||||
|
|
||||||
|
return avatarUrl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue