Category watch state (#7109)

* feat: wip, category watch change

* feat: pass data to client

* feat: allow changing state

* fix: account page categories

* fix: show in unread if topic is followed or category is watched

* feat: add default watch state to acp

* feat: save user category watch state

* feat: update unread recent pages

* fix: remove dupe code

* fix: flip conditions

* fix: handle empty arrays

* fix: ignore/watch on others profile

* feat: upgrade script for category states

if there are any users ignoring categories set their state in new zset and delete cid:<cid>:ignorers

* fix: upgrade

* fix: tests

* fix: redis count

* fix: more tests
This commit is contained in:
Barış Soner Uşaklı
2018-12-14 16:24:17 -05:00
committed by GitHub
parent 2104877c76
commit eb7ae54f81
28 changed files with 376 additions and 136 deletions

View File

@@ -21,6 +21,7 @@ require('./unread')(Categories);
require('./activeusers')(Categories);
require('./recentreplies')(Categories);
require('./update')(Categories);
require('./watch')(Categories);
Categories.exists = function (cid, callback) {
db.exists('category:' + cid, callback);
@@ -45,8 +46,8 @@ Categories.getCategoryById = function (data, callback) {
topicCount: function (next) {
Categories.getTopicCount(data, next);
},
isIgnored: function (next) {
Categories.isIgnored([data.cid], data.uid, next);
watchState: function (next) {
Categories.getWatchState([data.cid], data.uid, next);
},
parent: function (next) {
if (category.parentCid) {
@@ -64,7 +65,9 @@ Categories.getCategoryById = function (data, callback) {
category.topics = results.topics.topics;
category.nextStart = results.topics.nextStart;
category.topic_count = results.topicCount;
category.isIgnored = results.isIgnored[0];
category.isWatched = results.watchState[0] === Categories.watchStates.watching;
category.isNotWatched = results.watchState[0] === Categories.watchStates.notwatching;
category.isIgnored = results.watchState[0] === Categories.watchStates.ignoring;
category.parent = results.parent;
calculateTopicPostCount(category);
@@ -76,14 +79,6 @@ Categories.getCategoryById = function (data, callback) {
], callback);
};
Categories.isIgnored = function (cids, uid, callback) {
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, cids.map(() => false));
}
const keys = cids.map(cid => 'cid:' + cid + ':ignorers');
db.isMemberOfSortedSets(keys, uid, callback);
};
Categories.getAllCidsFromSet = function (key, callback) {
const cids = cache.get(key);
if (cids) {
@@ -443,20 +438,4 @@ Categories.buildForSelectCategories = function (categories, callback) {
callback(null, categoriesData);
};
Categories.getIgnorers = function (cid, start, stop, callback) {
db.getSortedSetRevRange('cid:' + cid + ':ignorers', start, stop, callback);
};
Categories.filterIgnoringUids = function (cid, uids, callback) {
async.waterfall([
function (next) {
db.isSortedSetMembers('cid:' + cid + ':ignorers', uids, next);
},
function (isIgnoring, next) {
const readingUids = uids.filter((uid, index) => uid && !isIgnoring[index]);
next(null, readingUids);
},
], callback);
};
Categories.async = require('../promisify')(Categories);