Node.js based forum software built for the modern web
fix(activitypub): handle duplicate votes in like and dislike
Julian Lamf875e9180bcb
diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.jsindex 934e9ce58f..db38dce554 100644--- a/src/activitypub/inbox.js+++ b/src/activitypub/inbox.js@@ -383,7 +383,15 @@ inbox.like = async (req) => {activitypub.helpers.log(`[activitypub/inbox/like] id ${id} via ${actor}`);- const result = await posts.upvote(id, actor);+ let result;+ try {+ result = await posts.upvote(id, actor);+ } catch (e) {+ if (e.message === '[[error:already-voting-for-this-post]]') {+ return;+ }+ throw e;+ }await activitypub.feps.announce(object.id, req.body);socketHelpers.upvote(result, 'notifications:upvoted-your-post-in');};@@ -423,7 +431,14 @@ inbox.dislike = async (req) => {activitypub.helpers.log(`[activitypub/inbox/dislike] id ${id} via ${actor}`);- await posts.downvote(id, actor);+ try {+ await posts.downvote(id, actor);+ } catch (e) {+ if (e.message === '[[error:already-voting-for-this-post]]') {+ return;+ }+ throw e;+ }await activitypub.feps.announce(object.id, req.body);};