mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-21 23:12:58 +01:00
refactor: topics.markAsUnreadForAll
fix fork test
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user