summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2018-05-29 19:45:08 +0000
committerJames Crayne <jim.crayne@gmail.com>2018-05-29 19:45:08 +0000
commita4d4c31015014cba7f9305710b57b589eb532f5a (patch)
tree722f7e8c1363b25f8dbca42c6dbdde54c523d642 /src/Network
parent4ce5feb72cdb452d0a6ba9cc326d541b292caedb (diff)
setNoSpam, and defaultTypingHook (why not?)
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index fe620757..2fb7f2c1 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -67,10 +67,13 @@ data SessionView = SessionView
67 { svNick :: TVar ByteString 67 { svNick :: TVar ByteString
68 , svStatus :: TVar UserStatus 68 , svStatus :: TVar UserStatus
69 , svStatusMsg :: TVar ByteString 69 , svStatusMsg :: TVar ByteString
70 , svTyping :: TVar TypingStatus
71 , svNoSpam :: TVar (Maybe NoSpam)
70 , svTheirNick :: TVar ByteString 72 , svTheirNick :: TVar ByteString
71 , svTheirStatus :: TVar UserStatus 73 , svTheirStatus :: TVar UserStatus
72 , svTheirStatusMsg :: TVar ByteString 74 , svTheirStatusMsg :: TVar ByteString
73 , svNoSpam :: TVar (Maybe NoSpam) 75 , svTheirTyping :: TVar TypingStatus
76 , svTheirNoSpam :: TVar (Maybe NoSpam)
74 , svGroups :: TVar (Map.Map GroupChatId (Set.Set SockAddr)) 77 , svGroups :: TVar (Map.Map GroupChatId (Set.Set SockAddr))
75 78
76 -- allthough these directories are not visible to others on the net 79 -- allthough these directories are not visible to others on the net
@@ -197,10 +200,13 @@ newSessionsState crypto unrechook hooks = do
197 nick <- atomically $ newTVar B.empty 200 nick <- atomically $ newTVar B.empty
198 status <- atomically $ newTVar Online 201 status <- atomically $ newTVar Online
199 statusmsg <- atomically $ newTVar B.empty 202 statusmsg <- atomically $ newTVar B.empty
203 typing <- atomically $ newTVar NotTyping
204 nospam <- atomically $ newTVar Nothing
200 theirnick <- atomically $ newTVar B.empty 205 theirnick <- atomically $ newTVar B.empty
201 theirstatus <- atomically $ newTVar Online 206 theirstatus <- atomically $ newTVar Online
202 theirstatusmsg <- atomically $ newTVar B.empty 207 theirstatusmsg <- atomically $ newTVar B.empty
203 nospam <- atomically $ newTVar Nothing 208 theirtyping <- atomically $ newTVar NotTyping
209 theirnospam <- atomically $ newTVar Nothing
204 grps <- atomically $ newTVar Map.empty 210 grps <- atomically $ newTVar Map.empty
205 pname <- getProgName 211 pname <- getProgName
206 cachedir <- sensibleCacheDirCreateIfMissing pname 212 cachedir <- sensibleCacheDirCreateIfMissing pname
@@ -221,10 +227,13 @@ newSessionsState crypto unrechook hooks = do
221 { svNick = nick 227 { svNick = nick
222 , svStatus = status 228 , svStatus = status
223 , svStatusMsg = statusmsg 229 , svStatusMsg = statusmsg
230 , svTyping = typing
231 , svNoSpam = nospam
224 , svTheirNick = theirnick 232 , svTheirNick = theirnick
225 , svTheirStatus = theirstatus 233 , svTheirStatus = theirstatus
226 , svTheirStatusMsg = theirstatusmsg 234 , svTheirStatusMsg = theirstatusmsg
227 , svNoSpam = nospam 235 , svTheirTyping = theirtyping
236 , svTheirNoSpam = theirnospam
228 , svGroups = grps 237 , svGroups = grps
229 , svCacheDir = cachedir 238 , svCacheDir = cachedir
230 , svTmpDir = tmpdir 239 , svTmpDir = tmpdir
@@ -675,6 +684,23 @@ setNick crypto session nick = do
675 let nickPacket = error "todo" 684 let nickPacket = error "todo"
676 return (Left "TODO: sendMessage crypto (NetCrypto nickPacket)") 685 return (Left "TODO: sendMessage crypto (NetCrypto nickPacket)")
677 -- return (Right ()) 686 -- return (Right ())
687 --
688setTyping :: TransportCrypto -> NetCryptoSession -> TypingStatus -> IO (Either String ())
689setTyping crypto session status = do
690 let viewVar = ncView session
691 atomically $ do
692 view <- readTVar viewVar
693 writeTVar (svTyping view) status
694 let typingPacket = error "todo"
695 return (Left "TODO: sendMessage crypto (NetCrypto typingPacket)")
696
697setNoSpam :: TransportCrypto -> NetCryptoSession -> Maybe NoSpam -> IO (Either String ())
698setNoSpam crypto session mbnospam = do
699 let viewVar = ncView session
700 atomically $ do
701 view <- readTVar viewVar
702 writeTVar (svNoSpam view) mbnospam
703 return (Right ())
678 704
679setStatus :: TransportCrypto -> NetCryptoSession -> UserStatus -> IO (Either String ()) 705setStatus :: TransportCrypto -> NetCryptoSession -> UserStatus -> IO (Either String ())
680setStatus crypto session status = do 706setStatus crypto session status = do
@@ -703,6 +729,7 @@ defaultCryptoDataHooks :: Map.Map MessageType [NetCryptoHook]
703defaultCryptoDataHooks 729defaultCryptoDataHooks
704 = Map.fromList 730 = Map.fromList
705 [ (Msg USERSTATUS,[defaultUserStatusHook]) 731 [ (Msg USERSTATUS,[defaultUserStatusHook])
732 , (Msg TYPING,[defaultTypingHook])
706 , (Msg NICKNAME, [defaultNicknameHook]) 733 , (Msg NICKNAME, [defaultNicknameHook])
707 , (Msg STATUSMESSAGE, [defaultStatusMsgHook]) 734 , (Msg STATUSMESSAGE, [defaultStatusMsgHook])
708 ] 735 ]
@@ -716,6 +743,15 @@ defaultUserStatusHook session cm@(TwoByte {msgID=USERSTATUS, msgByte=statusByte}
716 writeTVar (svTheirStatus view) status 743 writeTVar (svTheirStatus view) status
717 hookHelper True (Msg USERSTATUS) session cm 744 hookHelper True (Msg USERSTATUS) session cm
718 745
746defaultTypingHook :: NetCryptoSession -> CryptoMessage -> IO (Maybe (CryptoMessage -> CryptoMessage))
747defaultTypingHook session cm@(TwoByte {msgID=TYPING, msgByte=statusByte}) = do
748 let status = toEnum8 statusByte
749 viewVar = ncView session
750 atomically $ do
751 view <- readTVar viewVar
752 writeTVar (svTheirStatus view) status
753 hookHelper True (Msg TYPING) session cm
754
719defaultNicknameHook :: NetCryptoSession -> CryptoMessage -> IO (Maybe (CryptoMessage -> CryptoMessage)) 755defaultNicknameHook :: NetCryptoSession -> CryptoMessage -> IO (Maybe (CryptoMessage -> CryptoMessage))
720defaultNicknameHook session cm@(UpToN {msgID=NICKNAME, msgBytes=nick}) = do 756defaultNicknameHook session cm@(UpToN {msgID=NICKNAME, msgBytes=nick}) = do
721 let viewVar = ncView session 757 let viewVar = ncView session