This commit is contained in:
@@ -51,7 +51,7 @@ export default (notification: any) => new Promise<any>(async (resolve, reject) =
|
||||
case 'reply':
|
||||
case 'repost':
|
||||
case 'quote':
|
||||
case 'like':
|
||||
case 'reaction':
|
||||
case 'poll_vote':
|
||||
// Populate post
|
||||
_notification.post = await serializePost(_notification.post_id, me);
|
||||
|
43
src/api/serializers/post-reaction.ts
Normal file
43
src/api/serializers/post-reaction.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import * as mongo from 'mongodb';
|
||||
import deepcopy = require('deepcopy');
|
||||
import Reaction from '../models/post-reaction';
|
||||
import serializeUser from './user';
|
||||
|
||||
/**
|
||||
* Serialize a reaction
|
||||
*
|
||||
* @param {any} reaction
|
||||
* @param {any} me?
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
export default (
|
||||
reaction: any,
|
||||
me?: any
|
||||
) => new Promise<any>(async (resolve, reject) => {
|
||||
let _reaction: any;
|
||||
|
||||
// Populate the reaction if 'reaction' is ID
|
||||
if (mongo.ObjectID.prototype.isPrototypeOf(reaction)) {
|
||||
_reaction = await Reaction.findOne({
|
||||
_id: reaction
|
||||
});
|
||||
} else if (typeof reaction === 'string') {
|
||||
_reaction = await Reaction.findOne({
|
||||
_id: new mongo.ObjectID(reaction)
|
||||
});
|
||||
} else {
|
||||
_reaction = deepcopy(reaction);
|
||||
}
|
||||
|
||||
// Rename _id to id
|
||||
_reaction.id = _reaction._id;
|
||||
delete _reaction._id;
|
||||
|
||||
// Populate user
|
||||
_reaction.user = await serializeUser(_reaction.user_id, me);
|
||||
|
||||
resolve(_reaction);
|
||||
});
|
@@ -4,7 +4,7 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import deepcopy = require('deepcopy');
|
||||
import Post from '../models/post';
|
||||
import Like from '../models/like';
|
||||
import Reaction from '../models/post-reaction';
|
||||
import Vote from '../models/poll-vote';
|
||||
import serializeApp from './app';
|
||||
import serializeUser from './user';
|
||||
@@ -100,18 +100,18 @@ const self = (
|
||||
}
|
||||
}
|
||||
|
||||
// Check if it is liked
|
||||
// Fetch my reaction
|
||||
if (me && opts.detail) {
|
||||
const liked = await Like
|
||||
.count({
|
||||
const reaction = await Reaction
|
||||
.findOne({
|
||||
user_id: me._id,
|
||||
post_id: id,
|
||||
deleted_at: { $exists: false }
|
||||
}, {
|
||||
limit: 1
|
||||
});
|
||||
|
||||
_post.is_liked = liked === 1;
|
||||
if (reaction) {
|
||||
_post.my_reaction = reaction.reaction;
|
||||
}
|
||||
}
|
||||
|
||||
resolve(_post);
|
||||
|
Reference in New Issue
Block a user