Skip to content

Commit

Permalink
use msgid when creating reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
raykyri committed Aug 2, 2024
1 parent bb624f9 commit 7ad381e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const createReaction = async ({
jwt: userStore.getState().jwt,
...toCanvasSignedDataApiArgs(canvasSignedData),
comment_id: commentId,
comment_msg_id: commentMsgId,
},
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const createReaction = async ({
{
author_community_id: userStore.getState().activeAccount?.community?.id,
thread_id: threadId,
thread_msg_id: threadMsgId,
community_id: app.chain.id,
address,
reaction: reactionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const CommentReactionButton = ({
commentId: comment.id,
communityId: app.activeChainId(),
threadId: comment.threadId,
commentMsgId: comment.canvasMsgId,
}).catch((err) => {
if (err instanceof SessionKeyError) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const ReactionButton = ({
communityId: app.activeChainId(),
address: user.activeAccount?.address,
threadId: thread.id,
threadMsgId: thread.canvasMsgId,
reactionId: reactedId as number,
}).catch((e) => {
if (e instanceof SessionKeyError) {
Expand All @@ -102,6 +103,7 @@ export const ReactionButton = ({
communityId: app.activeChainId(),
address: activeAddress || '',
threadId: thread.id,
threadMsgId: thread.canvasMsgId,
reactionType: 'like',
isPWA: isAddedToHomeScreen,
}).catch((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const Errors = {
};

type CreateCommentReactionRequestParams = { id: string };
type CreateCommentReactionRequestBody = { reaction: string };
type CreateCommentReactionRequestBody = {
reaction: string;
comment_msg_id: string | null;
};
type CreateCommentReactionResponse = ReactionAttributes;

export const createCommentReactionHandler = async (
Expand All @@ -33,7 +36,7 @@ export const createCommentReactionHandler = async (
) => {
const { user, address } = req;
// @ts-expect-error <StrictNullChecks>
const { reaction } = req.body;
const { reaction, comment_msg_id: commentMsgId } = req.body;

if (!reaction) {
throw new AppError(Errors.InvalidReaction);
Expand Down Expand Up @@ -61,7 +64,7 @@ export const createCommentReactionHandler = async (
if (config.ENFORCE_SESSION_KEYS) {
const { canvasSignedData } = fromCanvasSignedDataApiArgs(req.body);
const canvasReaction = {
comment_id: commentId,
comment_id: commentMsgId ?? null,
address:
canvasSignedData.actionMessage.payload.did.split(':')[0] == 'polkadot'
? addressSwapper({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Errors = {
type CreateThreadReactionRequestParams = { id: string };
type CreateThreadReactionRequestBody = {
reaction: string;
thread_msg_id: string | null;
};
type CreateThreadReactionResponse = ReactionAttributes;

Expand All @@ -35,7 +36,7 @@ export const createThreadReactionHandler = async (
) => {
const { user, address } = req;
// @ts-expect-error <StrictNullChecks>
const { reaction } = req.body;
const { reaction, thread_msg_id: threadMsgId } = req.body;

if (!reaction) {
throw new AppError(Errors.InvalidReaction);
Expand Down Expand Up @@ -64,7 +65,7 @@ export const createThreadReactionHandler = async (
if (config.ENFORCE_SESSION_KEYS) {
const { canvasSignedData } = fromCanvasSignedDataApiArgs(req.body);
const canvasThreadReaction = {
thread_id: threadId,
thread_id: threadMsgId ?? null,
address:
canvasSignedData.actionMessage.payload.did.split(':')[0] == 'polkadot'
? addressSwapper({
Expand Down

0 comments on commit 7ad381e

Please sign in to comment.