feat: Update(Note)

This commit is contained in:
Julian Lam
2024-01-30 11:25:45 -05:00
parent 86a607ce8c
commit 0e59f3124e
2 changed files with 35 additions and 14 deletions

View File

@@ -51,28 +51,32 @@ activitypubApi.unfollow = async (caller, { uid }) => {
activitypubApi.create = {}; activitypubApi.create = {};
activitypubApi.create.post = async (caller, { pid }) => { // this might be better genericised... tbd. some of to/cc is built in mocks.
const post = (await posts.getPostSummaryByPids([pid], caller.uid, { stripTags: false })).pop(); async function buildRecipients(object, uid) {
if (!post) { const followers = await db.getSortedSetMembers(`followersRemote:${uid}`);
return; const { to } = object;
}
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 targets = new Set(followers);
const parentId = await posts.getPostField(object.inReplyTo, 'uid'); const parentId = await posts.getPostField(object.inReplyTo, 'uid');
if (activitypub.helpers.isUri(parentId)) { if (activitypub.helpers.isUri(parentId)) {
to.unshift(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 = await activitypub.mocks.note(post);
const { targets } = await buildRecipients(object, post.user.uid);
const payload = { const payload = {
type: 'Create', type: 'Create',
to, to: object.to,
cc, cc: object.cc,
object, object,
}; };
@@ -94,3 +98,17 @@ activitypubApi.update.profile = async (caller, { uid }) => {
object, 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);
};

View File

@@ -140,6 +140,8 @@ postsAPI.edit = async function (caller, data) {
if (!editResult.post.deleted) { if (!editResult.post.deleted) {
websockets.in(`topic_${editResult.topic.tid}`).emit('event:post_edited', editResult); websockets.in(`topic_${editResult.topic.tid}`).emit('event:post_edited', editResult);
await require('.').activitypub.update.note(caller, { post: postObj[0] });
return returnData; return returnData;
} }
@@ -152,6 +154,7 @@ postsAPI.edit = async function (caller, data) {
const uids = _.uniq(_.flatten(memberData).concat(String(caller.uid))); const uids = _.uniq(_.flatten(memberData).concat(String(caller.uid)));
uids.forEach(uid => websockets.in(`uid_${uid}`).emit('event:post_edited', editResult)); uids.forEach(uid => websockets.in(`uid_${uid}`).emit('event:post_edited', editResult));
return returnData; return returnData;
}; };