diff --git a/keyserver/src/deleters/farcaster-channel-tag-deleters.js b/keyserver/src/deleters/farcaster-channel-tag-deleters.js --- a/keyserver/src/deleters/farcaster-channel-tag-deleters.js +++ b/keyserver/src/deleters/farcaster-channel-tag-deleters.js @@ -1,19 +1,28 @@ // @flow import { farcasterChannelTagBlobHash } from 'lib/shared/community-utils.js'; -import type { DeleteFarcasterChannelTagRequest } from 'lib/types/community-types.js'; +import { + NEXT_CODE_VERSION, + hasMinCodeVersion, +} from 'lib/shared/version-utils.js'; +import type { + DeleteFarcasterChannelTagRequest, + DeleteFarcasterChannelTagResponse, +} from 'lib/types/community-types.js'; import { threadPermissions } from 'lib/types/thread-permission-types.js'; import { ServerError } from 'lib/utils/errors.js'; import { dbQuery, SQL } from '../database/database.js'; +import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js'; import { checkThreadPermission } from '../fetchers/thread-permission-fetchers.js'; import { deleteBlob } from '../services/blob.js'; import type { Viewer } from '../session/viewer'; +import { updateThread } from '../updaters/thread-updaters.js'; async function deleteFarcasterChannelTag( viewer: Viewer, request: DeleteFarcasterChannelTagRequest, -): Promise { +): Promise { const hasPermission = await checkThreadPermission( viewer, request.commCommunityID, @@ -39,7 +48,7 @@ blob_holder = NULL WHERE id = ${request.commCommunityID} AND farcaster_channel_id = ${request.farcasterChannelID}; - + COMMIT; SELECT @currentBlobHolder AS blobHolder; @@ -61,6 +70,34 @@ true, ); } + + const serverThreadInfos = await fetchServerThreadInfos({ + threadID: request.commCommunityID, + }); + const threadInfo = serverThreadInfos.threadInfos[request.commCommunityID]; + if (!threadInfo) { + return null; + } + const { avatar } = threadInfo; + if (avatar?.type !== 'farcaster') { + return null; + } + + const changeThreadSettingsResult = await updateThread(viewer, { + threadID: request.commCommunityID, + changes: { avatar: { type: 'remove' } }, + }); + + if ( + !hasMinCodeVersion(viewer.platformDetails, { + native: NEXT_CODE_VERSION, + web: NEXT_CODE_VERSION, + }) + ) { + return null; + } + + return changeThreadSettingsResult; } export { deleteFarcasterChannelTag }; diff --git a/keyserver/src/responders/farcaster-channel-tag-responders.js b/keyserver/src/responders/farcaster-channel-tag-responders.js --- a/keyserver/src/responders/farcaster-channel-tag-responders.js +++ b/keyserver/src/responders/farcaster-channel-tag-responders.js @@ -6,6 +6,7 @@ CreateOrUpdateFarcasterChannelTagRequest, CreateOrUpdateFarcasterChannelTagResponse, DeleteFarcasterChannelTagRequest, + DeleteFarcasterChannelTagResponse, } from 'lib/types/community-types'; import { tShape, tID } from 'lib/utils/validation-utils.js'; @@ -19,11 +20,11 @@ farcasterChannelID: t.String, }); -async function createOrUpdateFarcasterChannelTagResponder( +function createOrUpdateFarcasterChannelTagResponder( viewer: Viewer, request: CreateOrUpdateFarcasterChannelTagRequest, ): Promise { - return await createOrUpdateFarcasterChannelTag(viewer, request); + return createOrUpdateFarcasterChannelTag(viewer, request); } const deleteFarcasterChannelTagInputValidator: TInterface = @@ -32,11 +33,11 @@ farcasterChannelID: t.String, }); -async function deleteFarcasterChannelTagResponder( +function deleteFarcasterChannelTagResponder( viewer: Viewer, request: DeleteFarcasterChannelTagRequest, -): Promise { - await deleteFarcasterChannelTag(viewer, request); +): Promise { + return deleteFarcasterChannelTag(viewer, request); } export { diff --git a/lib/actions/community-actions.js b/lib/actions/community-actions.js --- a/lib/actions/community-actions.js +++ b/lib/actions/community-actions.js @@ -130,10 +130,16 @@ }, }; - await callKeyserverEndpoint('delete_farcaster_channel_tag', requests); + const responses = await callKeyserverEndpoint( + 'delete_farcaster_channel_tag', + requests, + ); + + const response = responses[keyserverID]; return { commCommunityID: input.commCommunityID, + ...response, }; }; diff --git a/lib/types/community-types.js b/lib/types/community-types.js --- a/lib/types/community-types.js +++ b/lib/types/community-types.js @@ -3,6 +3,7 @@ import t, { type TInterface } from 'tcomb'; import type { RawMessageInfo } from './message-types.js'; +import type { ChangeThreadSettingsResult } from './thread-types.js'; import type { ServerUpdateInfo } from './update-types.js'; import { tID, tShape } from '../utils/validation-utils.js'; @@ -71,8 +72,14 @@ +farcasterChannelID: string, }; +export type DeleteFarcasterChannelTagResponse = ChangeThreadSettingsResult; + export type DeleteFarcasterChannelTagPayload = { +commCommunityID: string, + +updatesResult?: ?{ + +newUpdates: $ReadOnlyArray, + }, + +newMessageInfos?: ?$ReadOnlyArray, }; export type OngoingJoinCommunityData = { diff --git a/lib/types/validators/endpoint-validators.js b/lib/types/validators/endpoint-validators.js --- a/lib/types/validators/endpoint-validators.js +++ b/lib/types/validators/endpoint-validators.js @@ -14,7 +14,10 @@ deleteEntryResponseValidator, restoreEntryResponseValidator, } from './entry-validators.js'; -import { createOrUpdateFarcasterChannelTagResponseValidator } from './farcaster-channel-tag-validators.js'; +import { + createOrUpdateFarcasterChannelTagResponseValidator, + deleteFarcasterChannelTagResponseValidator, +} from './farcaster-channel-tag-validators.js'; import { fetchInviteLinksResponseValidator, inviteLinkVerificationResponseValidator, @@ -184,7 +187,9 @@ create_or_update_farcaster_channel_tag: { validator: createOrUpdateFarcasterChannelTagResponseValidator, }, - delete_farcaster_channel_tag: { validator: t.Nil }, + delete_farcaster_channel_tag: { + validator: deleteFarcasterChannelTagResponseValidator, + }, }); export const endpointValidators = Object.freeze({ diff --git a/lib/types/validators/farcaster-channel-tag-validators.js b/lib/types/validators/farcaster-channel-tag-validators.js --- a/lib/types/validators/farcaster-channel-tag-validators.js +++ b/lib/types/validators/farcaster-channel-tag-validators.js @@ -1,9 +1,13 @@ // @flow -import t, { type TInterface } from 'tcomb'; +import t, { type TInterface, type TMaybe } from 'tcomb'; +import { changeThreadSettingsResultValidator } from './thread-validators.js'; import { tShape, tID } from '../../utils/validation-utils.js'; -import type { CreateOrUpdateFarcasterChannelTagResponse } from '../community-types'; +import type { + CreateOrUpdateFarcasterChannelTagResponse, + DeleteFarcasterChannelTagResponse, +} from '../community-types'; import { rawMessageInfoValidator } from '../message-types.js'; import { serverUpdateInfoValidator, @@ -25,3 +29,6 @@ newMessageInfos: t.maybe(t.list(rawMessageInfoValidator)), updatesResult: t.maybe(updatesResultValidator), }); + +export const deleteFarcasterChannelTagResponseValidator: TMaybe = + t.maybe(changeThreadSettingsResultValidator);