diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2018-10-29 20:32:42 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2018-10-29 20:32:42 +0900 |
| commit | d64dc458999afdc0bfd5f662a583bd1a0f6eebb3 (patch) | |
| tree | 7bafd2682c100ef3badb7dd0d992dbf35930678a /src/models/blocking.ts | |
| parent | Merge branch 'develop' of https://github.com/syuilo/misskey into develop (diff) | |
| download | sharkey-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/blocking.ts')
| -rw-r--r-- | src/models/blocking.ts | 41 |
1 files changed, 41 insertions, 0 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 + }); +} |