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 @@ -44,6 +44,7 @@ SubscriptionUpdateRequest, SubscriptionUpdateResponse, } from 'lib/types/subscription-types.js'; +import type { CreateUpdatesResult } from 'lib/types/update-types.js'; import type { PasswordUpdate } from 'lib/types/user-types.js'; import { updateUserAvatarRequestValidator } from 'lib/utils/avatar-utils.js'; import { @@ -628,10 +629,13 @@ await viewerAcknowledgmentUpdater(viewer, request.policy); } +export type UpdateUserAvatarResponse = { + +updates: CreateUpdatesResult, +}; async function updateUserAvatarResponder( viewer: Viewer, input: any, -): Promise { +): Promise { const request: UpdateUserAvatarRequest = input; await validateInput(viewer, updateUserAvatarRequestValidator, request); return await updateUserAvatar(viewer, request); diff --git a/keyserver/src/updaters/account-updaters.js b/keyserver/src/updaters/account-updaters.js --- a/keyserver/src/updaters/account-updaters.js +++ b/keyserver/src/updaters/account-updaters.js @@ -3,6 +3,7 @@ import invariant from 'invariant'; import bcrypt from 'twin-bcrypt'; +import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; import type { ResetPasswordRequest, UpdatePasswordRequest, @@ -14,7 +15,10 @@ UpdateUserAvatarRequest, } from 'lib/types/avatar-types.js'; import { updateTypes } from 'lib/types/update-types.js'; -import type { UpdateData } from 'lib/types/update-types.js'; +import type { + CreateUpdatesResult, + UpdateData, +} from 'lib/types/update-types.js'; import type { PasswordUpdate, UserInfo, @@ -27,7 +31,7 @@ import { dbQuery, SQL } from '../database/database.js'; import { getUploadURL } from '../fetchers/upload-fetchers.js'; import { fetchKnownUserInfos } from '../fetchers/user-fetchers.js'; -import { handleAsyncPromise } from '../responders/handlers.js'; +import type { UpdateUserAvatarResponse } from '../responders/user-responders.js'; import type { Viewer } from '../session/viewer.js'; async function accountUpdater( @@ -119,7 +123,7 @@ async function updateUserAvatar( viewer: Viewer, request: UpdateUserAvatarRequest, -): Promise { +): Promise { if (!viewer.loggedIn) { throw new ServerError('not_logged_in'); } @@ -183,8 +187,17 @@ const selectResult = resultSet.pop(); const knownUserInfos: UserInfos = await fetchKnownUserInfos(viewer); - const userUpdatesPromise = createUserAvatarUpdates(viewer, knownUserInfos); - handleAsyncPromise(userUpdatesPromise); + const updates: CreateUpdatesResult = await createUserAvatarUpdates( + viewer, + knownUserInfos, + ); + + if (hasMinCodeVersion(viewer.platformDetails, 215)) { + const updateUserAvatarResponse: UpdateUserAvatarResponse = { + updates, + }; + return updateUserAvatarResponse; + } if (request.type === 'remove') { return null; @@ -208,7 +221,7 @@ async function createUserAvatarUpdates( viewer: Viewer, knownUserInfos: UserInfos, -): Promise { +): Promise { const time = Date.now(); const userUpdates: $ReadOnlyArray = values(knownUserInfos).map( (user: UserInfo): UpdateData => ({ @@ -225,7 +238,7 @@ time, }; - await createUpdates([...userUpdates, currentUserUpdate], { + return await createUpdates([...userUpdates, currentUserUpdate], { viewer, updatesForCurrentSession: 'return', });