diff --git a/app/definitions/rest/v1/users.ts b/app/definitions/rest/v1/users.ts index fa624a5dea..751cfbf83f 100644 --- a/app/definitions/rest/v1/users.ts +++ b/app/definitions/rest/v1/users.ts @@ -1,4 +1,4 @@ -import { type IProfileParams } from '../../IProfile'; +import { type IAvatarSuggestion, type IProfileParams } from '../../IProfile'; import type { ITeam } from '../../ITeam'; import type { IUser, INotificationPreferences, IUserPreferences, IUserRegistered } from '../../IUser'; @@ -48,6 +48,12 @@ export type UsersEndpoints = { 'users.getUsernameSuggestion': { GET: () => { result: string }; }; + 'users.getAvatarSuggestion': { + GET: () => { + suggestions: { [service: string]: IAvatarSuggestion }; + success: boolean; + }; + }; 'users.resetAvatar': { POST: (params: { userId: string }) => {}; }; diff --git a/app/lib/services/restApi.ts b/app/lib/services/restApi.ts index 95ad3f86c7..fae5344771 100644 --- a/app/lib/services/restApi.ts +++ b/app/lib/services/restApi.ts @@ -677,9 +677,21 @@ export const getRoomRoles = ( // RC 0.65.0 sdk.get(`${roomTypeToApiType(type)}.roles`, { roomId }); -export const getAvatarSuggestion = (): Promise<{ [service: string]: IAvatarSuggestion }> => +export const getAvatarSuggestion = async (): Promise<{ [service: string]: IAvatarSuggestion }> => { + const serverVersion = reduxStore.getState().server.version; + + if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '5.4.0')) { + // RC 5.4.0 + const result = await sdk.get('users.getAvatarSuggestion'); + if (result.success && 'suggestions' in result) { + return result.suggestions; + } + return {}; + } + // RC 0.51.0 - sdk.methodCallWrapper('getAvatarSuggestion'); + return sdk.methodCallWrapper('getAvatarSuggestion'); +}; export const resetAvatar = (userId: string) => // RC 0.55.0