Introduce followed log and following log

This commit is contained in:
Akihiko Odaki 2018-04-02 21:57:36 +09:00
parent 7942f76acb
commit 319e905bf9
14 changed files with 101 additions and 117 deletions

View file

@ -3,6 +3,8 @@ import { sign } from 'http-signature';
import { URL } from 'url';
import User, { isLocalUser, pack as packUser } from '../../models/user';
import Following from '../../models/following';
import FollowingLog from '../../models/following-log';
import FollowedLog from '../../models/followed-log';
import event from '../../publishers/stream';
import notify from '../../publishers/notify';
import context from '../../remote/activitypub/renderer/context';
@ -21,6 +23,11 @@ export default ({ data }, done) => Following.findOne({ _id: data.following }).th
}
}),
promisedFollower.then(({ followingCount }) => FollowingLog.insert({
userId: followerId,
count: followingCount + 1
})),
// Increment followers count
User.update({ _id: followeeId }, {
$inc: {
@ -28,6 +35,11 @@ export default ({ data }, done) => Following.findOne({ _id: data.following }).th
}
}),
promisedFollowee.then(({ followersCount }) => FollowedLog.insert({
userId: followerId,
count: followersCount + 1
})),
// Notify
promisedFollowee.then(followee => followee.host === null ?
notify(followeeId, followerId, 'follow') : null),