mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: added mocks.actor and Update(Person) activity on profile update
This commit is contained in:
@@ -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,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user