git » sdk » commit 9d51abc

Update status on recent corrections as well

author Stephen Paul Weber
2025-10-17 02:39:54 UTC
committer Stephen Paul Weber
2025-10-17 02:43:11 UTC
parent 49ed31eb076099f210876305f0e5130e41f90d74

Update status on recent corrections as well

They aren't stored top level, so we need to do a table scan

borogove/persistence/IDB.js +22 -0

diff --git a/borogove/persistence/IDB.js b/borogove/persistence/IDB.js
index 16b3364..014c600 100644
--- a/borogove/persistence/IDB.js
+++ b/borogove/persistence/IDB.js
@@ -484,6 +484,28 @@ export default async (dbname, media, tokenize, stemmer) => {
 				result.update(newStatus);
 				return await hydrateMessage(newStatus);
 			}
+
+			// Maybe a correction? Check recent messages
+			const cursor = store.index("accounts").openCursor(
+				IDBKeyRange.bound([account], [account, []]),
+				"prev"
+			);
+			let count = 0;
+			while (true) {
+				const cresult = await promisifyRequest(cursor);
+				if (cresult && count < 1000) {
+					const value = cresult.value;
+					if (value?.versions?.[0]?.localId === localId && value?.direction === enums.MessageDirection.MessageSent && value?.status !== enums.MessageStatus.MessageDeliveredToDevice) {
+						const newStatus = { ...value, versions: [{ ...value.versions[0], status: status }, ...value.versions.slice(1)], status: status };
+						cresult.update(newStatus);
+						return await hydrateMessage(newStatus);
+					}
+					cresult.continue();
+				} else {
+					break;
+				}
+			}
+
 			throw "Message not found: " + localId;
 		},