Skip to content

Commit

Permalink
fix(backend): fix creating reactions bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Nov 10, 2024
1 parent ab4db3f commit 1f9370f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/server/api/endpoints/notes/reactions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export const meta = {
message: 'You are already reacting to that note.',
code: 'ALREADY_REACTED',
id: '71efcf98-86d6-4e2b-b2ad-9d032369366b'
},

cannotReactToRenote: {
message: 'You cannot react to Renote.',
code: 'CANNOT_REACT_TO_RENOTE',
id: 'eaccdc08-ddef-43fe-908f-d108faad57f5',
}
}
};
Expand All @@ -62,6 +68,7 @@ export default define(meta, async (ps, user) => {
});
await createReaction(user, note, ps.reaction, !!ps.dislike).catch(e => {
if (e.id === '51c42bb4-931a-456b-bff7-e5a8a70dd298') throw new ApiError(meta.errors.alreadyReacted);
if (e.id === '12c35529-3c79-4327-b1cc-e2cf63a71925') throw new ApiError(meta.errors.cannotReactToRenote);
throw e;
});
return;
Expand Down
6 changes: 5 additions & 1 deletion src/services/note/reaction/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import { perUserReactionsChart } from '../../chart';
import { genId } from '../../../misc/gen-id';
import { createNotification } from '../../create-notification';
import deleteReaction from './delete';
import { IdentifiableError } from '../../../misc/identifiable-error';

export default async (user: User, note: Note, reaction?: string, isDislike = false) => {
if (note.renoteId && note.text == null && note.poll == null && note.fileIds.length == 0) {
throw new IdentifiableError('12c35529-3c79-4327-b1cc-e2cf63a71925');
}
const dbReaction = await toDbReaction(reaction, user.host);
reaction = dbReaction ? dbReaction : await getFallbackReaction();
const isFallback = !dbReaction;
Expand All @@ -38,7 +42,7 @@ export default async (user: User, note: Note, reaction?: string, isDislike = fal
createdAt: new Date(),
noteId: note.id,
userId: user.id,
reaction,
reaction,
dislike: isDislike,
});

Expand Down

0 comments on commit 1f9370f

Please sign in to comment.