This commit is contained in:
syuilo 2018-05-29 00:36:52 +09:00
parent 5d82443389
commit bd1f3a2f01
3 changed files with 22 additions and 23 deletions

View File

@ -77,6 +77,7 @@ export type INote = {
host: string;
inbox?: string;
};
_replyIds?: mongo.ObjectID[];
};
/**

View File

@ -1,15 +1,8 @@
/**
* Module dependencies
*/
import $ from 'cafy'; import ID from '../../../../cafy-id';
import Note, { pack } from '../../../../models/note';
/**
* Show a replies of a note
*
* @param {any} params
* @param {any} user
* @return {Promise<any>}
* GEt replies of a note
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
@ -24,10 +17,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter
const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
if (sortError) return rej('invalid sort param');
// Lookup note
const note = await Note.findOne({
_id: noteId
@ -37,17 +26,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return rej('note not found');
}
// Issue query
const replies = await Note
.find({ replyId: note._id }, {
limit: limit,
skip: offset,
sort: {
_id: sort == 'asc' ? 1 : -1
}
});
const ids = note._replyIds.slice(offset, offset + limit);
// Serialize
res(await Promise.all(replies.map(async note =>
await pack(note, user))));
res(await Promise.all(ids.map(id => pack(id, user))));
});

View File

@ -172,6 +172,24 @@ export default async (user: IUser, data: {
}
});
if (data.reply) {
Note.update({ _id: data.reply._id }, {
$push: {
_replyIds: note._id
}
});
}
const isQuote = data.renote && (data.text || data.poll || data.media);
if (isQuote) {
Note.update({ _id: data.renote._id }, {
$push: {
_quoteIds: note._id
}
});
}
// Serialize
const noteObj = await pack(note);