mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
feat: Like(Note) and Undo(Like); federating likes
This commit is contained in:
@@ -8,6 +8,7 @@ const topics = require('../topics');
|
||||
const plugins = require('../plugins');
|
||||
const privileges = require('../privileges');
|
||||
const translator = require('../translator');
|
||||
const utils = require('../utils');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
const votesInProgress = {};
|
||||
@@ -99,17 +100,17 @@ module.exports = function (Posts) {
|
||||
};
|
||||
|
||||
function voteInProgress(pid, uid) {
|
||||
return Array.isArray(votesInProgress[uid]) && votesInProgress[uid].includes(parseInt(pid, 10));
|
||||
return Array.isArray(votesInProgress[uid]) && votesInProgress[uid].includes(String(pid));
|
||||
}
|
||||
|
||||
function putVoteInProgress(pid, uid) {
|
||||
votesInProgress[uid] = votesInProgress[uid] || [];
|
||||
votesInProgress[uid].push(parseInt(pid, 10));
|
||||
votesInProgress[uid].push(String(pid));
|
||||
}
|
||||
|
||||
function clearVoteProgress(pid, uid) {
|
||||
if (Array.isArray(votesInProgress[uid])) {
|
||||
const index = votesInProgress[uid].indexOf(parseInt(pid, 10));
|
||||
const index = votesInProgress[uid].indexOf(String(pid));
|
||||
if (index !== -1) {
|
||||
votesInProgress[uid].splice(index, 1);
|
||||
}
|
||||
@@ -171,8 +172,7 @@ module.exports = function (Posts) {
|
||||
}
|
||||
|
||||
async function vote(type, unvote, pid, uid, voteStatus) {
|
||||
uid = parseInt(uid, 10);
|
||||
if (uid <= 0) {
|
||||
if (utils.isNumber(uid) && parseInt(uid, 10) <= 0) {
|
||||
throw new Error('[[error:not-logged-in]]');
|
||||
}
|
||||
const now = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user