-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Order recently sent messages by local timestamp (#7012)
- Loading branch information
Showing
5 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
frontend/openchat-client/src/stores/recentlySentMessages.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createMapStore } from "./mapStore"; | ||
import { writable } from "svelte/store"; | ||
|
||
// Key: MessageId, Value: Timestamp | ||
export const recentlySentMessagesStore = createMapStore<bigint, bigint>( | ||
writable(new Map<bigint, bigint>()), | ||
); | ||
|
||
function pruneOldMessages(): void { | ||
if (recentlySentMessagesStore.size() > 0) { | ||
const oneMinuteAgo = BigInt(Date.now() - 60000); | ||
recentlySentMessagesStore.update((map) => { | ||
const newMap = new Map<bigint, bigint>(); | ||
for (const [key, value] of map.entries()) { | ||
if (value > oneMinuteAgo) { | ||
newMap.set(key, value); | ||
} | ||
} | ||
return newMap; | ||
}); | ||
} | ||
} | ||
|
||
// Prune old messages every 31 seconds | ||
window.setInterval(pruneOldMessages, 31000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters