mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-29 17:33:02 +00:00
wip
This commit is contained in:
parent
484d17f53f
commit
f14571dc42
4 changed files with 84 additions and 36 deletions
|
@ -2,7 +2,9 @@ import * as mongo from 'mongodb';
|
|||
import User, { IRemoteUser } from '../../../../models/user';
|
||||
import config from '../../../../config';
|
||||
import unfollow from '../../../../services/following/delete';
|
||||
import cancelRequest from '../../../../services/following/requests/cancel';
|
||||
import { IFollow } from '../../type';
|
||||
import FollowRequest from '../../../../models/follow-request';
|
||||
|
||||
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
|
@ -23,5 +25,14 @@ export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
|
|||
throw new Error('フォロー解除しようとしているユーザーはローカルユーザーではありません');
|
||||
}
|
||||
|
||||
await unfollow(actor, followee);
|
||||
const req = await FollowRequest.findOne({
|
||||
followerId: actor._id,
|
||||
followeeId: followee._id
|
||||
});
|
||||
|
||||
if (req) {
|
||||
await cancelRequest(actor, followee);
|
||||
} else {
|
||||
await unfollow(actor, followee);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,44 +8,11 @@ import pack from '../../remote/activitypub/renderer';
|
|||
import renderFollow from '../../remote/activitypub/renderer/follow';
|
||||
import renderAccept from '../../remote/activitypub/renderer/accept';
|
||||
import { deliver } from '../../queue';
|
||||
import FollowRequest from '../../models/follow-request';
|
||||
import createFollowRequest from './requests/create';
|
||||
|
||||
export default async function(follower: IUser, followee: IUser) {
|
||||
if (followee.isLocked) {
|
||||
await FollowRequest.insert({
|
||||
createdAt: new Date(),
|
||||
followerId: follower._id,
|
||||
followeeId: followee._id,
|
||||
|
||||
// 非正規化
|
||||
_follower: {
|
||||
host: follower.host,
|
||||
inbox: isRemoteUser(follower) ? follower.inbox : undefined
|
||||
},
|
||||
_followee: {
|
||||
host: followee.host,
|
||||
inbox: isRemoteUser(followee) ? followee.inbox : undefined
|
||||
}
|
||||
});
|
||||
|
||||
User.update({ _id: followee._id }, {
|
||||
$inc: {
|
||||
pendingReceivedFollowRequestsCount: 1
|
||||
}
|
||||
});
|
||||
|
||||
// Publish reciveRequest event
|
||||
if (isLocalUser(followee)) {
|
||||
packUser(follower, followee).then(packed => event(followee._id, 'reciveRequest', packed)),
|
||||
|
||||
// 通知を作成
|
||||
notify(followee._id, follower._id, 'reciveRequest');
|
||||
}
|
||||
|
||||
if (isLocalUser(follower) && isRemoteUser(followee)) {
|
||||
const content = pack(renderFollow(follower, followee));
|
||||
deliver(follower, content, followee.inbox);
|
||||
}
|
||||
await createFollowRequest(follower, followee);
|
||||
} else {
|
||||
const following = await Following.insert({
|
||||
createdAt: new Date(),
|
||||
|
|
24
src/services/following/requests/cancel.ts
Normal file
24
src/services/following/requests/cancel.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import User, { IUser, isRemoteUser, ILocalUser } from "../../../models/user";
|
||||
import FollowRequest from "../../../models/follow-request";
|
||||
import pack from '../../../remote/activitypub/renderer';
|
||||
import renderFollow from '../../../remote/activitypub/renderer/follow';
|
||||
import renderUndo from '../../../remote/activitypub/renderer/undo';
|
||||
import { deliver } from '../../../queue';
|
||||
|
||||
export default async function(followee: IUser, follower: IUser) {
|
||||
if (isRemoteUser(followee)) {
|
||||
const content = pack(renderUndo(renderFollow(follower, followee)));
|
||||
deliver(follower as ILocalUser, content, followee.inbox);
|
||||
}
|
||||
|
||||
await FollowRequest.remove({
|
||||
followeeId: followee._id,
|
||||
followerId: follower._id
|
||||
});
|
||||
|
||||
User.update({ _id: followee._id }, {
|
||||
$inc: {
|
||||
pendingReceivedFollowRequestsCount: -1
|
||||
}
|
||||
});
|
||||
}
|
46
src/services/following/requests/create.ts
Normal file
46
src/services/following/requests/create.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import User, { isLocalUser, isRemoteUser, pack as packUser, IUser } from '../../../models/user';
|
||||
import event from '../../../publishers/stream';
|
||||
import notify from '../../../publishers/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) {
|
||||
if (!followee.isLocked) throw '対象のアカウントは鍵アカウントではありません';
|
||||
|
||||
await FollowRequest.insert({
|
||||
createdAt: new Date(),
|
||||
followerId: follower._id,
|
||||
followeeId: followee._id,
|
||||
|
||||
// 非正規化
|
||||
_follower: {
|
||||
host: follower.host,
|
||||
inbox: isRemoteUser(follower) ? follower.inbox : undefined
|
||||
},
|
||||
_followee: {
|
||||
host: followee.host,
|
||||
inbox: isRemoteUser(followee) ? followee.inbox : undefined
|
||||
}
|
||||
});
|
||||
|
||||
User.update({ _id: followee._id }, {
|
||||
$inc: {
|
||||
pendingReceivedFollowRequestsCount: 1
|
||||
}
|
||||
});
|
||||
|
||||
// Publish reciveRequest event
|
||||
if (isLocalUser(followee)) {
|
||||
packUser(follower, followee).then(packed => event(followee._id, 'reciveRequest', packed)),
|
||||
|
||||
// 通知を作成
|
||||
notify(followee._id, follower._id, 'reciveRequest');
|
||||
}
|
||||
|
||||
if (isLocalUser(follower) && isRemoteUser(followee)) {
|
||||
const content = pack(renderFollow(follower, followee));
|
||||
deliver(follower, content, followee.inbox);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue