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:
Barış Soner Uşaklı
2024-06-17 11:18:48 -04:00
parent 05b7828e33
commit c021e7e80f
12 changed files with 162 additions and 28 deletions

View File

@@ -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) => {