diff --git a/keyserver/src/responders/thread-responders.js b/keyserver/src/responders/thread-responders.js --- a/keyserver/src/responders/thread-responders.js +++ b/keyserver/src/responders/thread-responders.js @@ -19,6 +19,7 @@ type ThreadFetchMediaRequest, threadTypes, } from 'lib/types/thread-types.js'; +import { updateUserAvatarRequestValidator } from 'lib/utils/avatar-utils.js'; import { values } from 'lib/utils/objects.js'; import { tShape, @@ -112,6 +113,7 @@ color: t.maybe(tColor), parentThreadID: t.maybe(t.String), newMemberIDs: t.maybe(t.list(t.String)), + avatar: t.maybe(updateUserAvatarRequestValidator), }), accountPassword: t.maybe(tPassword), }); diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js --- a/keyserver/src/updaters/thread-updaters.js +++ b/keyserver/src/updaters/thread-updaters.js @@ -356,6 +356,13 @@ sqlUpdate.parent_thread_id = parentThreadID; } + const { avatar } = request.changes; + if (avatar !== undefined && avatar !== null) { + changedFields.avatar = + avatar.type !== 'remove' ? JSON.stringify(avatar) : ''; + sqlUpdate.avatar = avatar.type !== 'remove' ? JSON.stringify(avatar) : null; + } + const threadType = request.changes.type; if (threadType !== null && threadType !== undefined) { changedFields.type = threadType; @@ -412,6 +419,12 @@ permission: threadPermissions.EDIT_THREAD_COLOR, }); } + if (sqlUpdate.avatar !== undefined) { + checks.push({ + check: 'permission', + permission: threadPermissions.EDIT_THREAD_AVATAR, + }); + } if (parentThreadID !== undefined || sqlUpdate.type !== undefined) { checks.push({ check: 'permission', diff --git a/lib/types/thread-types.js b/lib/types/thread-types.js --- a/lib/types/thread-types.js +++ b/lib/types/thread-types.js @@ -2,7 +2,7 @@ import invariant from 'invariant'; -import type { ClientAvatar } from './avatar-types.js'; +import type { ClientAvatar, UpdateUserAvatarRequest } from './avatar-types.js'; import type { Shape } from './core.js'; import type { CalendarQuery, RawEntryInfo } from './entry-types.js'; import type { Media } from './media-types.js'; @@ -384,6 +384,7 @@ +color: string, +parentThreadID: ?string, +newMemberIDs: $ReadOnlyArray, + +avatar: UpdateUserAvatarRequest, }>; export type UpdateThreadRequest = {