ストーキング実装

Closes #1511
This commit is contained in:
syuilo
2018-04-19 12:43:25 +09:00
parent d403869945
commit 0d5bc3be66
22 changed files with 310 additions and 80 deletions

View File

@@ -13,7 +13,18 @@ export default async function(follower: IUser, followee: IUser, activity?) {
const following = await Following.insert({
createdAt: new Date(),
followerId: follower._id,
followeeId: followee._id
followeeId: followee._id,
stalk: true,
// 非正規化
_follower: {
host: follower.host,
inbox: isRemoteUser(follower) ? follower.inbox : undefined
},
_followee: {
host: followee.host,
inbox: isRemoteUser(followee) ? followee.inbox : undefined
}
});
//#region Increment following count

View File

@@ -124,19 +124,8 @@ export default async (user: IUser, data: {
publishGlobalTimelineStream(noteObj);
// Fetch all followers
const followers = await Following.aggregate([{
$lookup: {
from: 'users',
localField: 'followerId',
foreignField: '_id',
as: 'user'
}
}, {
$match: {
followeeId: note.userId
}
}], {
_id: false
const followers = await Following.find({
followeeId: note.userId
});
if (!silent) {
@@ -157,12 +146,15 @@ export default async (user: IUser, data: {
deliver(user, await render(), data.renote._user.inbox);
}
Promise.all(followers.map(async follower => {
follower = follower.user[0];
Promise.all(followers.map(async following => {
const follower = following._follower;
if (isLocalUser(follower)) {
// この投稿が返信かつstalkフォローでないならスキップ
if (note.replyId && !following.stalk) return;
// Publish event to followers stream
stream(follower._id, 'note', noteObj);
stream(following.followerId, 'note', noteObj);
} else {
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信
if (isLocalUser(user)) {