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'; @@ -256,7 +254,9 @@ const updateUserAvatar = ( callServerEndpoint: CallServerEndpoint, - ): ((avatarDBContent: UpdateUserAvatarRequest) => Promise) => + ): (( + avatarDBContent: UpdateUserAvatarRequest, + ) => Promise) => async avatarDBContent => { return await callServerEndpoint('update_user_avatar', avatarDBContent); }; 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; + 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'; @@ -87,7 +87,10 @@ ThreadJoinPayload, ToggleMessagePinResult, } from './thread-types.js'; -import type { ClientUpdatesResultWithUserInfos } from './update-types.js'; +import type { + ClientUpdatesResultWithUserInfos, + CreateUpdatesResult, +} from './update-types.js'; import type { CurrentUserInfo, UserStore } from './user-types.js'; import type { Shape } from '../types/core.js'; import type { NotifPermissionAlertInfo } from '../utils/push-alerts.js'; @@ -933,7 +936,7 @@ } | { +type: 'UPDATE_USER_AVATAR_SUCCESS', - +payload: ?ClientAvatar, + +payload: CreateUpdatesResult, +loadingInfo: LoadingInfo, } | {