refactor: topics.markAsUnreadForAll

fix fork test
This commit is contained in:
Barış Soner Uşaklı
2022-12-22 09:53:04 -05:00
parent 2144650dd5
commit d1087106e4
5 changed files with 11 additions and 10 deletions

View File

@@ -34,7 +34,10 @@ SocketTopics.bookmark = async function (socket, data) {
}
const postcount = await topics.getTopicField(data.tid, 'postcount');
if (data.index > meta.config.bookmarkThreshold && postcount > meta.config.bookmarkThreshold) {
await topics.setUserBookmark(data.tid, socket.uid, data.index);
const currentIndex = await db.sortedSetScore(`tid:${data.tid}:bookmarks`, socket.uid);
if (!currentIndex || data.index > currentIndex) {
await topics.setUserBookmark(data.tid, socket.uid, data.index);
}
}
};

View File

@@ -54,7 +54,6 @@ module.exports = function (SocketTopics) {
throw new Error('[[error:no-privileges]]');
}
const isAdmin = await user.isAdministrator(socket.uid);
const now = Date.now();
await Promise.all(tids.map(async (tid) => {
const topicData = await topics.getTopicFields(tid, ['tid', 'cid']);
if (!topicData.tid) {
@@ -65,9 +64,6 @@ module.exports = function (SocketTopics) {
throw new Error('[[error:no-privileges]]');
}
await topics.markAsUnreadForAll(tid);
await topics.updateRecent(tid, now);
await db.sortedSetAdd(`cid:${topicData.cid}:tids:lastposttime`, now, tid);
await topics.setTopicField(tid, 'lastposttime', now);
}));
topics.pushUnreadCount(socket.uid);
};

View File

@@ -25,10 +25,7 @@ module.exports = function (Topics) {
if (parseInt(uid, 10) <= 0) {
return;
}
const currentIndex = await db.sortedSetScore(`tid:${tid}:bookmarks`, uid);
if (!currentIndex || index > currentIndex) {
await db.sortedSetAdd(`tid:${tid}:bookmarks`, index, uid);
}
await db.sortedSetAdd(`tid:${tid}:bookmarks`, index, uid);
};
Topics.getTopicBookmarks = async function (tid) {

View File

@@ -213,7 +213,7 @@ module.exports = function (Topics) {
async function onNewPost(postData, data) {
const { tid } = postData;
const { uid } = postData;
await Topics.markAsUnreadForAll(tid);
await Topics.markCategoryUnreadForAll(tid);
await Topics.markAsRead([tid], uid);
const [
userInfo,

View File

@@ -260,7 +260,12 @@ module.exports = function (Topics) {
};
Topics.markAsUnreadForAll = async function (tid) {
const now = Date.now();
const cid = await Topics.getTopicField(tid, 'cid');
await Topics.markCategoryUnreadForAll(tid);
await Topics.updateRecent(tid, now);
await db.sortedSetAdd(`cid:${cid}:tids:lastposttime`, now, tid);
await Topics.setTopicField(tid, 'lastposttime', now);
};
Topics.markAsRead = async function (tids, uid) {