Implement Channel Watching
This commit is contained in:
parent
2b3937d731
commit
d6b03c43eb
9 changed files with 244 additions and 27 deletions
|
|
@ -5,6 +5,7 @@ import * as mongo from 'mongodb';
|
|||
import deepcopy = require('deepcopy');
|
||||
import { IUser } from '../models/user';
|
||||
import { default as Channel, IChannel } from '../models/channel';
|
||||
import Watching from '../models/channel-watching';
|
||||
|
||||
/**
|
||||
* Serialize a channel
|
||||
|
|
@ -40,5 +41,26 @@ export default (
|
|||
// Remove needless properties
|
||||
delete _channel.user_id;
|
||||
|
||||
// Me
|
||||
const meId: mongo.ObjectID = me
|
||||
? mongo.ObjectID.prototype.isPrototypeOf(me)
|
||||
? me as mongo.ObjectID
|
||||
: typeof me === 'string'
|
||||
? new mongo.ObjectID(me)
|
||||
: (me as IUser)._id
|
||||
: null;
|
||||
|
||||
if (me) {
|
||||
//#region Watchしているかどうか
|
||||
const watch = await Watching.findOne({
|
||||
user_id: meId,
|
||||
channel_id: _channel.id,
|
||||
deleted_at: { $exists: false }
|
||||
});
|
||||
|
||||
_channel.is_watching = watch !== null;
|
||||
//#endregion
|
||||
}
|
||||
|
||||
resolve(_channel);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue