Post --> Note

Closes #1411
This commit is contained in:
syuilo
2018-04-08 02:30:37 +09:00
parent c7106d250c
commit a1b490afa7
167 changed files with 4440 additions and 1762 deletions

View File

@ -2,7 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
import Post from '../../../../models/post';
import Note from '../../../../models/note';
import User, { pack } from '../../../../models/user';
module.exports = (params, me) => new Promise(async (res, rej) => {
@ -27,8 +27,8 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
return rej('user not found');
}
// Fetch recent posts
const recentPosts = await Post.find({
// Fetch recent notes
const recentNotes = await Note.find({
userId: user._id,
replyId: {
$exists: true,
@ -46,13 +46,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
});
// 投稿が少なかったら中断
if (recentPosts.length === 0) {
if (recentNotes.length === 0) {
return res([]);
}
const replyTargetPosts = await Post.find({
const replyTargetNotes = await Note.find({
_id: {
$in: recentPosts.map(p => p.replyId)
$in: recentNotes.map(p => p.replyId)
},
userId: {
$ne: user._id
@ -66,9 +66,9 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const repliedUsers = {};
// Extract replies from recent posts
replyTargetPosts.forEach(post => {
const userId = post.userId.toString();
// Extract replies from recent notes
replyTargetNotes.forEach(note => {
const userId = note.userId.toString();
if (repliedUsers[userId]) {
repliedUsers[userId]++;
} else {

View File

@ -3,11 +3,11 @@
*/
import $ from 'cafy';
import getHostLower from '../../common/get-host-lower';
import Post, { pack } from '../../../../models/post';
import Note, { pack } from '../../../../models/note';
import User from '../../../../models/user';
/**
* Get posts of a user
* Get notes of a user
*
* @param {any} params
* @param {any} me
@ -124,14 +124,14 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
//#endregion
// Issue query
const posts = await Post
const notes = await Note
.find(query, {
limit: limit,
sort: sort
});
// Serialize
res(await Promise.all(posts.map(async (post) =>
await pack(post, me)
res(await Promise.all(notes.map(async (note) =>
await pack(note, me)
)));
});