Skip to content

Node.js based forum software built for the modern web

feat: added mocks.actor and Update(Person) activity on profile update

Julian Lam8453b83e9ea0
diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js
index fad3f12f4e..2b979eccc5 100644
--- a/src/activitypub/mocks.js
+++ b/src/activitypub/mocks.js
@@ -1,5 +1,7 @@
'use strict';
+const nconf = require('nconf');
+
const db = require('../database');
const user = require('../user');
@@ -114,3 +116,34 @@ Mocks.post = async (objects) => {
return single ? posts.pop() : posts;
};
+
+Mocks.actor = async (uid) => {
+ const { username, userslug, displayname: name, aboutme, picture, 'cover:url': cover } = await user.getUserData(uid);
+ const publicKey = await activitypub.getPublicKey(uid);
+
+ return {
+ '@context': [
+ 'https://www.w3.org/ns/activitystreams',
+ 'https://w3id.org/security/v1',
+ ],
+ id: `${nconf.get('url')}/user/${userslug}`,
+ url: `${nconf.get('url')}/user/${userslug}`,
+ followers: `${nconf.get('url')}/user/${userslug}/followers`,
+ following: `${nconf.get('url')}/user/${userslug}/following`,
+ inbox: `${nconf.get('url')}/user/${userslug}/inbox`,
+ outbox: `${nconf.get('url')}/user/${userslug}/outbox`,
+
+ type: 'Person',
+ name,
+ preferredUsername: username,
+ summary: aboutme,
+ icon: picture ? `${nconf.get('url')}${picture}` : null,
+ image: cover ? `${nconf.get('url')}${cover}` : null,
+
+ publicKey: {
+ id: `${nconf.get('url')}/user/${userslug}#key`,
+ owner: `${nconf.get('url')}/user/${userslug}`,
+ publicKeyPem: publicKey,
+ },
+ };
+};
diff --git a/src/api/activitypub.js b/src/api/activitypub.js
index dba7a972c1..810fbc732e 100644
--- a/src/api/activitypub.js
+++ b/src/api/activitypub.js
@@ -104,3 +104,19 @@ activitypubApi.create.post = async (caller, { post }) => {
await activitypub.send(caller.uid, Array.from(targets), payload);
};
+
+activitypubApi.update = {};
+
+activitypubApi.update.profile = async (caller, { uid }) => {
+ const [object, followers] = await Promise.all([
+ activitypub.mocks.actor(uid),
+ db.getSortedSetMembers(`followersRemote:${caller.uid}`),
+ ]);
+
+ await activitypub.send(caller.uid, followers, {
+ type: 'Update',
+ to: [activitypub._constants.publicAddress],
+ cc: [],
+ object,
+ });
+};
diff --git a/src/controllers/activitypub/actors.js b/src/controllers/activitypub/actors.js
index 9571d3659b..8282aad979 100644
--- a/src/controllers/activitypub/actors.js
+++ b/src/controllers/activitypub/actors.js
@@ -36,34 +36,8 @@ Actors.application = async function (req, res) {
Actors.user = async function (req, res) {
// todo: view:users priv gate
- const { userslug } = req.params;
const { uid } = res.locals;
- const { username, displayname: name, aboutme, picture, 'cover:url': cover } = await user.getUserData(uid);
- const publicKey = await activitypub.getPublicKey(uid);
+ const payload = await activitypub.mocks.actor(uid);
- res.status(200).json({
- '@context': [
- 'https://www.w3.org/ns/activitystreams',
- 'https://w3id.org/security/v1',
- ],
- id: `${nconf.get('url')}/user/${userslug}`,
- url: `${nconf.get('url')}/user/${userslug}`,
- followers: `${nconf.get('url')}/user/${userslug}/followers`,
- following: `${nconf.get('url')}/user/${userslug}/following`,
- inbox: `${nconf.get('url')}/user/${userslug}/inbox`,
- outbox: `${nconf.get('url')}/user/${userslug}/outbox`,
-
- type: 'Person',
- name,
- preferredUsername: username,
- summary: aboutme,
- icon: picture ? `${nconf.get('url')}${picture}` : null,
- image: cover ? `${nconf.get('url')}${cover}` : null,
-
- publicKey: {
- id: `${nconf.get('url')}/user/${userslug}#key`,
- owner: `${nconf.get('url')}/user/${userslug}`,
- publicKeyPem: publicKey,
- },
- });
+ res.status(200).json(payload);
};
diff --git a/src/user/profile.js b/src/user/profile.js
index 9c1792f0f6..e732e13687 100644
--- a/src/user/profile.js
+++ b/src/user/profile.js
@@ -11,6 +11,7 @@ const meta = require('../meta');
const db = require('../database');
const groups = require('../groups');
const plugins = require('../plugins');
+const api = require('../api');
module.exports = function (User) {
User.updateProfile = async function (uid, data, extraFields) {
@@ -65,6 +66,7 @@ module.exports = function (User) {
fields: fields,
oldData: oldData,
});
+ api.activitypub.update.profile({ uid }, { uid: updateUid });
return await User.getUserFields(updateUid, [
'email', 'username', 'userslug',