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 @@ -7,6 +7,7 @@ import type { DeleteFarcasterChannelTagRequest } from 'lib/types/community-types'; import { ServerError } from 'lib/utils/errors.js'; +import { dbQuery, SQL } from '../database/database.js'; import { deleteBlob } from '../services/blob.js'; import type { Viewer } from '../session/viewer'; @@ -14,19 +15,47 @@ viewer: Viewer, request: DeleteFarcasterChannelTagRequest, ): Promise { - const { farcasterChannelID, blobHolder } = request; - if (DISABLE_TAGGING_FARCASTER_CHANNEL) { throw new ServerError('internal_error'); } - await deleteBlob( - { - hash: farcasterChannelTagBlobHash(farcasterChannelID), - holder: blobHolder, - }, - true, - ); + const query = SQL` + START TRANSACTION; + + SELECT blob_holder INTO @currentBlobHolder + FROM communities + WHERE id = ${request.commCommunityID} + AND farcaster_channel_id = ${request.farcasterChannelID} + FOR UPDATE; + + UPDATE communities + SET + farcaster_channel_id = NULL, + blob_holder = NULL + WHERE id = ${request.commCommunityID} + AND farcaster_channel_id = ${request.farcasterChannelID}; + + COMMIT; + + SELECT @currentBlobHolder AS blobHolder; + `; + + const [transactionResult] = await dbQuery(query, { + multipleStatements: true, + }); + + const selectResult = transactionResult.pop(); + const [row] = selectResult; + + if (row?.blobHolder) { + await deleteBlob( + { + hash: farcasterChannelTagBlobHash(request.farcasterChannelID), + holder: row.blobHolder, + }, + true, + ); + } } 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 @@ -30,7 +30,6 @@ tShape({ commCommunityID: tID, farcasterChannelID: t.String, - blobHolder: t.String, }); async function deleteFarcasterChannelTagResponder( 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 @@ -77,7 +77,6 @@ [keyserverID]: { commCommunityID: input.commCommunityID, farcasterChannelID: input.farcasterChannelID, - blobHolder: input.blobHolder, }, }; 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 @@ -28,7 +28,6 @@ export type DeleteFarcasterChannelTagRequest = { +commCommunityID: string, +farcasterChannelID: string, - +blobHolder: string, }; export type DeleteFarcasterChannelTagPayload = {