refactor: topic mark read/unread routes

This commit is contained in:
Julian Lam
2023-04-24 14:14:16 -04:00
parent 82b4984b9d
commit 36895421ba
11 changed files with 192 additions and 118 deletions

View File

@@ -268,3 +268,27 @@ topicsAPI.deleteEvent = async (caller, { tid, eventId }) => {
await topics.events.purge(tid, [eventId]);
};
topicsAPI.markRead = async (caller, { tid }) => {
const hasMarked = await topics.markAsRead([tid], caller.uid);
const promises = [topics.markTopicNotificationsRead([tid], caller.uid)];
if (hasMarked) {
promises.push(topics.pushUnreadCount(caller.uid));
}
await Promise.all(promises);
};
topicsAPI.markUnread = async (caller, { tid }) => {
await topics.markUnread(tid, caller.uid);
topics.pushUnreadCount(caller.uid);
};
topicsAPI.bump = async (caller, { tid }) => {
const isAdminOrMod = await privileges.topics.isAdminOrMod(tid, caller.uid);
if (!isAdminOrMod) {
throw new Error('[[error:no-privileges]]');
}
await topics.markAsUnreadForAll(tid);
topics.pushUnreadCount(caller.uid);
};