yumechi-no-kuni/packages/backend/src/services/i/update.ts
syuilo 0e4a111f81 refactoring
Resolve #7779
2021-11-12 02:02:25 +09:00

19 lines
870 B
TypeScript

import renderUpdate from '@/remote/activitypub/renderer/update';
import { renderActivity } from '@/remote/activitypub/renderer/index';
import { Users } from '@/models/index';
import { User } from '@/models/entities/user';
import { renderPerson } from '@/remote/activitypub/renderer/person';
import { deliverToFollowers } from '@/remote/activitypub/deliver-manager';
import { deliverToRelays } from '../relay';
export async function publishToFollowers(userId: User['id']) {
const user = await Users.findOne(userId);
if (user == null) throw new Error('user not found');
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーならUpdateを配信
if (Users.isLocalUser(user)) {
const content = renderActivity(renderUpdate(await renderPerson(user), user));
deliverToFollowers(user, content);
deliverToRelays(user, content);
}
}