diff --git a/src/lib/types/user.ts b/src/lib/types/user.ts index 8e1509b14c..290eb31db0 100644 --- a/src/lib/types/user.ts +++ b/src/lib/types/user.ts @@ -1,5 +1,5 @@ -import gravatarUrl from 'gravatar-url'; import Joi from 'joi'; +import { generateImageUrl } from '../util/generateImageUrl'; export interface UserData { id: number; @@ -79,10 +79,7 @@ export default class User implements IUser { } generateImageUrl(): string { - return gravatarUrl(this.email || this.username || '' + this.id, { - size: 42, - default: 'retro', - }); + return generateImageUrl(this); } } diff --git a/src/lib/util/generateImageUrl.ts b/src/lib/util/generateImageUrl.ts new file mode 100644 index 0000000000..77110194a2 --- /dev/null +++ b/src/lib/util/generateImageUrl.ts @@ -0,0 +1,11 @@ +import gravatarUrl from 'gravatar-url'; + +export const generateImageUrl = (user: { + email: string; + username: string; + id: number; +}): string => + gravatarUrl(user.email || user.username || String(user.id), { + size: 42, + default: 'retro', + });