feat(flags): add comment flags (#1140)

* feat(flags): add comment flags

* fix(flags): address review feedback

* fix(flags): clear stale flag publish data
This commit is contained in:
Tommaso Casaburi
2026-05-24 23:14:36 +07:00
committed by GitHub
parent 804c14fc35
commit f74b33f43b
66 changed files with 1293 additions and 74 deletions
@@ -43,6 +43,10 @@ describe('publish stores', () => {
spoiler: true,
communityAddress: 'music-posting.eth',
title: 'Hello',
challengeRequest: {
challengeAnswers: ['bitsocial-flags:5chan:flag:country:auto'],
},
flairs: [{ text: 'flag:country:auto', type: 'country', code: 'auto' }],
};
usePublishPostStore.getState().setPublishPostStore(comment);
@@ -53,6 +57,10 @@ describe('publish stores', () => {
expect(state.publishCommentOptions.author).toEqual({ address: '0x123', role: 'mod', displayName: 'Poster Alias' });
expect(state.publishCommentOptions.communityAddress).toBe('music-posting.eth');
expect(state.publishCommentOptions.title).toBe('Hello');
expect(state.publishCommentOptions.challengeRequest).toEqual({
challengeAnswers: ['bitsocial-flags:5chan:flag:country:auto'],
});
expect(state.publishCommentOptions.flairs).toEqual([{ text: 'flag:country:auto', type: 'country', code: 'auto' }]);
state.publishCommentOptions.onChallengeVerification?.({} as never, comment);
expect(testState.alertChallengeVerificationFailedMock).toHaveBeenCalledWith({}, comment);
@@ -88,6 +96,10 @@ describe('publish stores', () => {
parentCid: 'parent-1',
spoiler: false,
communityAddress: 'music-posting.eth',
challengeRequest: {
challengeAnswers: ['bitsocial-flags:5chan:flag:pol:AC'],
},
flairs: [{ text: 'flag:pol:AC', type: 'pol', code: 'AC' }],
};
usePublishReplyStore.getState().setPublishReplyStore(comment);
@@ -98,6 +110,10 @@ describe('publish stores', () => {
expect(state.publishCommentOptions['parent-1']?.communityAddress).toBe('music-posting.eth');
expect(state.publishCommentOptions['parent-1']?.parentCid).toBe('parent-1');
expect(state.publishCommentOptions['parent-1']?.postCid).toBe('parent-1');
expect(state.publishCommentOptions['parent-1']?.challengeRequest).toEqual({
challengeAnswers: ['bitsocial-flags:5chan:flag:pol:AC'],
});
expect(state.publishCommentOptions['parent-1']?.flairs).toEqual([{ text: 'flag:pol:AC', type: 'pol', code: 'AC' }]);
state.publishCommentOptions['parent-1']?.onChallengeVerification?.({ token: 'challenge' } as never, comment);
expect(testState.alertChallengeVerificationFailedMock).toHaveBeenCalledWith({ token: 'challenge' }, comment);
+11 -1
View File
@@ -11,7 +11,9 @@ type SubmitState = {
title: string | undefined;
content: string | undefined;
link: string | undefined;
flairs: Comment['flairs'] | undefined;
spoiler: boolean | undefined;
challengeRequest: Record<string, unknown> | undefined;
publishCommentOptions: PublishCommentOptions;
setPublishPostStore: (data: Partial<SubmitState>) => void;
resetPublishPostStore: () => void;
@@ -24,11 +26,13 @@ const usePublishPostStore = create<SubmitState>((set) => ({
title: undefined,
content: undefined,
link: undefined,
flairs: undefined,
spoiler: undefined,
challengeRequest: undefined,
publishCommentOptions: {},
setPublishPostStore: (comment: Comment) =>
set(() => {
const { author, content, spoiler, title } = comment;
const { author, challengeRequest, content, flairs, spoiler, title } = comment;
const link = comment.link ? normalizePublishURL(comment.link) : undefined;
const communityAddress = getCommentCommunityAddress(comment);
@@ -44,7 +48,9 @@ const usePublishPostStore = create<SubmitState>((set) => ({
title,
content,
link,
flairs,
spoiler,
...(challengeRequest ? { challengeRequest } : {}),
onChallengeVerification: (challengeVerification: ChallengeVerification, comment: Comment) => {
alertChallengeVerificationFailed(challengeVerification, comment);
},
@@ -65,7 +71,9 @@ const usePublishPostStore = create<SubmitState>((set) => ({
title,
content,
link,
flairs,
spoiler,
challengeRequest,
publishCommentOptions,
};
}),
@@ -77,7 +85,9 @@ const usePublishPostStore = create<SubmitState>((set) => ({
title: undefined,
content: undefined,
link: undefined,
flairs: undefined,
spoiler: undefined,
challengeRequest: undefined,
publishCommentOptions: {},
}),
}));
+11 -1
View File
@@ -9,7 +9,9 @@ type ReplyState = {
displayName: { [parentCid: string]: string | undefined };
content: { [parentCid: string]: string | undefined };
link: { [parentCid: string]: string | undefined };
flairs: { [parentCid: string]: Comment['flairs'] | undefined };
spoiler: { [parentCid: string]: boolean | undefined };
challengeRequest: { [parentCid: string]: Record<string, unknown> | undefined };
publishCommentOptions: { [parentCid: string]: PublishCommentOptions | undefined };
setPublishReplyStore: (comment: Comment) => void;
resetPublishReplyStore: (parentCid: string) => void;
@@ -20,12 +22,14 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
displayName: {},
content: {},
link: {},
flairs: {},
spoiler: {},
challengeRequest: {},
publishCommentOptions: {},
setPublishReplyStore: (comment: Comment) =>
set((state) => {
const { parentCid, author, content, spoiler } = comment;
const { parentCid, author, challengeRequest, content, flairs, spoiler } = comment;
const link = comment.link ? normalizePublishURL(comment.link) : undefined;
const communityAddress = getCommentCommunityAddress(comment);
@@ -42,7 +46,9 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
postCid: comment?.postCid || parentCid,
content,
link,
flairs,
spoiler,
...(challengeRequest ? { challengeRequest } : {}),
onChallengeVerification: (challengeVerification: ChallengeVerification, comment: Comment) => {
alertChallengeVerificationFailed(challengeVerification, comment);
},
@@ -61,7 +67,9 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
displayName: { ...state.displayName, [parentCid]: displayName },
content: { ...state.content, [parentCid]: content },
link: { ...state.link, [parentCid]: link },
flairs: { ...state.flairs, [parentCid]: flairs },
spoiler: { ...state.spoiler, [parentCid]: spoiler },
challengeRequest: { ...state.challengeRequest, [parentCid]: challengeRequest },
publishCommentOptions: { ...state.publishCommentOptions, [parentCid]: publishCommentOptions },
};
}),
@@ -72,7 +80,9 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
displayName: { ...state.displayName, [parentCid]: undefined },
content: { ...state.content, [parentCid]: undefined },
link: { ...state.link, [parentCid]: undefined },
flairs: { ...state.flairs, [parentCid]: undefined },
spoiler: { ...state.spoiler, [parentCid]: undefined },
challengeRequest: { ...state.challengeRequest, [parentCid]: undefined },
publishCommentOptions: { ...state.publishCommentOptions, [parentCid]: undefined },
})),
}));