無駄なAP deliverをしないように (#5589)
* DeliverManager, note/create * recipe * followers delivers * comment * rename * fix * cleanup
This commit is contained in:
parent
b34b728fbb
commit
44ab428803
6 changed files with 182 additions and 153 deletions
|
@ -2,13 +2,13 @@ import config from '../../config';
|
|||
import renderAdd from '../../remote/activitypub/renderer/add';
|
||||
import renderRemove from '../../remote/activitypub/renderer/remove';
|
||||
import { renderActivity } from '../../remote/activitypub/renderer';
|
||||
import { deliver } from '../../queue';
|
||||
import { IdentifiableError } from '../../misc/identifiable-error';
|
||||
import { User, ILocalUser } from '../../models/entities/user';
|
||||
import { User } from '../../models/entities/user';
|
||||
import { Note } from '../../models/entities/note';
|
||||
import { Notes, UserNotePinings, Users, Followings } from '../../models';
|
||||
import { Notes, UserNotePinings, Users } from '../../models';
|
||||
import { UserNotePining } from '../../models/entities/user-note-pinings';
|
||||
import { genId } from '../../misc/gen-id';
|
||||
import { deliverToFollowers } from '../../remote/activitypub/deliver-manager';
|
||||
|
||||
/**
|
||||
* 指定した投稿をピン留めします
|
||||
|
@ -82,36 +82,9 @@ export async function deliverPinnedChange(userId: User['id'], noteId: Note['id']
|
|||
|
||||
if (!Users.isLocalUser(user)) return;
|
||||
|
||||
const queue = await CreateRemoteInboxes(user);
|
||||
|
||||
if (queue.length < 1) return;
|
||||
|
||||
const target = `${config.url}/users/${user.id}/collections/featured`;
|
||||
|
||||
const item = `${config.url}/notes/${noteId}`;
|
||||
const content = renderActivity(isAddition ? renderAdd(user, target, item) : renderRemove(user, target, item));
|
||||
for (const inbox of queue) {
|
||||
deliver(user, content, inbox);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ローカルユーザーのリモートフォロワーのinboxリストを作成する
|
||||
* @param user ローカルユーザー
|
||||
*/
|
||||
async function CreateRemoteInboxes(user: ILocalUser): Promise<string[]> {
|
||||
const followers = await Followings.find({
|
||||
followeeId: user.id
|
||||
});
|
||||
|
||||
const queue: string[] = [];
|
||||
|
||||
for (const following of followers) {
|
||||
if (Followings.isRemoteFollower(following)) {
|
||||
const inbox = following.followerSharedInbox || following.followerInbox;
|
||||
if (!queue.includes(inbox)) queue.push(inbox);
|
||||
}
|
||||
}
|
||||
|
||||
return queue;
|
||||
|
||||
deliverToFollowers(user, content);
|
||||
}
|
||||
|
|
|
@ -1,34 +1,17 @@
|
|||
import renderUpdate from '../../remote/activitypub/renderer/update';
|
||||
import { renderActivity } from '../../remote/activitypub/renderer';
|
||||
import { deliver } from '../../queue';
|
||||
import { Followings, Users } from '../../models';
|
||||
import { Users } from '../../models';
|
||||
import { User } from '../../models/entities/user';
|
||||
import { renderPerson } from '../../remote/activitypub/renderer/person';
|
||||
import { deliverToFollowers } from '../../remote/activitypub/deliver-manager';
|
||||
|
||||
export async function publishToFollowers(userId: User['id']) {
|
||||
const user = await Users.findOne(userId);
|
||||
if (user == null) throw new Error('user not found');
|
||||
|
||||
const followers = await Followings.find({
|
||||
followeeId: user.id
|
||||
});
|
||||
|
||||
const queue: string[] = [];
|
||||
|
||||
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーならUpdateを配信
|
||||
if (Users.isLocalUser(user)) {
|
||||
for (const following of followers) {
|
||||
if (Followings.isRemoteFollower(following)) {
|
||||
const inbox = following.followerSharedInbox || following.followerInbox;
|
||||
if (!queue.includes(inbox)) queue.push(inbox);
|
||||
}
|
||||
}
|
||||
|
||||
if (queue.length > 0) {
|
||||
const content = renderActivity(renderUpdate(await renderPerson(user), user));
|
||||
for (const inbox of queue) {
|
||||
deliver(user, content, inbox);
|
||||
}
|
||||
}
|
||||
const content = renderActivity(renderUpdate(await renderPerson(user), user));
|
||||
deliverToFollowers(user, content);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue