Send Update activity
This commit is contained in:
parent
3efffbcf22
commit
57a63d38aa
14
src/remote/activitypub/renderer/update.ts
Normal file
14
src/remote/activitypub/renderer/update.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import config from '../../../config';
|
||||
import { ILocalUser } from '../../../models/user';
|
||||
|
||||
export default (object: any, user: ILocalUser) => {
|
||||
const activity = {
|
||||
id: `${config.url}/users/${user._id}#updates/${new Date().getTime()}`,
|
||||
actor: `${config.url}/users/${user._id}`,
|
||||
type: 'Update',
|
||||
to: [ 'https://www.w3.org/ns/activitystreams#Public' ],
|
||||
object
|
||||
} as any;
|
||||
|
||||
return activity;
|
||||
};
|
@ -5,6 +5,7 @@ import DriveFile from '../../../../models/drive-file';
|
||||
import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
|
||||
import { IApp } from '../../../../models/app';
|
||||
import config from '../../../../config';
|
||||
import { publishToFollowers } from '../../../../services/i/update';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -144,4 +145,7 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a
|
||||
if (user.isLocked && isLocked === false) {
|
||||
acceptAllFollowRequests(user);
|
||||
}
|
||||
|
||||
// フォロワーにUpdateを配信
|
||||
publishToFollowers(user._id);
|
||||
});
|
||||
|
38
src/services/i/update.ts
Normal file
38
src/services/i/update.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import User, { isLocalUser, isRemoteUser } from '../../models/user';
|
||||
import Following from '../../models/following';
|
||||
import renderPerson from '../../remote/activitypub/renderer/person';
|
||||
import renderUpdate from '../../remote/activitypub/renderer/update';
|
||||
import packAp from '../../remote/activitypub/renderer';
|
||||
import { deliver } from '../../queue';
|
||||
|
||||
export async function publishToFollowers(userId: mongo.ObjectID) {
|
||||
const user = await User.findOne({
|
||||
_id: userId
|
||||
});
|
||||
|
||||
const followers = await Following.find({
|
||||
followeeId: user._id
|
||||
});
|
||||
|
||||
const queue: string[] = [];
|
||||
|
||||
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーならUpdateを配信
|
||||
if (isLocalUser(user)) {
|
||||
followers.map(following => {
|
||||
const follower = following._follower;
|
||||
|
||||
if (isRemoteUser(follower)) {
|
||||
const inbox = follower.sharedInbox || follower.inbox;
|
||||
if (!queue.includes(inbox)) queue.push(inbox);
|
||||
}
|
||||
});
|
||||
|
||||
if (queue.length > 0) {
|
||||
const content = packAp(renderUpdate(await renderPerson(user), user));
|
||||
queue.forEach(inbox => {
|
||||
deliver(user, content, inbox);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user