2022-02-27 02:07:39 +00:00
|
|
|
import renderUpdate from '@/remote/activitypub/renderer/update.js';
|
|
|
|
import { renderActivity } from '@/remote/activitypub/renderer/index.js';
|
|
|
|
import { Users } from '@/models/index.js';
|
|
|
|
import { User } from '@/models/entities/user.js';
|
|
|
|
import { renderPerson } from '@/remote/activitypub/renderer/person.js';
|
|
|
|
import { deliverToFollowers } from '@/remote/activitypub/deliver-manager.js';
|
|
|
|
import { deliverToRelays } from '../relay.js';
|
2018-09-01 11:17:30 +00:00
|
|
|
|
2022-10-16 22:06:22 +00:00
|
|
|
/**
|
|
|
|
* Send an Update activity to a user's followers.
|
|
|
|
* @param userId ID of user
|
|
|
|
*/
|
|
|
|
export async function publishToFollowers(userId: User['id']): Promise<void> {
|
2022-03-26 06:34:00 +00:00
|
|
|
const user = await Users.findOneBy({ id: userId });
|
2019-04-13 19:17:24 +00:00
|
|
|
if (user == null) throw new Error('user not found');
|
2018-09-01 11:17:30 +00:00
|
|
|
|
2022-10-16 22:06:22 +00:00
|
|
|
// Deliver Update if the follower is a remote user and the poster is a local user
|
2019-04-07 12:50:36 +00:00
|
|
|
if (Users.isLocalUser(user)) {
|
2019-11-09 09:51:54 +00:00
|
|
|
const content = renderActivity(renderUpdate(await renderPerson(user), user));
|
|
|
|
deliverToFollowers(user, content);
|
2020-05-10 09:42:31 +00:00
|
|
|
deliverToRelays(user, content);
|
2018-09-01 11:17:30 +00:00
|
|
|
}
|
|
|
|
}
|