Skip to content

Commit

Permalink
fix push to live feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Manwe-777 committed Oct 1, 2023
1 parent 86e955a commit 823fd48
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions public/tooldb-worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"6.3.7","branch":"dev","timestamp":1695928178227}
{"version":"6.3.8","branch":"dev","timestamp":1696202802802}
7 changes: 4 additions & 3 deletions tooldb-worker/pushToLivefeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, number>>();
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);
Expand Down

0 comments on commit 823fd48

Please sign in to comment.