diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-07-17 22:29:22 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-07-26 21:55:07 +0200 |
commit | 97427b2f49daa9d86661ad999d4da17ac7a4acb4 (patch) | |
tree | 9e8b064932c844a4cbd44a191f74f53776889cfc /src/Test.hs | |
parent | 479b63d8c30c0bc6e6475882d7fb573db5dad1f9 (diff) |
Contacts using Set sructure
Diffstat (limited to 'src/Test.hs')
-rw-r--r-- | src/Test.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Test.hs b/src/Test.hs index 8bd34ea..c106285 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -15,6 +15,7 @@ import Data.ByteString.Char8 qualified as BC import Data.ByteString.Lazy qualified as BL import Data.Foldable import Data.IP (fromSockAddr) +import Data.Ord import Data.Text (Text) import Data.Text qualified as T import Data.Text.Encoding @@ -25,6 +26,7 @@ import System.IO import System.IO.Error import Attach +import Contact import Identity import Network import Pairing @@ -194,6 +196,10 @@ commands = map (T.pack *** id) , ("attach-to", cmdAttachTo) , ("attach-accept", cmdAttachAccept) , ("attach-reject", cmdAttachReject) + , ("contact-request", cmdContactRequest) + , ("contact-accept", cmdContactAccept) + , ("contact-reject", cmdContactReject) + , ("contact-list", cmdContactList) ] cmdStore :: Command @@ -262,6 +268,7 @@ cmdStartServer = do peers <- liftIO $ newMVar (1, []) server <- liftIO $ startServer defaultServerOptions h (hPutStrLn stderr) [ someServiceAttr $ pairingAttributes (Proxy @AttachService) out peers "attach" + , someServiceAttr $ pairingAttributes (Proxy @ContactService) out peers "contact" , someService @SyncService Proxy ] @@ -353,3 +360,30 @@ cmdAttachReject :: Command cmdAttachReject = do [spidx] <- asks tiParams attachReject =<< getPeer spidx + +cmdContactRequest :: Command +cmdContactRequest = do + [spidx] <- asks tiParams + contactRequest =<< getPeer spidx + +cmdContactAccept :: Command +cmdContactAccept = do + [spidx] <- asks tiParams + contactAccept =<< getPeer spidx + +cmdContactReject :: Command +cmdContactReject = do + [spidx] <- asks tiParams + contactReject =<< getPeer spidx + +cmdContactList :: Command +cmdContactList = do + h <- maybe (fail "failed to reload head") return =<< maybe (fail "no current head") (liftIO . reloadHead) =<< gets tsHead + let contacts = fromSetBy (comparing contactName) . lookupSharedValue . lsShared . headObject $ h + forM_ contacts $ \c -> do + cmdOut $ concat + [ "contact-list-item " + , T.unpack $ contactName c + , case contactIdentity c of Nothing -> ""; Just idt -> " " ++ T.unpack (displayIdentity idt) + ] + cmdOut "contact-list-done" |