Add notification nav, show only replies in short format

This commit is contained in:
2026-04-17 00:29:51 -07:00
parent 1353acc4d1
commit e27cf391ef
10 changed files with 245 additions and 8 deletions

View File

@@ -433,6 +433,31 @@ export async function getRepliesForPost(postID) {
}
return replies;
}
export async function getNotificationsForUser(userID) {
const userPostIds = new Set(await getAllIds(userID));
const knownUsers = [...(await indexedDB.databases())]
.map(db => db.name?.replace('user_', '')).filter(Boolean);
let notifications = [];
for (const dbUserID of knownUsers) {
try {
const { store } = await getDBTransactionStore(dbUserID);
const index = store.index("postReplyIndex");
const results = await new Promise((resolve, reject) => {
const req = index.getAll();
req.onsuccess = () => resolve(req.result);
req.onerror = () => reject(req.error);
});
for (const r of results) {
if (r.data.reply_to_id && userPostIds.has(r.data.reply_to_id)) {
notifications.push(r);
}
}
}
catch (_) { }
}
notifications.sort((a, b) => new Date(b.data.post_timestamp).getTime() - new Date(a.data.post_timestamp).getTime());
return notifications;
}
export async function getPostsByIds(userID, postIDs) {
const { store } = await getDBTransactionStore(userID);
const index = store.index("postIDIndex");