summaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2018-10-29 20:32:42 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2018-10-29 20:32:42 +0900
commitd64dc458999afdc0bfd5f662a583bd1a0f6eebb3 (patch)
tree7bafd2682c100ef3badb7dd0d992dbf35930678a /src/models
parentMerge branch 'develop' of https://github.com/syuilo/misskey into develop (diff)
downloadsharkey-d64dc458999afdc0bfd5f662a583bd1a0f6eebb3.tar.gz
sharkey-d64dc458999afdc0bfd5f662a583bd1a0f6eebb3.tar.bz2
sharkey-d64dc458999afdc0bfd5f662a583bd1a0f6eebb3.zip
User blocking (Following part) (#3035)
* block wip * UndoBlock * UnBlock * wip * follow * UI * fix
Diffstat (limited to 'src/models')
-rw-r--r--src/models/blocking.ts41
-rw-r--r--src/models/user.ts27
2 files changed, 67 insertions, 1 deletions
diff --git a/src/models/blocking.ts b/src/models/blocking.ts
new file mode 100644
index 0000000000..9a6e4ce42d
--- /dev/null
+++ b/src/models/blocking.ts
@@ -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
+ });
+}
diff --git a/src/models/user.ts b/src/models/user.ts
index 25c4a9eb0f..e13802595c 100644
--- a/src/models/user.ts
+++ b/src/models/user.ts
@@ -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;
}