2018-09-01 13:17:30 +02:00
|
|
|
import renderUpdate from '../../remote/activitypub/renderer/update';
|
2019-01-30 18:29:36 +01:00
|
|
|
import { renderActivity } from '../../remote/activitypub/renderer';
|
2018-09-01 13:17:30 +02:00
|
|
|
import { deliver } from '../../queue';
|
2019-04-07 14:50:36 +02:00
|
|
|
import { Followings, Users } from '../../models';
|
|
|
|
import { User } from '../../models/entities/user';
|
|
|
|
import { renderPerson } from '../../remote/activitypub/renderer/person';
|
2018-09-01 13:17:30 +02:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
export async function publishToFollowers(userId: User['id']) {
|
2019-04-12 18:43:22 +02:00
|
|
|
const user = await Users.findOne(userId);
|
2019-04-13 21:17:24 +02:00
|
|
|
if (user == null) throw new Error('user not found');
|
2018-09-01 13:17:30 +02:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
const followers = await Followings.find({
|
|
|
|
followeeId: user.id
|
2018-09-01 13:17:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const queue: string[] = [];
|
|
|
|
|
|
|
|
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーならUpdateを配信
|
2019-04-07 14:50:36 +02:00
|
|
|
if (Users.isLocalUser(user)) {
|
2018-11-30 15:30:28 +01:00
|
|
|
for (const following of followers) {
|
2019-04-12 18:43:22 +02:00
|
|
|
if (Followings.isRemoteFollower(following)) {
|
2019-04-07 14:50:36 +02:00
|
|
|
const inbox = following.followerSharedInbox || following.followerInbox;
|
2018-09-01 13:17:30 +02:00
|
|
|
if (!queue.includes(inbox)) queue.push(inbox);
|
|
|
|
}
|
2018-11-30 15:30:28 +01:00
|
|
|
}
|
2018-09-01 13:17:30 +02:00
|
|
|
|
|
|
|
if (queue.length > 0) {
|
2019-01-30 18:29:36 +01:00
|
|
|
const content = renderActivity(renderUpdate(await renderPerson(user), user));
|
2018-12-11 12:36:55 +01:00
|
|
|
for (const inbox of queue) {
|
2018-09-01 13:17:30 +02:00
|
|
|
deliver(user, content, inbox);
|
2018-12-11 12:36:55 +01:00
|
|
|
}
|
2018-09-01 13:17:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|