Skip to content

Node.js based forum software built for the modern web

feat: Update(Note)

Julian Lam0e59f3124e37
diff --git a/src/api/activitypub.js b/src/api/activitypub.js
index 429c6e8afc..036396a00e 100644
--- a/src/api/activitypub.js
+++ b/src/api/activitypub.js
@@ -51,28 +51,32 @@ activitypubApi.unfollow = async (caller, { uid }) => {
activitypubApi.create = {};
+// this might be better genericised... tbd. some of to/cc is built in mocks.
+async function buildRecipients(object, uid) {
+ const followers = await db.getSortedSetMembers(`followersRemote:${uid}`);
+ const { to } = object;
+ const targets = new Set(followers);
+ const parentId = await posts.getPostField(object.inReplyTo, 'uid');
+ if (activitypub.helpers.isUri(parentId)) {
+ to.unshift(parentId);
+ }
+
+ return { targets };
+}
+
activitypubApi.create.post = async (caller, { pid }) => {
const post = (await posts.getPostSummaryByPids([pid], caller.uid, { stripTags: false })).pop();
if (!post) {
return;
}
- const [object, followers] = await Promise.all([
- activitypub.mocks.note(post),
- db.getSortedSetMembers(`followersRemote:${post.user.uid}`),
- ]);
-
- const { to, cc } = object;
- const targets = new Set(followers);
- const parentId = await posts.getPostField(object.inReplyTo, 'uid');
- if (activitypub.helpers.isUri(parentId)) {
- to.unshift(parentId);
- }
+ const object = await activitypub.mocks.note(post);
+ const { targets } = await buildRecipients(object, post.user.uid);
const payload = {
type: 'Create',
- to,
- cc,
+ to: object.to,
+ cc: object.cc,
object,
};
@@ -94,3 +98,17 @@ activitypubApi.update.profile = async (caller, { uid }) => {
object,
});
};
+
+activitypubApi.update.note = async (caller, { post }) => {
+ const object = await activitypub.mocks.note(post);
+ const { targets } = await buildRecipients(object, post.user.uid);
+
+ const payload = {
+ type: 'Update',
+ to: object.to,
+ cc: object.cc,
+ object,
+ };
+
+ await activitypub.send(caller.uid, Array.from(targets), payload);
+};
diff --git a/src/api/posts.js b/src/api/posts.js
index 3a1666b075..4533b4464c 100644
--- a/src/api/posts.js
+++ b/src/api/posts.js
@@ -140,6 +140,8 @@ postsAPI.edit = async function (caller, data) {
if (!editResult.post.deleted) {
websockets.in(`topic_${editResult.topic.tid}`).emit('event:post_edited', editResult);
+ await require('.').activitypub.update.note(caller, { post: postObj[0] });
+
return returnData;
}
@@ -152,6 +154,7 @@ postsAPI.edit = async function (caller, data) {
const uids = _.uniq(_.flatten(memberData).concat(String(caller.uid)));
uids.forEach(uid => websockets.in(`uid_${uid}`).emit('event:post_edited', editResult));
+
return returnData;
};