diff --git a/public/tooldb-worker/index.js b/public/tooldb-worker/index.js index 5796a4f..e4e478a 100644 --- a/public/tooldb-worker/index.js +++ b/public/tooldb-worker/index.js @@ -19,11 +19,10 @@ function afterLogin() { .queryKeys(`:${self.toolDb.user.pubKey}.draft-`) .then(handleDraftsIndex_1.default); } + self.toolDb.addKeyListener(`matches-livefeed-${currentDay}`, handleLiveFeed_1.default); + self.toolDb.getData(`matches-livefeed-${currentDay}`); self.toolDb.subscribeData("userids", true); - const liveFeedToday = `matches-livefeed-${currentDay}`; - self.toolDb.addKeyListener(liveFeedToday, handleLiveFeed_1.default); - self.toolDb.subscribeData(liveFeedToday); - self.toolDb.getData(liveFeedToday); + self.toolDb.subscribeData(`matches-livefeed-${currentDay}`); self.toolDb.getData("hiddenDecks", true, 5000).then((hidden) => { if (hidden) { self.globalData.hiddenDecks = hidden; @@ -703,12 +702,13 @@ async function pushToLiveFeed(key, match) { if (!self.globalData.liveFeed[key]) { // Create CRDT document with the new match added to it try { - const newLiveFeed = automerge_1.default.change(self.globalData.liveFeed, (doc) => { + const origDoc = automerge_1.default.init(); + const newLiveFeed = automerge_1.default.change(origDoc, (doc) => { doc[key] = new Date(match.internalMatch.date).getTime(); }); const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); - window.toolDb - .putCrdt(`matches-livefeed-${currentDay}`, automerge_1.default.getChanges(self.globalData.liveFeed, newLiveFeed), false) + self.toolDb + .putCrdt(`matches-livefeed-${currentDay}`, automerge_1.default.getChanges(origDoc, newLiveFeed), false) .catch(console.error); // self.globalData.liveFeed = newLiveFeed; } diff --git a/src/info.json b/src/info.json index ce72fbd..040dc04 100644 --- a/src/info.json +++ b/src/info.json @@ -1 +1 @@ -{"version":"6.3.7","branch":"dev","timestamp":1695928178227} \ No newline at end of file +{"version":"6.3.8","branch":"dev","timestamp":1696202802802} \ No newline at end of file diff --git a/tooldb-worker/pushToLivefeed.ts b/tooldb-worker/pushToLivefeed.ts index aa210ae..9e5b186 100644 --- a/tooldb-worker/pushToLivefeed.ts +++ b/tooldb-worker/pushToLivefeed.ts @@ -8,15 +8,16 @@ export default async function pushToLiveFeed(key: string, match: DbMatch) { if (!self.globalData.liveFeed[key]) { // Create CRDT document with the new match added to it try { - const newLiveFeed = Automerge.change(self.globalData.liveFeed, (doc) => { + const origDoc = Automerge.init>(); + const newLiveFeed = Automerge.change(origDoc, (doc) => { doc[key] = new Date(match.internalMatch.date).getTime(); }); const currentDay = Math.floor(new Date().getTime() / (86400 * 1000)); - window.toolDb + self.toolDb .putCrdt( `matches-livefeed-${currentDay}`, - Automerge.getChanges(self.globalData.liveFeed, newLiveFeed), + Automerge.getChanges(origDoc, newLiveFeed), false ) .catch(console.error);