iceshrimp-161sh/src/services/following/requests/create.ts
syuilo 023f895728 V10 (#2826)
* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update CHANGELOG.md

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update CHANGELOG.md

* Update CHANGELOG.md

* wip

* Update CHANGELOG.md

* wip

* wip

* wip

* wip
2018-10-07 11:06:17 +09:00

51 lines
1.6 KiB
TypeScript

import User, { isLocalUser, isRemoteUser, pack as packUser, IUser } from '../../../models/user';
import { publishMainStream } from '../../../stream';
import notify from '../../../notify';
import pack from '../../../remote/activitypub/renderer';
import renderFollow from '../../../remote/activitypub/renderer/follow';
import { deliver } from '../../../queue';
import FollowRequest from '../../../models/follow-request';
export default async function(follower: IUser, followee: IUser) {
await FollowRequest.insert({
createdAt: new Date(),
followerId: follower._id,
followeeId: followee._id,
// 非正規化
_follower: {
host: follower.host,
inbox: isRemoteUser(follower) ? follower.inbox : undefined,
sharedInbox: isRemoteUser(follower) ? follower.sharedInbox : undefined
},
_followee: {
host: followee.host,
inbox: isRemoteUser(followee) ? followee.inbox : undefined,
sharedInbox: isRemoteUser(followee) ? followee.sharedInbox : undefined
}
});
await User.update({ _id: followee._id }, {
$inc: {
pendingReceivedFollowRequestsCount: 1
}
});
// Publish receiveRequest event
if (isLocalUser(followee)) {
packUser(follower, followee).then(packed => publishMainStream(followee._id, 'receiveFollowRequest', packed));
packUser(followee, followee, {
detail: true
}).then(packed => publishMainStream(followee._id, 'meUpdated', packed));
// 通知を作成
notify(followee._id, follower._id, 'receiveFollowRequest');
}
if (isLocalUser(follower) && isRemoteUser(followee)) {
const content = pack(renderFollow(follower, followee));
deliver(follower, content, followee.inbox);
}
}