mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-10-11 22:07:17 +00:00
smp-server: remove delivered notification keys
This commit is contained in:
@@ -10,6 +10,7 @@ module Simplex.Messaging.Server.NtfStore
|
||||
storeNtf,
|
||||
deleteNtfs,
|
||||
deleteExpiredNtfs,
|
||||
deleteEmptyNtfs,
|
||||
) where
|
||||
|
||||
import Control.Concurrent.STM
|
||||
@@ -22,6 +23,7 @@ import Simplex.Messaging.Encoding.String
|
||||
import Simplex.Messaging.Protocol (EncNMsgMeta, MsgId, NotifierId)
|
||||
import Simplex.Messaging.TMap (TMap)
|
||||
import qualified Simplex.Messaging.TMap as TM
|
||||
import Simplex.Messaging.Util (whenM)
|
||||
|
||||
newtype NtfStore = NtfStore (TMap NotifierId (TVar [MsgNtf]))
|
||||
|
||||
@@ -57,6 +59,14 @@ deleteExpiredNtfs (NtfStore ns) old =
|
||||
else writeTVar v ntfs' >> pure (length ntfs - length ntfs')
|
||||
| otherwise -> pure 0
|
||||
|
||||
deleteEmptyNtfs :: NtfStore -> [(NotifierId, TVar [MsgNtf])] -> IO ()
|
||||
deleteEmptyNtfs (NtfStore ns) = mapM_ deleteEmpty
|
||||
where
|
||||
deleteEmpty (nId, v) =
|
||||
whenM (null <$> readTVarIO v) $
|
||||
atomically $
|
||||
TM.lookup nId ns >>= mapM_ (\v' -> whenM (null <$> readTVar v') $ TM.delete nId ns)
|
||||
|
||||
data NtfLogRecord = NLRv1 NotifierId MsgNtf
|
||||
|
||||
instance StrEncoding MsgNtf where
|
||||
|
||||
Reference in New Issue
Block a user