Page MenuHomePhabricator

D7152.diff
No OneTemporary

D7152.diff

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
@@ -26,7 +26,10 @@
notificationTypeValues,
logInActionSources,
} from 'lib/types/account-types.js';
-import type { UpdateUserAvatarRequest } from 'lib/types/avatar-types.js';
+import type {
+ ClientAvatar,
+ UpdateUserAvatarRequest,
+} from 'lib/types/avatar-types.js';
import type {
IdentityKeysBlob,
SignedIdentityKeysBlob,
@@ -102,6 +105,7 @@
checkAndSendPasswordResetEmail,
updatePassword,
updateUserSettings,
+ updateUserAvatar,
} from '../updaters/account-updaters.js';
import { userSubscriptionUpdater } from '../updaters/user-subscription-updaters.js';
import { viewerAcknowledgmentUpdater } from '../updaters/viewer-acknowledgment-updater.js';
@@ -675,9 +679,10 @@
async function updateUserAvatarResponder(
viewer: Viewer,
input: any,
-): Promise<void> {
+): Promise<?ClientAvatar> {
const request: UpdateUserAvatarRequest = input;
await validateInput(viewer, updateUserAvatarRequestValidator, request);
+ return await updateUserAvatar(viewer, request);
}
export {
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
@@ -9,6 +9,10 @@
UpdateUserSettingsRequest,
LogInResponse,
} from 'lib/types/account-types.js';
+import type {
+ ClientAvatar,
+ UpdateUserAvatarRequest,
+} from 'lib/types/avatar-types.js';
import { updateTypes } from 'lib/types/update-types.js';
import type { PasswordUpdate } from 'lib/types/user-types.js';
import { ServerError } from 'lib/utils/errors.js';
@@ -110,10 +114,36 @@
await dbQuery(createOrUpdateSettingsQuery);
}
+async function updateUserAvatar(
+ viewer: Viewer,
+ request: UpdateUserAvatarRequest,
+): Promise<?ClientAvatar> {
+ if (!viewer.loggedIn) {
+ throw new ServerError('not_logged_in');
+ }
+
+ const newAvatarValue =
+ request.type === 'remove' ? null : JSON.stringify(request);
+
+ const query = SQL`
+ UPDATE users
+ SET avatar = ${newAvatarValue}
+ WHERE id = ${viewer.userID}
+ `;
+ await dbQuery(query);
+
+ if (request.type === 'remove' || request.type === 'image') {
+ // TODO: Handle construction of `ClientImageAvatar` when `type === 'image'`
+ return null;
+ }
+ return request;
+}
+
export {
accountUpdater,
checkAndSendVerificationEmail,
checkAndSendPasswordResetEmail,
updateUserSettings,
updatePassword,
+ updateUserAvatar,
};

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 29, 3:46 PM (22 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2597414
Default Alt Text
D7152.diff (2 KB)

Event Timeline