wip
This commit is contained in:
		
							parent
							
								
									7d4d9dbaa6
								
							
						
					
					
						commit
						3d5cdb8d2d
					
				
					 237 changed files with 1661 additions and 1354 deletions
				
			
		| 
						 | 
					@ -55,10 +55,10 @@ export default (req: express.Request) => new Promise<IAuthContext>(async (resolv
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const app = await App
 | 
							const app = await App
 | 
				
			||||||
			.findOne({ _id: accessToken.app_id });
 | 
								.findOne({ _id: accessToken.appId });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const user = await User
 | 
							const user = await User
 | 
				
			||||||
			.findOne({ _id: accessToken.user_id });
 | 
								.findOne({ _id: accessToken.userId });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return resolve({
 | 
							return resolve({
 | 
				
			||||||
			app: app,
 | 
								app: app,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -208,7 +208,7 @@ class SigninContext extends Context {
 | 
				
			||||||
		if (this.temporaryUser == null) {
 | 
							if (this.temporaryUser == null) {
 | 
				
			||||||
			// Fetch user
 | 
								// Fetch user
 | 
				
			||||||
			const user: IUser = await User.findOne({
 | 
								const user: IUser = await User.findOne({
 | 
				
			||||||
				username_lower: query.toLowerCase(),
 | 
									usernameLower: query.toLowerCase(),
 | 
				
			||||||
				host: null
 | 
									host: null
 | 
				
			||||||
			}, {
 | 
								}, {
 | 
				
			||||||
				fields: {
 | 
									fields: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -115,7 +115,7 @@ class LineBot extends BotCore {
 | 
				
			||||||
			actions.push({
 | 
								actions.push({
 | 
				
			||||||
				type: 'uri',
 | 
									type: 'uri',
 | 
				
			||||||
				label: 'Twitterアカウントを見る',
 | 
									label: 'Twitterアカウントを見る',
 | 
				
			||||||
				uri: `https://twitter.com/${user.account.twitter.screen_name}`
 | 
									uri: `https://twitter.com/${user.account.twitter.screenName}`
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -142,7 +142,7 @@ class LineBot extends BotCore {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public async showUserTimelinePostback(userId: string) {
 | 
						public async showUserTimelinePostback(userId: string) {
 | 
				
			||||||
		const tl = await require('../../endpoints/users/posts')({
 | 
							const tl = await require('../../endpoints/users/posts')({
 | 
				
			||||||
			user_id: userId,
 | 
								userId: userId,
 | 
				
			||||||
			limit: 5
 | 
								limit: 5
 | 
				
			||||||
		}, this.user);
 | 
							}, this.user);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -174,7 +174,7 @@ module.exports = async (app: express.Application) => {
 | 
				
			||||||
			const user = await User.findOne({
 | 
								const user = await User.findOne({
 | 
				
			||||||
				host: null,
 | 
									host: null,
 | 
				
			||||||
				'account.line': {
 | 
									'account.line': {
 | 
				
			||||||
					user_id: sourceId
 | 
										userId: sourceId
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -184,7 +184,7 @@ module.exports = async (app: express.Application) => {
 | 
				
			||||||
				User.update(user._id, {
 | 
									User.update(user._id, {
 | 
				
			||||||
					$set: {
 | 
										$set: {
 | 
				
			||||||
						'account.line': {
 | 
											'account.line': {
 | 
				
			||||||
							user_id: sourceId
 | 
												userId: sourceId
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
| 
						 | 
					@ -194,7 +194,7 @@ module.exports = async (app: express.Application) => {
 | 
				
			||||||
				User.update(user._id, {
 | 
									User.update(user._id, {
 | 
				
			||||||
					$set: {
 | 
										$set: {
 | 
				
			||||||
						'account.line': {
 | 
											'account.line': {
 | 
				
			||||||
							user_id: null
 | 
												userId: null
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										306
									
								
								src/api/common/add-file-to-drive.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										306
									
								
								src/api/common/add-file-to-drive.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,306 @@
 | 
				
			||||||
 | 
					import { Buffer } from 'buffer';
 | 
				
			||||||
 | 
					import * as fs from 'fs';
 | 
				
			||||||
 | 
					import * as tmp from 'tmp';
 | 
				
			||||||
 | 
					import * as stream from 'stream';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import * as mongodb from 'mongodb';
 | 
				
			||||||
 | 
					import * as crypto from 'crypto';
 | 
				
			||||||
 | 
					import * as _gm from 'gm';
 | 
				
			||||||
 | 
					import * as debug from 'debug';
 | 
				
			||||||
 | 
					import fileType = require('file-type');
 | 
				
			||||||
 | 
					import prominence = require('prominence');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import DriveFile, { getGridFSBucket } from '../models/drive-file';
 | 
				
			||||||
 | 
					import DriveFolder from '../models/drive-folder';
 | 
				
			||||||
 | 
					import { pack } from '../models/drive-file';
 | 
				
			||||||
 | 
					import event, { publishDriveStream } from '../event';
 | 
				
			||||||
 | 
					import config from '../../conf';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const gm = _gm.subClass({
 | 
				
			||||||
 | 
						imageMagick: true
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const log = debug('misskey:register-drive-file');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const tmpFile = (): Promise<string> => new Promise((resolve, reject) => {
 | 
				
			||||||
 | 
						tmp.file((e, path) => {
 | 
				
			||||||
 | 
							if (e) return reject(e);
 | 
				
			||||||
 | 
							resolve(path);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const addToGridFS = (name: string, readable: stream.Readable, type: string, metadata: any): Promise<any> =>
 | 
				
			||||||
 | 
						getGridFSBucket()
 | 
				
			||||||
 | 
							.then(bucket => new Promise((resolve, reject) => {
 | 
				
			||||||
 | 
								const writeStream = bucket.openUploadStream(name, { contentType: type, metadata });
 | 
				
			||||||
 | 
								writeStream.once('finish', (doc) => { resolve(doc); });
 | 
				
			||||||
 | 
								writeStream.on('error', reject);
 | 
				
			||||||
 | 
								readable.pipe(writeStream);
 | 
				
			||||||
 | 
							}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const addFile = async (
 | 
				
			||||||
 | 
						user: any,
 | 
				
			||||||
 | 
						path: string,
 | 
				
			||||||
 | 
						name: string = null,
 | 
				
			||||||
 | 
						comment: string = null,
 | 
				
			||||||
 | 
						folderId: mongodb.ObjectID = null,
 | 
				
			||||||
 | 
						force: boolean = false
 | 
				
			||||||
 | 
					) => {
 | 
				
			||||||
 | 
						log(`registering ${name} (user: ${user.username}, path: ${path})`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Calculate hash, get content type and get file size
 | 
				
			||||||
 | 
						const [hash, [mime, ext], size] = await Promise.all([
 | 
				
			||||||
 | 
							// hash
 | 
				
			||||||
 | 
							((): Promise<string> => new Promise((res, rej) => {
 | 
				
			||||||
 | 
								const readable = fs.createReadStream(path);
 | 
				
			||||||
 | 
								const hash = crypto.createHash('md5');
 | 
				
			||||||
 | 
								const chunks = [];
 | 
				
			||||||
 | 
								readable
 | 
				
			||||||
 | 
									.on('error', rej)
 | 
				
			||||||
 | 
									.pipe(hash)
 | 
				
			||||||
 | 
									.on('error', rej)
 | 
				
			||||||
 | 
									.on('data', (chunk) => chunks.push(chunk))
 | 
				
			||||||
 | 
									.on('end', () => {
 | 
				
			||||||
 | 
										const buffer = Buffer.concat(chunks);
 | 
				
			||||||
 | 
										res(buffer.toString('hex'));
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
							}))(),
 | 
				
			||||||
 | 
							// mime
 | 
				
			||||||
 | 
							((): Promise<[string, string | null]> => new Promise((res, rej) => {
 | 
				
			||||||
 | 
								const readable = fs.createReadStream(path);
 | 
				
			||||||
 | 
								readable
 | 
				
			||||||
 | 
									.on('error', rej)
 | 
				
			||||||
 | 
									.once('data', (buffer: Buffer) => {
 | 
				
			||||||
 | 
										readable.destroy();
 | 
				
			||||||
 | 
										const type = fileType(buffer);
 | 
				
			||||||
 | 
										if (type) {
 | 
				
			||||||
 | 
											return res([type.mime, type.ext]);
 | 
				
			||||||
 | 
										} else {
 | 
				
			||||||
 | 
											// 種類が同定できなかったら application/octet-stream にする
 | 
				
			||||||
 | 
											return res(['application/octet-stream', null]);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
							}))(),
 | 
				
			||||||
 | 
							// size
 | 
				
			||||||
 | 
							((): Promise<number> => new Promise((res, rej) => {
 | 
				
			||||||
 | 
								fs.stat(path, (err, stats) => {
 | 
				
			||||||
 | 
									if (err) return rej(err);
 | 
				
			||||||
 | 
									res(stats.size);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}))()
 | 
				
			||||||
 | 
						]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log(`hash: ${hash}, mime: ${mime}, ext: ${ext}, size: ${size}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// detect name
 | 
				
			||||||
 | 
						const detectedName: string = name || (ext ? `untitled.${ext}` : 'untitled');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!force) {
 | 
				
			||||||
 | 
							// Check if there is a file with the same hash
 | 
				
			||||||
 | 
							const much = await DriveFile.findOne({
 | 
				
			||||||
 | 
								md5: hash,
 | 
				
			||||||
 | 
								'metadata.userId': user._id
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (much !== null) {
 | 
				
			||||||
 | 
								log('file with same hash is found');
 | 
				
			||||||
 | 
								return much;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								log('file with same hash is not found');
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const [wh, avgColor, folder] = await Promise.all([
 | 
				
			||||||
 | 
							// Width and height (when image)
 | 
				
			||||||
 | 
							(async () => {
 | 
				
			||||||
 | 
								// 画像かどうか
 | 
				
			||||||
 | 
								if (!/^image\/.*$/.test(mime)) {
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								const imageType = mime.split('/')[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// 画像でもPNGかJPEGかGIFでないならスキップ
 | 
				
			||||||
 | 
								if (imageType != 'png' && imageType != 'jpeg' && imageType != 'gif') {
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								log('calculate image width and height...');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Calculate width and height
 | 
				
			||||||
 | 
								const g = gm(fs.createReadStream(path), name);
 | 
				
			||||||
 | 
								const size = await prominence(g).size();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								log(`image width and height is calculated: ${size.width}, ${size.height}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return [size.width, size.height];
 | 
				
			||||||
 | 
							})(),
 | 
				
			||||||
 | 
							// average color (when image)
 | 
				
			||||||
 | 
							(async () => {
 | 
				
			||||||
 | 
								// 画像かどうか
 | 
				
			||||||
 | 
								if (!/^image\/.*$/.test(mime)) {
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								const imageType = mime.split('/')[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// 画像でもPNGかJPEGでないならスキップ
 | 
				
			||||||
 | 
								if (imageType != 'png' && imageType != 'jpeg') {
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								log('calculate average color...');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								const buffer = await prominence(gm(fs.createReadStream(path), name)
 | 
				
			||||||
 | 
									.setFormat('ppm')
 | 
				
			||||||
 | 
									.resize(1, 1)) // 1pxのサイズに縮小して平均色を取得するというハック
 | 
				
			||||||
 | 
									.toBuffer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								const r = buffer.readUInt8(buffer.length - 3);
 | 
				
			||||||
 | 
								const g = buffer.readUInt8(buffer.length - 2);
 | 
				
			||||||
 | 
								const b = buffer.readUInt8(buffer.length - 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								log(`average color is calculated: ${r}, ${g}, ${b}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return [r, g, b];
 | 
				
			||||||
 | 
							})(),
 | 
				
			||||||
 | 
							// folder
 | 
				
			||||||
 | 
							(async () => {
 | 
				
			||||||
 | 
								if (!folderId) {
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								const driveFolder = await DriveFolder.findOne({
 | 
				
			||||||
 | 
									_id: folderId,
 | 
				
			||||||
 | 
									userId: user._id
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
								if (!driveFolder) {
 | 
				
			||||||
 | 
									throw 'folder-not-found';
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return driveFolder;
 | 
				
			||||||
 | 
							})(),
 | 
				
			||||||
 | 
							// usage checker
 | 
				
			||||||
 | 
							(async () => {
 | 
				
			||||||
 | 
								// Calculate drive usage
 | 
				
			||||||
 | 
								const usage = await DriveFile
 | 
				
			||||||
 | 
									.aggregate([{
 | 
				
			||||||
 | 
										$match: { 'metadata.userId': user._id }
 | 
				
			||||||
 | 
									}, {
 | 
				
			||||||
 | 
										$project: {
 | 
				
			||||||
 | 
											length: true
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}, {
 | 
				
			||||||
 | 
										$group: {
 | 
				
			||||||
 | 
											_id: null,
 | 
				
			||||||
 | 
											usage: { $sum: '$length' }
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}])
 | 
				
			||||||
 | 
									.then((aggregates: any[]) => {
 | 
				
			||||||
 | 
										if (aggregates.length > 0) {
 | 
				
			||||||
 | 
											return aggregates[0].usage;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										return 0;
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								log(`drive usage is ${usage}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// If usage limit exceeded
 | 
				
			||||||
 | 
								if (usage + size > user.driveCapacity) {
 | 
				
			||||||
 | 
									throw 'no-free-space';
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})()
 | 
				
			||||||
 | 
						]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const readable = fs.createReadStream(path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const properties = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (wh) {
 | 
				
			||||||
 | 
							properties['width'] = wh[0];
 | 
				
			||||||
 | 
							properties['height'] = wh[1];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (avgColor) {
 | 
				
			||||||
 | 
							properties['avgColor'] = avgColor;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return addToGridFS(detectedName, readable, mime, {
 | 
				
			||||||
 | 
							userId: user._id,
 | 
				
			||||||
 | 
							folderId: folder !== null ? folder._id : null,
 | 
				
			||||||
 | 
							comment: comment,
 | 
				
			||||||
 | 
							properties: properties
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Add file to drive
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param user User who wish to add file
 | 
				
			||||||
 | 
					 * @param file File path or readableStream
 | 
				
			||||||
 | 
					 * @param comment Comment
 | 
				
			||||||
 | 
					 * @param type File type
 | 
				
			||||||
 | 
					 * @param folderId Folder ID
 | 
				
			||||||
 | 
					 * @param force If set to true, forcibly upload the file even if there is a file with the same hash.
 | 
				
			||||||
 | 
					 * @return Object that represents added file
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export default (user: any, file: string | stream.Readable, ...args) => new Promise<any>((resolve, reject) => {
 | 
				
			||||||
 | 
						// Get file path
 | 
				
			||||||
 | 
						new Promise((res: (v: [string, boolean]) => void, rej) => {
 | 
				
			||||||
 | 
							if (typeof file === 'string') {
 | 
				
			||||||
 | 
								res([file, false]);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (typeof file === 'object' && typeof file.read === 'function') {
 | 
				
			||||||
 | 
								tmpFile()
 | 
				
			||||||
 | 
									.then(path => {
 | 
				
			||||||
 | 
										const readable: stream.Readable = file;
 | 
				
			||||||
 | 
										const writable = fs.createWriteStream(path);
 | 
				
			||||||
 | 
										readable
 | 
				
			||||||
 | 
											.on('error', rej)
 | 
				
			||||||
 | 
											.on('end', () => {
 | 
				
			||||||
 | 
												res([path, true]);
 | 
				
			||||||
 | 
											})
 | 
				
			||||||
 | 
											.pipe(writable)
 | 
				
			||||||
 | 
											.on('error', rej);
 | 
				
			||||||
 | 
									})
 | 
				
			||||||
 | 
									.catch(rej);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							rej(new Error('un-compatible file.'));
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						.then(([path, shouldCleanup]): Promise<any> => new Promise((res, rej) => {
 | 
				
			||||||
 | 
							addFile(user, path, ...args)
 | 
				
			||||||
 | 
								.then(file => {
 | 
				
			||||||
 | 
									res(file);
 | 
				
			||||||
 | 
									if (shouldCleanup) {
 | 
				
			||||||
 | 
										fs.unlink(path, (e) => {
 | 
				
			||||||
 | 
											if (e) log(e.stack);
 | 
				
			||||||
 | 
										});
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								.catch(rej);
 | 
				
			||||||
 | 
						}))
 | 
				
			||||||
 | 
						.then(file => {
 | 
				
			||||||
 | 
							log(`drive file has been created ${file._id}`);
 | 
				
			||||||
 | 
							resolve(file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							pack(file).then(serializedFile => {
 | 
				
			||||||
 | 
								// Publish drive_file_created event
 | 
				
			||||||
 | 
								event(user._id, 'drive_file_created', serializedFile);
 | 
				
			||||||
 | 
								publishDriveStream(user._id, 'file_created', serializedFile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Register to search database
 | 
				
			||||||
 | 
								if (config.elasticsearch.enable) {
 | 
				
			||||||
 | 
									const es = require('../../db/elasticsearch');
 | 
				
			||||||
 | 
									es.index({
 | 
				
			||||||
 | 
										index: 'misskey',
 | 
				
			||||||
 | 
										type: 'drive_file',
 | 
				
			||||||
 | 
										id: file._id.toString(),
 | 
				
			||||||
 | 
										body: {
 | 
				
			||||||
 | 
											name: file.name,
 | 
				
			||||||
 | 
											userId: user._id.toString()
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						.catch(reject);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
| 
						 | 
					@ -100,7 +100,7 @@ const addFile = async (
 | 
				
			||||||
		// Check if there is a file with the same hash
 | 
							// Check if there is a file with the same hash
 | 
				
			||||||
		const much = await DriveFile.findOne({
 | 
							const much = await DriveFile.findOne({
 | 
				
			||||||
			md5: hash,
 | 
								md5: hash,
 | 
				
			||||||
			'metadata.user_id': user._id
 | 
								'metadata.userId': user._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (much !== null) {
 | 
							if (much !== null) {
 | 
				
			||||||
| 
						 | 
					@ -172,7 +172,7 @@ const addFile = async (
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			const driveFolder = await DriveFolder.findOne({
 | 
								const driveFolder = await DriveFolder.findOne({
 | 
				
			||||||
				_id: folderId,
 | 
									_id: folderId,
 | 
				
			||||||
				user_id: user._id
 | 
									userId: user._id
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
			if (!driveFolder) {
 | 
								if (!driveFolder) {
 | 
				
			||||||
				throw 'folder-not-found';
 | 
									throw 'folder-not-found';
 | 
				
			||||||
| 
						 | 
					@ -184,7 +184,7 @@ const addFile = async (
 | 
				
			||||||
			// Calculate drive usage
 | 
								// Calculate drive usage
 | 
				
			||||||
			const usage = await DriveFile
 | 
								const usage = await DriveFile
 | 
				
			||||||
				.aggregate([{
 | 
									.aggregate([{
 | 
				
			||||||
					$match: { 'metadata.user_id': user._id }
 | 
										$match: { 'metadata.userId': user._id }
 | 
				
			||||||
				}, {
 | 
									}, {
 | 
				
			||||||
					$project: {
 | 
										$project: {
 | 
				
			||||||
						length: true
 | 
											length: true
 | 
				
			||||||
| 
						 | 
					@ -205,7 +205,7 @@ const addFile = async (
 | 
				
			||||||
			log(`drive usage is ${usage}`);
 | 
								log(`drive usage is ${usage}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// If usage limit exceeded
 | 
								// If usage limit exceeded
 | 
				
			||||||
			if (usage + size > user.drive_capacity) {
 | 
								if (usage + size > user.driveCapacity) {
 | 
				
			||||||
				throw 'no-free-space';
 | 
									throw 'no-free-space';
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		})()
 | 
							})()
 | 
				
			||||||
| 
						 | 
					@ -221,12 +221,12 @@ const addFile = async (
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (averageColor) {
 | 
						if (averageColor) {
 | 
				
			||||||
		properties['average_color'] = averageColor;
 | 
							properties['avgColor'] = averageColor;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return addToGridFS(detectedName, readable, mime, {
 | 
						return addToGridFS(detectedName, readable, mime, {
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		folder_id: folder !== null ? folder._id : null,
 | 
							folderId: folder !== null ? folder._id : null,
 | 
				
			||||||
		comment: comment,
 | 
							comment: comment,
 | 
				
			||||||
		properties: properties
 | 
							properties: properties
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					@ -297,7 +297,7 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi
 | 
				
			||||||
					id: file._id.toString(),
 | 
										id: file._id.toString(),
 | 
				
			||||||
					body: {
 | 
										body: {
 | 
				
			||||||
						name: file.name,
 | 
											name: file.name,
 | 
				
			||||||
						user_id: user._id.toString()
 | 
											userId: user._id.toString()
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,17 +6,17 @@ export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
 | 
				
			||||||
	// SELECT followee
 | 
						// SELECT followee
 | 
				
			||||||
	const myfollowing = await Following
 | 
						const myfollowing = await Following
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			follower_id: me,
 | 
								followerId: me,
 | 
				
			||||||
			// 削除されたドキュメントは除く
 | 
								// 削除されたドキュメントは除く
 | 
				
			||||||
			deleted_at: { $exists: false }
 | 
								deletedAt: { $exists: false }
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			fields: {
 | 
								fields: {
 | 
				
			||||||
				followee_id: true
 | 
									followeeId: true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// ID list of other users who the I follows
 | 
						// ID list of other users who the I follows
 | 
				
			||||||
	const myfollowingIds = myfollowing.map(follow => follow.followee_id);
 | 
						const myfollowingIds = myfollowing.map(follow => follow.followeeId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (includeMe) {
 | 
						if (includeMe) {
 | 
				
			||||||
		myfollowingIds.push(me);
 | 
							myfollowingIds.push(me);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,11 +16,11 @@ export default (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create notification
 | 
						// Create notification
 | 
				
			||||||
	const notification = await Notification.insert(Object.assign({
 | 
						const notification = await Notification.insert(Object.assign({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		notifiee_id: notifiee,
 | 
							notifieeId: notifiee,
 | 
				
			||||||
		notifier_id: notifier,
 | 
							notifierId: notifier,
 | 
				
			||||||
		type: type,
 | 
							type: type,
 | 
				
			||||||
		is_read: false
 | 
							isRead: false
 | 
				
			||||||
	}, content));
 | 
						}, content));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	resolve(notification);
 | 
						resolve(notification);
 | 
				
			||||||
| 
						 | 
					@ -31,14 +31,14 @@ export default (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
 | 
						// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
 | 
				
			||||||
	setTimeout(async () => {
 | 
						setTimeout(async () => {
 | 
				
			||||||
		const fresh = await Notification.findOne({ _id: notification._id }, { is_read: true });
 | 
							const fresh = await Notification.findOne({ _id: notification._id }, { isRead: true });
 | 
				
			||||||
		if (!fresh.is_read) {
 | 
							if (!fresh.isRead) {
 | 
				
			||||||
			//#region ただしミュートしているユーザーからの通知なら無視
 | 
								//#region ただしミュートしているユーザーからの通知なら無視
 | 
				
			||||||
			const mute = await Mute.find({
 | 
								const mute = await Mute.find({
 | 
				
			||||||
				muter_id: notifiee,
 | 
									muterId: notifiee,
 | 
				
			||||||
				deleted_at: { $exists: false }
 | 
									deletedAt: { $exists: false }
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
			const mutedUserIds = mute.map(m => m.mutee_id.toString());
 | 
								const mutedUserIds = mute.map(m => m.muteeId.toString());
 | 
				
			||||||
			if (mutedUserIds.indexOf(notifier.toString()) != -1) {
 | 
								if (mutedUserIds.indexOf(notifier.toString()) != -1) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch
 | 
						// Fetch
 | 
				
			||||||
	const subscriptions = await Subscription.find({
 | 
						const subscriptions = await Subscription.find({
 | 
				
			||||||
		user_id: userId
 | 
							userId: userId
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	subscriptions.forEach(subscription => {
 | 
						subscriptions.forEach(subscription => {
 | 
				
			||||||
| 
						 | 
					@ -41,7 +41,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (err.statusCode == 410) {
 | 
								if (err.statusCode == 410) {
 | 
				
			||||||
				Subscription.remove({
 | 
									Subscription.remove({
 | 
				
			||||||
					user_id: userId,
 | 
										userId: userId,
 | 
				
			||||||
					endpoint: subscription.endpoint,
 | 
										endpoint: subscription.endpoint,
 | 
				
			||||||
					auth: subscription.auth,
 | 
										auth: subscription.auth,
 | 
				
			||||||
					publickey: subscription.publickey
 | 
										publickey: subscription.publickey
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,12 +37,12 @@ export default (
 | 
				
			||||||
	// Update documents
 | 
						// Update documents
 | 
				
			||||||
	await Message.update({
 | 
						await Message.update({
 | 
				
			||||||
		_id: { $in: ids },
 | 
							_id: { $in: ids },
 | 
				
			||||||
		user_id: otherpartyId,
 | 
							userId: otherpartyId,
 | 
				
			||||||
		recipient_id: userId,
 | 
							recipientId: userId,
 | 
				
			||||||
		is_read: false
 | 
							isRead: false
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			is_read: true
 | 
								isRead: true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		multi: true
 | 
							multi: true
 | 
				
			||||||
| 
						 | 
					@ -55,8 +55,8 @@ export default (
 | 
				
			||||||
	// Calc count of my unread messages
 | 
						// Calc count of my unread messages
 | 
				
			||||||
	const count = await Message
 | 
						const count = await Message
 | 
				
			||||||
		.count({
 | 
							.count({
 | 
				
			||||||
			recipient_id: userId,
 | 
								recipientId: userId,
 | 
				
			||||||
			is_read: false
 | 
								isRead: false
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (count == 0) {
 | 
						if (count == 0) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,10 +29,10 @@ export default (
 | 
				
			||||||
	// Update documents
 | 
						// Update documents
 | 
				
			||||||
	await Notification.update({
 | 
						await Notification.update({
 | 
				
			||||||
		_id: { $in: ids },
 | 
							_id: { $in: ids },
 | 
				
			||||||
		is_read: false
 | 
							isRead: false
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			is_read: true
 | 
								isRead: true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		multi: true
 | 
							multi: true
 | 
				
			||||||
| 
						 | 
					@ -41,8 +41,8 @@ export default (
 | 
				
			||||||
	// Calc count of my unread notifications
 | 
						// Calc count of my unread notifications
 | 
				
			||||||
	const count = await Notification
 | 
						const count = await Notification
 | 
				
			||||||
		.count({
 | 
							.count({
 | 
				
			||||||
			notifiee_id: userId,
 | 
								notifieeId: userId,
 | 
				
			||||||
			is_read: false
 | 
								isRead: false
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (count == 0) {
 | 
						if (count == 0) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,15 +3,15 @@ import Watching from '../models/post-watching';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async (me: mongodb.ObjectID, post: object) => {
 | 
					export default async (me: mongodb.ObjectID, post: object) => {
 | 
				
			||||||
	// 自分の投稿はwatchできない
 | 
						// 自分の投稿はwatchできない
 | 
				
			||||||
	if (me.equals((post as any).user_id)) {
 | 
						if (me.equals((post as any).userId)) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if watching now
 | 
						// if watching now
 | 
				
			||||||
	const exist = await Watching.findOne({
 | 
						const exist = await Watching.findOne({
 | 
				
			||||||
		post_id: (post as any)._id,
 | 
							postId: (post as any)._id,
 | 
				
			||||||
		user_id: me,
 | 
							userId: me,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist !== null) {
 | 
						if (exist !== null) {
 | 
				
			||||||
| 
						 | 
					@ -19,8 +19,8 @@ export default async (me: mongodb.ObjectID, post: object) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	await Watching.insert({
 | 
						await Watching.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		post_id: (post as any)._id,
 | 
							postId: (post as any)._id,
 | 
				
			||||||
		user_id: me
 | 
							userId: me
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,23 +18,23 @@ module.exports = params => new Promise(async (res, rej) => {
 | 
				
			||||||
	const datas = await Post
 | 
						const datas = await Post
 | 
				
			||||||
		.aggregate([
 | 
							.aggregate([
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				repost_id: '$repost_id',
 | 
									repostId: '$repostId',
 | 
				
			||||||
				reply_id: '$reply_id',
 | 
									replyId: '$replyId',
 | 
				
			||||||
				created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
									createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				date: {
 | 
									date: {
 | 
				
			||||||
					year: { $year: '$created_at' },
 | 
										year: { $year: '$createdAt' },
 | 
				
			||||||
					month: { $month: '$created_at' },
 | 
										month: { $month: '$createdAt' },
 | 
				
			||||||
					day: { $dayOfMonth: '$created_at' }
 | 
										day: { $dayOfMonth: '$createdAt' }
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				type: {
 | 
									type: {
 | 
				
			||||||
					$cond: {
 | 
										$cond: {
 | 
				
			||||||
						if: { $ne: ['$repost_id', null] },
 | 
											if: { $ne: ['$repostId', null] },
 | 
				
			||||||
						then: 'repost',
 | 
											then: 'repost',
 | 
				
			||||||
						else: {
 | 
											else: {
 | 
				
			||||||
							$cond: {
 | 
												$cond: {
 | 
				
			||||||
								if: { $ne: ['$reply_id', null] },
 | 
													if: { $ne: ['$replyId', null] },
 | 
				
			||||||
								then: 'reply',
 | 
													then: 'reply',
 | 
				
			||||||
								else: 'post'
 | 
													else: 'post'
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params) => new Promise(async (res, rej) => {
 | 
					module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup post
 | 
						// Lookup post
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					@ -27,15 +27,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const datas = await Reaction
 | 
						const datas = await Reaction
 | 
				
			||||||
		.aggregate([
 | 
							.aggregate([
 | 
				
			||||||
			{ $match: { post_id: post._id } },
 | 
								{ $match: { postId: post._id } },
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
									createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				date: {
 | 
									date: {
 | 
				
			||||||
					year: { $year: '$created_at' },
 | 
										year: { $year: '$createdAt' },
 | 
				
			||||||
					month: { $month: '$created_at' },
 | 
										month: { $month: '$createdAt' },
 | 
				
			||||||
					day: { $dayOfMonth: '$created_at' }
 | 
										day: { $dayOfMonth: '$createdAt' }
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $group: {
 | 
								{ $group: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params) => new Promise(async (res, rej) => {
 | 
					module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup post
 | 
						// Lookup post
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					@ -29,10 +29,10 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const reactions = await Reaction
 | 
						const reactions = await Reaction
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			post_id: post._id,
 | 
								postId: post._id,
 | 
				
			||||||
			$or: [
 | 
								$or: [
 | 
				
			||||||
				{ deleted_at: { $exists: false } },
 | 
									{ deletedAt: { $exists: false } },
 | 
				
			||||||
				{ deleted_at: { $gt: startTime } }
 | 
									{ deletedAt: { $gt: startTime } }
 | 
				
			||||||
			]
 | 
								]
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			sort: {
 | 
								sort: {
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			fields: {
 | 
								fields: {
 | 
				
			||||||
				_id: false,
 | 
									_id: false,
 | 
				
			||||||
				post_id: false
 | 
									postId: false
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,7 +55,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
		// day = day.getTime();
 | 
							// day = day.getTime();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const count = reactions.filter(r =>
 | 
							const count = reactions.filter(r =>
 | 
				
			||||||
			r.created_at < day && (r.deleted_at == null || r.deleted_at > day)
 | 
								r.createdAt < day && (r.deletedAt == null || r.deletedAt > day)
 | 
				
			||||||
		).length;
 | 
							).length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		graph.push({
 | 
							graph.push({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,9 +11,9 @@ import Post from '../../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params) => new Promise(async (res, rej) => {
 | 
					module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup post
 | 
						// Lookup post
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					@ -28,13 +28,13 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
		.aggregate([
 | 
							.aggregate([
 | 
				
			||||||
			{ $match: { reply: post._id } },
 | 
								{ $match: { reply: post._id } },
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
									createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				date: {
 | 
									date: {
 | 
				
			||||||
					year: { $year: '$created_at' },
 | 
										year: { $year: '$createdAt' },
 | 
				
			||||||
					month: { $month: '$created_at' },
 | 
										month: { $month: '$createdAt' },
 | 
				
			||||||
					day: { $dayOfMonth: '$created_at' }
 | 
										day: { $dayOfMonth: '$createdAt' }
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $group: {
 | 
								{ $group: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,9 +11,9 @@ import Post from '../../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params) => new Promise(async (res, rej) => {
 | 
					module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup post
 | 
						// Lookup post
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					@ -26,15 +26,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const datas = await Post
 | 
						const datas = await Post
 | 
				
			||||||
		.aggregate([
 | 
							.aggregate([
 | 
				
			||||||
			{ $match: { repost_id: post._id } },
 | 
								{ $match: { repostId: post._id } },
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
									createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				date: {
 | 
									date: {
 | 
				
			||||||
					year: { $year: '$created_at' },
 | 
										year: { $year: '$createdAt' },
 | 
				
			||||||
					month: { $month: '$created_at' },
 | 
										month: { $month: '$createdAt' },
 | 
				
			||||||
					day: { $dayOfMonth: '$created_at' }
 | 
										day: { $dayOfMonth: '$createdAt' }
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $group: {
 | 
								{ $group: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,8 +22,8 @@ module.exports = params => new Promise(async (res, rej) => {
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			fields: {
 | 
								fields: {
 | 
				
			||||||
				_id: false,
 | 
									_id: false,
 | 
				
			||||||
				created_at: true,
 | 
									createdAt: true,
 | 
				
			||||||
				deleted_at: true
 | 
									deletedAt: true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,11 +44,11 @@ module.exports = params => new Promise(async (res, rej) => {
 | 
				
			||||||
		// day = day.getTime();
 | 
							// day = day.getTime();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const total = users.filter(u =>
 | 
							const total = users.filter(u =>
 | 
				
			||||||
			u.created_at < dayEnd && (u.deleted_at == null || u.deleted_at > dayEnd)
 | 
								u.createdAt < dayEnd && (u.deletedAt == null || u.deletedAt > dayEnd)
 | 
				
			||||||
		).length;
 | 
							).length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const created = users.filter(u =>
 | 
							const created = users.filter(u =>
 | 
				
			||||||
			u.created_at < dayEnd && u.created_at > dayStart
 | 
								u.createdAt < dayEnd && u.createdAt > dayStart
 | 
				
			||||||
		).length;
 | 
							).length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		graph.push({
 | 
							graph.push({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,9 +18,9 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$;
 | 
						const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$;
 | 
				
			||||||
	if (limitErr) return rej('invalid limit param');
 | 
						if (limitErr) return rej('invalid limit param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [userId, userIdErr] = $(params.user_id).id().$;
 | 
						const [userId, userIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (userIdErr) return rej('invalid user_id param');
 | 
						if (userIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup user
 | 
						// Lookup user
 | 
				
			||||||
	const user = await User.findOne({
 | 
						const user = await User.findOne({
 | 
				
			||||||
| 
						 | 
					@ -37,25 +37,25 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const datas = await Post
 | 
						const datas = await Post
 | 
				
			||||||
		.aggregate([
 | 
							.aggregate([
 | 
				
			||||||
			{ $match: { user_id: user._id } },
 | 
								{ $match: { userId: user._id } },
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				repost_id: '$repost_id',
 | 
									repostId: '$repostId',
 | 
				
			||||||
				reply_id: '$reply_id',
 | 
									replyId: '$replyId',
 | 
				
			||||||
				created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
									createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				date: {
 | 
									date: {
 | 
				
			||||||
					year: { $year: '$created_at' },
 | 
										year: { $year: '$createdAt' },
 | 
				
			||||||
					month: { $month: '$created_at' },
 | 
										month: { $month: '$createdAt' },
 | 
				
			||||||
					day: { $dayOfMonth: '$created_at' }
 | 
										day: { $dayOfMonth: '$createdAt' }
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				type: {
 | 
									type: {
 | 
				
			||||||
					$cond: {
 | 
										$cond: {
 | 
				
			||||||
						if: { $ne: ['$repost_id', null] },
 | 
											if: { $ne: ['$repostId', null] },
 | 
				
			||||||
						then: 'repost',
 | 
											then: 'repost',
 | 
				
			||||||
						else: {
 | 
											else: {
 | 
				
			||||||
							$cond: {
 | 
												$cond: {
 | 
				
			||||||
								if: { $ne: ['$reply_id', null] },
 | 
													if: { $ne: ['$replyId', null] },
 | 
				
			||||||
								then: 'reply',
 | 
													then: 'reply',
 | 
				
			||||||
								else: 'post'
 | 
													else: 'post'
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Following from '../../../models/following';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params) => new Promise(async (res, rej) => {
 | 
					module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [userId, userIdErr] = $(params.user_id).id().$;
 | 
						const [userId, userIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (userIdErr) return rej('invalid user_id param');
 | 
						if (userIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup user
 | 
						// Lookup user
 | 
				
			||||||
	const user = await User.findOne({
 | 
						const user = await User.findOne({
 | 
				
			||||||
| 
						 | 
					@ -33,17 +33,17 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const following = await Following
 | 
						const following = await Following
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			followee_id: user._id,
 | 
								followeeId: user._id,
 | 
				
			||||||
			$or: [
 | 
								$or: [
 | 
				
			||||||
				{ deleted_at: { $exists: false } },
 | 
									{ deletedAt: { $exists: false } },
 | 
				
			||||||
				{ deleted_at: { $gt: startTime } }
 | 
									{ deletedAt: { $gt: startTime } }
 | 
				
			||||||
			]
 | 
								]
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			_id: false,
 | 
								_id: false,
 | 
				
			||||||
			follower_id: false,
 | 
								followerId: false,
 | 
				
			||||||
			followee_id: false
 | 
								followeeId: false
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			sort: { created_at: -1 }
 | 
								sort: { createdAt: -1 }
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const graph = [];
 | 
						const graph = [];
 | 
				
			||||||
| 
						 | 
					@ -57,7 +57,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
		// day = day.getTime();
 | 
							// day = day.getTime();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const count = following.filter(f =>
 | 
							const count = following.filter(f =>
 | 
				
			||||||
			f.created_at < day && (f.deleted_at == null || f.deleted_at > day)
 | 
								f.createdAt < day && (f.deletedAt == null || f.deletedAt > day)
 | 
				
			||||||
		).length;
 | 
							).length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		graph.push({
 | 
							graph.push({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Following from '../../../models/following';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params) => new Promise(async (res, rej) => {
 | 
					module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [userId, userIdErr] = $(params.user_id).id().$;
 | 
						const [userId, userIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (userIdErr) return rej('invalid user_id param');
 | 
						if (userIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup user
 | 
						// Lookup user
 | 
				
			||||||
	const user = await User.findOne({
 | 
						const user = await User.findOne({
 | 
				
			||||||
| 
						 | 
					@ -33,17 +33,17 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const following = await Following
 | 
						const following = await Following
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			follower_id: user._id,
 | 
								followerId: user._id,
 | 
				
			||||||
			$or: [
 | 
								$or: [
 | 
				
			||||||
				{ deleted_at: { $exists: false } },
 | 
									{ deletedAt: { $exists: false } },
 | 
				
			||||||
				{ deleted_at: { $gt: startTime } }
 | 
									{ deletedAt: { $gt: startTime } }
 | 
				
			||||||
			]
 | 
								]
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			_id: false,
 | 
								_id: false,
 | 
				
			||||||
			follower_id: false,
 | 
								followerId: false,
 | 
				
			||||||
			followee_id: false
 | 
								followeeId: false
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			sort: { created_at: -1 }
 | 
								sort: { createdAt: -1 }
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const graph = [];
 | 
						const graph = [];
 | 
				
			||||||
| 
						 | 
					@ -56,7 +56,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
		day = new Date(day.setHours(23));
 | 
							day = new Date(day.setHours(23));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const count = following.filter(f =>
 | 
							const count = following.filter(f =>
 | 
				
			||||||
			f.created_at < day && (f.deleted_at == null || f.deleted_at > day)
 | 
								f.createdAt < day && (f.deletedAt == null || f.deletedAt > day)
 | 
				
			||||||
		).length;
 | 
							).length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		graph.push({
 | 
							graph.push({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Post from '../../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params) => new Promise(async (res, rej) => {
 | 
					module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [userId, userIdErr] = $(params.user_id).id().$;
 | 
						const [userId, userIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (userIdErr) return rej('invalid user_id param');
 | 
						if (userIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup user
 | 
						// Lookup user
 | 
				
			||||||
	const user = await User.findOne({
 | 
						const user = await User.findOne({
 | 
				
			||||||
| 
						 | 
					@ -31,25 +31,25 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const datas = await Post
 | 
						const datas = await Post
 | 
				
			||||||
		.aggregate([
 | 
							.aggregate([
 | 
				
			||||||
			{ $match: { user_id: user._id } },
 | 
								{ $match: { userId: user._id } },
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				repost_id: '$repost_id',
 | 
									repostId: '$repostId',
 | 
				
			||||||
				reply_id: '$reply_id',
 | 
									replyId: '$replyId',
 | 
				
			||||||
				created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
									createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				date: {
 | 
									date: {
 | 
				
			||||||
					year: { $year: '$created_at' },
 | 
										year: { $year: '$createdAt' },
 | 
				
			||||||
					month: { $month: '$created_at' },
 | 
										month: { $month: '$createdAt' },
 | 
				
			||||||
					day: { $dayOfMonth: '$created_at' }
 | 
										day: { $dayOfMonth: '$createdAt' }
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				type: {
 | 
									type: {
 | 
				
			||||||
					$cond: {
 | 
										$cond: {
 | 
				
			||||||
						if: { $ne: ['$repost_id', null] },
 | 
											if: { $ne: ['$repostId', null] },
 | 
				
			||||||
						then: 'repost',
 | 
											then: 'repost',
 | 
				
			||||||
						else: {
 | 
											else: {
 | 
				
			||||||
							$cond: {
 | 
												$cond: {
 | 
				
			||||||
								if: { $ne: ['$reply_id', null] },
 | 
													if: { $ne: ['$replyId', null] },
 | 
				
			||||||
								then: 'reply',
 | 
													then: 'reply',
 | 
				
			||||||
								else: 'post'
 | 
													else: 'post'
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params) => new Promise(async (res, rej) => {
 | 
					module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [userId, userIdErr] = $(params.user_id).id().$;
 | 
						const [userId, userIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (userIdErr) return rej('invalid user_id param');
 | 
						if (userIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup user
 | 
						// Lookup user
 | 
				
			||||||
	const user = await User.findOne({
 | 
						const user = await User.findOne({
 | 
				
			||||||
| 
						 | 
					@ -31,15 +31,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const datas = await Reaction
 | 
						const datas = await Reaction
 | 
				
			||||||
		.aggregate([
 | 
							.aggregate([
 | 
				
			||||||
			{ $match: { user_id: user._id } },
 | 
								{ $match: { userId: user._id } },
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
									createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $project: {
 | 
								{ $project: {
 | 
				
			||||||
				date: {
 | 
									date: {
 | 
				
			||||||
					year: { $year: '$created_at' },
 | 
										year: { $year: '$createdAt' },
 | 
				
			||||||
					month: { $month: '$created_at' },
 | 
										month: { $month: '$createdAt' },
 | 
				
			||||||
					day: { $dayOfMonth: '$created_at' }
 | 
										day: { $dayOfMonth: '$createdAt' }
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}},
 | 
								}},
 | 
				
			||||||
			{ $group: {
 | 
								{ $group: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@ import App, { isValidNameId, pack } from '../../models/app';
 | 
				
			||||||
 *     parameters:
 | 
					 *     parameters:
 | 
				
			||||||
 *       - $ref: "#/parameters/AccessToken"
 | 
					 *       - $ref: "#/parameters/AccessToken"
 | 
				
			||||||
 *       -
 | 
					 *       -
 | 
				
			||||||
 *         name: name_id
 | 
					 *         name: nameId
 | 
				
			||||||
 *         description: Application unique name
 | 
					 *         description: Application unique name
 | 
				
			||||||
 *         in: formData
 | 
					 *         in: formData
 | 
				
			||||||
 *         required: true
 | 
					 *         required: true
 | 
				
			||||||
| 
						 | 
					@ -66,9 +66,9 @@ import App, { isValidNameId, pack } from '../../models/app';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'name_id' parameter
 | 
						// Get 'nameId' parameter
 | 
				
			||||||
	const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
 | 
						const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$;
 | 
				
			||||||
	if (nameIdErr) return rej('invalid name_id param');
 | 
						if (nameIdErr) return rej('invalid nameId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'name' parameter
 | 
						// Get 'name' parameter
 | 
				
			||||||
	const [name, nameErr] = $(params.name).string().$;
 | 
						const [name, nameErr] = $(params.name).string().$;
 | 
				
			||||||
| 
						 | 
					@ -92,11 +92,11 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create account
 | 
						// Create account
 | 
				
			||||||
	const app = await App.insert({
 | 
						const app = await App.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		name: name,
 | 
							name: name,
 | 
				
			||||||
		name_id: nameId,
 | 
							nameId: nameId,
 | 
				
			||||||
		name_id_lower: nameId.toLowerCase(),
 | 
							nameIdLower: nameId.toLowerCase(),
 | 
				
			||||||
		description: description,
 | 
							description: description,
 | 
				
			||||||
		permission: permission,
 | 
							permission: permission,
 | 
				
			||||||
		callback_url: callbackUrl,
 | 
							callback_url: callbackUrl,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,12 +7,12 @@ import { isValidNameId } from '../../../models/app';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @swagger
 | 
					 * @swagger
 | 
				
			||||||
 * /app/name_id/available:
 | 
					 * /app/nameId/available:
 | 
				
			||||||
 *   post:
 | 
					 *   post:
 | 
				
			||||||
 *     summary: Check available name_id on creation an application
 | 
					 *     summary: Check available nameId on creation an application
 | 
				
			||||||
 *     parameters:
 | 
					 *     parameters:
 | 
				
			||||||
 *       -
 | 
					 *       -
 | 
				
			||||||
 *         name: name_id
 | 
					 *         name: nameId
 | 
				
			||||||
 *         description: Application unique name
 | 
					 *         description: Application unique name
 | 
				
			||||||
 *         in: formData
 | 
					 *         in: formData
 | 
				
			||||||
 *         required: true
 | 
					 *         required: true
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,7 @@ import { isValidNameId } from '../../../models/app';
 | 
				
			||||||
 *           type: object
 | 
					 *           type: object
 | 
				
			||||||
 *           properties:
 | 
					 *           properties:
 | 
				
			||||||
 *             available:
 | 
					 *             available:
 | 
				
			||||||
 *               description: Whether name_id is available
 | 
					 *               description: Whether nameId is available
 | 
				
			||||||
 *               type: boolean
 | 
					 *               type: boolean
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *       default:
 | 
					 *       default:
 | 
				
			||||||
| 
						 | 
					@ -35,20 +35,20 @@ import { isValidNameId } from '../../../models/app';
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Check available name_id of app
 | 
					 * Check available nameId of app
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param {any} params
 | 
					 * @param {any} params
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = async (params) => new Promise(async (res, rej) => {
 | 
					module.exports = async (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'name_id' parameter
 | 
						// Get 'nameId' parameter
 | 
				
			||||||
	const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
 | 
						const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$;
 | 
				
			||||||
	if (nameIdErr) return rej('invalid name_id param');
 | 
						if (nameIdErr) return rej('invalid nameId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get exist
 | 
						// Get exist
 | 
				
			||||||
	const exist = await App
 | 
						const exist = await App
 | 
				
			||||||
		.count({
 | 
							.count({
 | 
				
			||||||
			name_id_lower: nameId.toLowerCase()
 | 
								nameIdLower: nameId.toLowerCase()
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			limit: 1
 | 
								limit: 1
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,15 +9,15 @@ import App, { pack } from '../../models/app';
 | 
				
			||||||
 * /app/show:
 | 
					 * /app/show:
 | 
				
			||||||
 *   post:
 | 
					 *   post:
 | 
				
			||||||
 *     summary: Show an application's information
 | 
					 *     summary: Show an application's information
 | 
				
			||||||
 *     description: Require app_id or name_id
 | 
					 *     description: Require appId or nameId
 | 
				
			||||||
 *     parameters:
 | 
					 *     parameters:
 | 
				
			||||||
 *       -
 | 
					 *       -
 | 
				
			||||||
 *         name: app_id
 | 
					 *         name: appId
 | 
				
			||||||
 *         description: Application ID
 | 
					 *         description: Application ID
 | 
				
			||||||
 *         in: formData
 | 
					 *         in: formData
 | 
				
			||||||
 *         type: string
 | 
					 *         type: string
 | 
				
			||||||
 *       -
 | 
					 *       -
 | 
				
			||||||
 *         name: name_id
 | 
					 *         name: nameId
 | 
				
			||||||
 *         description: Application unique name
 | 
					 *         description: Application unique name
 | 
				
			||||||
 *         in: formData
 | 
					 *         in: formData
 | 
				
			||||||
 *         type: string
 | 
					 *         type: string
 | 
				
			||||||
| 
						 | 
					@ -44,22 +44,22 @@ import App, { pack } from '../../models/app';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'app_id' parameter
 | 
						// Get 'appId' parameter
 | 
				
			||||||
	const [appId, appIdErr] = $(params.app_id).optional.id().$;
 | 
						const [appId, appIdErr] = $(params.appId).optional.id().$;
 | 
				
			||||||
	if (appIdErr) return rej('invalid app_id param');
 | 
						if (appIdErr) return rej('invalid appId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'name_id' parameter
 | 
						// Get 'nameId' parameter
 | 
				
			||||||
	const [nameId, nameIdErr] = $(params.name_id).optional.string().$;
 | 
						const [nameId, nameIdErr] = $(params.nameId).optional.string().$;
 | 
				
			||||||
	if (nameIdErr) return rej('invalid name_id param');
 | 
						if (nameIdErr) return rej('invalid nameId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (appId === undefined && nameId === undefined) {
 | 
						if (appId === undefined && nameId === undefined) {
 | 
				
			||||||
		return rej('app_id or name_id is required');
 | 
							return rej('appId or nameId is required');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup app
 | 
						// Lookup app
 | 
				
			||||||
	const app = appId !== undefined
 | 
						const app = appId !== undefined
 | 
				
			||||||
		? await App.findOne({ _id: appId })
 | 
							? await App.findOne({ _id: appId })
 | 
				
			||||||
		: await App.findOne({ name_id_lower: nameId.toLowerCase() });
 | 
							: await App.findOne({ nameIdLower: nameId.toLowerCase() });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (app === null) {
 | 
						if (app === null) {
 | 
				
			||||||
		return rej('app not found');
 | 
							return rej('app not found');
 | 
				
			||||||
| 
						 | 
					@ -67,6 +67,6 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send response
 | 
						// Send response
 | 
				
			||||||
	res(await pack(app, user, {
 | 
						res(await pack(app, user, {
 | 
				
			||||||
		includeSecret: isSecure && app.user_id.equals(user._id)
 | 
							includeSecret: isSecure && app.userId.equals(user._id)
 | 
				
			||||||
	}));
 | 
						}));
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,14 +56,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch exist access token
 | 
						// Fetch exist access token
 | 
				
			||||||
	const exist = await AccessToken.findOne({
 | 
						const exist = await AccessToken.findOne({
 | 
				
			||||||
		app_id: session.app_id,
 | 
							appId: session.appId,
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist === null) {
 | 
						if (exist === null) {
 | 
				
			||||||
		// Lookup app
 | 
							// Lookup app
 | 
				
			||||||
		const app = await App.findOne({
 | 
							const app = await App.findOne({
 | 
				
			||||||
			_id: session.app_id
 | 
								_id: session.appId
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Generate Hash
 | 
							// Generate Hash
 | 
				
			||||||
| 
						 | 
					@ -73,9 +73,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Insert access token doc
 | 
							// Insert access token doc
 | 
				
			||||||
		await AccessToken.insert({
 | 
							await AccessToken.insert({
 | 
				
			||||||
			created_at: new Date(),
 | 
								createdAt: new Date(),
 | 
				
			||||||
			app_id: session.app_id,
 | 
								appId: session.appId,
 | 
				
			||||||
			user_id: user._id,
 | 
								userId: user._id,
 | 
				
			||||||
			token: accessToken,
 | 
								token: accessToken,
 | 
				
			||||||
			hash: hash
 | 
								hash: hash
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
| 
						 | 
					@ -84,7 +84,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Update session
 | 
						// Update session
 | 
				
			||||||
	await AuthSess.update(session._id, {
 | 
						await AuthSess.update(session._id, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			user_id: user._id
 | 
								userId: user._id
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,8 +63,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create session token document
 | 
						// Create session token document
 | 
				
			||||||
	const doc = await AuthSess.insert({
 | 
						const doc = await AuthSess.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		app_id: app._id,
 | 
							appId: app._id,
 | 
				
			||||||
		token: token
 | 
							token: token
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,17 +23,17 @@ import AuthSess, { pack } from '../../../models/auth-session';
 | 
				
			||||||
 *         schema:
 | 
					 *         schema:
 | 
				
			||||||
 *           type: object
 | 
					 *           type: object
 | 
				
			||||||
 *           properties:
 | 
					 *           properties:
 | 
				
			||||||
 *             created_at:
 | 
					 *             createdAt:
 | 
				
			||||||
 *               type: string
 | 
					 *               type: string
 | 
				
			||||||
 *               format: date-time
 | 
					 *               format: date-time
 | 
				
			||||||
 *               description: Date and time of the session creation
 | 
					 *               description: Date and time of the session creation
 | 
				
			||||||
 *             app_id:
 | 
					 *             appId:
 | 
				
			||||||
 *               type: string
 | 
					 *               type: string
 | 
				
			||||||
 *               description: Application ID
 | 
					 *               description: Application ID
 | 
				
			||||||
 *             token:
 | 
					 *             token:
 | 
				
			||||||
 *               type: string
 | 
					 *               type: string
 | 
				
			||||||
 *               description: Session Token
 | 
					 *               description: Session Token
 | 
				
			||||||
 *             user_id:
 | 
					 *             userId:
 | 
				
			||||||
 *               type: string
 | 
					 *               type: string
 | 
				
			||||||
 *               description: ID of user who create the session
 | 
					 *               description: ID of user who create the session
 | 
				
			||||||
 *             app:
 | 
					 *             app:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,21 +71,21 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const session = await AuthSess
 | 
						const session = await AuthSess
 | 
				
			||||||
		.findOne({
 | 
							.findOne({
 | 
				
			||||||
			token: token,
 | 
								token: token,
 | 
				
			||||||
			app_id: app._id
 | 
								appId: app._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (session === null) {
 | 
						if (session === null) {
 | 
				
			||||||
		return rej('session not found');
 | 
							return rej('session not found');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (session.user_id == null) {
 | 
						if (session.userId == null) {
 | 
				
			||||||
		return rej('this session is not allowed yet');
 | 
							return rej('this session is not allowed yet');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Lookup access token
 | 
						// Lookup access token
 | 
				
			||||||
	const accessToken = await AccessToken.findOne({
 | 
						const accessToken = await AccessToken.findOne({
 | 
				
			||||||
		app_id: app._id,
 | 
							appId: app._id,
 | 
				
			||||||
		user_id: session.user_id
 | 
							userId: session.userId
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Delete session
 | 
						// Delete session
 | 
				
			||||||
| 
						 | 
					@ -101,8 +101,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Response
 | 
						// Response
 | 
				
			||||||
	res({
 | 
						res({
 | 
				
			||||||
		access_token: accessToken.token,
 | 
							accessToken: accessToken.token,
 | 
				
			||||||
		user: await pack(session.user_id, null, {
 | 
							user: await pack(session.userId, null, {
 | 
				
			||||||
			detail: true
 | 
								detail: true
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,11 +20,11 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create a channel
 | 
						// Create a channel
 | 
				
			||||||
	const channel = await Channel.insert({
 | 
						const channel = await Channel.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		title: title,
 | 
							title: title,
 | 
				
			||||||
		index: 0,
 | 
							index: 0,
 | 
				
			||||||
		watching_count: 1
 | 
							watchingCount: 1
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Response
 | 
						// Response
 | 
				
			||||||
| 
						 | 
					@ -32,8 +32,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create Watching
 | 
						// Create Watching
 | 
				
			||||||
	await Watching.insert({
 | 
						await Watching.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		channel_id: channel._id
 | 
							channelId: channel._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,9 +30,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		return rej('cannot set since_id and until_id');
 | 
							return rej('cannot set since_id and until_id');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'channel_id' parameter
 | 
						// Get 'channelId' parameter
 | 
				
			||||||
	const [channelId, channelIdErr] = $(params.channel_id).id().$;
 | 
						const [channelId, channelIdErr] = $(params.channelId).id().$;
 | 
				
			||||||
	if (channelIdErr) return rej('invalid channel_id param');
 | 
						if (channelIdErr) return rej('invalid channelId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch channel
 | 
						// Fetch channel
 | 
				
			||||||
	const channel: IChannel = await Channel.findOne({
 | 
						const channel: IChannel = await Channel.findOne({
 | 
				
			||||||
| 
						 | 
					@ -49,7 +49,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		channel_id: channel._id
 | 
							channelId: channel._id
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (sinceId) {
 | 
						if (sinceId) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Channel, { IChannel, pack } from '../../models/channel';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'channel_id' parameter
 | 
						// Get 'channelId' parameter
 | 
				
			||||||
	const [channelId, channelIdErr] = $(params.channel_id).id().$;
 | 
						const [channelId, channelIdErr] = $(params.channelId).id().$;
 | 
				
			||||||
	if (channelIdErr) return rej('invalid channel_id param');
 | 
						if (channelIdErr) return rej('invalid channelId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch channel
 | 
						// Fetch channel
 | 
				
			||||||
	const channel: IChannel = await Channel.findOne({
 | 
						const channel: IChannel = await Channel.findOne({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,9 +13,9 @@ import Watching from '../../models/channel-watching';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'channel_id' parameter
 | 
						// Get 'channelId' parameter
 | 
				
			||||||
	const [channelId, channelIdErr] = $(params.channel_id).id().$;
 | 
						const [channelId, channelIdErr] = $(params.channelId).id().$;
 | 
				
			||||||
	if (channelIdErr) return rej('invalid channel_id param');
 | 
						if (channelIdErr) return rej('invalid channelId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//#region Fetch channel
 | 
						//#region Fetch channel
 | 
				
			||||||
	const channel = await Channel.findOne({
 | 
						const channel = await Channel.findOne({
 | 
				
			||||||
| 
						 | 
					@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//#region Check whether not watching
 | 
						//#region Check whether not watching
 | 
				
			||||||
	const exist = await Watching.findOne({
 | 
						const exist = await Watching.findOne({
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		channel_id: channel._id,
 | 
							channelId: channel._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist === null) {
 | 
						if (exist === null) {
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		_id: exist._id
 | 
							_id: exist._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			deleted_at: new Date()
 | 
								deletedAt: new Date()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,7 +54,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Decrement watching count
 | 
						// Decrement watching count
 | 
				
			||||||
	Channel.update(channel._id, {
 | 
						Channel.update(channel._id, {
 | 
				
			||||||
		$inc: {
 | 
							$inc: {
 | 
				
			||||||
			watching_count: -1
 | 
								watchingCount: -1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,9 +13,9 @@ import Watching from '../../models/channel-watching';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'channel_id' parameter
 | 
						// Get 'channelId' parameter
 | 
				
			||||||
	const [channelId, channelIdErr] = $(params.channel_id).id().$;
 | 
						const [channelId, channelIdErr] = $(params.channelId).id().$;
 | 
				
			||||||
	if (channelIdErr) return rej('invalid channel_id param');
 | 
						if (channelIdErr) return rej('invalid channelId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//#region Fetch channel
 | 
						//#region Fetch channel
 | 
				
			||||||
	const channel = await Channel.findOne({
 | 
						const channel = await Channel.findOne({
 | 
				
			||||||
| 
						 | 
					@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//#region Check whether already watching
 | 
						//#region Check whether already watching
 | 
				
			||||||
	const exist = await Watching.findOne({
 | 
						const exist = await Watching.findOne({
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		channel_id: channel._id,
 | 
							channelId: channel._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist !== null) {
 | 
						if (exist !== null) {
 | 
				
			||||||
| 
						 | 
					@ -41,9 +41,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create Watching
 | 
						// Create Watching
 | 
				
			||||||
	await Watching.insert({
 | 
						await Watching.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		channel_id: channel._id
 | 
							channelId: channel._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send response
 | 
						// Send response
 | 
				
			||||||
| 
						 | 
					@ -52,7 +52,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Increment watching count
 | 
						// Increment watching count
 | 
				
			||||||
	Channel.update(channel._id, {
 | 
						Channel.update(channel._id, {
 | 
				
			||||||
		$inc: {
 | 
							$inc: {
 | 
				
			||||||
			watching_count: 1
 | 
								watchingCount: 1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Calculate drive usage
 | 
						// Calculate drive usage
 | 
				
			||||||
	const usage = ((await DriveFile
 | 
						const usage = ((await DriveFile
 | 
				
			||||||
		.aggregate([
 | 
							.aggregate([
 | 
				
			||||||
			{ $match: { 'metadata.user_id': user._id } },
 | 
								{ $match: { 'metadata.userId': user._id } },
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				$project: {
 | 
									$project: {
 | 
				
			||||||
					length: true
 | 
										length: true
 | 
				
			||||||
| 
						 | 
					@ -31,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		}).usage;
 | 
							}).usage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res({
 | 
						res({
 | 
				
			||||||
		capacity: user.drive_capacity,
 | 
							capacity: user.driveCapacity,
 | 
				
			||||||
		usage: usage
 | 
							usage: usage
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,9 +30,9 @@ module.exports = async (params, user, app) => {
 | 
				
			||||||
		throw 'cannot set since_id and until_id';
 | 
							throw 'cannot set since_id and until_id';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'folder_id' parameter
 | 
						// Get 'folderId' parameter
 | 
				
			||||||
	const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
 | 
						const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
 | 
				
			||||||
	if (folderIdErr) throw 'invalid folder_id param';
 | 
						if (folderIdErr) throw 'invalid folderId param';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'type' parameter
 | 
						// Get 'type' parameter
 | 
				
			||||||
	const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).$;
 | 
						const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).$;
 | 
				
			||||||
| 
						 | 
					@ -43,8 +43,8 @@ module.exports = async (params, user, app) => {
 | 
				
			||||||
		_id: -1
 | 
							_id: -1
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		'metadata.user_id': user._id,
 | 
							'metadata.userId': user._id,
 | 
				
			||||||
		'metadata.folder_id': folderId
 | 
							'metadata.folderId': folderId
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
	if (sinceId) {
 | 
						if (sinceId) {
 | 
				
			||||||
		sort._id = 1;
 | 
							sort._id = 1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,9 +33,9 @@ module.exports = async (file, params, user): Promise<any> => {
 | 
				
			||||||
		name = null;
 | 
							name = null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'folder_id' parameter
 | 
						// Get 'folderId' parameter
 | 
				
			||||||
	const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
 | 
						const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
 | 
				
			||||||
	if (folderIdErr) throw 'invalid folder_id param';
 | 
						if (folderIdErr) throw 'invalid folderId param';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	try {
 | 
						try {
 | 
				
			||||||
		// Create file
 | 
							// Create file
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,16 +16,16 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const [name, nameErr] = $(params.name).string().$;
 | 
						const [name, nameErr] = $(params.name).string().$;
 | 
				
			||||||
	if (nameErr) return rej('invalid name param');
 | 
						if (nameErr) return rej('invalid name param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'folder_id' parameter
 | 
						// Get 'folderId' parameter
 | 
				
			||||||
	const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
 | 
						const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
 | 
				
			||||||
	if (folderIdErr) return rej('invalid folder_id param');
 | 
						if (folderIdErr) return rej('invalid folderId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Issue query
 | 
						// Issue query
 | 
				
			||||||
	const files = await DriveFile
 | 
						const files = await DriveFile
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			filename: name,
 | 
								filename: name,
 | 
				
			||||||
			'metadata.user_id': user._id,
 | 
								'metadata.userId': user._id,
 | 
				
			||||||
			'metadata.folder_id': folderId
 | 
								'metadata.folderId': folderId
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,15 +12,15 @@ import DriveFile, { pack } from '../../../models/drive-file';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = async (params, user) => {
 | 
					module.exports = async (params, user) => {
 | 
				
			||||||
	// Get 'file_id' parameter
 | 
						// Get 'fileId' parameter
 | 
				
			||||||
	const [fileId, fileIdErr] = $(params.file_id).id().$;
 | 
						const [fileId, fileIdErr] = $(params.fileId).id().$;
 | 
				
			||||||
	if (fileIdErr) throw 'invalid file_id param';
 | 
						if (fileIdErr) throw 'invalid fileId param';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch file
 | 
						// Fetch file
 | 
				
			||||||
	const file = await DriveFile
 | 
						const file = await DriveFile
 | 
				
			||||||
		.findOne({
 | 
							.findOne({
 | 
				
			||||||
			_id: fileId,
 | 
								_id: fileId,
 | 
				
			||||||
			'metadata.user_id': user._id
 | 
								'metadata.userId': user._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (file === null) {
 | 
						if (file === null) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,15 +14,15 @@ import { publishDriveStream } from '../../../event';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'file_id' parameter
 | 
						// Get 'fileId' parameter
 | 
				
			||||||
	const [fileId, fileIdErr] = $(params.file_id).id().$;
 | 
						const [fileId, fileIdErr] = $(params.fileId).id().$;
 | 
				
			||||||
	if (fileIdErr) return rej('invalid file_id param');
 | 
						if (fileIdErr) return rej('invalid fileId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch file
 | 
						// Fetch file
 | 
				
			||||||
	const file = await DriveFile
 | 
						const file = await DriveFile
 | 
				
			||||||
		.findOne({
 | 
							.findOne({
 | 
				
			||||||
			_id: fileId,
 | 
								_id: fileId,
 | 
				
			||||||
			'metadata.user_id': user._id
 | 
								'metadata.userId': user._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (file === null) {
 | 
						if (file === null) {
 | 
				
			||||||
| 
						 | 
					@ -34,33 +34,33 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (nameErr) return rej('invalid name param');
 | 
						if (nameErr) return rej('invalid name param');
 | 
				
			||||||
	if (name) file.filename = name;
 | 
						if (name) file.filename = name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'folder_id' parameter
 | 
						// Get 'folderId' parameter
 | 
				
			||||||
	const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
 | 
						const [folderId, folderIdErr] = $(params.folderId).optional.nullable.id().$;
 | 
				
			||||||
	if (folderIdErr) return rej('invalid folder_id param');
 | 
						if (folderIdErr) return rej('invalid folderId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (folderId !== undefined) {
 | 
						if (folderId !== undefined) {
 | 
				
			||||||
		if (folderId === null) {
 | 
							if (folderId === null) {
 | 
				
			||||||
			file.metadata.folder_id = null;
 | 
								file.metadata.folderId = null;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			// Fetch folder
 | 
								// Fetch folder
 | 
				
			||||||
			const folder = await DriveFolder
 | 
								const folder = await DriveFolder
 | 
				
			||||||
				.findOne({
 | 
									.findOne({
 | 
				
			||||||
					_id: folderId,
 | 
										_id: folderId,
 | 
				
			||||||
					user_id: user._id
 | 
										userId: user._id
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (folder === null) {
 | 
								if (folder === null) {
 | 
				
			||||||
				return rej('folder-not-found');
 | 
									return rej('folder-not-found');
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			file.metadata.folder_id = folder._id;
 | 
								file.metadata.folderId = folder._id;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	await DriveFile.update(file._id, {
 | 
						await DriveFile.update(file._id, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			filename: file.filename,
 | 
								filename: file.filename,
 | 
				
			||||||
			'metadata.folder_id': file.metadata.folder_id
 | 
								'metadata.folderId': file.metadata.folderId
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,9 +18,9 @@ module.exports = async (params, user): Promise<any> => {
 | 
				
			||||||
	const [url, urlErr] = $(params.url).string().$;
 | 
						const [url, urlErr] = $(params.url).string().$;
 | 
				
			||||||
	if (urlErr) throw 'invalid url param';
 | 
						if (urlErr) throw 'invalid url param';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'folder_id' parameter
 | 
						// Get 'folderId' parameter
 | 
				
			||||||
	const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
 | 
						const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
 | 
				
			||||||
	if (folderIdErr) throw 'invalid folder_id param';
 | 
						if (folderIdErr) throw 'invalid folderId param';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return pack(await uploadFromUrl(url, user, folderId));
 | 
						return pack(await uploadFromUrl(url, user, folderId));
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,17 +30,17 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		return rej('cannot set since_id and until_id');
 | 
							return rej('cannot set since_id and until_id');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'folder_id' parameter
 | 
						// Get 'folderId' parameter
 | 
				
			||||||
	const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
 | 
						const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
 | 
				
			||||||
	if (folderIdErr) return rej('invalid folder_id param');
 | 
						if (folderIdErr) return rej('invalid folderId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Construct query
 | 
						// Construct query
 | 
				
			||||||
	const sort = {
 | 
						const sort = {
 | 
				
			||||||
		_id: -1
 | 
							_id: -1
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		parent_id: folderId
 | 
							parentId: folderId
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
	if (sinceId) {
 | 
						if (sinceId) {
 | 
				
			||||||
		sort._id = 1;
 | 
							sort._id = 1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,9 +17,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const [name = '無題のフォルダー', nameErr] = $(params.name).optional.string().pipe(isValidFolderName).$;
 | 
						const [name = '無題のフォルダー', nameErr] = $(params.name).optional.string().pipe(isValidFolderName).$;
 | 
				
			||||||
	if (nameErr) return rej('invalid name param');
 | 
						if (nameErr) return rej('invalid name param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'parent_id' parameter
 | 
						// Get 'parentId' parameter
 | 
				
			||||||
	const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
 | 
						const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$;
 | 
				
			||||||
	if (parentIdErr) return rej('invalid parent_id param');
 | 
						if (parentIdErr) return rej('invalid parentId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If the parent folder is specified
 | 
						// If the parent folder is specified
 | 
				
			||||||
	let parent = null;
 | 
						let parent = null;
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		parent = await DriveFolder
 | 
							parent = await DriveFolder
 | 
				
			||||||
			.findOne({
 | 
								.findOne({
 | 
				
			||||||
				_id: parentId,
 | 
									_id: parentId,
 | 
				
			||||||
				user_id: user._id
 | 
									userId: user._id
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (parent === null) {
 | 
							if (parent === null) {
 | 
				
			||||||
| 
						 | 
					@ -38,10 +38,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create folder
 | 
						// Create folder
 | 
				
			||||||
	const folder = await DriveFolder.insert({
 | 
						const folder = await DriveFolder.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		name: name,
 | 
							name: name,
 | 
				
			||||||
		parent_id: parent !== null ? parent._id : null,
 | 
							parentId: parent !== null ? parent._id : null,
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,16 +16,16 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const [name, nameErr] = $(params.name).string().$;
 | 
						const [name, nameErr] = $(params.name).string().$;
 | 
				
			||||||
	if (nameErr) return rej('invalid name param');
 | 
						if (nameErr) return rej('invalid name param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'parent_id' parameter
 | 
						// Get 'parentId' parameter
 | 
				
			||||||
	const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
 | 
						const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$;
 | 
				
			||||||
	if (parentIdErr) return rej('invalid parent_id param');
 | 
						if (parentIdErr) return rej('invalid parentId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Issue query
 | 
						// Issue query
 | 
				
			||||||
	const folders = await DriveFolder
 | 
						const folders = await DriveFolder
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			name: name,
 | 
								name: name,
 | 
				
			||||||
			user_id: user._id,
 | 
								userId: user._id,
 | 
				
			||||||
			parent_id: parentId
 | 
								parentId: parentId
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,15 +12,15 @@ import DriveFolder, { pack } from '../../../models/drive-folder';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'folder_id' parameter
 | 
						// Get 'folderId' parameter
 | 
				
			||||||
	const [folderId, folderIdErr] = $(params.folder_id).id().$;
 | 
						const [folderId, folderIdErr] = $(params.folderId).id().$;
 | 
				
			||||||
	if (folderIdErr) return rej('invalid folder_id param');
 | 
						if (folderIdErr) return rej('invalid folderId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get folder
 | 
						// Get folder
 | 
				
			||||||
	const folder = await DriveFolder
 | 
						const folder = await DriveFolder
 | 
				
			||||||
		.findOne({
 | 
							.findOne({
 | 
				
			||||||
			_id: folderId,
 | 
								_id: folderId,
 | 
				
			||||||
			user_id: user._id
 | 
								userId: user._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (folder === null) {
 | 
						if (folder === null) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,15 +13,15 @@ import { publishDriveStream } from '../../../event';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'folder_id' parameter
 | 
						// Get 'folderId' parameter
 | 
				
			||||||
	const [folderId, folderIdErr] = $(params.folder_id).id().$;
 | 
						const [folderId, folderIdErr] = $(params.folderId).id().$;
 | 
				
			||||||
	if (folderIdErr) return rej('invalid folder_id param');
 | 
						if (folderIdErr) return rej('invalid folderId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch folder
 | 
						// Fetch folder
 | 
				
			||||||
	const folder = await DriveFolder
 | 
						const folder = await DriveFolder
 | 
				
			||||||
		.findOne({
 | 
							.findOne({
 | 
				
			||||||
			_id: folderId,
 | 
								_id: folderId,
 | 
				
			||||||
			user_id: user._id
 | 
								userId: user._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (folder === null) {
 | 
						if (folder === null) {
 | 
				
			||||||
| 
						 | 
					@ -33,18 +33,18 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (nameErr) return rej('invalid name param');
 | 
						if (nameErr) return rej('invalid name param');
 | 
				
			||||||
	if (name) folder.name = name;
 | 
						if (name) folder.name = name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'parent_id' parameter
 | 
						// Get 'parentId' parameter
 | 
				
			||||||
	const [parentId, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
 | 
						const [parentId, parentIdErr] = $(params.parentId).optional.nullable.id().$;
 | 
				
			||||||
	if (parentIdErr) return rej('invalid parent_id param');
 | 
						if (parentIdErr) return rej('invalid parentId param');
 | 
				
			||||||
	if (parentId !== undefined) {
 | 
						if (parentId !== undefined) {
 | 
				
			||||||
		if (parentId === null) {
 | 
							if (parentId === null) {
 | 
				
			||||||
			folder.parent_id = null;
 | 
								folder.parentId = null;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			// Get parent folder
 | 
								// Get parent folder
 | 
				
			||||||
			const parent = await DriveFolder
 | 
								const parent = await DriveFolder
 | 
				
			||||||
				.findOne({
 | 
									.findOne({
 | 
				
			||||||
					_id: parentId,
 | 
										_id: parentId,
 | 
				
			||||||
					user_id: user._id
 | 
										userId: user._id
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (parent === null) {
 | 
								if (parent === null) {
 | 
				
			||||||
| 
						 | 
					@ -58,25 +58,25 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
					_id: folderId
 | 
										_id: folderId
 | 
				
			||||||
				}, {
 | 
									}, {
 | 
				
			||||||
					_id: true,
 | 
										_id: true,
 | 
				
			||||||
					parent_id: true
 | 
										parentId: true
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (folder2._id.equals(folder._id)) {
 | 
									if (folder2._id.equals(folder._id)) {
 | 
				
			||||||
					return true;
 | 
										return true;
 | 
				
			||||||
				} else if (folder2.parent_id) {
 | 
									} else if (folder2.parentId) {
 | 
				
			||||||
					return await checkCircle(folder2.parent_id);
 | 
										return await checkCircle(folder2.parentId);
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					return false;
 | 
										return false;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (parent.parent_id !== null) {
 | 
								if (parent.parentId !== null) {
 | 
				
			||||||
				if (await checkCircle(parent.parent_id)) {
 | 
									if (await checkCircle(parent.parentId)) {
 | 
				
			||||||
					return rej('detected-circular-definition');
 | 
										return rej('detected-circular-definition');
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			folder.parent_id = parent._id;
 | 
								folder.parentId = parent._id;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,7 +84,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	DriveFolder.update(folder._id, {
 | 
						DriveFolder.update(folder._id, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			name: folder.name,
 | 
								name: folder.name,
 | 
				
			||||||
			parent_id: folder.parent_id
 | 
								parentId: folder.parentId
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,7 +38,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		_id: -1
 | 
							_id: -1
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		'metadata.user_id': user._id
 | 
							'metadata.userId': user._id
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
	if (sinceId) {
 | 
						if (sinceId) {
 | 
				
			||||||
		sort._id = 1;
 | 
							sort._id = 1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,9 +17,9 @@ import event from '../../event';
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const follower = user;
 | 
						const follower = user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [userId, userIdErr] = $(params.user_id).id().$;
 | 
						const [userId, userIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (userIdErr) return rej('invalid user_id param');
 | 
						if (userIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 自分自身
 | 
						// 自分自身
 | 
				
			||||||
	if (user._id.equals(userId)) {
 | 
						if (user._id.equals(userId)) {
 | 
				
			||||||
| 
						 | 
					@ -42,9 +42,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if already following
 | 
						// Check if already following
 | 
				
			||||||
	const exist = await Following.findOne({
 | 
						const exist = await Following.findOne({
 | 
				
			||||||
		follower_id: follower._id,
 | 
							followerId: follower._id,
 | 
				
			||||||
		followee_id: followee._id,
 | 
							followeeId: followee._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist !== null) {
 | 
						if (exist !== null) {
 | 
				
			||||||
| 
						 | 
					@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create following
 | 
						// Create following
 | 
				
			||||||
	await Following.insert({
 | 
						await Following.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		follower_id: follower._id,
 | 
							followerId: follower._id,
 | 
				
			||||||
		followee_id: followee._id
 | 
							followeeId: followee._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send response
 | 
						// Send response
 | 
				
			||||||
| 
						 | 
					@ -64,14 +64,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Increment following count
 | 
						// Increment following count
 | 
				
			||||||
	User.update(follower._id, {
 | 
						User.update(follower._id, {
 | 
				
			||||||
		$inc: {
 | 
							$inc: {
 | 
				
			||||||
			following_count: 1
 | 
								followingCount: 1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Increment followers count
 | 
						// Increment followers count
 | 
				
			||||||
	User.update({ _id: followee._id }, {
 | 
						User.update({ _id: followee._id }, {
 | 
				
			||||||
		$inc: {
 | 
							$inc: {
 | 
				
			||||||
			followers_count: 1
 | 
								followersCount: 1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,9 +16,9 @@ import event from '../../event';
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const follower = user;
 | 
						const follower = user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [userId, userIdErr] = $(params.user_id).id().$;
 | 
						const [userId, userIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (userIdErr) return rej('invalid user_id param');
 | 
						if (userIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if the followee is yourself
 | 
						// Check if the followee is yourself
 | 
				
			||||||
	if (user._id.equals(userId)) {
 | 
						if (user._id.equals(userId)) {
 | 
				
			||||||
| 
						 | 
					@ -41,9 +41,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check not following
 | 
						// Check not following
 | 
				
			||||||
	const exist = await Following.findOne({
 | 
						const exist = await Following.findOne({
 | 
				
			||||||
		follower_id: follower._id,
 | 
							followerId: follower._id,
 | 
				
			||||||
		followee_id: followee._id,
 | 
							followeeId: followee._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist === null) {
 | 
						if (exist === null) {
 | 
				
			||||||
| 
						 | 
					@ -55,7 +55,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		_id: exist._id
 | 
							_id: exist._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			deleted_at: new Date()
 | 
								deletedAt: new Date()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,14 +65,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Decrement following count
 | 
						// Decrement following count
 | 
				
			||||||
	User.update({ _id: follower._id }, {
 | 
						User.update({ _id: follower._id }, {
 | 
				
			||||||
		$inc: {
 | 
							$inc: {
 | 
				
			||||||
			following_count: -1
 | 
								followingCount: -1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Decrement followers count
 | 
						// Decrement followers count
 | 
				
			||||||
	User.update({ _id: followee._id }, {
 | 
						User.update({ _id: followee._id }, {
 | 
				
			||||||
		$inc: {
 | 
							$inc: {
 | 
				
			||||||
			followers_count: -1
 | 
								followersCount: -1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,7 +22,7 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
 | 
				
			||||||
	// Update lastUsedAt
 | 
						// Update lastUsedAt
 | 
				
			||||||
	User.update({ _id: user._id }, {
 | 
						User.update({ _id: user._id }, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			'account.last_used_at': new Date()
 | 
								'account.lastUsedAt': new Date()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,12 +12,12 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const _token = token.replace(/\s/g, '');
 | 
						const _token = token.replace(/\s/g, '');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (user.two_factor_temp_secret == null) {
 | 
						if (user.twoFactorTempSecret == null) {
 | 
				
			||||||
		return rej('二段階認証の設定が開始されていません');
 | 
							return rej('二段階認証の設定が開始されていません');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const verified = (speakeasy as any).totp.verify({
 | 
						const verified = (speakeasy as any).totp.verify({
 | 
				
			||||||
		secret: user.two_factor_temp_secret,
 | 
							secret: user.twoFactorTempSecret,
 | 
				
			||||||
		encoding: 'base32',
 | 
							encoding: 'base32',
 | 
				
			||||||
		token: _token
 | 
							token: _token
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					@ -28,8 +28,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	await User.update(user._id, {
 | 
						await User.update(user._id, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			'account.two_factor_secret': user.two_factor_temp_secret,
 | 
								'account.twoFactorSecret': user.twoFactorTempSecret,
 | 
				
			||||||
			'account.two_factor_enabled': true
 | 
								'account.twoFactorEnabled': true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	await User.update(user._id, {
 | 
						await User.update(user._id, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			two_factor_temp_secret: secret.base32
 | 
								twoFactorTempSecret: secret.base32
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,8 +19,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	await User.update(user._id, {
 | 
						await User.update(user._id, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			'account.two_factor_secret': null,
 | 
								'account.twoFactorSecret': null,
 | 
				
			||||||
			'account.two_factor_enabled': false
 | 
								'account.twoFactorEnabled': false
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,8 +25,8 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		select[`data.${key}`] = true;
 | 
							select[`data.${key}`] = true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	const appdata = await Appdata.findOne({
 | 
						const appdata = await Appdata.findOne({
 | 
				
			||||||
		app_id: app._id,
 | 
							appId: app._id,
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		fields: select
 | 
							fields: select
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,11 +43,11 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	await Appdata.update({
 | 
						await Appdata.update({
 | 
				
			||||||
		app_id: app._id,
 | 
							appId: app._id,
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	}, Object.assign({
 | 
						}, Object.assign({
 | 
				
			||||||
		app_id: app._id,
 | 
							appId: app._id,
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
			$set: set
 | 
								$set: set
 | 
				
			||||||
		}), {
 | 
							}), {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get tokens
 | 
						// Get tokens
 | 
				
			||||||
	const tokens = await AccessToken
 | 
						const tokens = await AccessToken
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			user_id: user._id
 | 
								userId: user._id
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			limit: limit,
 | 
								limit: limit,
 | 
				
			||||||
			skip: offset,
 | 
								skip: offset,
 | 
				
			||||||
| 
						 | 
					@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
	res(await Promise.all(tokens.map(async token =>
 | 
						res(await Promise.all(tokens.map(async token =>
 | 
				
			||||||
		await pack(token.app_id))));
 | 
							await pack(token.appId))));
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get favorites
 | 
						// Get favorites
 | 
				
			||||||
	const favorites = await Favorite
 | 
						const favorites = await Favorite
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			user_id: user._id
 | 
								userId: user._id
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			limit: limit,
 | 
								limit: limit,
 | 
				
			||||||
			skip: offset,
 | 
								skip: offset,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const mute = await Mute.find({
 | 
						const mute = await Mute.find({
 | 
				
			||||||
		muter_id: user._id,
 | 
							muterId: user._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		notifiee_id: user._id,
 | 
							notifieeId: user._id,
 | 
				
			||||||
		$and: [{
 | 
							$and: [{
 | 
				
			||||||
			notifier_id: {
 | 
								notifierId: {
 | 
				
			||||||
				$nin: mute.map(m => m.mutee_id)
 | 
									$nin: mute.map(m => m.muteeId)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}]
 | 
							}]
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
| 
						 | 
					@ -69,7 +69,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		const followingIds = await getFriends(user._id);
 | 
							const followingIds = await getFriends(user._id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		query.$and.push({
 | 
							query.$and.push({
 | 
				
			||||||
			notifier_id: {
 | 
								notifierId: {
 | 
				
			||||||
				$in: followingIds
 | 
									$in: followingIds
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,14 +14,14 @@ import { pack } from '../../models/user';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch pinee
 | 
						// Fetch pinee
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
		_id: postId,
 | 
							_id: postId,
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (post === null) {
 | 
						if (post === null) {
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	await User.update(user._id, {
 | 
						await User.update(user._id, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			pinned_post_id: post._id
 | 
								pinnedPostId: post._id
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const sort = {
 | 
						const sort = {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,20 +36,20 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
 | 
				
			||||||
	if (birthdayErr) return rej('invalid birthday param');
 | 
						if (birthdayErr) return rej('invalid birthday param');
 | 
				
			||||||
	if (birthday !== undefined) user.account.profile.birthday = birthday;
 | 
						if (birthday !== undefined) user.account.profile.birthday = birthday;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'avatar_id' parameter
 | 
						// Get 'avatarId' parameter
 | 
				
			||||||
	const [avatarId, avatarIdErr] = $(params.avatar_id).optional.id().$;
 | 
						const [avatarId, avatarIdErr] = $(params.avatarId).optional.id().$;
 | 
				
			||||||
	if (avatarIdErr) return rej('invalid avatar_id param');
 | 
						if (avatarIdErr) return rej('invalid avatarId param');
 | 
				
			||||||
	if (avatarId) user.avatar_id = avatarId;
 | 
						if (avatarId) user.avatarId = avatarId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'banner_id' parameter
 | 
						// Get 'bannerId' parameter
 | 
				
			||||||
	const [bannerId, bannerIdErr] = $(params.banner_id).optional.id().$;
 | 
						const [bannerId, bannerIdErr] = $(params.bannerId).optional.id().$;
 | 
				
			||||||
	if (bannerIdErr) return rej('invalid banner_id param');
 | 
						if (bannerIdErr) return rej('invalid bannerId param');
 | 
				
			||||||
	if (bannerId) user.banner_id = bannerId;
 | 
						if (bannerId) user.bannerId = bannerId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'is_bot' parameter
 | 
						// Get 'isBot' parameter
 | 
				
			||||||
	const [isBot, isBotErr] = $(params.is_bot).optional.boolean().$;
 | 
						const [isBot, isBotErr] = $(params.isBot).optional.boolean().$;
 | 
				
			||||||
	if (isBotErr) return rej('invalid is_bot param');
 | 
						if (isBotErr) return rej('invalid isBot param');
 | 
				
			||||||
	if (isBot != null) user.account.is_bot = isBot;
 | 
						if (isBot != null) user.account.isBot = isBot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'auto_watch' parameter
 | 
						// Get 'auto_watch' parameter
 | 
				
			||||||
	const [autoWatch, autoWatchErr] = $(params.auto_watch).optional.boolean().$;
 | 
						const [autoWatch, autoWatchErr] = $(params.auto_watch).optional.boolean().$;
 | 
				
			||||||
| 
						 | 
					@ -60,10 +60,10 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			name: user.name,
 | 
								name: user.name,
 | 
				
			||||||
			description: user.description,
 | 
								description: user.description,
 | 
				
			||||||
			avatar_id: user.avatar_id,
 | 
								avatarId: user.avatarId,
 | 
				
			||||||
			banner_id: user.banner_id,
 | 
								bannerId: user.bannerId,
 | 
				
			||||||
			'account.profile': user.account.profile,
 | 
								'account.profile': user.account.profile,
 | 
				
			||||||
			'account.is_bot': user.account.is_bot,
 | 
								'account.isBot': user.account.isBot,
 | 
				
			||||||
			'account.settings': user.account.settings
 | 
								'account.settings': user.account.settings
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,14 +22,14 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (valueErr) return rej('invalid value param');
 | 
						if (valueErr) return rej('invalid value param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const x = {};
 | 
						const x = {};
 | 
				
			||||||
	x[`account.client_settings.${name}`] = value;
 | 
						x[`account.clientSettings.${name}`] = value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	await User.update(user._id, {
 | 
						await User.update(user._id, {
 | 
				
			||||||
		$set: x
 | 
							$set: x
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
	user.account.client_settings[name] = value;
 | 
						user.account.clientSettings[name] = value;
 | 
				
			||||||
	const iObj = await pack(user, user, {
 | 
						const iObj = await pack(user, user, {
 | 
				
			||||||
		detail: true,
 | 
							detail: true,
 | 
				
			||||||
		includeSecrets: true
 | 
							includeSecrets: true
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (home) {
 | 
						if (home) {
 | 
				
			||||||
		await User.update(user._id, {
 | 
							await User.update(user._id, {
 | 
				
			||||||
			$set: {
 | 
								$set: {
 | 
				
			||||||
				'account.client_settings.home': home
 | 
									'account.clientSettings.home': home
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,7 +38,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if (id == null && data == null) return rej('you need to set id and data params if home param unset');
 | 
							if (id == null && data == null) return rej('you need to set id and data params if home param unset');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const _home = user.account.client_settings.home;
 | 
							const _home = user.account.clientSettings.home;
 | 
				
			||||||
		const widget = _home.find(w => w.id == id);
 | 
							const widget = _home.find(w => w.id == id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (widget == null) return rej('widget not found');
 | 
							if (widget == null) return rej('widget not found');
 | 
				
			||||||
| 
						 | 
					@ -47,7 +47,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		await User.update(user._id, {
 | 
							await User.update(user._id, {
 | 
				
			||||||
			$set: {
 | 
								$set: {
 | 
				
			||||||
				'account.client_settings.home': _home
 | 
									'account.clientSettings.home': _home
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (home) {
 | 
						if (home) {
 | 
				
			||||||
		await User.update(user._id, {
 | 
							await User.update(user._id, {
 | 
				
			||||||
			$set: {
 | 
								$set: {
 | 
				
			||||||
				'account.client_settings.mobile_home': home
 | 
									'account.clientSettings.mobile_home': home
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if (id == null && data == null) return rej('you need to set id and data params if home param unset');
 | 
							if (id == null && data == null) return rej('you need to set id and data params if home param unset');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const _home = user.account.client_settings.mobile_home || [];
 | 
							const _home = user.account.clientSettings.mobile_home || [];
 | 
				
			||||||
		const widget = _home.find(w => w.id == id);
 | 
							const widget = _home.find(w => w.id == id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (widget == null) return rej('widget not found');
 | 
							if (widget == null) return rej('widget not found');
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		await User.update(user._id, {
 | 
							await User.update(user._id, {
 | 
				
			||||||
			$set: {
 | 
								$set: {
 | 
				
			||||||
				'account.client_settings.mobile_home': _home
 | 
									'account.clientSettings.mobile_home': _home
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,25 +19,25 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (limitErr) return rej('invalid limit param');
 | 
						if (limitErr) return rej('invalid limit param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const mute = await Mute.find({
 | 
						const mute = await Mute.find({
 | 
				
			||||||
		muter_id: user._id,
 | 
							muterId: user._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get history
 | 
						// Get history
 | 
				
			||||||
	const history = await History
 | 
						const history = await History
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			user_id: user._id,
 | 
								userId: user._id,
 | 
				
			||||||
			partner: {
 | 
								partnerId: {
 | 
				
			||||||
				$nin: mute.map(m => m.mutee_id)
 | 
									$nin: mute.map(m => m.muteeId)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			limit: limit,
 | 
								limit: limit,
 | 
				
			||||||
			sort: {
 | 
								sort: {
 | 
				
			||||||
				updated_at: -1
 | 
									updatedAt: -1
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
	res(await Promise.all(history.map(async h =>
 | 
						res(await Promise.all(history.map(async h =>
 | 
				
			||||||
		await pack(h.message, user))));
 | 
							await pack(h.messageId, user))));
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,9 +15,9 @@ import read from '../../common/read-messaging-message';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [recipientId, recipientIdErr] = $(params.user_id).id().$;
 | 
						const [recipientId, recipientIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (recipientIdErr) return rej('invalid user_id param');
 | 
						if (recipientIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch recipient
 | 
						// Fetch recipient
 | 
				
			||||||
	const recipient = await User.findOne({
 | 
						const recipient = await User.findOne({
 | 
				
			||||||
| 
						 | 
					@ -55,11 +55,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		$or: [{
 | 
							$or: [{
 | 
				
			||||||
			user_id: user._id,
 | 
								userId: user._id,
 | 
				
			||||||
			recipient_id: recipient._id
 | 
								recipientId: recipient._id
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			user_id: recipient._id,
 | 
								userId: recipient._id,
 | 
				
			||||||
			recipient_id: user._id
 | 
								recipientId: user._id
 | 
				
			||||||
		}]
 | 
							}]
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,9 +21,9 @@ import config from '../../../../conf';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [recipientId, recipientIdErr] = $(params.user_id).id().$;
 | 
						const [recipientId, recipientIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (recipientIdErr) return rej('invalid user_id param');
 | 
						if (recipientIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Myself
 | 
						// Myself
 | 
				
			||||||
	if (recipientId.equals(user._id)) {
 | 
						if (recipientId.equals(user._id)) {
 | 
				
			||||||
| 
						 | 
					@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
 | 
						const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
 | 
				
			||||||
	if (textErr) return rej('invalid text');
 | 
						if (textErr) return rej('invalid text');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'file_id' parameter
 | 
						// Get 'fileId' parameter
 | 
				
			||||||
	const [fileId, fileIdErr] = $(params.file_id).optional.id().$;
 | 
						const [fileId, fileIdErr] = $(params.fileId).optional.id().$;
 | 
				
			||||||
	if (fileIdErr) return rej('invalid file_id param');
 | 
						if (fileIdErr) return rej('invalid fileId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let file = null;
 | 
						let file = null;
 | 
				
			||||||
	if (fileId !== undefined) {
 | 
						if (fileId !== undefined) {
 | 
				
			||||||
		file = await DriveFile.findOne({
 | 
							file = await DriveFile.findOne({
 | 
				
			||||||
			_id: fileId,
 | 
								_id: fileId,
 | 
				
			||||||
			'metadata.user_id': user._id
 | 
								'metadata.userId': user._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (file === null) {
 | 
							if (file === null) {
 | 
				
			||||||
| 
						 | 
					@ -70,12 +70,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// メッセージを作成
 | 
						// メッセージを作成
 | 
				
			||||||
	const message = await Message.insert({
 | 
						const message = await Message.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		file_id: file ? file._id : undefined,
 | 
							fileId: file ? file._id : undefined,
 | 
				
			||||||
		recipient_id: recipient._id,
 | 
							recipientId: recipient._id,
 | 
				
			||||||
		text: text ? text : undefined,
 | 
							text: text ? text : undefined,
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		is_read: false
 | 
							isRead: false
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
| 
						 | 
					@ -85,32 +85,32 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	res(messageObj);
 | 
						res(messageObj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 自分のストリーム
 | 
						// 自分のストリーム
 | 
				
			||||||
	publishMessagingStream(message.user_id, message.recipient_id, 'message', messageObj);
 | 
						publishMessagingStream(message.userId, message.recipientId, 'message', messageObj);
 | 
				
			||||||
	publishMessagingIndexStream(message.user_id, 'message', messageObj);
 | 
						publishMessagingIndexStream(message.userId, 'message', messageObj);
 | 
				
			||||||
	publishUserStream(message.user_id, 'messaging_message', messageObj);
 | 
						publishUserStream(message.userId, 'messaging_message', messageObj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 相手のストリーム
 | 
						// 相手のストリーム
 | 
				
			||||||
	publishMessagingStream(message.recipient_id, message.user_id, 'message', messageObj);
 | 
						publishMessagingStream(message.recipientId, message.userId, 'message', messageObj);
 | 
				
			||||||
	publishMessagingIndexStream(message.recipient_id, 'message', messageObj);
 | 
						publishMessagingIndexStream(message.recipientId, 'message', messageObj);
 | 
				
			||||||
	publishUserStream(message.recipient_id, 'messaging_message', messageObj);
 | 
						publishUserStream(message.recipientId, 'messaging_message', messageObj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する
 | 
						// 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する
 | 
				
			||||||
	setTimeout(async () => {
 | 
						setTimeout(async () => {
 | 
				
			||||||
		const freshMessage = await Message.findOne({ _id: message._id }, { is_read: true });
 | 
							const freshMessage = await Message.findOne({ _id: message._id }, { isRead: true });
 | 
				
			||||||
		if (!freshMessage.is_read) {
 | 
							if (!freshMessage.isRead) {
 | 
				
			||||||
			//#region ただしミュートされているなら発行しない
 | 
								//#region ただしミュートされているなら発行しない
 | 
				
			||||||
			const mute = await Mute.find({
 | 
								const mute = await Mute.find({
 | 
				
			||||||
				muter_id: recipient._id,
 | 
									muterId: recipient._id,
 | 
				
			||||||
				deleted_at: { $exists: false }
 | 
									deletedAt: { $exists: false }
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
			const mutedUserIds = mute.map(m => m.mutee_id.toString());
 | 
								const mutedUserIds = mute.map(m => m.muteeId.toString());
 | 
				
			||||||
			if (mutedUserIds.indexOf(user._id.toString()) != -1) {
 | 
								if (mutedUserIds.indexOf(user._id.toString()) != -1) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			//#endregion
 | 
								//#endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			publishUserStream(message.recipient_id, 'unread_messaging_message', messageObj);
 | 
								publishUserStream(message.recipientId, 'unread_messaging_message', messageObj);
 | 
				
			||||||
			pushSw(message.recipient_id, 'unread_messaging_message', messageObj);
 | 
								pushSw(message.recipientId, 'unread_messaging_message', messageObj);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}, 3000);
 | 
						}, 3000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -130,26 +130,26 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 履歴作成(自分)
 | 
						// 履歴作成(自分)
 | 
				
			||||||
	History.update({
 | 
						History.update({
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		partner: recipient._id
 | 
							partnerId: recipient._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		updated_at: new Date(),
 | 
							updatedAt: new Date(),
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		partner: recipient._id,
 | 
							partnerId: recipient._id,
 | 
				
			||||||
		message: message._id
 | 
							messageId: message._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		upsert: true
 | 
							upsert: true
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 履歴作成(相手)
 | 
						// 履歴作成(相手)
 | 
				
			||||||
	History.update({
 | 
						History.update({
 | 
				
			||||||
		user_id: recipient._id,
 | 
							userId: recipient._id,
 | 
				
			||||||
		partner: user._id
 | 
							partnerId: user._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		updated_at: new Date(),
 | 
							updatedAt: new Date(),
 | 
				
			||||||
		user_id: recipient._id,
 | 
							userId: recipient._id,
 | 
				
			||||||
		partner: user._id,
 | 
							partnerId: user._id,
 | 
				
			||||||
		message: message._id
 | 
							messageId: message._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		upsert: true
 | 
							upsert: true
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,18 +13,18 @@ import Mute from '../../models/mute';
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const mute = await Mute.find({
 | 
						const mute = await Mute.find({
 | 
				
			||||||
		muter_id: user._id,
 | 
							muterId: user._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	const mutedUserIds = mute.map(m => m.mutee_id);
 | 
						const mutedUserIds = mute.map(m => m.muteeId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const count = await Message
 | 
						const count = await Message
 | 
				
			||||||
		.count({
 | 
							.count({
 | 
				
			||||||
			user_id: {
 | 
								userId: {
 | 
				
			||||||
				$nin: mutedUserIds
 | 
									$nin: mutedUserIds
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			recipient_id: user._id,
 | 
								recipientId: user._id,
 | 
				
			||||||
			is_read: false
 | 
								isRead: false
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res({
 | 
						res({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,9 +15,9 @@ import Mute from '../../models/mute';
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const muter = user;
 | 
						const muter = user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [userId, userIdErr] = $(params.user_id).id().$;
 | 
						const [userId, userIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (userIdErr) return rej('invalid user_id param');
 | 
						if (userIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 自分自身
 | 
						// 自分自身
 | 
				
			||||||
	if (user._id.equals(userId)) {
 | 
						if (user._id.equals(userId)) {
 | 
				
			||||||
| 
						 | 
					@ -40,9 +40,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if already muting
 | 
						// Check if already muting
 | 
				
			||||||
	const exist = await Mute.findOne({
 | 
						const exist = await Mute.findOne({
 | 
				
			||||||
		muter_id: muter._id,
 | 
							muterId: muter._id,
 | 
				
			||||||
		mutee_id: mutee._id,
 | 
							muteeId: mutee._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist !== null) {
 | 
						if (exist !== null) {
 | 
				
			||||||
| 
						 | 
					@ -51,9 +51,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create mute
 | 
						// Create mute
 | 
				
			||||||
	await Mute.insert({
 | 
						await Mute.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		muter_id: muter._id,
 | 
							muterId: muter._id,
 | 
				
			||||||
		mutee_id: mutee._id,
 | 
							muteeId: mutee._id,
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send response
 | 
						// Send response
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,9 +15,9 @@ import Mute from '../../models/mute';
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const muter = user;
 | 
						const muter = user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [userId, userIdErr] = $(params.user_id).id().$;
 | 
						const [userId, userIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (userIdErr) return rej('invalid user_id param');
 | 
						if (userIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if the mutee is yourself
 | 
						// Check if the mutee is yourself
 | 
				
			||||||
	if (user._id.equals(userId)) {
 | 
						if (user._id.equals(userId)) {
 | 
				
			||||||
| 
						 | 
					@ -40,9 +40,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check not muting
 | 
						// Check not muting
 | 
				
			||||||
	const exist = await Mute.findOne({
 | 
						const exist = await Mute.findOne({
 | 
				
			||||||
		muter_id: muter._id,
 | 
							muterId: muter._id,
 | 
				
			||||||
		mutee_id: mutee._id,
 | 
							muteeId: mutee._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist === null) {
 | 
						if (exist === null) {
 | 
				
			||||||
| 
						 | 
					@ -54,7 +54,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		_id: exist._id
 | 
							_id: exist._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			deleted_at: new Date()
 | 
								deletedAt: new Date()
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,15 +28,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Construct query
 | 
						// Construct query
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		muter_id: me._id,
 | 
							muterId: me._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (iknow) {
 | 
						if (iknow) {
 | 
				
			||||||
		// Get my friends
 | 
							// Get my friends
 | 
				
			||||||
		const myFriends = await getFriends(me._id);
 | 
							const myFriends = await getFriends(me._id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		query.mutee_id = {
 | 
							query.muteeId = {
 | 
				
			||||||
			$in: myFriends
 | 
								$in: myFriends
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -63,7 +63,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
	const users = await Promise.all(mutes.map(async m =>
 | 
						const users = await Promise.all(mutes.map(async m =>
 | 
				
			||||||
		await pack(m.mutee_id, me, { detail: true })));
 | 
							await pack(m.muteeId, me, { detail: true })));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Response
 | 
						// Response
 | 
				
			||||||
	res({
 | 
						res({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (offsetErr) return rej('invalid offset param');
 | 
						if (offsetErr) return rej('invalid offset param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Execute query
 | 
						// Execute query
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,18 +13,18 @@ import Mute from '../../models/mute';
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const mute = await Mute.find({
 | 
						const mute = await Mute.find({
 | 
				
			||||||
		muter_id: user._id,
 | 
							muterId: user._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	const mutedUserIds = mute.map(m => m.mutee_id);
 | 
						const mutedUserIds = mute.map(m => m.muteeId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const count = await Notification
 | 
						const count = await Notification
 | 
				
			||||||
		.count({
 | 
							.count({
 | 
				
			||||||
			notifiee_id: user._id,
 | 
								notifieeId: user._id,
 | 
				
			||||||
			notifier_id: {
 | 
								notifierId: {
 | 
				
			||||||
				$nin: mutedUserIds
 | 
									$nin: mutedUserIds
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			is_read: false
 | 
								isRead: false
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res({
 | 
						res({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,11 +14,11 @@ import event from '../../event';
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Update documents
 | 
						// Update documents
 | 
				
			||||||
	await Notification.update({
 | 
						await Notification.update({
 | 
				
			||||||
		notifiee_id: user._id,
 | 
							notifieeId: user._id,
 | 
				
			||||||
		is_read: false
 | 
							isRead: false
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		$set: {
 | 
							$set: {
 | 
				
			||||||
			is_read: true
 | 
								isRead: true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		multi: true
 | 
							multi: true
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,14 +24,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const q: any = my ? {
 | 
						const q: any = my ? {
 | 
				
			||||||
		is_started: true,
 | 
							isStarted: true,
 | 
				
			||||||
		$or: [{
 | 
							$or: [{
 | 
				
			||||||
			user1_id: user._id
 | 
								user1Id: user._id
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			user2_id: user._id
 | 
								user2Id: user._id
 | 
				
			||||||
		}]
 | 
							}]
 | 
				
			||||||
	} : {
 | 
						} : {
 | 
				
			||||||
		is_started: true
 | 
							isStarted: true
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const sort = {
 | 
						const sort = {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,9 +14,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const o = new Othello(game.settings.map, {
 | 
						const o = new Othello(game.settings.map, {
 | 
				
			||||||
		isLlotheo: game.settings.is_llotheo,
 | 
							isLlotheo: game.settings.isLlotheo,
 | 
				
			||||||
		canPutEverywhere: game.settings.can_put_everywhere,
 | 
							canPutEverywhere: game.settings.canPutEverywhere,
 | 
				
			||||||
		loopedBoard: game.settings.looped_board
 | 
							loopedBoard: game.settings.loopedBoard
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	game.logs.forEach(log => {
 | 
						game.logs.forEach(log => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ import Matching, { pack as packMatching } from '../../models/othello-matching';
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Find session
 | 
						// Find session
 | 
				
			||||||
	const invitations = await Matching.find({
 | 
						const invitations = await Matching.find({
 | 
				
			||||||
		child_id: user._id
 | 
							childId: user._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		sort: {
 | 
							sort: {
 | 
				
			||||||
			_id: -1
 | 
								_id: -1
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,19 +6,19 @@ import publishUserStream, { publishOthelloStream } from '../../event';
 | 
				
			||||||
import { eighteight } from '../../../common/othello/maps';
 | 
					import { eighteight } from '../../../common/othello/maps';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'user_id' parameter
 | 
						// Get 'userId' parameter
 | 
				
			||||||
	const [childId, childIdErr] = $(params.user_id).id().$;
 | 
						const [childId, childIdErr] = $(params.userId).id().$;
 | 
				
			||||||
	if (childIdErr) return rej('invalid user_id param');
 | 
						if (childIdErr) return rej('invalid userId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Myself
 | 
						// Myself
 | 
				
			||||||
	if (childId.equals(user._id)) {
 | 
						if (childId.equals(user._id)) {
 | 
				
			||||||
		return rej('invalid user_id param');
 | 
							return rej('invalid userId param');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Find session
 | 
						// Find session
 | 
				
			||||||
	const exist = await Matching.findOne({
 | 
						const exist = await Matching.findOne({
 | 
				
			||||||
		parent_id: childId,
 | 
							parentId: childId,
 | 
				
			||||||
		child_id: user._id
 | 
							childId: user._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist) {
 | 
						if (exist) {
 | 
				
			||||||
| 
						 | 
					@ -29,28 +29,28 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Create game
 | 
							// Create game
 | 
				
			||||||
		const game = await OthelloGame.insert({
 | 
							const game = await OthelloGame.insert({
 | 
				
			||||||
			created_at: new Date(),
 | 
								createdAt: new Date(),
 | 
				
			||||||
			user1_id: exist.parent_id,
 | 
								user1Id: exist.parentId,
 | 
				
			||||||
			user2_id: user._id,
 | 
								user2Id: user._id,
 | 
				
			||||||
			user1_accepted: false,
 | 
								user1Accepted: false,
 | 
				
			||||||
			user2_accepted: false,
 | 
								user2Accepted: false,
 | 
				
			||||||
			is_started: false,
 | 
								isStarted: false,
 | 
				
			||||||
			is_ended: false,
 | 
								isEnded: false,
 | 
				
			||||||
			logs: [],
 | 
								logs: [],
 | 
				
			||||||
			settings: {
 | 
								settings: {
 | 
				
			||||||
				map: eighteight.data,
 | 
									map: eighteight.data,
 | 
				
			||||||
				bw: 'random',
 | 
									bw: 'random',
 | 
				
			||||||
				is_llotheo: false
 | 
									isLlotheo: false
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Reponse
 | 
							// Reponse
 | 
				
			||||||
		res(await packGame(game, user));
 | 
							res(await packGame(game, user));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		publishOthelloStream(exist.parent_id, 'matched', await packGame(game, exist.parent_id));
 | 
							publishOthelloStream(exist.parentId, 'matched', await packGame(game, exist.parentId));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const other = await Matching.count({
 | 
							const other = await Matching.count({
 | 
				
			||||||
			child_id: user._id
 | 
								childId: user._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (other == 0) {
 | 
							if (other == 0) {
 | 
				
			||||||
| 
						 | 
					@ -72,14 +72,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 以前のセッションはすべて削除しておく
 | 
							// 以前のセッションはすべて削除しておく
 | 
				
			||||||
		await Matching.remove({
 | 
							await Matching.remove({
 | 
				
			||||||
			parent_id: user._id
 | 
								parentId: user._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// セッションを作成
 | 
							// セッションを作成
 | 
				
			||||||
		const matching = await Matching.insert({
 | 
							const matching = await Matching.insert({
 | 
				
			||||||
			created_at: new Date(),
 | 
								createdAt: new Date(),
 | 
				
			||||||
			parent_id: user._id,
 | 
								parentId: user._id,
 | 
				
			||||||
			child_id: child._id
 | 
								childId: child._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Reponse
 | 
							// Reponse
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ import Matching from '../../../models/othello-matching';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	await Matching.remove({
 | 
						await Matching.remove({
 | 
				
			||||||
		parent_id: user._id
 | 
							parentId: user._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res();
 | 
						res();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,15 +65,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (reply != undefined) {
 | 
						if (reply != undefined) {
 | 
				
			||||||
		query.reply_id = reply ? { $exists: true, $ne: null } : null;
 | 
							query.replyId = reply ? { $exists: true, $ne: null } : null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (repost != undefined) {
 | 
						if (repost != undefined) {
 | 
				
			||||||
		query.repost_id = repost ? { $exists: true, $ne: null } : null;
 | 
							query.repostId = repost ? { $exists: true, $ne: null } : null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (media != undefined) {
 | 
						if (media != undefined) {
 | 
				
			||||||
		query.media_ids = media ? { $exists: true, $ne: null } : null;
 | 
							query.mediaIds = media ? { $exists: true, $ne: null } : null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (poll != undefined) {
 | 
						if (poll != undefined) {
 | 
				
			||||||
| 
						 | 
					@ -82,7 +82,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO
 | 
						// TODO
 | 
				
			||||||
	//if (bot != undefined) {
 | 
						//if (bot != undefined) {
 | 
				
			||||||
	//	query.is_bot = bot;
 | 
						//	query.isBot = bot;
 | 
				
			||||||
	//}
 | 
						//}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Issue query
 | 
						// Issue query
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,13 +12,13 @@ import Post from '../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (!user.account.is_pro) {
 | 
						if (!user.account.isPro) {
 | 
				
			||||||
		return rej('This endpoint is available only from a Pro account');
 | 
							return rej('This endpoint is available only from a Pro account');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get categorizee
 | 
						// Get categorizee
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'limit' parameter
 | 
						// Get 'limit' parameter
 | 
				
			||||||
	const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
 | 
						const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
 | 
				
			||||||
| 
						 | 
					@ -48,13 +48,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (p.reply_id) {
 | 
							if (p.replyId) {
 | 
				
			||||||
			await get(p.reply_id);
 | 
								await get(p.replyId);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (post.reply_id) {
 | 
						if (post.replyId) {
 | 
				
			||||||
		await get(post.reply_id);
 | 
							await get(post.replyId);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,9 +33,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
 | 
						const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
 | 
				
			||||||
	if (textErr) return rej('invalid text');
 | 
						if (textErr) return rej('invalid text');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'via_mobile' parameter
 | 
						// Get 'viaMobile' parameter
 | 
				
			||||||
	const [viaMobile = false, viaMobileErr] = $(params.via_mobile).optional.boolean().$;
 | 
						const [viaMobile = false, viaMobileErr] = $(params.viaMobile).optional.boolean().$;
 | 
				
			||||||
	if (viaMobileErr) return rej('invalid via_mobile');
 | 
						if (viaMobileErr) return rej('invalid viaMobile');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'tags' parameter
 | 
						// Get 'tags' parameter
 | 
				
			||||||
	const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$;
 | 
						const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$;
 | 
				
			||||||
| 
						 | 
					@ -53,9 +53,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		.$;
 | 
							.$;
 | 
				
			||||||
	if (geoErr) return rej('invalid geo');
 | 
						if (geoErr) return rej('invalid geo');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'media_ids' parameter
 | 
						// Get 'mediaIds' parameter
 | 
				
			||||||
	const [mediaIds, mediaIdsErr] = $(params.media_ids).optional.array('id').unique().range(1, 4).$;
 | 
						const [mediaIds, mediaIdsErr] = $(params.mediaIds).optional.array('id').unique().range(1, 4).$;
 | 
				
			||||||
	if (mediaIdsErr) return rej('invalid media_ids');
 | 
						if (mediaIdsErr) return rej('invalid mediaIds');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let files = [];
 | 
						let files = [];
 | 
				
			||||||
	if (mediaIds !== undefined) {
 | 
						if (mediaIds !== undefined) {
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
			// SELECT _id
 | 
								// SELECT _id
 | 
				
			||||||
			const entity = await DriveFile.findOne({
 | 
								const entity = await DriveFile.findOne({
 | 
				
			||||||
				_id: mediaId,
 | 
									_id: mediaId,
 | 
				
			||||||
				'metadata.user_id': user._id
 | 
									'metadata.userId': user._id
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (entity === null) {
 | 
								if (entity === null) {
 | 
				
			||||||
| 
						 | 
					@ -80,9 +80,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		files = null;
 | 
							files = null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'repost_id' parameter
 | 
						// Get 'repostId' parameter
 | 
				
			||||||
	const [repostId, repostIdErr] = $(params.repost_id).optional.id().$;
 | 
						const [repostId, repostIdErr] = $(params.repostId).optional.id().$;
 | 
				
			||||||
	if (repostIdErr) return rej('invalid repost_id');
 | 
						if (repostIdErr) return rej('invalid repostId');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let repost: IPost = null;
 | 
						let repost: IPost = null;
 | 
				
			||||||
	let isQuote = false;
 | 
						let isQuote = false;
 | 
				
			||||||
| 
						 | 
					@ -94,13 +94,13 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (repost == null) {
 | 
							if (repost == null) {
 | 
				
			||||||
			return rej('repostee is not found');
 | 
								return rej('repostee is not found');
 | 
				
			||||||
		} else if (repost.repost_id && !repost.text && !repost.media_ids) {
 | 
							} else if (repost.repostId && !repost.text && !repost.mediaIds) {
 | 
				
			||||||
			return rej('cannot repost to repost');
 | 
								return rej('cannot repost to repost');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Fetch recently post
 | 
							// Fetch recently post
 | 
				
			||||||
		const latestPost = await Post.findOne({
 | 
							const latestPost = await Post.findOne({
 | 
				
			||||||
			user_id: user._id
 | 
								userId: user._id
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			sort: {
 | 
								sort: {
 | 
				
			||||||
				_id: -1
 | 
									_id: -1
 | 
				
			||||||
| 
						 | 
					@ -111,8 +111,8 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 直近と同じRepost対象かつ引用じゃなかったらエラー
 | 
							// 直近と同じRepost対象かつ引用じゃなかったらエラー
 | 
				
			||||||
		if (latestPost &&
 | 
							if (latestPost &&
 | 
				
			||||||
			latestPost.repost_id &&
 | 
								latestPost.repostId &&
 | 
				
			||||||
			latestPost.repost_id.equals(repost._id) &&
 | 
								latestPost.repostId.equals(repost._id) &&
 | 
				
			||||||
			!isQuote) {
 | 
								!isQuote) {
 | 
				
			||||||
			return rej('cannot repost same post that already reposted in your latest post');
 | 
								return rej('cannot repost same post that already reposted in your latest post');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -125,9 +125,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'reply_id' parameter
 | 
						// Get 'replyId' parameter
 | 
				
			||||||
	const [replyId, replyIdErr] = $(params.reply_id).optional.id().$;
 | 
						const [replyId, replyIdErr] = $(params.replyId).optional.id().$;
 | 
				
			||||||
	if (replyIdErr) return rej('invalid reply_id');
 | 
						if (replyIdErr) return rej('invalid replyId');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let reply: IPost = null;
 | 
						let reply: IPost = null;
 | 
				
			||||||
	if (replyId !== undefined) {
 | 
						if (replyId !== undefined) {
 | 
				
			||||||
| 
						 | 
					@ -141,14 +141,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 返信対象が引用でないRepostだったらエラー
 | 
							// 返信対象が引用でないRepostだったらエラー
 | 
				
			||||||
		if (reply.repost_id && !reply.text && !reply.media_ids) {
 | 
							if (reply.repostId && !reply.text && !reply.mediaIds) {
 | 
				
			||||||
			return rej('cannot reply to repost');
 | 
								return rej('cannot reply to repost');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'channel_id' parameter
 | 
						// Get 'channelId' parameter
 | 
				
			||||||
	const [channelId, channelIdErr] = $(params.channel_id).optional.id().$;
 | 
						const [channelId, channelIdErr] = $(params.channelId).optional.id().$;
 | 
				
			||||||
	if (channelIdErr) return rej('invalid channel_id');
 | 
						if (channelIdErr) return rej('invalid channelId');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let channel: IChannel = null;
 | 
						let channel: IChannel = null;
 | 
				
			||||||
	if (channelId !== undefined) {
 | 
						if (channelId !== undefined) {
 | 
				
			||||||
| 
						 | 
					@ -162,12 +162,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 返信対象の投稿がこのチャンネルじゃなかったらダメ
 | 
							// 返信対象の投稿がこのチャンネルじゃなかったらダメ
 | 
				
			||||||
		if (reply && !channelId.equals(reply.channel_id)) {
 | 
							if (reply && !channelId.equals(reply.channelId)) {
 | 
				
			||||||
			return rej('チャンネル内部からチャンネル外部の投稿に返信することはできません');
 | 
								return rej('チャンネル内部からチャンネル外部の投稿に返信することはできません');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Repost対象の投稿がこのチャンネルじゃなかったらダメ
 | 
							// Repost対象の投稿がこのチャンネルじゃなかったらダメ
 | 
				
			||||||
		if (repost && !channelId.equals(repost.channel_id)) {
 | 
							if (repost && !channelId.equals(repost.channelId)) {
 | 
				
			||||||
			return rej('チャンネル内部からチャンネル外部の投稿をRepostすることはできません');
 | 
								return rej('チャンネル内部からチャンネル外部の投稿をRepostすることはできません');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -177,12 +177,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		// 返信対象の投稿がチャンネルへの投稿だったらダメ
 | 
							// 返信対象の投稿がチャンネルへの投稿だったらダメ
 | 
				
			||||||
		if (reply && reply.channel_id != null) {
 | 
							if (reply && reply.channelId != null) {
 | 
				
			||||||
			return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません');
 | 
								return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Repost対象の投稿がチャンネルへの投稿だったらダメ
 | 
							// Repost対象の投稿がチャンネルへの投稿だったらダメ
 | 
				
			||||||
		if (repost && repost.channel_id != null) {
 | 
							if (repost && repost.channelId != null) {
 | 
				
			||||||
			return rej('チャンネル外部からチャンネル内部の投稿をRepostすることはできません');
 | 
								return rej('チャンネル外部からチャンネル内部の投稿をRepostすることはできません');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -206,7 +206,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// テキストが無いかつ添付ファイルが無いかつRepostも無いかつ投票も無かったらエラー
 | 
						// テキストが無いかつ添付ファイルが無いかつRepostも無いかつ投票も無かったらエラー
 | 
				
			||||||
	if (text === undefined && files === null && repost === null && poll === undefined) {
 | 
						if (text === undefined && files === null && repost === null && poll === undefined) {
 | 
				
			||||||
		return rej('text, media_ids, repost_id or poll is required');
 | 
							return rej('text, mediaIds, repostId or poll is required');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 直近の投稿と重複してたらエラー
 | 
						// 直近の投稿と重複してたらエラー
 | 
				
			||||||
| 
						 | 
					@ -214,14 +214,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (user.latest_post) {
 | 
						if (user.latest_post) {
 | 
				
			||||||
		if (deepEqual({
 | 
							if (deepEqual({
 | 
				
			||||||
			text: user.latest_post.text,
 | 
								text: user.latest_post.text,
 | 
				
			||||||
			reply: user.latest_post.reply_id ? user.latest_post.reply_id.toString() : null,
 | 
								reply: user.latest_post.replyId ? user.latest_post.replyId.toString() : null,
 | 
				
			||||||
			repost: user.latest_post.repost_id ? user.latest_post.repost_id.toString() : null,
 | 
								repost: user.latest_post.repostId ? user.latest_post.repostId.toString() : null,
 | 
				
			||||||
			media_ids: (user.latest_post.media_ids || []).map(id => id.toString())
 | 
								mediaIds: (user.latest_post.mediaIds || []).map(id => id.toString())
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			text: text,
 | 
								text: text,
 | 
				
			||||||
			reply: reply ? reply._id.toString() : null,
 | 
								reply: reply ? reply._id.toString() : null,
 | 
				
			||||||
			repost: repost ? repost._id.toString() : null,
 | 
								repost: repost ? repost._id.toString() : null,
 | 
				
			||||||
			media_ids: (files || []).map(file => file._id.toString())
 | 
								mediaIds: (files || []).map(file => file._id.toString())
 | 
				
			||||||
		})) {
 | 
							})) {
 | 
				
			||||||
			return rej('duplicate');
 | 
								return rej('duplicate');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -246,23 +246,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 投稿を作成
 | 
						// 投稿を作成
 | 
				
			||||||
	const post = await Post.insert({
 | 
						const post = await Post.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		channel_id: channel ? channel._id : undefined,
 | 
							channelId: channel ? channel._id : undefined,
 | 
				
			||||||
		index: channel ? channel.index + 1 : undefined,
 | 
							index: channel ? channel.index + 1 : undefined,
 | 
				
			||||||
		media_ids: files ? files.map(file => file._id) : undefined,
 | 
							mediaIds: files ? files.map(file => file._id) : undefined,
 | 
				
			||||||
		reply_id: reply ? reply._id : undefined,
 | 
							replyId: reply ? reply._id : undefined,
 | 
				
			||||||
		repost_id: repost ? repost._id : undefined,
 | 
							repostId: repost ? repost._id : undefined,
 | 
				
			||||||
		poll: poll,
 | 
							poll: poll,
 | 
				
			||||||
		text: text,
 | 
							text: text,
 | 
				
			||||||
		tags: tags,
 | 
							tags: tags,
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		app_id: app ? app._id : null,
 | 
							appId: app ? app._id : null,
 | 
				
			||||||
		via_mobile: viaMobile,
 | 
							viaMobile: viaMobile,
 | 
				
			||||||
		geo,
 | 
							geo,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 以下非正規化データ
 | 
							// 以下非正規化データ
 | 
				
			||||||
		_reply: reply ? { user_id: reply.user_id } : undefined,
 | 
							_reply: reply ? { userId: reply.userId } : undefined,
 | 
				
			||||||
		_repost: repost ? { user_id: repost.user_id } : undefined,
 | 
							_repost: repost ? { userId: repost.userId } : undefined,
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Serialize
 | 
						// Serialize
 | 
				
			||||||
| 
						 | 
					@ -293,10 +293,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		// Publish event
 | 
							// Publish event
 | 
				
			||||||
		if (!user._id.equals(mentionee)) {
 | 
							if (!user._id.equals(mentionee)) {
 | 
				
			||||||
			const mentioneeMutes = await Mute.find({
 | 
								const mentioneeMutes = await Mute.find({
 | 
				
			||||||
				muter_id: mentionee,
 | 
									muterId: mentionee,
 | 
				
			||||||
				deleted_at: { $exists: false }
 | 
									deletedAt: { $exists: false }
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
			const mentioneesMutedUserIds = mentioneeMutes.map(m => m.mutee_id.toString());
 | 
								const mentioneesMutedUserIds = mentioneeMutes.map(m => m.muteeId.toString());
 | 
				
			||||||
			if (mentioneesMutedUserIds.indexOf(user._id.toString()) == -1) {
 | 
								if (mentioneesMutedUserIds.indexOf(user._id.toString()) == -1) {
 | 
				
			||||||
				event(mentionee, reason, postObj);
 | 
									event(mentionee, reason, postObj);
 | 
				
			||||||
				pushSw(mentionee, reason, postObj);
 | 
									pushSw(mentionee, reason, postObj);
 | 
				
			||||||
| 
						 | 
					@ -312,17 +312,17 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		// Fetch all followers
 | 
							// Fetch all followers
 | 
				
			||||||
		const followers = await Following
 | 
							const followers = await Following
 | 
				
			||||||
			.find({
 | 
								.find({
 | 
				
			||||||
				followee_id: user._id,
 | 
									followeeId: user._id,
 | 
				
			||||||
				// 削除されたドキュメントは除く
 | 
									// 削除されたドキュメントは除く
 | 
				
			||||||
				deleted_at: { $exists: false }
 | 
									deletedAt: { $exists: false }
 | 
				
			||||||
			}, {
 | 
								}, {
 | 
				
			||||||
				follower_id: true,
 | 
									followerId: true,
 | 
				
			||||||
				_id: false
 | 
									_id: false
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Publish event to followers stream
 | 
							// Publish event to followers stream
 | 
				
			||||||
		followers.forEach(following =>
 | 
							followers.forEach(following =>
 | 
				
			||||||
			event(following.follower_id, 'post', postObj));
 | 
								event(following.followerId, 'post', postObj));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// チャンネルへの投稿
 | 
						// チャンネルへの投稿
 | 
				
			||||||
| 
						 | 
					@ -339,21 +339,21 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Get channel watchers
 | 
							// Get channel watchers
 | 
				
			||||||
		const watches = await ChannelWatching.find({
 | 
							const watches = await ChannelWatching.find({
 | 
				
			||||||
			channel_id: channel._id,
 | 
								channelId: channel._id,
 | 
				
			||||||
			// 削除されたドキュメントは除く
 | 
								// 削除されたドキュメントは除く
 | 
				
			||||||
			deleted_at: { $exists: false }
 | 
								deletedAt: { $exists: false }
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// チャンネルの視聴者(のタイムライン)に配信
 | 
							// チャンネルの視聴者(のタイムライン)に配信
 | 
				
			||||||
		watches.forEach(w => {
 | 
							watches.forEach(w => {
 | 
				
			||||||
			event(w.user_id, 'post', postObj);
 | 
								event(w.userId, 'post', postObj);
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Increment my posts count
 | 
						// Increment my posts count
 | 
				
			||||||
	User.update({ _id: user._id }, {
 | 
						User.update({ _id: user._id }, {
 | 
				
			||||||
		$inc: {
 | 
							$inc: {
 | 
				
			||||||
			posts_count: 1
 | 
								postsCount: 1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -367,26 +367,26 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 自分自身へのリプライでない限りは通知を作成
 | 
							// 自分自身へのリプライでない限りは通知を作成
 | 
				
			||||||
		notify(reply.user_id, user._id, 'reply', {
 | 
							notify(reply.userId, user._id, 'reply', {
 | 
				
			||||||
			post_id: post._id
 | 
								postId: post._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Fetch watchers
 | 
							// Fetch watchers
 | 
				
			||||||
		Watching
 | 
							Watching
 | 
				
			||||||
			.find({
 | 
								.find({
 | 
				
			||||||
				post_id: reply._id,
 | 
									postId: reply._id,
 | 
				
			||||||
				user_id: { $ne: user._id },
 | 
									userId: { $ne: user._id },
 | 
				
			||||||
				// 削除されたドキュメントは除く
 | 
									// 削除されたドキュメントは除く
 | 
				
			||||||
				deleted_at: { $exists: false }
 | 
									deletedAt: { $exists: false }
 | 
				
			||||||
			}, {
 | 
								}, {
 | 
				
			||||||
				fields: {
 | 
									fields: {
 | 
				
			||||||
					user_id: true
 | 
										userId: true
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
			.then(watchers => {
 | 
								.then(watchers => {
 | 
				
			||||||
				watchers.forEach(watcher => {
 | 
									watchers.forEach(watcher => {
 | 
				
			||||||
					notify(watcher.user_id, user._id, 'reply', {
 | 
										notify(watcher.userId, user._id, 'reply', {
 | 
				
			||||||
						post_id: post._id
 | 
											postId: post._id
 | 
				
			||||||
					});
 | 
										});
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
| 
						 | 
					@ -397,33 +397,33 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Add mention
 | 
							// Add mention
 | 
				
			||||||
		addMention(reply.user_id, 'reply');
 | 
							addMention(reply.userId, 'reply');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If it is repost
 | 
						// If it is repost
 | 
				
			||||||
	if (repost) {
 | 
						if (repost) {
 | 
				
			||||||
		// Notify
 | 
							// Notify
 | 
				
			||||||
		const type = text ? 'quote' : 'repost';
 | 
							const type = text ? 'quote' : 'repost';
 | 
				
			||||||
		notify(repost.user_id, user._id, type, {
 | 
							notify(repost.userId, user._id, type, {
 | 
				
			||||||
			post_id: post._id
 | 
								postId: post._id
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Fetch watchers
 | 
							// Fetch watchers
 | 
				
			||||||
		Watching
 | 
							Watching
 | 
				
			||||||
			.find({
 | 
								.find({
 | 
				
			||||||
				post_id: repost._id,
 | 
									postId: repost._id,
 | 
				
			||||||
				user_id: { $ne: user._id },
 | 
									userId: { $ne: user._id },
 | 
				
			||||||
				// 削除されたドキュメントは除く
 | 
									// 削除されたドキュメントは除く
 | 
				
			||||||
				deleted_at: { $exists: false }
 | 
									deletedAt: { $exists: false }
 | 
				
			||||||
			}, {
 | 
								}, {
 | 
				
			||||||
				fields: {
 | 
									fields: {
 | 
				
			||||||
					user_id: true
 | 
										userId: true
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
			.then(watchers => {
 | 
								.then(watchers => {
 | 
				
			||||||
				watchers.forEach(watcher => {
 | 
									watchers.forEach(watcher => {
 | 
				
			||||||
					notify(watcher.user_id, user._id, type, {
 | 
										notify(watcher.userId, user._id, type, {
 | 
				
			||||||
						post_id: post._id
 | 
											postId: post._id
 | 
				
			||||||
					});
 | 
										});
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
| 
						 | 
					@ -436,18 +436,18 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
		// If it is quote repost
 | 
							// If it is quote repost
 | 
				
			||||||
		if (text) {
 | 
							if (text) {
 | 
				
			||||||
			// Add mention
 | 
								// Add mention
 | 
				
			||||||
			addMention(repost.user_id, 'quote');
 | 
								addMention(repost.userId, 'quote');
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			// Publish event
 | 
								// Publish event
 | 
				
			||||||
			if (!user._id.equals(repost.user_id)) {
 | 
								if (!user._id.equals(repost.userId)) {
 | 
				
			||||||
				event(repost.user_id, 'repost', postObj);
 | 
									event(repost.userId, 'repost', postObj);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 今までで同じ投稿をRepostしているか
 | 
							// 今までで同じ投稿をRepostしているか
 | 
				
			||||||
		const existRepost = await Post.findOne({
 | 
							const existRepost = await Post.findOne({
 | 
				
			||||||
			user_id: user._id,
 | 
								userId: user._id,
 | 
				
			||||||
			repost_id: repost._id,
 | 
								repostId: repost._id,
 | 
				
			||||||
			_id: {
 | 
								_id: {
 | 
				
			||||||
				$ne: post._id
 | 
									$ne: post._id
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -494,15 +494,15 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
 | 
				
			||||||
			if (mentionee == null) return;
 | 
								if (mentionee == null) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// 既に言及されたユーザーに対する返信や引用repostの場合も無視
 | 
								// 既に言及されたユーザーに対する返信や引用repostの場合も無視
 | 
				
			||||||
			if (reply && reply.user_id.equals(mentionee._id)) return;
 | 
								if (reply && reply.userId.equals(mentionee._id)) return;
 | 
				
			||||||
			if (repost && repost.user_id.equals(mentionee._id)) return;
 | 
								if (repost && repost.userId.equals(mentionee._id)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Add mention
 | 
								// Add mention
 | 
				
			||||||
			addMention(mentionee._id, 'mention');
 | 
								addMention(mentionee._id, 'mention');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Create notification
 | 
								// Create notification
 | 
				
			||||||
			notify(mentionee._id, user._id, 'mention', {
 | 
								notify(mentionee._id, user._id, 'mention', {
 | 
				
			||||||
				post_id: post._id
 | 
									postId: post._id
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,9 +13,9 @@ import Post from '../../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get favoritee
 | 
						// Get favoritee
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if already favorited
 | 
						// if already favorited
 | 
				
			||||||
	const exist = await Favorite.findOne({
 | 
						const exist = await Favorite.findOne({
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist !== null) {
 | 
						if (exist !== null) {
 | 
				
			||||||
| 
						 | 
					@ -38,9 +38,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create favorite
 | 
						// Create favorite
 | 
				
			||||||
	await Favorite.insert({
 | 
						await Favorite.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send response
 | 
						// Send response
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,9 +13,9 @@ import Post from '../../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get favoritee
 | 
						// Get favoritee
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if already favorited
 | 
						// if already favorited
 | 
				
			||||||
	const exist = await Favorite.findOne({
 | 
						const exist = await Favorite.findOne({
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist === null) {
 | 
						if (exist === null) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (following) {
 | 
						if (following) {
 | 
				
			||||||
		const followingIds = await getFriends(user._id);
 | 
							const followingIds = await getFriends(user._id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		query.user_id = {
 | 
							query.userId = {
 | 
				
			||||||
			$in: followingIds
 | 
								$in: followingIds
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,22 +23,22 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get votes
 | 
						// Get votes
 | 
				
			||||||
	const votes = await Vote.find({
 | 
						const votes = await Vote.find({
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		fields: {
 | 
							fields: {
 | 
				
			||||||
			_id: false,
 | 
								_id: false,
 | 
				
			||||||
			post_id: true
 | 
								postId: true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const nin = votes && votes.length != 0 ? votes.map(v => v.post_id) : [];
 | 
						const nin = votes && votes.length != 0 ? votes.map(v => v.postId) : [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const posts = await Post
 | 
						const posts = await Post
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			_id: {
 | 
								_id: {
 | 
				
			||||||
				$nin: nin
 | 
									$nin: nin
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			user_id: {
 | 
								userId: {
 | 
				
			||||||
				$ne: user._id
 | 
									$ne: user._id
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			poll: {
 | 
								poll: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,9 +17,9 @@ import { publishPostStream } from '../../../event';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get votee
 | 
						// Get votee
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					@ -43,8 +43,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if already voted
 | 
						// if already voted
 | 
				
			||||||
	const exist = await Vote.findOne({
 | 
						const exist = await Vote.findOne({
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		user_id: user._id
 | 
							userId: user._id
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist !== null) {
 | 
						if (exist !== null) {
 | 
				
			||||||
| 
						 | 
					@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create vote
 | 
						// Create vote
 | 
				
			||||||
	await Vote.insert({
 | 
						await Vote.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		choice: choice
 | 
							choice: choice
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,27 +73,27 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	publishPostStream(post._id, 'poll_voted');
 | 
						publishPostStream(post._id, 'poll_voted');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Notify
 | 
						// Notify
 | 
				
			||||||
	notify(post.user_id, user._id, 'poll_vote', {
 | 
						notify(post.userId, user._id, 'poll_vote', {
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		choice: choice
 | 
							choice: choice
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch watchers
 | 
						// Fetch watchers
 | 
				
			||||||
	Watching
 | 
						Watching
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			post_id: post._id,
 | 
								postId: post._id,
 | 
				
			||||||
			user_id: { $ne: user._id },
 | 
								userId: { $ne: user._id },
 | 
				
			||||||
			// 削除されたドキュメントは除く
 | 
								// 削除されたドキュメントは除く
 | 
				
			||||||
			deleted_at: { $exists: false }
 | 
								deletedAt: { $exists: false }
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			fields: {
 | 
								fields: {
 | 
				
			||||||
				user_id: true
 | 
									userId: true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		.then(watchers => {
 | 
							.then(watchers => {
 | 
				
			||||||
			watchers.forEach(watcher => {
 | 
								watchers.forEach(watcher => {
 | 
				
			||||||
				notify(watcher.user_id, user._id, 'poll_vote', {
 | 
									notify(watcher.userId, user._id, 'poll_vote', {
 | 
				
			||||||
					post_id: post._id,
 | 
										postId: post._id,
 | 
				
			||||||
					choice: choice
 | 
										choice: choice
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,9 +13,9 @@ import Reaction, { pack } from '../../models/post-reaction';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'limit' parameter
 | 
						// Get 'limit' parameter
 | 
				
			||||||
	const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
 | 
						const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
 | 
				
			||||||
| 
						 | 
					@ -41,8 +41,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Issue query
 | 
						// Issue query
 | 
				
			||||||
	const reactions = await Reaction
 | 
						const reactions = await Reaction
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			post_id: post._id,
 | 
								postId: post._id,
 | 
				
			||||||
			deleted_at: { $exists: false }
 | 
								deletedAt: { $exists: false }
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			limit: limit,
 | 
								limit: limit,
 | 
				
			||||||
			skip: offset,
 | 
								skip: offset,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,9 +18,9 @@ import { publishPostStream, pushSw } from '../../../event';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'reaction' parameter
 | 
						// Get 'reaction' parameter
 | 
				
			||||||
	const [reaction, reactionErr] = $(params.reaction).string().or([
 | 
						const [reaction, reactionErr] = $(params.reaction).string().or([
 | 
				
			||||||
| 
						 | 
					@ -46,15 +46,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Myself
 | 
						// Myself
 | 
				
			||||||
	if (post.user_id.equals(user._id)) {
 | 
						if (post.userId.equals(user._id)) {
 | 
				
			||||||
		return rej('cannot react to my post');
 | 
							return rej('cannot react to my post');
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if already reacted
 | 
						// if already reacted
 | 
				
			||||||
	const exist = await Reaction.findOne({
 | 
						const exist = await Reaction.findOne({
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist !== null) {
 | 
						if (exist !== null) {
 | 
				
			||||||
| 
						 | 
					@ -63,9 +63,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create reaction
 | 
						// Create reaction
 | 
				
			||||||
	await Reaction.insert({
 | 
						await Reaction.insert({
 | 
				
			||||||
		created_at: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		reaction: reaction
 | 
							reaction: reaction
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,33 +83,33 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	publishPostStream(post._id, 'reacted');
 | 
						publishPostStream(post._id, 'reacted');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Notify
 | 
						// Notify
 | 
				
			||||||
	notify(post.user_id, user._id, 'reaction', {
 | 
						notify(post.userId, user._id, 'reaction', {
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		reaction: reaction
 | 
							reaction: reaction
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pushSw(post.user_id, 'reaction', {
 | 
						pushSw(post.userId, 'reaction', {
 | 
				
			||||||
		user: await packUser(user, post.user_id),
 | 
							user: await packUser(user, post.userId),
 | 
				
			||||||
		post: await packPost(post, post.user_id),
 | 
							post: await packPost(post, post.userId),
 | 
				
			||||||
		reaction: reaction
 | 
							reaction: reaction
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch watchers
 | 
						// Fetch watchers
 | 
				
			||||||
	Watching
 | 
						Watching
 | 
				
			||||||
		.find({
 | 
							.find({
 | 
				
			||||||
			post_id: post._id,
 | 
								postId: post._id,
 | 
				
			||||||
			user_id: { $ne: user._id },
 | 
								userId: { $ne: user._id },
 | 
				
			||||||
			// 削除されたドキュメントは除く
 | 
								// 削除されたドキュメントは除く
 | 
				
			||||||
			deleted_at: { $exists: false }
 | 
								deletedAt: { $exists: false }
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			fields: {
 | 
								fields: {
 | 
				
			||||||
				user_id: true
 | 
									userId: true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		.then(watchers => {
 | 
							.then(watchers => {
 | 
				
			||||||
			watchers.forEach(watcher => {
 | 
								watchers.forEach(watcher => {
 | 
				
			||||||
				notify(watcher.user_id, user._id, 'reaction', {
 | 
									notify(watcher.userId, user._id, 'reaction', {
 | 
				
			||||||
					post_id: post._id,
 | 
										postId: post._id,
 | 
				
			||||||
					reaction: reaction
 | 
										reaction: reaction
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,9 +14,9 @@ import Post from '../../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Fetch unreactee
 | 
						// Fetch unreactee
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if already unreacted
 | 
						// if already unreacted
 | 
				
			||||||
	const exist = await Reaction.findOne({
 | 
						const exist = await Reaction.findOne({
 | 
				
			||||||
		post_id: post._id,
 | 
							postId: post._id,
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist === null) {
 | 
						if (exist === null) {
 | 
				
			||||||
| 
						 | 
					@ -43,7 +43,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		_id: exist._id
 | 
							_id: exist._id
 | 
				
			||||||
	}, {
 | 
						}, {
 | 
				
			||||||
			$set: {
 | 
								$set: {
 | 
				
			||||||
				deleted_at: new Date()
 | 
									deletedAt: new Date()
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'limit' parameter
 | 
						// Get 'limit' parameter
 | 
				
			||||||
	const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
 | 
						const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Issue query
 | 
						// Issue query
 | 
				
			||||||
	const replies = await Post
 | 
						const replies = await Post
 | 
				
			||||||
		.find({ reply_id: post._id }, {
 | 
							.find({ replyId: post._id }, {
 | 
				
			||||||
			limit: limit,
 | 
								limit: limit,
 | 
				
			||||||
			skip: offset,
 | 
								skip: offset,
 | 
				
			||||||
			sort: {
 | 
								sort: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'limit' parameter
 | 
						// Get 'limit' parameter
 | 
				
			||||||
	const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
 | 
						const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
 | 
				
			||||||
| 
						 | 
					@ -47,7 +47,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
		_id: -1
 | 
							_id: -1
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		repost_id: post._id
 | 
							repostId: post._id
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
	if (sinceId) {
 | 
						if (sinceId) {
 | 
				
			||||||
		sort._id = 1;
 | 
							sort._id = 1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,13 +21,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const [text, textError] = $(params.text).optional.string().$;
 | 
						const [text, textError] = $(params.text).optional.string().$;
 | 
				
			||||||
	if (textError) return rej('invalid text param');
 | 
						if (textError) return rej('invalid text param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'include_user_ids' parameter
 | 
						// Get 'include_userIds' parameter
 | 
				
			||||||
	const [includeUserIds = [], includeUserIdsErr] = $(params.include_user_ids).optional.array('id').$;
 | 
						const [includeUserIds = [], includeUserIdsErr] = $(params.include_userIds).optional.array('id').$;
 | 
				
			||||||
	if (includeUserIdsErr) return rej('invalid include_user_ids param');
 | 
						if (includeUserIdsErr) return rej('invalid include_userIds param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'exclude_user_ids' parameter
 | 
						// Get 'exclude_userIds' parameter
 | 
				
			||||||
	const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_user_ids).optional.array('id').$;
 | 
						const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_userIds).optional.array('id').$;
 | 
				
			||||||
	if (excludeUserIdsErr) return rej('invalid exclude_user_ids param');
 | 
						if (excludeUserIdsErr) return rej('invalid exclude_userIds param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'include_user_usernames' parameter
 | 
						// Get 'include_user_usernames' parameter
 | 
				
			||||||
	const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.include_user_usernames).optional.array('string').$;
 | 
						const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.include_user_usernames).optional.array('string').$;
 | 
				
			||||||
| 
						 | 
					@ -81,7 +81,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (includeUserUsernames != null) {
 | 
						if (includeUserUsernames != null) {
 | 
				
			||||||
		const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
 | 
							const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
 | 
				
			||||||
			const _user = await User.findOne({
 | 
								const _user = await User.findOne({
 | 
				
			||||||
				username_lower: username.toLowerCase()
 | 
									usernameLower: username.toLowerCase()
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
			return _user ? _user._id : null;
 | 
								return _user ? _user._id : null;
 | 
				
			||||||
		}))).filter(id => id != null);
 | 
							}))).filter(id => id != null);
 | 
				
			||||||
| 
						 | 
					@ -92,7 +92,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (excludeUserUsernames != null) {
 | 
						if (excludeUserUsernames != null) {
 | 
				
			||||||
		const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
 | 
							const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
 | 
				
			||||||
			const _user = await User.findOne({
 | 
								const _user = await User.findOne({
 | 
				
			||||||
				username_lower: username.toLowerCase()
 | 
									usernameLower: username.toLowerCase()
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
			return _user ? _user._id : null;
 | 
								return _user ? _user._id : null;
 | 
				
			||||||
		}))).filter(id => id != null);
 | 
							}))).filter(id => id != null);
 | 
				
			||||||
| 
						 | 
					@ -143,13 +143,13 @@ async function search(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (includeUserIds && includeUserIds.length != 0) {
 | 
						if (includeUserIds && includeUserIds.length != 0) {
 | 
				
			||||||
		push({
 | 
							push({
 | 
				
			||||||
			user_id: {
 | 
								userId: {
 | 
				
			||||||
				$in: includeUserIds
 | 
									$in: includeUserIds
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	} else if (excludeUserIds && excludeUserIds.length != 0) {
 | 
						} else if (excludeUserIds && excludeUserIds.length != 0) {
 | 
				
			||||||
		push({
 | 
							push({
 | 
				
			||||||
			user_id: {
 | 
								userId: {
 | 
				
			||||||
				$nin: excludeUserIds
 | 
									$nin: excludeUserIds
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
| 
						 | 
					@ -158,7 +158,7 @@ async function search(
 | 
				
			||||||
	if (following != null && me != null) {
 | 
						if (following != null && me != null) {
 | 
				
			||||||
		const ids = await getFriends(me._id, false);
 | 
							const ids = await getFriends(me._id, false);
 | 
				
			||||||
		push({
 | 
							push({
 | 
				
			||||||
			user_id: following ? {
 | 
								userId: following ? {
 | 
				
			||||||
				$in: ids
 | 
									$in: ids
 | 
				
			||||||
			} : {
 | 
								} : {
 | 
				
			||||||
				$nin: ids.concat(me._id)
 | 
									$nin: ids.concat(me._id)
 | 
				
			||||||
| 
						 | 
					@ -168,45 +168,45 @@ async function search(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (me != null) {
 | 
						if (me != null) {
 | 
				
			||||||
		const mutes = await Mute.find({
 | 
							const mutes = await Mute.find({
 | 
				
			||||||
			muter_id: me._id,
 | 
								muterId: me._id,
 | 
				
			||||||
			deleted_at: { $exists: false }
 | 
								deletedAt: { $exists: false }
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
		const mutedUserIds = mutes.map(m => m.mutee_id);
 | 
							const mutedUserIds = mutes.map(m => m.muteeId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		switch (mute) {
 | 
							switch (mute) {
 | 
				
			||||||
			case 'mute_all':
 | 
								case 'mute_all':
 | 
				
			||||||
				push({
 | 
									push({
 | 
				
			||||||
					user_id: {
 | 
										userId: {
 | 
				
			||||||
						$nin: mutedUserIds
 | 
											$nin: mutedUserIds
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					'_reply.user_id': {
 | 
										'_reply.userId': {
 | 
				
			||||||
						$nin: mutedUserIds
 | 
											$nin: mutedUserIds
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					'_repost.user_id': {
 | 
										'_repost.userId': {
 | 
				
			||||||
						$nin: mutedUserIds
 | 
											$nin: mutedUserIds
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'mute_related':
 | 
								case 'mute_related':
 | 
				
			||||||
				push({
 | 
									push({
 | 
				
			||||||
					'_reply.user_id': {
 | 
										'_reply.userId': {
 | 
				
			||||||
						$nin: mutedUserIds
 | 
											$nin: mutedUserIds
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					'_repost.user_id': {
 | 
										'_repost.userId': {
 | 
				
			||||||
						$nin: mutedUserIds
 | 
											$nin: mutedUserIds
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'mute_direct':
 | 
								case 'mute_direct':
 | 
				
			||||||
				push({
 | 
									push({
 | 
				
			||||||
					user_id: {
 | 
										userId: {
 | 
				
			||||||
						$nin: mutedUserIds
 | 
											$nin: mutedUserIds
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case 'direct_only':
 | 
								case 'direct_only':
 | 
				
			||||||
				push({
 | 
									push({
 | 
				
			||||||
					user_id: {
 | 
										userId: {
 | 
				
			||||||
						$in: mutedUserIds
 | 
											$in: mutedUserIds
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
| 
						 | 
					@ -214,11 +214,11 @@ async function search(
 | 
				
			||||||
			case 'related_only':
 | 
								case 'related_only':
 | 
				
			||||||
				push({
 | 
									push({
 | 
				
			||||||
					$or: [{
 | 
										$or: [{
 | 
				
			||||||
						'_reply.user_id': {
 | 
											'_reply.userId': {
 | 
				
			||||||
							$in: mutedUserIds
 | 
												$in: mutedUserIds
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}, {
 | 
										}, {
 | 
				
			||||||
						'_repost.user_id': {
 | 
											'_repost.userId': {
 | 
				
			||||||
							$in: mutedUserIds
 | 
												$in: mutedUserIds
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}]
 | 
										}]
 | 
				
			||||||
| 
						 | 
					@ -227,15 +227,15 @@ async function search(
 | 
				
			||||||
			case 'all_only':
 | 
								case 'all_only':
 | 
				
			||||||
				push({
 | 
									push({
 | 
				
			||||||
					$or: [{
 | 
										$or: [{
 | 
				
			||||||
						user_id: {
 | 
											userId: {
 | 
				
			||||||
							$in: mutedUserIds
 | 
												$in: mutedUserIds
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}, {
 | 
										}, {
 | 
				
			||||||
						'_reply.user_id': {
 | 
											'_reply.userId': {
 | 
				
			||||||
							$in: mutedUserIds
 | 
												$in: mutedUserIds
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}, {
 | 
										}, {
 | 
				
			||||||
						'_repost.user_id': {
 | 
											'_repost.userId': {
 | 
				
			||||||
							$in: mutedUserIds
 | 
												$in: mutedUserIds
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}]
 | 
										}]
 | 
				
			||||||
| 
						 | 
					@ -247,7 +247,7 @@ async function search(
 | 
				
			||||||
	if (reply != null) {
 | 
						if (reply != null) {
 | 
				
			||||||
		if (reply) {
 | 
							if (reply) {
 | 
				
			||||||
			push({
 | 
								push({
 | 
				
			||||||
				reply_id: {
 | 
									replyId: {
 | 
				
			||||||
					$exists: true,
 | 
										$exists: true,
 | 
				
			||||||
					$ne: null
 | 
										$ne: null
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -255,11 +255,11 @@ async function search(
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			push({
 | 
								push({
 | 
				
			||||||
				$or: [{
 | 
									$or: [{
 | 
				
			||||||
					reply_id: {
 | 
										replyId: {
 | 
				
			||||||
						$exists: false
 | 
											$exists: false
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}, {
 | 
									}, {
 | 
				
			||||||
					reply_id: null
 | 
										replyId: null
 | 
				
			||||||
				}]
 | 
									}]
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -268,7 +268,7 @@ async function search(
 | 
				
			||||||
	if (repost != null) {
 | 
						if (repost != null) {
 | 
				
			||||||
		if (repost) {
 | 
							if (repost) {
 | 
				
			||||||
			push({
 | 
								push({
 | 
				
			||||||
				repost_id: {
 | 
									repostId: {
 | 
				
			||||||
					$exists: true,
 | 
										$exists: true,
 | 
				
			||||||
					$ne: null
 | 
										$ne: null
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -276,11 +276,11 @@ async function search(
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			push({
 | 
								push({
 | 
				
			||||||
				$or: [{
 | 
									$or: [{
 | 
				
			||||||
					repost_id: {
 | 
										repostId: {
 | 
				
			||||||
						$exists: false
 | 
											$exists: false
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}, {
 | 
									}, {
 | 
				
			||||||
					repost_id: null
 | 
										repostId: null
 | 
				
			||||||
				}]
 | 
									}]
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -289,7 +289,7 @@ async function search(
 | 
				
			||||||
	if (media != null) {
 | 
						if (media != null) {
 | 
				
			||||||
		if (media) {
 | 
							if (media) {
 | 
				
			||||||
			push({
 | 
								push({
 | 
				
			||||||
				media_ids: {
 | 
									mediaIds: {
 | 
				
			||||||
					$exists: true,
 | 
										$exists: true,
 | 
				
			||||||
					$ne: null
 | 
										$ne: null
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -297,11 +297,11 @@ async function search(
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			push({
 | 
								push({
 | 
				
			||||||
				$or: [{
 | 
									$or: [{
 | 
				
			||||||
					media_ids: {
 | 
										mediaIds: {
 | 
				
			||||||
						$exists: false
 | 
											$exists: false
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}, {
 | 
									}, {
 | 
				
			||||||
					media_ids: null
 | 
										mediaIds: null
 | 
				
			||||||
				}]
 | 
									}]
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -330,7 +330,7 @@ async function search(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (sinceDate) {
 | 
						if (sinceDate) {
 | 
				
			||||||
		push({
 | 
							push({
 | 
				
			||||||
			created_at: {
 | 
								createdAt: {
 | 
				
			||||||
				$gt: new Date(sinceDate)
 | 
									$gt: new Date(sinceDate)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
| 
						 | 
					@ -338,7 +338,7 @@ async function search(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (untilDate) {
 | 
						if (untilDate) {
 | 
				
			||||||
		push({
 | 
							push({
 | 
				
			||||||
			created_at: {
 | 
								createdAt: {
 | 
				
			||||||
				$lt: new Date(untilDate)
 | 
									$lt: new Date(untilDate)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
 | 
				
			||||||
 * @return {Promise<any>}
 | 
					 * @return {Promise<any>}
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
					module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	// Get 'post_id' parameter
 | 
						// Get 'postId' parameter
 | 
				
			||||||
	const [postId, postIdErr] = $(params.post_id).id().$;
 | 
						const [postId, postIdErr] = $(params.postId).id().$;
 | 
				
			||||||
	if (postIdErr) return rej('invalid post_id param');
 | 
						if (postIdErr) return rej('invalid postId param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get post
 | 
						// Get post
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const post = await Post.findOne({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,17 +49,17 @@ module.exports = async (params, user, app) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Watchしているチャンネルを取得
 | 
							// Watchしているチャンネルを取得
 | 
				
			||||||
		watchingChannelIds: ChannelWatching.find({
 | 
							watchingChannelIds: ChannelWatching.find({
 | 
				
			||||||
			user_id: user._id,
 | 
								userId: user._id,
 | 
				
			||||||
			// 削除されたドキュメントは除く
 | 
								// 削除されたドキュメントは除く
 | 
				
			||||||
			deleted_at: { $exists: false }
 | 
								deletedAt: { $exists: false }
 | 
				
			||||||
		}).then(watches => watches.map(w => w.channel_id)),
 | 
							}).then(watches => watches.map(w => w.channelId)),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// ミュートしているユーザーを取得
 | 
							// ミュートしているユーザーを取得
 | 
				
			||||||
		mutedUserIds: Mute.find({
 | 
							mutedUserIds: Mute.find({
 | 
				
			||||||
			muter_id: user._id,
 | 
								muterId: user._id,
 | 
				
			||||||
			// 削除されたドキュメントは除く
 | 
								// 削除されたドキュメントは除く
 | 
				
			||||||
			deleted_at: { $exists: false }
 | 
								deletedAt: { $exists: false }
 | 
				
			||||||
		}).then(ms => ms.map(m => m.mutee_id))
 | 
							}).then(ms => ms.map(m => m.muteeId))
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//#region Construct query
 | 
						//#region Construct query
 | 
				
			||||||
| 
						 | 
					@ -70,31 +70,31 @@ module.exports = async (params, user, app) => {
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		$or: [{
 | 
							$or: [{
 | 
				
			||||||
			// フォローしている人のタイムラインへの投稿
 | 
								// フォローしている人のタイムラインへの投稿
 | 
				
			||||||
			user_id: {
 | 
								userId: {
 | 
				
			||||||
				$in: followingIds
 | 
									$in: followingIds
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			// 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
 | 
								// 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
 | 
				
			||||||
			$or: [{
 | 
								$or: [{
 | 
				
			||||||
				channel_id: {
 | 
									channelId: {
 | 
				
			||||||
					$exists: false
 | 
										$exists: false
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}, {
 | 
								}, {
 | 
				
			||||||
				channel_id: null
 | 
									channelId: null
 | 
				
			||||||
			}]
 | 
								}]
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			// Watchしているチャンネルへの投稿
 | 
								// Watchしているチャンネルへの投稿
 | 
				
			||||||
			channel_id: {
 | 
								channelId: {
 | 
				
			||||||
				$in: watchingChannelIds
 | 
									$in: watchingChannelIds
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}],
 | 
							}],
 | 
				
			||||||
		// mute
 | 
							// mute
 | 
				
			||||||
		user_id: {
 | 
							userId: {
 | 
				
			||||||
			$nin: mutedUserIds
 | 
								$nin: mutedUserIds
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		'_reply.user_id': {
 | 
							'_reply.userId': {
 | 
				
			||||||
			$nin: mutedUserIds
 | 
								$nin: mutedUserIds
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		'_repost.user_id': {
 | 
							'_repost.userId': {
 | 
				
			||||||
			$nin: mutedUserIds
 | 
								$nin: mutedUserIds
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
| 
						 | 
					@ -110,11 +110,11 @@ module.exports = async (params, user, app) => {
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	} else if (sinceDate) {
 | 
						} else if (sinceDate) {
 | 
				
			||||||
		sort._id = 1;
 | 
							sort._id = 1;
 | 
				
			||||||
		query.created_at = {
 | 
							query.createdAt = {
 | 
				
			||||||
			$gt: new Date(sinceDate)
 | 
								$gt: new Date(sinceDate)
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	} else if (untilDate) {
 | 
						} else if (untilDate) {
 | 
				
			||||||
		query.created_at = {
 | 
							query.createdAt = {
 | 
				
			||||||
			$lt: new Date(untilDate)
 | 
								$lt: new Date(untilDate)
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,7 +38,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	if (pollErr) return rej('invalid poll param');
 | 
						if (pollErr) return rej('invalid poll param');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		created_at: {
 | 
							createdAt: {
 | 
				
			||||||
			$gte: new Date(Date.now() - ms('1days'))
 | 
								$gte: new Date(Date.now() - ms('1days'))
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		repost_count: {
 | 
							repost_count: {
 | 
				
			||||||
| 
						 | 
					@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
 | 
				
			||||||
	} as any;
 | 
						} as any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (reply != undefined) {
 | 
						if (reply != undefined) {
 | 
				
			||||||
		query.reply_id = reply ? { $exists: true, $ne: null } : null;
 | 
							query.replyId = reply ? { $exists: true, $ne: null } : null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (repost != undefined) {
 | 
						if (repost != undefined) {
 | 
				
			||||||
		query.repost_id = repost ? { $exists: true, $ne: null } : null;
 | 
							query.repostId = repost ? { $exists: true, $ne: null } : null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (media != undefined) {
 | 
						if (media != undefined) {
 | 
				
			||||||
		query.media_ids = media ? { $exists: true, $ne: null } : null;
 | 
							query.mediaIds = media ? { $exists: true, $ne: null } : null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (poll != undefined) {
 | 
						if (poll != undefined) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ import User from '../models/user';
 | 
				
			||||||
 *         schema:
 | 
					 *         schema:
 | 
				
			||||||
 *           type: object
 | 
					 *           type: object
 | 
				
			||||||
 *           properties:
 | 
					 *           properties:
 | 
				
			||||||
 *             posts_count:
 | 
					 *             postsCount:
 | 
				
			||||||
 *               description: count of all posts of misskey
 | 
					 *               description: count of all posts of misskey
 | 
				
			||||||
 *               type: number
 | 
					 *               type: number
 | 
				
			||||||
 *             users_count:
 | 
					 *             users_count:
 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,7 @@ module.exports = params => new Promise(async (res, rej) => {
 | 
				
			||||||
		.count();
 | 
							.count();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res({
 | 
						res({
 | 
				
			||||||
		posts_count: postsCount,
 | 
							postsCount: postsCount,
 | 
				
			||||||
		users_count: usersCount
 | 
							users_count: usersCount
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,11 +28,11 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if already subscribed
 | 
						// if already subscribed
 | 
				
			||||||
	const exist = await Subscription.findOne({
 | 
						const exist = await Subscription.findOne({
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		endpoint: endpoint,
 | 
							endpoint: endpoint,
 | 
				
			||||||
		auth: auth,
 | 
							auth: auth,
 | 
				
			||||||
		publickey: publickey,
 | 
							publickey: publickey,
 | 
				
			||||||
		deleted_at: { $exists: false }
 | 
							deletedAt: { $exists: false }
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (exist !== null) {
 | 
						if (exist !== null) {
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,7 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	await Subscription.insert({
 | 
						await Subscription.insert({
 | 
				
			||||||
		user_id: user._id,
 | 
							userId: user._id,
 | 
				
			||||||
		endpoint: endpoint,
 | 
							endpoint: endpoint,
 | 
				
			||||||
		auth: auth,
 | 
							auth: auth,
 | 
				
			||||||
		publickey: publickey
 | 
							publickey: publickey
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,7 @@ module.exports = async (params) => new Promise(async (res, rej) => {
 | 
				
			||||||
	const exist = await User
 | 
						const exist = await User
 | 
				
			||||||
		.count({
 | 
							.count({
 | 
				
			||||||
			host: null,
 | 
								host: null,
 | 
				
			||||||
			username_lower: username.toLowerCase()
 | 
								usernameLower: username.toLowerCase()
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			limit: 1
 | 
								limit: 1
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
Some files were not shown because too many files have changed in this diff Show more
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue