Skip to content

Commit

Permalink
reset avatar when deleteFarcasterChannelTag is called
Browse files Browse the repository at this point in the history
Summary:
if a tagged community has a farcaster avatar, we should reset it to NULL when the tag is removed

Depends on D13778

Test Plan:
Tested in conjunction with previous diff

| id    | name | avatar | description |

Created community

| 84426 | Oct23 | NULL  | NULL |

Tagged community with spam channel. NULL description was replaced with description from neynar. (also confirmed that avatar and description were updated on client)

| 84426 | Oct23 | {"type":"farcaster"} | Dedicated channel for everything $SPAM |

Removed tag. avatar was reset to NULL. description remained

| 84426 | Oct23 | NULL | Dedicated channel for everything $SPAM |

Removed description from native app. It was set to an empty string

| 84426 | Oct23 | NULL |         |

Added a new description from app.

| 84426 | Oct23 | NULL | Asdf |

Tagged community with a different channel. Avatar changed but description remained the same.

| 84426 | Oct23 | {"type":"farcaster"} | Asdf |

Removed tag

| 84426 | Oct23 | NULL | Asdf |

Removed description

| 84426 | Oct23 | NULL |         |

Tagged community with a different channel. empty string description was replaced with description from neynar

| 84426 | Oct23 | {"type":"farcaster"} | your musings, thoughts & dreams; welcome here |

Removed tag and set a custom emoji avatar

| 84426 | Oct23 | {"type":"emoji","emoji":"?","color":"57697f"} | your musings, thoughts & dreams; welcome here |

Added and removed a new tag, avatar was not overwritten

| 84426 | Oct23 | {"type":"emoji","emoji":"?","color":"57697f"} | your musings, thoughts & dreams; welcome here |

Reviewers: ashoat

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D13779
  • Loading branch information
vdhanan committed Oct 25, 2024
1 parent e97081b commit 5ca379f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 13 deletions.
43 changes: 40 additions & 3 deletions keyserver/src/deleters/farcaster-channel-tag-deleters.js
Original file line number Diff line number Diff line change
@@ -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<void> {
): Promise<?DeleteFarcasterChannelTagResponse> {
const hasPermission = await checkThreadPermission(
viewer,
request.commCommunityID,
Expand All @@ -39,7 +48,7 @@ async function deleteFarcasterChannelTag(
blob_holder = NULL
WHERE id = ${request.commCommunityID}
AND farcaster_channel_id = ${request.farcasterChannelID};
COMMIT;
SELECT @currentBlobHolder AS blobHolder;
Expand All @@ -61,6 +70,34 @@ async function deleteFarcasterChannelTag(
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 };
11 changes: 6 additions & 5 deletions keyserver/src/responders/farcaster-channel-tag-responders.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
CreateOrUpdateFarcasterChannelTagRequest,
CreateOrUpdateFarcasterChannelTagResponse,
DeleteFarcasterChannelTagRequest,
DeleteFarcasterChannelTagResponse,
} from 'lib/types/community-types';
import { tShape, tID } from 'lib/utils/validation-utils.js';

Expand All @@ -19,11 +20,11 @@ const createOrUpdateFarcasterChannelTagInputValidator: TInterface<CreateOrUpdate
farcasterChannelID: t.String,
});

async function createOrUpdateFarcasterChannelTagResponder(
function createOrUpdateFarcasterChannelTagResponder(
viewer: Viewer,
request: CreateOrUpdateFarcasterChannelTagRequest,
): Promise<CreateOrUpdateFarcasterChannelTagResponse> {
return await createOrUpdateFarcasterChannelTag(viewer, request);
return createOrUpdateFarcasterChannelTag(viewer, request);
}

const deleteFarcasterChannelTagInputValidator: TInterface<DeleteFarcasterChannelTagRequest> =
Expand All @@ -32,11 +33,11 @@ const deleteFarcasterChannelTagInputValidator: TInterface<DeleteFarcasterChannel
farcasterChannelID: t.String,
});

async function deleteFarcasterChannelTagResponder(
function deleteFarcasterChannelTagResponder(
viewer: Viewer,
request: DeleteFarcasterChannelTagRequest,
): Promise<void> {
await deleteFarcasterChannelTag(viewer, request);
): Promise<?DeleteFarcasterChannelTagResponse> {
return deleteFarcasterChannelTag(viewer, request);
}

export {
Expand Down
8 changes: 7 additions & 1 deletion lib/actions/community-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,16 @@ const deleteFarcasterChannelTag =
},
};

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,
};
};

Expand Down
7 changes: 7 additions & 0 deletions lib/types/community-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -71,8 +72,14 @@ export type DeleteFarcasterChannelTagRequest = {
+farcasterChannelID: string,
};

export type DeleteFarcasterChannelTagResponse = ChangeThreadSettingsResult;

export type DeleteFarcasterChannelTagPayload = {
+commCommunityID: string,
+updatesResult?: ?{
+newUpdates: $ReadOnlyArray<ServerUpdateInfo>,
},
+newMessageInfos?: ?$ReadOnlyArray<RawMessageInfo>,
};

export type OngoingJoinCommunityData = {
Expand Down
9 changes: 7 additions & 2 deletions lib/types/validators/endpoint-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
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,
Expand Down Expand Up @@ -184,7 +187,9 @@ const httpPreferredEndpoints = Object.freeze({
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({
Expand Down
11 changes: 9 additions & 2 deletions lib/types/validators/farcaster-channel-tag-validators.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,3 +29,6 @@ export const createOrUpdateFarcasterChannelTagResponseValidator: TInterface<Crea
newMessageInfos: t.maybe(t.list(rawMessageInfoValidator)),
updatesResult: t.maybe(updatesResultValidator),
});

export const deleteFarcasterChannelTagResponseValidator: TMaybe<void | DeleteFarcasterChannelTagResponse> =
t.maybe(changeThreadSettingsResultValidator);

0 comments on commit 5ca379f

Please sign in to comment.