mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-24 15:43:18 +02:00
wip
This commit is contained in:
parent
9fdb125960
commit
9599a31239
2 changed files with 71 additions and 0 deletions
50
src/models/follow-requests.ts
Normal file
50
src/models/follow-requests.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import db from '../db/mongodb';
|
||||
|
||||
const FollowRequest = db.get<IFollowRequest>('followRequests');
|
||||
FollowRequest.createIndex(['followerId', 'followeeId'], { unique: true });
|
||||
export default FollowRequest;
|
||||
|
||||
export type IFollowRequest = {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
followeeId: mongo.ObjectID;
|
||||
followerId: mongo.ObjectID;
|
||||
|
||||
// 非正規化
|
||||
_followee: {
|
||||
host: string;
|
||||
inbox?: string;
|
||||
},
|
||||
_follower: {
|
||||
host: string;
|
||||
inbox?: string;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* FollowRequestを物理削除します
|
||||
*/
|
||||
export async function deleteFollowRequest(followRequest: string | mongo.ObjectID | IFollowRequest) {
|
||||
let f: IFollowRequest;
|
||||
|
||||
// Populate
|
||||
if (mongo.ObjectID.prototype.isPrototypeOf(followRequest)) {
|
||||
f = await FollowRequest.findOne({
|
||||
_id: followRequest
|
||||
});
|
||||
} else if (typeof followRequest === 'string') {
|
||||
f = await FollowRequest.findOne({
|
||||
_id: new mongo.ObjectID(followRequest)
|
||||
});
|
||||
} else {
|
||||
f = followRequest as IFollowRequest;
|
||||
}
|
||||
|
||||
if (f == null) return;
|
||||
|
||||
// このFollowingを削除
|
||||
await FollowRequest.remove({
|
||||
_id: f._id
|
||||
});
|
||||
}
|
|
@ -22,6 +22,7 @@ import FollowedLog, { deleteFollowedLog } from './followed-log';
|
|||
import SwSubscription, { deleteSwSubscription } from './sw-subscription';
|
||||
import Notification, { deleteNotification } from './notification';
|
||||
import UserList, { deleteUserList } from './user-list';
|
||||
import FollowRequest, { deleteFollowRequest } from './follow-requests';
|
||||
|
||||
const User = db.get<IUser>('users');
|
||||
|
||||
|
@ -50,7 +51,17 @@ type IUserBase = {
|
|||
data: any;
|
||||
description: string;
|
||||
pinnedNoteId: mongo.ObjectID;
|
||||
|
||||
/**
|
||||
* 凍結されているか否か
|
||||
*/
|
||||
isSuspended: boolean;
|
||||
|
||||
/**
|
||||
* 鍵アカウントか否か
|
||||
*/
|
||||
isLocked: boolean;
|
||||
|
||||
host: string;
|
||||
};
|
||||
|
||||
|
@ -240,6 +251,16 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) {
|
|||
await Following.find({ followeeId: u._id })
|
||||
).map(x => deleteFollowing(x)));
|
||||
|
||||
// このユーザーのFollowRequestをすべて削除
|
||||
await Promise.all((
|
||||
await FollowRequest.find({ followerId: u._id })
|
||||
).map(x => deleteFollowRequest(x)));
|
||||
|
||||
// このユーザーへのFollowRequestをすべて削除
|
||||
await Promise.all((
|
||||
await FollowRequest.find({ followeeId: u._id })
|
||||
).map(x => deleteFollowRequest(x)));
|
||||
|
||||
// このユーザーのFollowingLogをすべて削除
|
||||
await Promise.all((
|
||||
await FollowingLog.find({ userId: u._id })
|
||||
|
|
Loading…
Reference in a new issue