mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-05-25 12:04:32 +00:00
ntf: separate notifierKey from SMPQueueNtf (#382)
This commit is contained in:
@@ -17,7 +17,7 @@ import qualified Data.Map.Strict as M
|
||||
import Data.Set (Set, insert)
|
||||
import qualified Simplex.Messaging.Crypto as C
|
||||
import Simplex.Messaging.Notifications.Protocol
|
||||
import Simplex.Messaging.Protocol (NotifierId, ProtocolServer)
|
||||
import Simplex.Messaging.Protocol (NtfPrivateSignKey)
|
||||
import Simplex.Messaging.TMap (TMap)
|
||||
import qualified Simplex.Messaging.TMap as TM
|
||||
import Simplex.Messaging.Util (whenM, ($>>=), (<$$>))
|
||||
@@ -27,7 +27,7 @@ data NtfStore = NtfStore
|
||||
tokenRegistrations :: TMap DeviceToken (TMap ByteString NtfTokenId),
|
||||
subscriptions :: TMap NtfSubscriptionId NtfSubData,
|
||||
tokenSubscriptions :: TMap NtfTokenId (TVar (Set NtfSubscriptionId)),
|
||||
subscriptionLookup :: TMap (NtfTokenId, ProtocolServer, NotifierId) NtfSubscriptionId
|
||||
subscriptionLookup :: TMap (NtfTokenId, SMPQueueNtf) NtfSubscriptionId
|
||||
}
|
||||
|
||||
newNtfStore :: STM NtfStore
|
||||
@@ -66,6 +66,7 @@ mkNtfTknData ntfTknId (NewNtfTkn token tknVerifyKey _) tknDhKeys tknDhSecret tkn
|
||||
|
||||
data NtfSubData = NtfSubData
|
||||
{ smpQueue :: SMPQueueNtf,
|
||||
notifierKey :: NtfPrivateSignKey,
|
||||
tokenId :: NtfTokenId,
|
||||
subStatus :: TVar NtfSubStatus
|
||||
}
|
||||
@@ -133,12 +134,12 @@ getNtfSubscription st subId =
|
||||
(sub,) <$$> getActiveNtfToken st tokenId
|
||||
|
||||
findNtfSubscription :: NtfStore -> NewNtfEntity 'Subscription -> STM (Maybe (NtfTknData, Maybe NtfSubData))
|
||||
findNtfSubscription st (NewNtfSub tknId SMPQueueNtf {smpServer, notifierId}) = do
|
||||
findNtfSubscription st (NewNtfSub tknId smpQueue _) = do
|
||||
getActiveNtfToken st tknId >>= mapM (\tkn -> (tkn,) <$> getSub)
|
||||
where
|
||||
getSub :: STM (Maybe NtfSubData)
|
||||
getSub =
|
||||
TM.lookup (tknId, smpServer, notifierId) (subscriptionLookup st)
|
||||
TM.lookup (tknId, smpQueue) (subscriptionLookup st)
|
||||
$>>= (`TM.lookup` subscriptions st)
|
||||
|
||||
getActiveNtfToken :: NtfStore -> NtfTokenId -> STM (Maybe NtfTknData)
|
||||
@@ -148,18 +149,18 @@ getActiveNtfToken st tknId =
|
||||
pure $ if tStatus == NTActive then Just tkn else Nothing
|
||||
|
||||
mkNtfSubData :: NewNtfEntity 'Subscription -> STM NtfSubData
|
||||
mkNtfSubData (NewNtfSub tokenId smpQueue) = do
|
||||
mkNtfSubData (NewNtfSub tokenId smpQueue notifierKey) = do
|
||||
subStatus <- newTVar NSNew
|
||||
pure NtfSubData {smpQueue, tokenId, subStatus}
|
||||
pure NtfSubData {smpQueue, tokenId, subStatus, notifierKey}
|
||||
|
||||
addNtfSubscription :: NtfStore -> NtfSubscriptionId -> NtfSubData -> STM (Maybe ())
|
||||
addNtfSubscription st subId sub@NtfSubData {smpQueue = SMPQueueNtf {smpServer, notifierId}, tokenId} =
|
||||
addNtfSubscription st subId sub@NtfSubData {smpQueue, tokenId} =
|
||||
TM.lookup tokenId (tokenSubscriptions st) >>= mapM insertSub
|
||||
where
|
||||
insertSub ts = do
|
||||
modifyTVar' ts $ insert subId
|
||||
TM.insert subId sub $ subscriptions st
|
||||
TM.insert (tokenId, smpServer, notifierId) subId (subscriptionLookup st)
|
||||
TM.insert (tokenId, smpQueue) subId (subscriptionLookup st)
|
||||
|
||||
-- getNtfRec :: NtfStore -> SNtfEntity e -> NtfEntityId -> STM (Maybe (NtfEntityRec e))
|
||||
-- getNtfRec st ent entId = case ent of
|
||||
|
||||
Reference in New Issue
Block a user