hippofish/src/services/i/update.ts
syuilo 987168b863
strictNullChecks (#4666)
* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip
2019-04-13 01:43:22 +09:00

34 lines
1.1 KiB
TypeScript

import renderUpdate from '../../remote/activitypub/renderer/update';
import { renderActivity } from '../../remote/activitypub/renderer';
import { deliver } from '../../queue';
import { Followings, Users } from '../../models';
import { User } from '../../models/entities/user';
import { renderPerson } from '../../remote/activitypub/renderer/person';
export async function publishToFollowers(userId: User['id']) {
const user = await Users.findOne(userId);
if (user == null) throw 'user not found';
const followers = await Followings.find({
followeeId: user.id
});
const queue: string[] = [];
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーならUpdateを配信
if (Users.isLocalUser(user)) {
for (const following of followers) {
if (Followings.isRemoteFollower(following)) {
const inbox = following.followerSharedInbox || following.followerInbox;
if (!queue.includes(inbox)) queue.push(inbox);
}
}
if (queue.length > 0) {
const content = renderActivity(renderUpdate(await renderPerson(user), user));
for (const inbox of queue) {
deliver(user, content, inbox);
}
}
}
}