mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
feat: Update(Person)
This commit is contained in:
@@ -9,7 +9,7 @@ const activitypub = module.parent.exports;
|
|||||||
|
|
||||||
const Actors = module.exports;
|
const Actors = module.exports;
|
||||||
|
|
||||||
Actors.assert = async (ids) => {
|
Actors.assert = async (ids, options = {}) => {
|
||||||
// Handle single values
|
// Handle single values
|
||||||
if (!Array.isArray(ids)) {
|
if (!Array.isArray(ids)) {
|
||||||
ids = [ids];
|
ids = [ids];
|
||||||
@@ -19,8 +19,10 @@ Actors.assert = async (ids) => {
|
|||||||
ids = ids.filter(id => !utils.isNumber(id));
|
ids = ids.filter(id => !utils.isNumber(id));
|
||||||
|
|
||||||
// Filter out existing
|
// Filter out existing
|
||||||
const exists = await db.isSortedSetMembers('usersRemote:lastCrawled', ids);
|
if (!options.update) {
|
||||||
ids = ids.filter((id, idx) => !exists[idx]);
|
const exists = await db.isSortedSetMembers('usersRemote:lastCrawled', ids.map(id => ((typeof id === 'object' && id.hasOwnProperty('id')) ? id.id : id)));
|
||||||
|
ids = ids.filter((id, idx) => !exists[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
if (!ids.length) {
|
if (!ids.length) {
|
||||||
return true;
|
return true;
|
||||||
@@ -28,7 +30,7 @@ Actors.assert = async (ids) => {
|
|||||||
|
|
||||||
const actors = await Promise.all(ids.map(async (id) => {
|
const actors = await Promise.all(ids.map(async (id) => {
|
||||||
try {
|
try {
|
||||||
const actor = await activitypub.get(0, id);
|
const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? await activitypub.get(0, id) : id;
|
||||||
|
|
||||||
// Follow counts
|
// Follow counts
|
||||||
try {
|
try {
|
||||||
@@ -40,7 +42,7 @@ Actors.assert = async (ids) => {
|
|||||||
actor.followingCount = following.totalItems;
|
actor.followingCount = following.totalItems;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// no action required
|
// no action required
|
||||||
winston.verbose(`[activitypub/actor.assert] Unable to retrieve follower counts for ${id}`);
|
winston.verbose(`[activitypub/actor.assert] Unable to retrieve follower counts for ${actor.id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post count
|
// Post count
|
||||||
|
|||||||
@@ -25,13 +25,24 @@ inbox.create = async (req) => {
|
|||||||
|
|
||||||
inbox.update = async (req) => {
|
inbox.update = async (req) => {
|
||||||
const { object } = req.body;
|
const { object } = req.body;
|
||||||
const postData = await activitypub.mocks.post(object);
|
|
||||||
|
|
||||||
if (postData) {
|
switch (object.type) {
|
||||||
await activitypub.notes.assert(0, [postData], { update: true });
|
case 'Note': {
|
||||||
winston.info(`[activitypub/inbox] Updating note ${postData.pid}`);
|
const postData = await activitypub.mocks.post(object);
|
||||||
} else {
|
|
||||||
winston.warn('[activitypub/inbox] Received object was not a note');
|
if (postData) {
|
||||||
|
await activitypub.notes.assert(0, [postData], { update: true });
|
||||||
|
winston.info(`[activitypub/inbox.update] Updating note ${postData.pid}`);
|
||||||
|
} else {
|
||||||
|
winston.warn(`[activitypub/inbox.update] Received note did not parse properly (id: ${object.id})`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'Person': {
|
||||||
|
await activitypub.actors.assert(object, { update: true });
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user