mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +01:00
refactor: announces
store number of announces on post hash, show announces like votes, with tooltip and a way to see all, remove them from topic.events so they dont load all tid:<tid>:posts everytime topic is loaded
This commit is contained in:
@@ -365,14 +365,24 @@ Notes.announce.list = async ({ pid, tid }) => {
|
||||
|
||||
Notes.announce.add = async (pid, actor, timestamp = Date.now()) => {
|
||||
await db.sortedSetAdd(`pid:${pid}:announces`, timestamp, actor);
|
||||
await posts.setPostField(pid, 'announces', await db.sortedSetCard(`pid:${pid}:announces`));
|
||||
};
|
||||
|
||||
Notes.announce.remove = async (pid, actor) => {
|
||||
await db.sortedSetRemove(`pid:${pid}:announces`, actor);
|
||||
const count = await db.sortedSetCard(`pid:${pid}:announces`);
|
||||
if (count > 0) {
|
||||
await posts.setPostField(pid, 'announces', count);
|
||||
} else {
|
||||
await db.deleteObjectField(`post:${pid}`, 'announces');
|
||||
}
|
||||
};
|
||||
|
||||
Notes.announce.removeAll = async (pid) => {
|
||||
await db.delete(`pid:${pid}:announces`);
|
||||
await Promise.all([
|
||||
db.delete(`pid:${pid}:announces`),
|
||||
db.deleteObjectField(`post:${pid}`, 'announces'),
|
||||
]);
|
||||
};
|
||||
|
||||
Notes.delete = async (pids) => {
|
||||
|
||||
Reference in New Issue
Block a user