Skip to content

Commit 79300ba

Browse files
committed
MOBILE-4362 url: Use isThemeImageUrl function when needed
1 parent bfaadfb commit 79300ba

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

src/core/components/user-avatar/user-avatar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events';
2020
import { USER_PROFILE_PICTURE_UPDATED, CoreUserBasicData } from '@features/user/services/user';
2121
import { CoreNavigator } from '@services/navigator';
2222
import { CoreNetwork } from '@services/network';
23-
import { CoreUrl } from '@singletons/url';
2423
import { CoreUserHelper } from '@features/user/services/user-helper';
24+
import { CoreUrlUtils } from '@services/utils/url';
2525

2626
/**
2727
* Component to display a "user avatar".
@@ -111,7 +111,7 @@ export class CoreUserAvatarComponent implements OnInit, OnChanges, OnDestroy {
111111
this.initials = CoreUserHelper.getUserInitials(this.user);
112112
}
113113

114-
if (this.initials && this.avatarUrl && CoreUrl.parse(this.avatarUrl)?.path?.startsWith('/theme/image.php')) {
114+
if (this.initials && this.avatarUrl && CoreUrlUtils.isThemeImageUrl(this.avatarUrl)) {
115115
this.avatarUrl = undefined;
116116
}
117117

src/core/features/question/services/question-helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { makeSingleton, Translate } from '@singletons';
2727
import { CoreQuestion, CoreQuestionProvider, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from './question';
2828
import { CoreQuestionDelegate } from './question-delegate';
2929
import { CoreIcons } from '@singletons/icons';
30+
import { CoreUrlUtils } from '@services/utils/url';
3031

3132
/**
3233
* Service with some common functions to handle questions.
@@ -678,7 +679,7 @@ export class CoreQuestionHelperProvider {
678679
return;
679680
}
680681

681-
if (fileUrl.indexOf('theme/image.php') > -1 && fileUrl.indexOf('flagged') > -1) {
682+
if (CoreUrlUtils.isThemeImageUrl(fileUrl) && fileUrl.indexOf('flagged') > -1) {
682683
// Ignore flag images.
683684
return;
684685
}

src/core/features/user/pages/about/about.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { CoreSite } from '@classes/site';
3333
import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper';
3434
import { CoreMimetypeUtils } from '@services/utils/mimetype';
3535
import { Translate } from '@singletons';
36+
import { CoreUrlUtils } from '@services/utils/url';
3637

3738
/**
3839
* Page that displays info about a user.
@@ -247,7 +248,7 @@ export class CoreUserAboutPage implements OnInit, OnDestroy {
247248
return 'undefined';
248249
}
249250

250-
if (avatarUrl.startsWith(`${this.site?.siteUrl}/theme/image.php`)) {
251+
if (CoreUrlUtils.isThemeImageUrl(avatarUrl, this.site?.siteUrl)) {
251252
return 'default';
252253
}
253254

src/core/features/user/services/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@servic
2727
import { CoreError } from '@classes/errors/error';
2828
import { USERS_TABLE_NAME, CoreUserDBRecord } from './database/user';
2929
import { CoreUserHelper } from './user-helper';
30-
import { CoreUrl } from '@singletons/url';
30+
import { CoreUrlUtils } from '@services/utils/url';
3131

3232
const ROOT_CACHE_KEY = 'mmUser:';
3333

@@ -671,7 +671,7 @@ export class CoreUserProvider {
671671
// Do not prefetch when initials are set and image is default.
672672
if ('firstname' in entry || 'lastname' in entry) {
673673
const initials = CoreUserHelper.getUserInitials(entry);
674-
if (initials && imageUrl && CoreUrl.parse(imageUrl)?.path === '/theme/image.php') {
674+
if (initials && imageUrl && CoreUrlUtils.isThemeImageUrl(imageUrl)) {
675675
return;
676676
}
677677
}

src/core/services/utils/url.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,16 @@ export class CoreUrlUtilsProvider {
493493
/**
494494
* Returns if a URL is a theme image URL.
495495
*
496-
* @param url The URL to test.
496+
* @param imageUrl The URL to test.
497+
* @param siteUrl The Site Url.
497498
* @returns Whether the URL is a theme image URL.
498499
*/
499-
isThemeImageUrl(url: string): boolean {
500-
return url?.indexOf('/theme/image.php') !== -1;
500+
isThemeImageUrl(imageUrl: string, siteUrl?: string): boolean {
501+
if (siteUrl) {
502+
return imageUrl.startsWith(`${siteUrl}/theme/image.php`);
503+
}
504+
505+
return imageUrl?.indexOf('/theme/image.php') !== -1;
501506
}
502507

503508
/**

0 commit comments

Comments
 (0)