Merge branch 'develop' into activitypub

This commit is contained in:
Barış Soner Uşaklı
2024-07-25 11:26:29 -04:00
63 changed files with 486 additions and 244 deletions

View File

@@ -331,12 +331,19 @@ postsAPI.getVoters = async function (caller, data) {
}
const { pid } = data;
const cid = await posts.getCidByPid(pid);
if (!await canSeeVotes(caller.uid, cid)) {
const [canSeeUpvotes, canSeeDownvotes] = await Promise.all([
canSeeVotes(caller.uid, cid, 'upvoteVisibility'),
canSeeVotes(caller.uid, cid, 'downvoteVisibility'),
]);
if (!canSeeUpvotes && !canSeeDownvotes) {
throw new Error('[[error:no-privileges]]');
}
const showDownvotes = !meta.config['downvote:disabled'];
const repSystemDisabled = meta.config['reputation:disabled'];
const showUpvotes = canSeeUpvotes && !repSystemDisabled;
const showDownvotes = canSeeDownvotes && !meta.config['downvote:disabled'] && !repSystemDisabled;
const [upvoteUids, downvoteUids] = await Promise.all([
db.getSetMembers(`pid:${data.pid}:upvote`),
showUpvotes ? db.getSetMembers(`pid:${data.pid}:upvote`) : [],
showDownvotes ? db.getSetMembers(`pid:${data.pid}:downvote`) : [],
]);
@@ -348,6 +355,7 @@ postsAPI.getVoters = async function (caller, data) {
return {
upvoteCount: upvoters.length,
downvoteCount: downvoters.length,
showUpvotes: showUpvotes,
showDownvotes: showDownvotes,
upvoters: upvoters,
downvoters: downvoters,
@@ -360,7 +368,7 @@ postsAPI.getUpvoters = async function (caller, data) {
}
const { pid } = data;
const cid = await posts.getCidByPid(pid);
if (!await canSeeVotes(caller.uid, cid)) {
if (!await canSeeVotes(caller.uid, cid, 'upvoteVisibility')) {
throw new Error('[[error:no-privileges]]');
}
@@ -415,7 +423,7 @@ postsAPI.getAnnouncers = async (caller, data) => {
};
};
async function canSeeVotes(uid, cids) {
async function canSeeVotes(uid, cids, type) {
const isArray = Array.isArray(cids);
if (!isArray) {
cids = [cids];
@@ -434,8 +442,8 @@ async function canSeeVotes(uid, cids) {
(
cidToAllowed[cid] &&
(
meta.config.voteVisibility === 'all' ||
(meta.config.voteVisibility === 'loggedin' && parseInt(uid, 10) > 0)
meta.config[type] === 'all' ||
(meta.config[type] === 'loggedin' && parseInt(uid, 10) > 0)
)
)
);