User blocking (Following part) (#3035)

* block wip

* UndoBlock

* UnBlock

* wip

* follow

* UI

* fix
This commit is contained in:
MeiMei
2018-10-29 20:32:42 +09:00
committed by syuilo
parent bcb0588409
commit d64dc45899
17 changed files with 537 additions and 4 deletions

41
src/models/blocking.ts Normal file
View File

@ -0,0 +1,41 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
import isObjectId from '../misc/is-objectid';
const Blocking = db.get<IBlocking>('blocking');
Blocking.createIndex(['blockerId', 'blockeeId'], { unique: true });
export default Blocking;
export type IBlocking = {
_id: mongo.ObjectID;
createdAt: Date;
blockeeId: mongo.ObjectID;
blockerId: mongo.ObjectID;
};
/**
* Blockingを物理削除します
*/
export async function deleteBlocking(blocking: string | mongo.ObjectID | IBlocking) {
let f: IBlocking;
// Populate
if (isObjectId(blocking)) {
f = await Blocking.findOne({
_id: blocking
});
} else if (typeof blocking === 'string') {
f = await Blocking.findOne({
_id: new mongo.ObjectID(blocking)
});
} else {
f = blocking as IBlocking;
}
if (f == null) return;
// このBlockingを削除
await Blocking.remove({
_id: f._id
});
}

View File

@ -6,6 +6,7 @@ import db from '../db/mongodb';
import isObjectId from '../misc/is-objectid';
import Note, { packMany as packNoteMany, deleteNote } from './note';
import Following, { deleteFollowing } from './following';
import Blocking, { deleteBlocking } from './blocking';
import Mute, { deleteMute } from './mute';
import { getFriendIds } from '../server/api/common/get-friends';
import config from '../config';
@ -275,6 +276,16 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) {
await FollowRequest.find({ followeeId: u._id })
).map(x => deleteFollowRequest(x)));
// このユーザーのBlockingをすべて削除
await Promise.all((
await Blocking.find({ blockerId: u._id })
).map(x => deleteBlocking(x)));
// このユーザーへのBlockingをすべて削除
await Promise.all((
await Blocking.find({ blockeeId: u._id })
).map(x => deleteBlocking(x)));
// このユーザーのSwSubscriptionをすべて削除
await Promise.all((
await SwSubscription.find({ userId: u._id })
@ -427,7 +438,7 @@ export const pack = (
}
if (meId && !meId.equals(_user.id)) {
const [following1, following2, followReq1, followReq2, mute] = await Promise.all([
const [following1, following2, followReq1, followReq2, toBlocking, fromBlocked, mute] = await Promise.all([
Following.findOne({
followerId: meId,
followeeId: _user.id
@ -444,6 +455,14 @@ export const pack = (
followerId: _user.id,
followeeId: meId
}),
Blocking.findOne({
blockerId: meId,
blockeeId: _user.id
}),
Blocking.findOne({
blockerId: _user.id,
blockeeId: meId
}),
Mute.findOne({
muterId: meId,
muteeId: _user.id
@ -460,6 +479,12 @@ export const pack = (
// Whether the user is followed
_user.isFollowed = following2 !== null;
// Whether the user is blocking
_user.isBlocking = toBlocking !== null;
// Whether the user is blocked
_user.isBlocked = fromBlocked !== null;
// Whether the user is muted
_user.isMuted = mute !== null;
}