mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-05 07:10:30 +01:00
feat: asserted topics and posts to remote categories will notify and add to unread based on remote category watch state
This commit is contained in:
@@ -7,6 +7,7 @@ const events = require('../events');
|
||||
const user = require('../user');
|
||||
const groups = require('../groups');
|
||||
const privileges = require('../privileges');
|
||||
const utils = require('../utils');
|
||||
|
||||
const activitypubApi = require('./activitypub');
|
||||
|
||||
@@ -157,7 +158,9 @@ categoriesAPI.getTopics = async (caller, data) => {
|
||||
|
||||
categoriesAPI.setWatchState = async (caller, { cid, state, uid }) => {
|
||||
let targetUid = caller.uid;
|
||||
const cids = Array.isArray(cid) ? cid.map(cid => parseInt(cid, 10)) : [parseInt(cid, 10)];
|
||||
let cids = Array.isArray(cid) ? cid : [cid];
|
||||
cids = cids.map(cid => (utils.isNumber(cid) ? parseInt(cid, 10) : cid));
|
||||
|
||||
if (uid) {
|
||||
targetUid = uid;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const db = require('../database');
|
||||
const user = require('../user');
|
||||
const activitypub = require('../activitypub');
|
||||
const utils = require('../utils');
|
||||
|
||||
module.exports = function (Categories) {
|
||||
Categories.watchStates = {
|
||||
@@ -32,7 +33,11 @@ module.exports = function (Categories) {
|
||||
user.getSettings(uid),
|
||||
db.sortedSetsScore(keys, uid),
|
||||
]);
|
||||
return states.map(state => state || Categories.watchStates[userSettings.categoryWatchState]);
|
||||
|
||||
const fallbacks = cids.map(cid => (utils.isNumber(cid) ?
|
||||
Categories.watchStates[userSettings.categoryWatchState] : Categories.watchStates.notwatching));
|
||||
|
||||
return states.map((state, idx) => state || fallbacks[idx]);
|
||||
};
|
||||
|
||||
Categories.getIgnorers = async function (cid, start, stop) {
|
||||
|
||||
@@ -20,6 +20,11 @@ const uidToSystemGroup = {
|
||||
};
|
||||
|
||||
helpers.isUsersAllowedTo = async function (privilege, uids, cid) {
|
||||
// Remote categories inherit world pseudo-category privileges
|
||||
if (!utils.isNumber(cid)) {
|
||||
cid = -1;
|
||||
}
|
||||
|
||||
const [hasUserPrivilege, hasGroupPrivilege] = await Promise.all([
|
||||
groups.isMembers(uids, `cid:${cid}:privileges:${privilege}`),
|
||||
groups.isMembersOfGroupList(uids, `cid:${cid}:privileges:groups:${privilege}`),
|
||||
|
||||
@@ -67,7 +67,11 @@ module.exports = function (User) {
|
||||
};
|
||||
|
||||
User.getCategoriesByStates = async function (uid, states) {
|
||||
const cids = await categories.getAllCidsFromSet('categories:cid');
|
||||
const remoteCids = await db.getObjectValues('handle:cid');
|
||||
const cids = [
|
||||
(await categories.getAllCidsFromSet('categories:cid')),
|
||||
...remoteCids,
|
||||
];
|
||||
if (!(parseInt(uid, 10) > 0)) {
|
||||
return cids;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user