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