mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-22 20:32:28 +01:00
fix: missing awaits, more comprehensive 1b12 tests
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
const nconf = require('nconf');
|
||||
|
||||
const posts = require('../posts');
|
||||
const utils = require('../utils');
|
||||
|
||||
const activitypub = module.parent.exports;
|
||||
const Feps = module.exports;
|
||||
@@ -13,7 +14,7 @@ Feps.announce = async function announce(id, activity) {
|
||||
({ id: localId } = await activitypub.helpers.resolveLocalId(id));
|
||||
}
|
||||
const cid = await posts.getCidByPid(localId || id);
|
||||
if (cid === -1) {
|
||||
if (cid === -1 || !utils.isNumber(cid)) { // local cids only
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ inbox.create = async (req) => {
|
||||
|
||||
const asserted = await activitypub.notes.assert(0, object, { cid });
|
||||
if (asserted) {
|
||||
activitypub.feps.announce(object.id, req.body);
|
||||
await activitypub.feps.announce(object.id, req.body);
|
||||
// api.activitypub.add(req, { pid: object.id });
|
||||
}
|
||||
};
|
||||
@@ -244,7 +244,7 @@ inbox.like = async (req) => {
|
||||
activitypub.helpers.log(`[activitypub/inbox/like] id ${id} via ${actor}`);
|
||||
|
||||
const result = await posts.upvote(id, actor);
|
||||
activitypub.feps.announce(object.id, req.body);
|
||||
await activitypub.feps.announce(object.id, req.body);
|
||||
socketHelpers.upvote(result, 'notifications:upvoted-your-post-in');
|
||||
};
|
||||
|
||||
|
||||
@@ -310,7 +310,15 @@ activitypubApi.delete.note = enabledCheck(async (caller, { pid }) => {
|
||||
activitypubApi.like = {};
|
||||
|
||||
activitypubApi.like.note = enabledCheck(async (caller, { pid }) => {
|
||||
if (!activitypub.helpers.isUri(pid)) { // remote only
|
||||
const payload = {
|
||||
id: `${nconf.get('url')}/uid/${caller.uid}#activity/like/${encodeURIComponent(pid)}`,
|
||||
type: 'Like',
|
||||
actor: `${nconf.get('url')}/uid/${caller.uid}`,
|
||||
object: utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid,
|
||||
};
|
||||
|
||||
if (!activitypub.helpers.isUri(pid)) { // only 1b12 announce for local likes
|
||||
await activitypub.feps.announce(pid, payload);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -319,13 +327,6 @@ activitypubApi.like.note = enabledCheck(async (caller, { pid }) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
id: `${nconf.get('url')}/uid/${caller.uid}#activity/like/${encodeURIComponent(pid)}`,
|
||||
type: 'Like',
|
||||
actor: `${nconf.get('url')}/uid/${caller.uid}`,
|
||||
object: pid,
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
activitypub.send('uid', caller.uid, [uid], payload),
|
||||
activitypub.feps.announce(pid, payload),
|
||||
|
||||
@@ -137,12 +137,12 @@ async function executeCommand(caller, command, eventName, notification, data) {
|
||||
}
|
||||
if (result && command === 'upvote') {
|
||||
socketHelpers.upvote(result, notification);
|
||||
api.activitypub.like.note(caller, { pid: data.pid });
|
||||
await api.activitypub.like.note(caller, { pid: data.pid });
|
||||
} else if (result && notification) {
|
||||
socketHelpers.sendNotificationToPostOwner(data.pid, caller.uid, command, notification);
|
||||
} else if (result && command === 'unvote') {
|
||||
socketHelpers.rescindUpvoteNotification(data.pid, caller.uid);
|
||||
api.activitypub.undo.like(caller, { pid: data.pid });
|
||||
await api.activitypub.undo.like(caller, { pid: data.pid });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user