mistykey/packages/backend/src/services/user-list/push.ts
syuilo d071d18dd7
refactor: Use ESM (#8358)
* wip

* wip

* fix

* clean up

* Update tsconfig.json

* Update activitypub.ts

* wip
2022-02-27 11:07:39 +09:00

27 lines
1.1 KiB
TypeScript

import { publishUserListStream } from '@/services/stream.js';
import { User } from '@/models/entities/user.js';
import { UserList } from '@/models/entities/user-list.js';
import { UserListJoinings, Users } from '@/models/index.js';
import { UserListJoining } from '@/models/entities/user-list-joining.js';
import { genId } from '@/misc/gen-id.js';
import { fetchProxyAccount } from '@/misc/fetch-proxy-account.js';
import createFollowing from '../following/create.js';
export async function pushUserToUserList(target: User, list: UserList) {
await UserListJoinings.insert({
id: genId(),
createdAt: new Date(),
userId: target.id,
userListId: list.id,
} as UserListJoining);
publishUserListStream(list.id, 'userAdded', await Users.pack(target));
// このインスタンス内にこのリモートユーザーをフォローしているユーザーがいなくても投稿を受け取るためにダミーのユーザーがフォローしたということにする
if (Users.isRemoteUser(target)) {
const proxy = await fetchProxyAccount();
if (proxy) {
createFollowing(proxy, target);
}
}
}