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; host: string;
inbox?: string; inbox?: string;
}; };
_replyIds?: mongo.ObjectID[];
}; };
/** /**

View file

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