mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 20:45:58 +01:00
feat: handle Update(Note) when object has limited visibility, #12834
This commit is contained in:
@@ -10,6 +10,7 @@ const posts = require('../posts');
|
|||||||
const topics = require('../topics');
|
const topics = require('../topics');
|
||||||
const categories = require('../categories');
|
const categories = require('../categories');
|
||||||
const notifications = require('../notifications');
|
const notifications = require('../notifications');
|
||||||
|
const messaging = require('../messaging');
|
||||||
const flags = require('../flags');
|
const flags = require('../flags');
|
||||||
const api = require('../api');
|
const api = require('../api');
|
||||||
const activitypub = require('.');
|
const activitypub = require('.');
|
||||||
@@ -63,7 +64,8 @@ inbox.create = async (req) => {
|
|||||||
const { object } = req.body;
|
const { object } = req.body;
|
||||||
|
|
||||||
// Alternative logic for non-public objects
|
// Alternative logic for non-public objects
|
||||||
if (![...object.to, ...object.cc].includes(activitypub._constants.publicAddress)) {
|
const isPublic = [...object.to, ...object.cc].includes(activitypub._constants.publicAddress);
|
||||||
|
if (!isPublic) {
|
||||||
return await activitypub.notes.assertPrivate(object);
|
return await activitypub.notes.assertPrivate(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,11 +78,7 @@ inbox.create = async (req) => {
|
|||||||
|
|
||||||
inbox.update = async (req) => {
|
inbox.update = async (req) => {
|
||||||
const { actor, object } = req.body;
|
const { actor, object } = req.body;
|
||||||
|
const isPublic = [...object.to, ...object.cc].includes(activitypub._constants.publicAddress);
|
||||||
// Temporary, reject non-public notes.
|
|
||||||
if (![...object.to, ...object.cc].includes(activitypub._constants.publicAddress)) {
|
|
||||||
throw new Error('[[error:activitypub.not-implemented]]');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Origin checking
|
// Origin checking
|
||||||
const actorHostname = new URL(actor).hostname;
|
const actorHostname = new URL(actor).hostname;
|
||||||
@@ -91,20 +89,40 @@ inbox.update = async (req) => {
|
|||||||
|
|
||||||
switch (object.type) {
|
switch (object.type) {
|
||||||
case 'Note': {
|
case 'Note': {
|
||||||
const exists = await posts.exists(object.id);
|
const [isNote, isMessage] = await Promise.all([
|
||||||
|
posts.exists(object.id),
|
||||||
|
messaging.messageExists(object.id),
|
||||||
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (exists) {
|
switch (true) {
|
||||||
|
case isNote: {
|
||||||
const postData = await activitypub.mocks.post(object);
|
const postData = await activitypub.mocks.post(object);
|
||||||
await posts.edit(postData);
|
await posts.edit(postData);
|
||||||
const isDeleted = await posts.getPostField(object.id, 'deleted');
|
const isDeleted = await posts.getPostField(object.id, 'deleted');
|
||||||
if (isDeleted) {
|
if (isDeleted) {
|
||||||
await api.posts.restore({ uid: actor }, { pid: object.id });
|
await api.posts.restore({ uid: actor }, { pid: object.id });
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case isMessage: {
|
||||||
|
const roomId = await messaging.getMessageField(object.id, 'roomId');
|
||||||
|
await messaging.editMessage(actor, object.id, roomId, object.content);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
if (!isPublic) {
|
||||||
|
return await activitypub.notes.assertPrivate(object);
|
||||||
|
}
|
||||||
|
|
||||||
const asserted = await activitypub.notes.assert(0, object.id);
|
const asserted = await activitypub.notes.assert(0, object.id);
|
||||||
if (asserted) {
|
if (asserted) {
|
||||||
announce(object.id, req.body);
|
announce(object.id, req.body);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject('Update', object, actor);
|
reject('Update', object, actor);
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ activitypubApi.update.privateNote = enabledCheck(async (caller, { messageObj })
|
|||||||
object,
|
object,
|
||||||
};
|
};
|
||||||
|
|
||||||
await activitypub.send('uid', messageObj.fromuid, targets, payload);
|
await activitypub.send('uid', caller.uid, targets, payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
activitypubApi.delete = {};
|
activitypubApi.delete = {};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const user = require('../user');
|
|||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
const api = require('../api');
|
const api = require('../api');
|
||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
|
const utils = require('../utils');
|
||||||
|
|
||||||
const sockets = require('../socket.io');
|
const sockets = require('../socket.io');
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ module.exports = function (Messaging) {
|
|||||||
messages: messages,
|
messages: messages,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isPublic) {
|
if (!isPublic && utils.isNumber(messages[0].fromuid)) {
|
||||||
api.activitypub.update.privateNote({ uid: messages[0].fromuid }, { messageObj: messages[0] });
|
api.activitypub.update.privateNote({ uid: messages[0].fromuid }, { messageObj: messages[0] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ module.exports = function (Messaging) {
|
|||||||
try {
|
try {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
sendNotification(fromUid, roomId, messageObj),
|
sendNotification(fromUid, roomId, messageObj),
|
||||||
!isPublic ? api.activitypub.create.privateNote({ uid: fromUid }, { messageObj }) : null,
|
!isPublic && utils.isNumber(fromUid) ?
|
||||||
|
api.activitypub.create.privateNote({ uid: fromUid }, { messageObj }) : null,
|
||||||
]);
|
]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
winston.error(`[messaging/notifications] Unabled to send notification\n${err.stack}`);
|
winston.error(`[messaging/notifications] Unabled to send notification\n${err.stack}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user