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.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;
// 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 = 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);
};

View File

@@ -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;
};