diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js --- a/keyserver/src/responders/user-responders.js +++ b/keyserver/src/responders/user-responders.js @@ -6,6 +6,7 @@ import t from 'tcomb'; import bcrypt from 'twin-bcrypt'; +import type { UpdateUserAvatarResponse } from 'lib/actions/user-actions.js'; import { baseLegalPolicies, policies } from 'lib/facts/policies.js'; import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; import type { diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -10,10 +10,7 @@ UpdateUserSettingsRequest, PolicyAcknowledgmentRequest, } from '../types/account-types.js'; -import type { - ClientAvatar, - UpdateUserAvatarRequest, -} from '../types/avatar-types.js'; +import type { UpdateUserAvatarRequest } from '../types/avatar-types.js'; import type { GetSessionPublicKeysArgs } from '../types/request-types.js'; import type { UserSearchResult } from '../types/search-types.js'; import type { @@ -24,6 +21,7 @@ SubscriptionUpdateRequest, SubscriptionUpdateResult, } from '../types/subscription-types.js'; +import type { CreateUpdatesResult } from '../types/update-types.js'; import type { UserInfo, PasswordUpdate } from '../types/user-types.js'; import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; import { getConfig } from '../utils/config.js'; @@ -253,12 +251,21 @@ success: 'UPDATE_USER_AVATAR_SUCCESS', failed: 'UPDATE_USER_AVATAR_FAILED', }); +export type UpdateUserAvatarResponse = { + +updates: CreateUpdatesResult, +}; const updateUserAvatar = ( callServerEndpoint: CallServerEndpoint, - ): ((avatarDBContent: UpdateUserAvatarRequest) => Promise) => + ): (( + avatarDBContent: UpdateUserAvatarRequest, + ) => Promise) => async avatarDBContent => { - return await callServerEndpoint('update_user_avatar', avatarDBContent); + const { updates }: UpdateUserAvatarResponse = await callServerEndpoint( + 'update_user_avatar', + avatarDBContent, + ); + return { updates }; }; export { diff --git a/lib/reducers/user-reducer.js b/lib/reducers/user-reducer.js --- a/lib/reducers/user-reducer.js +++ b/lib/reducers/user-reducer.js @@ -99,10 +99,19 @@ state && !state.anonymous ) { - return { - ...state, - avatar: action.payload, - }; + const { viewerUpdates } = action.payload.updates; + for (const update of viewerUpdates) { + if ( + update.type === updateTypes.UPDATE_CURRENT_USER && + !_isEqual(update.currentUserInfo.avatar)(state.avatar) + ) { + return { + ...state, + avatar: update.currentUserInfo.avatar, + }; + } + } + return state; } else if (action.type === setUserSettingsActionTypes.success) { if (state?.settings) { return { diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -12,7 +12,7 @@ QueueActivityUpdatesPayload, SetThreadUnreadStatusPayload, } from './activity-types.js'; -import type { ClientAvatar, UpdateUserAvatarRequest } from './avatar-types.js'; +import type { UpdateUserAvatarRequest } from './avatar-types.js'; import type { CryptoStore } from './crypto-types.js'; import type { ClientDBDraftInfo, DraftStore } from './draft-types.js'; import type { EnabledApps, SupportedApps } from './enabled-apps.js'; @@ -89,6 +89,7 @@ } from './thread-types.js'; import type { ClientUpdatesResultWithUserInfos } from './update-types.js'; import type { CurrentUserInfo, UserStore } from './user-types.js'; +import type { UpdateUserAvatarResponse } from '../actions/user-actions.js'; import type { Shape } from '../types/core.js'; import type { NotifPermissionAlertInfo } from '../utils/push-alerts.js'; @@ -933,7 +934,7 @@ } | { +type: 'UPDATE_USER_AVATAR_SUCCESS', - +payload: ?ClientAvatar, + +payload: UpdateUserAvatarResponse, +loadingInfo: LoadingInfo, } | {