Merge pull request #65 from simplex-chat/v4

v0.4.0
This commit is contained in:
Evgeny Poberezkin authored and GitHub committed 2021-09-11 20:18:53 +01:00
commit 471652a042
41 files changed
+6348 -878

No files matched your search

+9 -8
View File
@@ -4,6 +4,7 @@ on:
push:
branches:
- master
- v4
tags:
- "v*"
pull_request:
@@ -49,24 +50,24 @@ jobs:
- os: ubuntu-20.04
cache_path: ~/.stack
stack_args: "--test"
artifact_rel_path: /bin/dog-food
asset_name: dog-food-ubuntu-20_04-x86-64
artifact_rel_path: /bin/simplex-chat
asset_name: simplex-chat-ubuntu-20_04-x86-64
- os: ubuntu-18.04
cache_path: ~/.stack
stack_args: "--test"
artifact_rel_path: /bin/dog-food
asset_name: dog-food-ubuntu-18_04-x86-64
artifact_rel_path: /bin/simplex-chat
asset_name: simplex-chat-ubuntu-18_04-x86-64
- os: macos-latest
cache_path: ~/.stack
stack_args: "--test"
artifact_rel_path: /bin/dog-food
asset_name: dog-food-macos-x86-64
artifact_rel_path: /bin/simplex-chat
asset_name: simplex-chat-macos-x86-64
# TODO enable tests for windows once fixed (remove stack_args altogether)
- os: windows-latest
cache_path: C:/sr
stack_args: ""
artifact_rel_path: /bin/dog-food.exe
asset_name: dog-food-windows-x86-64
artifact_rel_path: /bin/simplex-chat.exe
asset_name: simplex-chat-windows-x86-64
steps:
- name: Clone project
uses: actions/checkout@v2
+1
View File
@@ -48,3 +48,4 @@ stack.yaml.lock
# chat database
*.db
*.db.bak
+1 -1
View File
@@ -7,4 +7,4 @@ WORKDIR /project
RUN stack install
FROM scratch AS export-stage
COPY --from=build-stage /root/.local/bin/dog-food /
COPY --from=build-stage /root/.local/bin/simplex-chat /
+58 -36
View File
@@ -7,19 +7,21 @@
[![GitHub build](https://github.com/simplex-chat/simplex-chat/workflows/build/badge.svg)](https://github.com/simplex-chat/simplex-chat/actions?query=workflow%3Abuild)
[![GitHub release](https://img.shields.io/github/v/release/simplex-chat/simplex-chat)](https://github.com/simplex-chat/simplex-chat/releases)
> **NEW in v0.4: [groups](#groups) and [sending files](#sending-files)!**
The motivation for SimpleX chat is [presented here](./simplex.md).
SimpleX chat prototype is a thin terminal UI on top of [SimpleXMQ](https://github.com/simplex-chat/simplexmq) message broker that uses [SMP protocols](https://github.com/simplex-chat/simplexmq/blob/master/protocol).
See [simplex.chat](https://simplex.chat) website for chat demo and the explanations of the system and how SMP protocol works.
![simplex-chat](./images/simplex-chat.gif)
![simplex-chat](./images/connection.gif)
## Table of contents
- [Disclaimer](#disclaimer)
- [Network topology](#network-topology)
- [Current features of the terminal chat](#current-features-of-the-terminal-chat)
- [Terminal chat features](#terminal-chat-features)
- [Installation](#installation)
- [Download chat client](#download-chat-client)
- [Build from source](#build-from-source)
@@ -28,8 +30,10 @@ See [simplex.chat](https://simplex.chat) website for chat demo and the explanati
- [Usage](#usage)
- [Running the chat client](#running-the-chat-client)
- [How to use SimpleX chat](#how-to-use-simplex-chat)
- [Groups](#groups)
- [Sending files](#sending-files)
- [Access chat history](#access-chat-history)
- [Roadmap](#roadmap)
- [Future roadmap](#future-roadmap)
- [License](#license)
## Disclaimer
@@ -50,11 +54,13 @@ Unlike federated networks, the participating server nodes do NOT have records of
The routing of messages relies on the knowledge of client devices how user contacts and groups map at any given moment of time to these disposable queues on server nodes.
## Current features of the terminal chat
## Terminal chat features
- 1-to-1 chat with multiple people in the same terminal window.
- Group messaging.
- Sending files to contacts and groups.
- Auto-populated recipient name - just type your messages to reply to the sender once the connection is established.
- Demo SMP server available at `smp1.simplex.im:5223` - you can deploy your own server (`smp-server` executable in [simplexmq](https://github.com/simplex-chat/simplexmq) repo).
- Demo SMP servers available and pre-configured in the app - or you can [deploy your own server](https://github.com/simplex-chat/simplexmq#using-smp-server-and-smp-agent).
- No global identity or any names visible to the server(s), ensuring full privacy of your contacts and conversations.
- E2E encryption, with RSA public key that has to be passed out-of-band (see [How to use SimpleX chat](#how-to-use-simplex-chat)).
- Message signing and verification with automatically generated RSA keys.
@@ -62,7 +68,7 @@ The routing of messages relies on the knowledge of client devices how user conta
- Authentication of each command/message by SMP servers with automatically generated RSA key pairs.
- TCP transport encryption using SMP transport protocol.
RSA keys are not used as identity, they are randomly generated for each contact. 2048 bit keys are used, it can be changed to 4096-bit in code via [rsaKeySize setting](https://github.com/simplex-chat/simplex-chat/blob/master/apps/dog-food/Main.hs).
RSA keys are not used as identity, they are randomly generated for each contact.
## Installation
@@ -74,7 +80,7 @@ Download the chat binary for your system from the [latest stable release](https:
```sh
chmod +x <binary>
mv <binary> ~/.local/bin/dog-food
mv <binary> ~/.local/bin/simplex-chat
```
(or any other preferred location on PATH).
@@ -84,7 +90,7 @@ On MacOS you also need to [allow Gatekeeper to run it](https://support.apple.com
#### Windows
```sh
move <binary> %APPDATA%/local/bin/dog-food.exe
move <binary> %APPDATA%/local/bin/simplex-chat.exe
```
### Build from source
@@ -121,54 +127,72 @@ $ stack install
### Running the chat client
To start the chat client, run `dog-food` (as in [eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food)) from the terminal.
To start the chat client, run `simplex-chat` from the terminal.
By default, app data directory is created in the home directory (`~/.simplex`, or `%APPDATA%/simplex` on Windows), and SQLite database file `smp-chat.db` is initialized in it.
By default, app data directory is created in the home directory (`~/.simplex`, or `%APPDATA%/simplex` on Windows), and two SQLite database files `simplex.chat.db` and `simplex.agent.db` are initialized in it.
The default SMP server is `smp1.simplex.im#pLdiGvm0jD1CMblnov6Edd/391OrYsShw+RgdfR0ChA=` (base-64 encoded string after server host is the transport key digest) - it is pre-configured in the app.
To specify a different file path for the chat database use `-d` command line option:
To specify a different file path prefix for the database files use `-d` command line option:
```shell
$ dog-food -d my-chat.db
$ simplex-chat -d alice
```
Running above, for example, would create `alice.chat.db` and `alice.agent.db` database files in current directory.
Default SMP servers are hosted on Linode (London, UK and Fremont, CA) - they are [pre-configured in the app](https://github.com/simplex-chat/simplex-chat/blob/master/src/Simplex/Chat/Options.hs#L40). Base-64 encoded string after server host is the transport key digest.
If you deployed your own SMP server(s) you can configure client via `-s` option:
```shell
$ dog-food -s smp.example.com:5223#KXNE1m2E1m0lm92WGKet9CL6+lO742Vy5G6nsrkvgs8=
$ simplex-chat -s smp.example.com:5223#KXNE1m2E1m0lm92WGKet9CL6+lO742Vy5G6nsrkvgs8=
```
The base-64 encoded string in server address is the digest of RSA transport handshake key that the server will generate on the first run and output its digest.
You can still talk to people using default or any other server - it only affects the location of the message queue when you initiate the connection (and the reply queue can be on another server, as set by the other party's client).
Run `dog-food --help` to see all available options.
Run `simplex-chat -h` to see all available options.
### How to use SimpleX chat
Once you have started the chat, you will be prompted to specify your "display name" and an optional "full name" to create a local chat profile. Your display name is an alias for your contacts to refer to you by - it is not unique and does not serve as a global identity. In case different contacts chose the same display name, the chat client adds a numeric suffix to their local display names.
This diagram shows how to connect and message a contact:
<div align="center">
<img align="center" src="images/how-to-use-simplex.svg">
</div>
Once you have started the chat, use `/add <name1>` to create a new connection and generate an invitation (`<name1>` is any name you want to use for that contact). The add command will output an invitation. Send this invitation to your contact via any other channel.
Once you've set up your local profile, enter `/c` (for `/connect`) to create a new connection and generate an invitation. Send this invitation to your contact via any other channel.
The invitation has the format `smp::<server>::<queue_id>::<rsa_public_key_for_this_queue_only>`. The invitation can only be used once and even if this is intercepted, the attacker would not be able to use it to send you the messages via this queue once your contact confirms that the connection is established.
The contact who received the invitation should use `/connect <name2> <invitation>` to accept the connection (`<name2>` is any name that the accepting contact wants to use for you).
The contact who received the invitation should enter `/c <invitation>` to accept the connection. This establishes the connection, and both parties are notified.
Once the contact has used the `/connect` command, a connection is established and both parties are notified.
They would then use `@<name> <message>` commands to send messages. One may also press Space or just start typing a message to send a message to the contact that was the last.
If your contact is disconnected, restart the chat client - it may happen if you lose internet connection.
They would then use `@<name> <message>` commands to send messages. You may also just start typing a message to send it to the contact that was the last.
Use `/help` in chat to see the list of available commands.
### Groups
To create a group use `/g <group>`, the add contacts to it with `/a <group> <name>`and send messages with `#<group> <message>`. Use `/help groups` for other commands.
![simplex-chat](./images/groups.gif)
> **Please note**: the groups are not stored on any server, they are maintained as a list of members in the app database to whom the messages will be sent.
### Sending files
You can send a file to your contact with `/f @<contact> <file_path>` - the recipient will have to accept it before it is sent. Use `/help files` for other commands.
![simplex-chat](./images/file-transfer.gif)
You can send files to a group with `/f #<group> <file_path>`.
### Access chat history
> 🚧 **Section currently out of date - will be updated soon** 🏗
SimpleX chat stores all your contacts and conversations in a local database file, making it private and portable by design, fully owned and controlled by you.
You can search your chat history via SQLite database file:
@@ -188,20 +212,18 @@ order by internal_id desc;
> **Please note:** SQLite foreign key constraints are disabled by default, and must be **[enabled separately for each database connection](https://sqlite.org/foreignkeys.html#fk_enable)**. The latter can be achieved by running `PRAGMA foreign_keys = ON;` command on an open database connection. By running data altering queries without enabling foreign keys prior to that, you may risk putting your database in an inconsistent state.
## Roadmap
## Future roadmap
The consumer ready system will have these parts implemented:
1. Application level chat protocol. This will allow to separate physical server connection management from logical chat contacts, and to support all common chat functions. Currently in progress in [v4 branch](https://github.com/simplex-chat/simplex-chat/tree/v4).
2. Symmetric groups support in SMP agent protocol, as a foundation for chat groups.
3. SMP queue redundancy and rotation in SMP agent protocol.
4. Message delivery confirmation in SMP agent protocol.
5. Multi-agent/device data synchronization - to use chat on multiple devices.
6. Synchronous streams support in SMP and SMP agent protocols, to support file transfer.
7. Desktop and mobile apps.
8. Scripts for simple SMP server deployment to hosting providers: Linode ([done](https://github.com/simplex-chat/simplexmq#deploy-smp-server-on-linode)), Digital Ocean and Heroku.
9. Public broadcast channels.
10. Optional public contact/group addresses using DNS-based contact addresses (like email) to establish connections, but not using it to route messages - in this way you will keep all your contacts and groups even if you lose the control of the domain.
1. Mobile and desktop apps (in progress).
2. SMP protocol improvements:
- SMP queue redundancy and rotation.
- Message delivery confirmation.
- Support multiple devices.
3. Privacy-preserving identity server for optional DNS-based contact/group addresses to simplify connection and discovery, but not used to deliver messages:
- keep all your contacts and groups even if you lose the domain.
- the server doesn't have information about your contacts and groups.
4. Media server to optimize sending large files to groups.
5. Channels server for large groups and broadcast channels.
## License
-108
View File
@@ -1,108 +0,0 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module ChatTerminal
( ChatTerminal (..),
newChatTerminal,
chatTerminal,
ttyContact,
ttyFromContact,
)
where
import ChatTerminal.Basic
import ChatTerminal.Core
import ChatTerminal.Editor
import Control.Concurrent (threadDelay)
import Control.Concurrent.Async (race_)
import Control.Monad
import Control.Monad.IO.Class (liftIO)
import Data.Time.Format (defaultTimeLocale, formatTime)
import Data.Time.LocalTime (getZonedTime)
import Numeric.Natural
import Styled
import System.Terminal
import Types
import UnliftIO.STM
newChatTerminal :: Natural -> TermMode -> IO ChatTerminal
newChatTerminal qSize termMode = do
inputQ <- newTBQueueIO qSize
outputQ <- newTBQueueIO qSize
activeTo <- newTVarIO ActiveNone
termSize <- withTerminal . runTerminalT $ getWindowSize
let lastRow = height termSize - 1
termState <- newTVarIO newTermState
termLock <- newTMVarIO ()
nextMessageRow <- newTVarIO lastRow
threadDelay 500000 -- this delay is the same as timeout in getTerminalSize
return ChatTerminal {inputQ, outputQ, activeTo, termMode, termState, termSize, nextMessageRow, termLock}
newTermState :: TerminalState
newTermState =
TerminalState
{ inputString = "",
inputPosition = 0,
inputPrompt = "> ",
previousInput = ""
}
chatTerminal :: ChatTerminal -> IO ()
chatTerminal ct
| termSize ct == Size 0 0 || termMode ct == TermModeBasic =
run basicReceiveFromTTY basicSendToTTY
| otherwise = do
withTerminal . runTerminalT $ updateInput ct
run receiveFromTTY sendToTTY
where
run receive send = race_ (receive ct) (send ct)
basicReceiveFromTTY :: ChatTerminal -> IO ()
basicReceiveFromTTY ct =
forever $ getLn >>= atomically . writeTBQueue (inputQ ct)
basicSendToTTY :: ChatTerminal -> IO ()
basicSendToTTY ct = forever $ readOutputQ ct >>= mapM_ putStyledLn
withTermLock :: MonadTerminal m => ChatTerminal -> m () -> m ()
withTermLock ChatTerminal {termLock} action = do
_ <- atomically $ takeTMVar termLock
action
atomically $ putTMVar termLock ()
receiveFromTTY :: ChatTerminal -> IO ()
receiveFromTTY ct@ChatTerminal {inputQ, activeTo, termSize, termState} =
withTerminal . runTerminalT . forever $
getKey >>= processKey >> withTermLock ct (updateInput ct)
where
processKey :: MonadTerminal m => (Key, Modifiers) -> m ()
processKey = \case
(EnterKey, _) -> submitInput
key -> atomically $ do
ac <- readTVar activeTo
modifyTVar termState $ updateTermState ac (width termSize) key
submitInput :: MonadTerminal m => m ()
submitInput = do
msg <- atomically $ do
ts <- readTVar termState
let s = inputString ts
writeTVar termState $ ts {inputString = "", inputPosition = 0, previousInput = s}
writeTBQueue inputQ s
return s
withTermLock ct $ do
localTime <- liftIO getZonedTime
let localTimeStr = formatTime defaultTimeLocale "%H:%M" localTime
printMessage ct [styleMessage localTimeStr msg]
sendToTTY :: ChatTerminal -> IO ()
sendToTTY ct = forever $ do
-- `readOutputQ` should be outside of `withTerminal` (see #94)
msg <- readOutputQ ct
withTerminal . runTerminalT . withTermLock ct $ do
printMessage ct msg
updateInput ct
readOutputQ :: ChatTerminal -> IO [StyledString]
readOutputQ = atomically . readTBQueue . outputQ
-89
View File
@@ -1,89 +0,0 @@
{-# LANGUAGE LambdaCase #-}
module ChatTerminal.Basic where
import Control.Monad.IO.Class (liftIO)
import Styled
import System.Console.ANSI.Types
import System.Exit (exitSuccess)
import System.Terminal as C
getLn :: IO String
getLn = withTerminal $ runTerminalT getTermLine
putStyledLn :: StyledString -> IO ()
putStyledLn s =
withTerminal . runTerminalT $
putStyled s >> C.putLn >> flush
-- Currently it is assumed that the message does not have internal line breaks.
-- Previous implementation "kind of" supported them,
-- but it was not determining the number of printed lines correctly
-- because of accounting for control sequences in length
putStyled :: MonadTerminal m => StyledString -> m ()
putStyled (s1 :<>: s2) = putStyled s1 >> putStyled s2
putStyled (Styled [] s) = putString s
putStyled (Styled sgr s) = setSGR sgr >> putString s >> resetAttributes
setSGR :: MonadTerminal m => [SGR] -> m ()
setSGR = mapM_ $ \case
Reset -> resetAttributes
SetConsoleIntensity BoldIntensity -> setAttribute bold
SetConsoleIntensity _ -> resetAttribute bold
SetItalicized True -> setAttribute italic
SetItalicized _ -> resetAttribute italic
SetUnderlining NoUnderline -> resetAttribute underlined
SetUnderlining _ -> setAttribute underlined
SetSwapForegroundBackground True -> setAttribute inverted
SetSwapForegroundBackground _ -> resetAttribute inverted
SetColor l i c -> setAttribute . layer l . intensity i $ color c
SetBlinkSpeed _ -> pure ()
SetVisible _ -> pure ()
SetRGBColor _ _ -> pure ()
SetPaletteColor _ _ -> pure ()
SetDefaultColor _ -> pure ()
where
layer = \case
Foreground -> foreground
Background -> background
intensity = \case
Dull -> id
Vivid -> bright
color = \case
Black -> black
Red -> red
Green -> green
Yellow -> yellow
Blue -> blue
Magenta -> magenta
Cyan -> cyan
White -> white
getKey :: MonadTerminal m => m (Key, Modifiers)
getKey =
flush >> awaitEvent >>= \case
Left Interrupt -> liftIO exitSuccess
Right (KeyEvent key ms) -> pure (key, ms)
_ -> getKey
getTermLine :: MonadTerminal m => m String
getTermLine = getChars ""
where
getChars s =
getKey >>= \(key, ms) -> case key of
CharKey c
| ms == mempty || ms == shiftKey -> do
C.putChar c
flush
getChars (c : s)
| otherwise -> getChars s
EnterKey -> do
C.putLn
flush
pure $ reverse s
BackspaceKey -> do
moveCursorBackward 1
eraseChars 1
flush
getChars $ if null s then s else tail s
_ -> getChars s
-61
View File
@@ -1,61 +0,0 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
module ChatTerminal.Editor where
import ChatTerminal.Basic
import ChatTerminal.Core
import Styled
import System.Terminal
import UnliftIO.STM
-- debug :: MonadTerminal m => String -> m ()
-- debug s = do
-- saveCursor
-- setCursorPosition $ Position 0 0
-- putString s
-- restoreCursor
updateInput :: forall m. MonadTerminal m => ChatTerminal -> m ()
updateInput ct@ChatTerminal {termSize = Size {height, width}, termState, nextMessageRow} = do
hideCursor
ts <- readTVarIO termState
nmr <- readTVarIO nextMessageRow
let ih = inputHeight ts ct
iStart = height - ih
prompt = inputPrompt ts
Position {row, col} = positionRowColumn width $ length prompt + inputPosition ts
if nmr >= iStart
then atomically $ writeTVar nextMessageRow iStart
else clearLines nmr iStart
setCursorPosition $ Position {row = max nmr iStart, col = 0}
putString $ prompt <> inputString ts <> " "
eraseInLine EraseForward
setCursorPosition $ Position {row = iStart + row, col}
showCursor
flush
where
clearLines :: Int -> Int -> m ()
clearLines from till
| from >= till = return ()
| otherwise = do
setCursorPosition $ Position {row = from, col = 0}
eraseInLine EraseForward
clearLines (from + 1) till
printMessage :: forall m. MonadTerminal m => ChatTerminal -> [StyledString] -> m ()
printMessage ChatTerminal {termSize = Size {height, width}, nextMessageRow} msg = do
nmr <- readTVarIO nextMessageRow
setCursorPosition $ Position {row = nmr, col = 0}
mapM_ printStyled msg
flush
let lc = sum $ map lineCount msg
atomically . writeTVar nextMessageRow $ min (height - 1) (nmr + lc)
where
lineCount :: StyledString -> Int
lineCount s = sLength s `div` width + 1
printStyled :: StyledString -> m ()
printStyled s = do
putStyled s
eraseInLine EraseForward
putLn
-394
View File
@@ -1,394 +0,0 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import ChatOptions
import ChatTerminal
import ChatTerminal.Core
import Control.Applicative ((<|>))
import Control.Concurrent.STM
import Control.Logger.Simple
import Control.Monad.Reader
import Data.Attoparsec.ByteString.Char8 (Parser)
import qualified Data.Attoparsec.ByteString.Char8 as A
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Functor (($>))
import Data.List (intersperse)
import qualified Data.Text as T
import Data.Text.Encoding
import Data.Time.Clock (DiffTime, UTCTime)
import Data.Time.Format (defaultTimeLocale, formatTime)
import Data.Time.LocalTime
import Notification
import Numeric.Natural
import Simplex.Chat.Markdown
import Simplex.Messaging.Agent (getSMPAgentClient, runSMPAgentClient)
import Simplex.Messaging.Agent.Client (AgentClient (..))
import Simplex.Messaging.Agent.Env.SQLite
import Simplex.Messaging.Agent.Protocol
import Simplex.Messaging.Client (smpDefaultConfig)
import Simplex.Messaging.Parsers (parseAll)
import Simplex.Messaging.Util (raceAny_)
import Styled
import System.Console.ANSI.Types
import System.Directory (getAppUserDataDirectory)
import Types
cfg :: AgentConfig
cfg =
AgentConfig
{ tcpPort = undefined, -- agent does not listen to TCP
smpServers = undefined, -- filled in from options
rsaKeySize = 2048 `div` 8,
connIdBytes = 12,
tbqSize = 16,
dbFile = "smp-chat.db",
smpCfg = smpDefaultConfig
}
logCfg :: LogConfig
logCfg = LogConfig {lc_file = Nothing, lc_stderr = True}
data ChatClient = ChatClient
{ inQ :: TBQueue ChatCommand,
outQ :: TBQueue ChatResponse,
notifyQ :: TBQueue Notification,
displayNotification :: Notification -> IO ()
}
-- | GroupMessage ChatGroup ByteString
-- | AddToGroup Contact
data ChatCommand
= ChatHelp
| MarkdownHelp
| AddConnection Contact
| Connect Contact SMPQueueInfo
| DeleteConnection Contact
| SendMessage Contact ByteString
| NewGroup Group
| AddToGroup Group Contact
| RemoveFromGroup Group Contact
| DeleteGroup Group
| ListGroup Group
| SendGroupMessage Group ByteString
deriving (Show)
chatCommandP :: Parser ChatCommand
chatCommandP =
("/help" <|> "/h") $> ChatHelp
<|> ("/group #" <|> "/g #") *> (NewGroup <$> group)
<|> ("/add #" <|> "/a #") *> (AddToGroup <$> group <* A.space <*> contact)
<|> ("/remove #" <|> "/rm #") *> (RemoveFromGroup <$> group <* A.space <*> contact)
<|> ("/delete #" <|> "/d #") *> (DeleteGroup <$> group)
<|> ("/members #" <|> "/ms #") *> (ListGroup <$> group)
<|> A.char '#' *> (SendGroupMessage <$> group <* A.space <*> A.takeByteString)
<|> ("/add " <|> "/a ") *> (AddConnection <$> contact)
<|> ("/connect " <|> "/c ") *> (Connect <$> contact <* A.space <*> smpQueueInfoP)
<|> ("/delete " <|> "/d ") *> (DeleteConnection <$> contact)
<|> A.char '@' *> (SendMessage <$> contact <* A.space <*> A.takeByteString)
<|> ("/markdown" <|> "/m") $> MarkdownHelp
where
contact = Contact <$> A.takeTill (== ' ')
group = Group <$> A.takeTill (== ' ')
data ChatResponse
= ChatHelpInfo
| MarkdownInfo
| Invitation SMPQueueInfo
| Connected Contact
| Confirmation Contact
| ReceivedMessage Contact UTCTime ByteString MsgIntegrity
| Disconnected Contact
| GroupMembers Group [Contact]
| ReceivedGroupMessage Group Contact UTCTime ByteString MsgIntegrity
| GroupConfirmation Group
| YesYes
| ContactError ConnectionErrorType Contact
| GroupError AgentErrorType Group
| ErrorInput ByteString
| ChatError AgentErrorType
| NoChatResponse
serializeChatResponse :: ChatOpts -> TimeZone -> ZonedTime -> ChatResponse -> [StyledString]
serializeChatResponse _ localTz currentTime = \case
ChatHelpInfo -> chatHelpInfo
MarkdownInfo -> markdownInfo
Invitation qInfo ->
[ "pass this invitation to your contact (via any channel): ",
"",
(bPlain . serializeSmpQueueInfo) qInfo,
"",
"and ask them to connect: /c <name_for_you> <invitation_above>"
]
Connected c -> [ttyContact c <> " connected"]
Confirmation c -> [ttyContact c <> " ok"]
ReceivedMessage c utcTime t mi -> receivedMessage utcTime t mi $ ttyFromContact c
ReceivedGroupMessage g c utcTime t mi -> receivedMessage utcTime t mi $ ttyFromGroup g c
Disconnected c -> ["disconnected from " <> ttyContact c <> " - restart chat"]
GroupMembers g cs -> [ttyGroup g <> ": " <> plain (B.unpack . B.intercalate ", " $ map toBs cs)]
GroupConfirmation g -> [ttyGroup g <> " ok"]
YesYes -> ["you got it!"]
ContactError e c -> case e of
NOT_FOUND -> ["no contact " <> ttyContact c]
DUPLICATE -> ["contact " <> ttyContact c <> " already exists"]
SIMPLEX -> ["contact " <> ttyContact c <> " did not accept invitation yet"]
GroupError e g -> case e of
BCAST B_NOT_FOUND -> ["no group " <> ttyGroup g]
BCAST B_DUPLICATE -> ["group " <> ttyGroup g <> " already exists"]
CONN NOT_FOUND -> ["cannot add unknown contact to the group " <> ttyGroup g]
CONN DUPLICATE -> ["this contact is already in the group " <> ttyGroup g]
CONN SIMPLEX -> ["this contact did not not accept invitation yet"]
_ -> ["chat error: " <> plain (show e)]
ErrorInput t -> ["invalid input: " <> bPlain t]
ChatError e -> ["chat error: " <> plain (show e)]
NoChatResponse -> [""]
where
receivedMessage :: UTCTime -> ByteString -> MsgIntegrity -> StyledString -> [StyledString]
receivedMessage utcTime t mi from =
prependFirst (formatUTCTime utcTime <> " " <> from) (msgPlain t) ++ showIntegrity mi
prependFirst :: StyledString -> [StyledString] -> [StyledString]
prependFirst s [] = [s]
prependFirst s (s' : ss) = (s <> s') : ss
formatUTCTime :: UTCTime -> StyledString
formatUTCTime utcTime = do
let localTime = utcToLocalTime localTz utcTime
format =
if (localDay localTime < localDay (zonedTimeToLocalTime currentTime))
&& (timeOfDayToTime (localTimeOfDay localTime) > (6 * 60 * 60 :: DiffTime))
then "%m-%d" -- if message is from yesterday or before and 6 hours has passed since midnight
else "%H:%M"
styleTime $ formatTime defaultTimeLocale format localTime
msgPlain :: ByteString -> [StyledString]
msgPlain = map styleMarkdownText . T.lines . safeDecodeUtf8
showIntegrity :: MsgIntegrity -> [StyledString]
showIntegrity MsgOk = []
showIntegrity (MsgError err) = msgError $ case err of
MsgSkipped fromId toId ->
"skipped message ID " <> show fromId
<> if fromId == toId then "" else ".." <> show toId
MsgBadId msgId -> "unexpected message ID " <> show msgId
MsgBadHash -> "incorrect message hash"
MsgDuplicate -> "duplicate message ID"
msgError :: String -> [StyledString]
msgError s = [styled (Colored Red) s]
chatHelpInfo :: [StyledString]
chatHelpInfo =
map
styleMarkdown
[ Markdown (Colored Cyan) "Using Simplex chat prototype.",
"Follow these steps to set up a connection:",
"",
Markdown (Colored Green) "Step 1: " <> Markdown (Colored Cyan) "/add bob" <> " -- Alice adds her contact, Bob (she can use any name).",
indent <> "Alice should send the invitation printed by the /add command",
indent <> "to her contact, Bob, out-of-band, via any trusted channel.",
"",
Markdown (Colored Green) "Step 2: " <> Markdown (Colored Cyan) "/connect alice <invitation>" <> " -- Bob accepts the invitation.",
indent <> "Bob also can use any name for his contact, Alice,",
indent <> "followed by the invitation he received out-of-band.",
"",
Markdown (Colored Green) "Step 3: " <> "Bob and Alice are notified that the connection is set up,",
indent <> "both can now send messages:",
indent <> Markdown (Colored Cyan) "@bob Hello, Bob!" <> " -- Alice messages Bob.",
indent <> Markdown (Colored Cyan) "@alice Hey, Alice!" <> " -- Bob replies to Alice.",
"",
Markdown (Colored Green) "Other commands:",
indent <> Markdown (Colored Cyan) "/delete" <> " -- deletes contact and all messages with them.",
indent <> Markdown (Colored Cyan) "/markdown" <> " -- prints the supported markdown syntax.",
"",
"The commands may be abbreviated to a single letter: " <> listCommands ["/a", "/c", "/d", "/m"]
]
where
listCommands = mconcat . intersperse ", " . map highlight
highlight = Markdown (Colored Cyan)
indent = " "
markdownInfo :: [StyledString]
markdownInfo =
map
styleMarkdown
[ "Markdown:",
" *bold* - " <> Markdown Bold "bold text",
" _italic_ - " <> Markdown Italic "italic text" <> " (shown as underlined)",
" +underlined+ - " <> Markdown Underline "underlined text",
" ~strikethrough~ - " <> Markdown StrikeThrough "strikethrough text" <> " (shown as inverse)",
" `code snippet` - " <> Markdown Snippet "a + b // no *markdown* here",
" !1 text! - " <> red "red text" <> " (1-6: red, green, blue, yellow, cyan, magenta)",
" #secret# - " <> Markdown Secret "secret text" <> " (can be copy-pasted)"
]
where
red = Markdown (Colored Red)
main :: IO ()
main = do
opts@ChatOpts {dbFile, smpServers, termMode} <- welcomeGetOpts
t <- newChatClient (tbqSize cfg)
ct <- newChatTerminal (tbqSize cfg) termMode
-- setLogLevel LogInfo -- LogError
-- withGlobalLogging logCfg $ do
env <- newSMPAgentEnv cfg {dbFile, smpServers}
dogFoodChat t ct env opts
welcomeGetOpts :: IO ChatOpts
welcomeGetOpts = do
appDir <- getAppUserDataDirectory "simplex"
opts@ChatOpts {dbFile} <- getChatOpts appDir
putStrLn "SimpleX chat prototype v0.3.1"
putStrLn $ "db: " <> dbFile
putStrLn "type \"/help\" or \"/h\" for usage info"
pure opts
dogFoodChat :: ChatClient -> ChatTerminal -> Env -> ChatOpts -> IO ()
dogFoodChat t ct env opts = do
c <- runReaderT getSMPAgentClient env
localTz <- liftIO getCurrentTimeZone
raceAny_
[ runReaderT (runSMPAgentClient c) env,
sendToAgent t ct c,
sendToChatTerm t ct opts localTz,
receiveFromAgent t ct c,
receiveFromChatTerm t ct,
showNotifications t,
chatTerminal ct
]
newChatClient :: Natural -> IO ChatClient
newChatClient qSize = do
inQ <- newTBQueueIO qSize
outQ <- newTBQueueIO qSize
notifyQ <- newTBQueueIO qSize
displayNotification <- initializeNotifications
return ChatClient {inQ, outQ, notifyQ, displayNotification}
receiveFromChatTerm :: ChatClient -> ChatTerminal -> IO ()
receiveFromChatTerm t ct = forever $ do
atomically (readTBQueue $ inputQ ct)
>>= processOrError . parseAll chatCommandP . encodeUtf8 . T.pack
where
processOrError = \case
Left err -> writeOutQ . ErrorInput $ B.pack err
Right ChatHelp -> writeOutQ ChatHelpInfo
Right MarkdownHelp -> writeOutQ MarkdownInfo
Right cmd -> atomically $ writeTBQueue (inQ t) cmd
writeOutQ = atomically . writeTBQueue (outQ t)
sendToChatTerm :: ChatClient -> ChatTerminal -> ChatOpts -> TimeZone -> IO ()
sendToChatTerm ChatClient {outQ} ChatTerminal {outputQ} opts localTz = forever $ do
atomically (readTBQueue outQ) >>= \case
NoChatResponse -> return ()
resp -> do
currentTime <- liftIO getZonedTime
atomically . writeTBQueue outputQ $ serializeChatResponse opts localTz currentTime resp
sendToAgent :: ChatClient -> ChatTerminal -> AgentClient -> IO ()
sendToAgent ChatClient {inQ} ct AgentClient {rcvQ} = do
atomically $ writeTBQueue rcvQ $ ATransmission "1" (Conn "") SUBALL -- hack for subscribing to all
forever . atomically $ do
cmd <- readTBQueue inQ
writeTBQueue rcvQ `mapM_` agentTransmission cmd
setActiveTo cmd
where
setActiveTo :: ChatCommand -> STM ()
setActiveTo = \case
SendMessage a _ -> setActive ct $ ActiveC a
SendGroupMessage g _ -> setActive ct $ ActiveG g
DeleteConnection a -> unsetActive ct $ ActiveC a
DeleteGroup g -> unsetActive ct $ ActiveG g
_ -> pure ()
agentTransmission :: ChatCommand -> Maybe (ATransmission 'Client)
agentTransmission = \case
AddConnection a -> transmission a NEW
Connect a qInfo -> transmission a $ JOIN qInfo $ ReplyMode On
DeleteConnection a -> transmission a DEL
SendMessage a msg -> transmission a $ SEND msg
NewGroup g -> bTransmission g NEW
AddToGroup g a -> bTransmission g $ ADD (Conn $ toBs a)
RemoveFromGroup g a -> bTransmission g $ REM (Conn $ toBs a)
DeleteGroup g -> bTransmission g DEL
ListGroup g -> bTransmission g LS
SendGroupMessage g msg -> bTransmission g $ SEND $ serializeGroupMessage g msg
ChatHelp -> Nothing
MarkdownHelp -> Nothing
transmission :: EntityCommand 'Conn_ c => Contact -> ACommand 'Client c -> Maybe (ATransmission 'Client)
transmission (Contact a) cmd = Just $ ATransmission "1" (Conn a) cmd
bTransmission :: EntityCommand 'Broadcast_ c => Group -> ACommand 'Client c -> Maybe (ATransmission 'Client)
bTransmission (Group g) cmd = Just $ ATransmission "1" (Broadcast g) cmd
receiveFromAgent :: ChatClient -> ChatTerminal -> AgentClient -> IO ()
receiveFromAgent t ct c = forever . atomically $ do
resp <- chatResponse <$> readTBQueue (sndQ c)
writeTBQueue (outQ t) resp
setActiveTo resp
sendNotification resp
where
chatResponse :: ATransmission 'Agent -> ChatResponse
chatResponse (ATransmission _ entity resp) = case entity of
Conn a -> connectionResponse a resp
Broadcast g -> broadcastResponse g resp
_ -> NoChatResponse
connectionResponse :: EntityCommand 'Conn_ c => ByteString -> ACommand 'Agent c -> ChatResponse
connectionResponse a = \case
INV qInfo -> Invitation qInfo
CON -> Connected contact
END -> Disconnected contact
MSG {msgBody, msgIntegrity, brokerMeta} -> case parseAll groupMessageP msgBody of
Right (group, msg) -> ReceivedGroupMessage group contact (snd brokerMeta) msg msgIntegrity
_ -> ReceivedMessage contact (snd brokerMeta) msgBody msgIntegrity
SENT _ -> NoChatResponse
OK -> Confirmation contact
ERR (CONN e) -> ContactError e contact
ERR e -> ChatError e
where
contact = Contact a
broadcastResponse :: EntityCommand 'Broadcast_ c => ByteString -> ACommand 'Agent c -> ChatResponse
broadcastResponse g = \case
MS as -> GroupMembers group $ map (Contact . fromConn) as
SENT _ -> NoChatResponse
OK -> GroupConfirmation group
ERR e@(CONN _) -> GroupError e group
ERR e@(BCAST _) -> GroupError e group
ERR e -> ChatError e
where
group = Group g
setActiveTo :: ChatResponse -> STM ()
setActiveTo = \case
Connected a -> setActive ct $ ActiveC a
ReceivedMessage a _ _ _ -> setActive ct $ ActiveC a
ReceivedGroupMessage g _ _ _ _ -> setActive ct $ ActiveG g
Disconnected a -> unsetActive ct $ ActiveC a
_ -> pure ()
sendNotification :: ChatResponse -> STM ()
sendNotification = \case
ReceivedMessage c' _ msg _ -> notify $ Notification ("@" <> toBs c') msg
ReceivedGroupMessage g c' _ msg _ -> notify $ Notification ("#" <> fromGroup g <> " @" <> toBs c') msg
Disconnected c' -> notify $ Notification ("@" <> toBs c') "disconnected"
_ -> pure ()
notify :: Notification -> STM ()
notify n = writeTBQueue (notifyQ t) n
showNotifications :: ChatClient -> IO ()
showNotifications t = forever $ atomically (readTBQueue $ notifyQ t) >>= displayNotification t
groupMessageP :: Parser (Group, ByteString)
groupMessageP =
let group = Group <$> A.takeTill (== ' ')
in "####" *> ((,) <$> group <* A.space <*> A.takeByteString)
serializeGroupMessage :: Group -> ByteString -> ByteString
serializeGroupMessage (Group g) msg = "####" <> g <> " " <> msg
setActive :: ChatTerminal -> ActiveTo -> STM ()
setActive ct = writeTVar (activeTo ct)
unsetActive :: ChatTerminal -> ActiveTo -> STM ()
unsetActive ct a = modifyTVar (activeTo ct) unset
where
unset a' = if a == a' then ActiveNone else a'
-16
View File
@@ -1,16 +0,0 @@
{-# LANGUAGE LambdaCase #-}
module Types where
import Data.ByteString.Char8 (ByteString)
newtype Contact = Contact {toBs :: ByteString} deriving (Eq, Show)
newtype Group = Group {fromGroup :: ByteString} deriving (Eq, Show)
data TermMode = TermModeBasic | TermModeEditor deriving (Eq)
termModeName :: TermMode -> String
termModeName = \case
TermModeBasic -> "basic"
TermModeEditor -> "editor"
+119
View File
@@ -0,0 +1,119 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Demo where
import Simplex.Chat.Styled
import System.Console.ANSI.Types
import System.Terminal
someViewUpdate :: Monad m => m ()
someViewUpdate = pure ()
chatLayoutDemo :: MonadTerminal m => m ()
chatLayoutDemo =
mapM_
putStyledLn
[ " search " <> Styled gray "(ctrl-s) " <> lineV <> Styled toContact " @bob " <> "Bob Roberts " <> Styled greenColor "@john" <> "",
" " <> lineV <> Styled gray " 14:15 online profile (ctrl-p)",
lineH 20 <> crossover <> lineH 59,
"* " <> Styled [SetConsoleIntensity BoldIntensity] "all chats " <> " " <> lineV <> "",
Styled gray " (ctrl-a) " <> lineV <> "",
"*" <> Styled toContact " @alice " <> Styled darkGray "14:37 " <> lineV <> "",
Styled gray " Hello there! ... " <> lineV <> "",
Styled selected " " <> Styled (toContact <> selected) " @bob " <> Styled (selected <> gray) "12:35 " <> lineV <> "",
Styled selected " All good, John... " <> lineV <> "",
"*" <> Styled group " #team " <> Styled darkGray "10:55 " <> lineV <> "",
Styled gray " What's up ther... " <> lineV <> "",
" " <> Styled toContact " @tom " <> Styled darkGray "Wed " <> lineV <> "",
Styled gray " Have you seen ... " <> lineV <> "",
" " <> lineV,
" " <> lineV,
" " <> lineV,
" " <> lineV,
" " <> lineV,
" " <> lineV <> Styled greenColor " ✔︎" <> Styled darkGray " 12:30" <> Styled toContact " @bob" <> " hey bob - how is it going?",
" " <> lineV <> Styled greenColor " ✔︎" <> Styled darkGray " " <> Styled toContact " " <> " let's meet soon!",
" " <> lineV <> " *" <> Styled darkGray " 12:35" <> Styled contact " bob>" <> " All good, John! How are you?",
" " <> teeL <> lineH 59,
" " <> lineV <> " > " <> Styled toContact "@bob" <> " 😀 This is the message that will be sent to @bob"
]
>> putStyled (Styled ctrlKeys " help (ctrl-h) new contact (ctrl-n) choose chat (ctrl-↓↑) new group (ctrl-g) ")
contact :: [SGR]
contact = [SetConsoleIntensity BoldIntensity, SetColor Foreground Vivid Yellow]
toContact :: [SGR]
toContact = [SetConsoleIntensity BoldIntensity, SetColor Foreground Vivid Cyan]
group :: [SGR]
group = [SetConsoleIntensity BoldIntensity, SetColor Foreground Vivid Cyan]
selected :: [SGR]
selected = [SetColor Background Vivid Black]
ctrlKeys :: [SGR]
ctrlKeys = [SetColor Background Dull White, SetColor Foreground Dull Black]
gray :: [SGR]
gray = [SetColor Foreground Dull White]
darkGray :: [SGR]
darkGray = [SetColor Foreground Vivid Black]
greenColor :: [SGR]
greenColor = [SetColor Foreground Vivid Green]
lineV :: StyledString
lineV = Styled selected " " -- "\x2502"
lineH :: Int -> StyledString
lineH n = Styled darkGray $ replicate n '\x2500'
teeL :: StyledString
teeL = Styled selected " " -- "\x251C"
crossover :: StyledString
crossover = Styled selected " " -- "\x253C"
putStyledLn :: MonadTerminal m => StyledString -> m ()
putStyledLn s = putStyled s >> putLn
putStyled :: MonadTerminal m => StyledString -> m ()
putStyled (s1 :<>: s2) = putStyled s1 >> putStyled s2
putStyled (Styled [] s) = putString s
putStyled (Styled sgr s) = setSGR sgr >> putString s >> resetAttributes
setSGR :: MonadTerminal m => [SGR] -> m ()
setSGR = mapM_ $ \case
Reset -> resetAttributes
SetConsoleIntensity BoldIntensity -> setAttribute bold
SetConsoleIntensity _ -> resetAttribute bold
SetItalicized True -> setAttribute italic
SetItalicized _ -> resetAttribute italic
SetUnderlining NoUnderline -> resetAttribute underlined
SetUnderlining _ -> setAttribute underlined
SetSwapForegroundBackground True -> setAttribute inverted
SetSwapForegroundBackground _ -> resetAttribute inverted
SetColor l i c -> setAttribute . layer l . intensity i $ color c
SetBlinkSpeed _ -> pure ()
SetVisible _ -> pure ()
SetRGBColor _ _ -> pure ()
SetPaletteColor _ _ -> pure ()
SetDefaultColor _ -> pure ()
where
layer = \case
Foreground -> foreground
Background -> background
intensity = \case
Dull -> id
Vivid -> bright
color = \case
Black -> black
Red -> red
Green -> green
Yellow -> yellow
Blue -> blue
Magenta -> magenta
Cyan -> cyan
White -> white
+58
View File
@@ -0,0 +1,58 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Simplex.Chat
import Simplex.Chat.Options
import System.Directory (getAppUserDataDirectory)
import System.Terminal (withTerminal)
main :: IO ()
main = do
opts <- welcomeGetOpts
t <- withTerminal pure
simplexChat defaultChatConfig opts t
welcomeGetOpts :: IO ChatOpts
welcomeGetOpts = do
appDir <- getAppUserDataDirectory "simplex"
opts@ChatOpts {dbFile} <- getChatOpts appDir
putStrLn "SimpleX chat prototype v0.3.1"
putStrLn $ "db: " <> dbFile <> ".chat.db, " <> dbFile <> ".agent.db"
putStrLn "type \"/help\" or \"/h\" for usage info"
pure opts
-- defaultSettings :: C.Size -> C.VirtualTerminalSettings
-- defaultSettings size =
-- C.VirtualTerminalSettings
-- { C.virtualType = "xterm",
-- C.virtualWindowSize = pure size,
-- C.virtualEvent = retry,
-- C.virtualInterrupt = retry
-- }
-- main :: IO ()
-- main = do
-- void $ createStore "simplex-chat.db" 4
-- hFlush stdout
-- -- ChatTerminal {termSize} <- newChatTerminal
-- -- pos <- C.withVirtualTerminal (defaultSettings termSize) $
-- -- \t -> runTerminalT (C.setAlternateScreenBuffer True >> C.putString "a" >> C.flush >> C.getCursorPosition) t
-- -- print pos
-- -- race_ (printEvents t) (updateTerminal t)
-- void . withTerminal . runTerminalT $ chatLayoutDemo >> C.flush >> C.awaitEvent
-- printEvents :: C.VirtualTerminal -> IO ()
-- printEvents t = forever $ do
-- event <- withTerminal . runTerminalT $ C.flush >> C.awaitEvent
-- runTerminalT (putStringLn $ show event) t
-- updateTerminal :: C.VirtualTerminal -> IO ()
-- updateTerminal t = forever $ do
-- threadDelay 10000
-- win <- readTVarIO $ C.virtualWindow t
-- withTerminal . runTerminalT $ mapM_ C.putStringLn win >> C.flush
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

+10 -10
View File
@@ -1,24 +1,24 @@
<svg width="389" height="849" viewBox="0 0 389 849" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="389" height="849" fill="white"/>
<path d="M32 25.5C30.4548 25.5 28.9444 25.9582 27.6596 26.8166C26.3749 27.6751 25.3735 28.8952 24.7822 30.3228C24.1909 31.7503 24.0362 33.3212 24.3376 34.8366C24.6391 36.3521 25.3831 37.7442 26.4757 38.8368C27.5683 39.9294 28.9604 40.6734 30.4759 40.9749C31.9913 41.2763 33.5622 41.1216 34.9897 40.5303C36.4173 39.939 37.6374 38.9377 38.4959 37.6529C39.3543 36.3681 39.8125 34.8577 39.8125 33.3125C39.8125 31.2405 38.9894 29.2534 37.5243 27.7882C36.0591 26.3231 34.072 25.5 32 25.5ZM32 38C31.0729 38 30.1666 37.7251 29.3958 37.21C28.6249 36.6949 28.0241 35.9629 27.6693 35.1063C27.3145 34.2498 27.2217 33.3073 27.4026 32.398C27.5834 31.4887 28.0299 30.6535 28.6854 29.9979C29.341 29.3424 30.1762 28.8959 31.0855 28.7151C31.9948 28.5342 32.9373 28.627 33.7938 28.9818C34.6504 29.3366 35.3824 29.9374 35.8975 30.7083C36.4126 31.4791 36.6875 32.3854 36.6875 33.3125C36.6863 34.5553 36.192 35.7469 35.3132 36.6257C34.4344 37.5045 33.2428 37.9988 32 38Z" fill="#07B4B9"/>
<path d="M32 16.125C27.6735 16.125 23.4442 17.4079 19.8469 19.8116C16.2496 22.2153 13.4458 25.6317 11.7901 29.6288C10.1345 33.6259 9.70128 38.0243 10.5453 42.2676C11.3894 46.5109 13.4728 50.4087 16.532 53.468C19.5913 56.5272 23.4891 58.6106 27.7324 59.4547C31.9757 60.2987 36.3741 59.8655 40.3712 58.2099C44.3683 56.5542 47.7848 53.7504 50.1884 50.1531C52.5921 46.5558 53.875 42.3265 53.875 38C53.8684 32.2004 51.5616 26.6403 47.4607 22.5393C43.3597 18.4384 37.7996 16.1316 32 16.125V16.125ZM22.625 54.2141V52.0625C22.6263 50.8197 23.1205 49.6281 23.9993 48.7493C24.8781 47.8705 26.0697 47.3762 27.3125 47.375H36.6875C37.9303 47.3762 39.1219 47.8705 40.0007 48.7493C40.8795 49.6281 41.3738 50.8197 41.375 52.0625V54.2141C38.53 55.8753 35.2946 56.7508 32 56.7508C28.7055 56.7508 25.4701 55.8753 22.625 54.2141V54.2141ZM44.4875 51.9469C44.4564 49.8974 43.6214 47.9422 42.1624 46.5025C40.7034 45.0628 38.7372 44.2539 36.6875 44.25H27.3125C25.2628 44.2539 23.2966 45.0628 21.8376 46.5025C20.3787 47.9422 19.5436 49.8974 19.5125 51.9469C16.679 49.4168 14.6808 46.0857 13.7826 42.3948C12.8843 38.7038 13.1283 34.8271 14.4823 31.2779C15.8362 27.7287 18.2363 24.6745 21.3647 22.5196C24.493 20.3648 28.2021 19.211 32.0008 19.211C35.7995 19.211 39.5086 20.3648 42.6369 22.5196C45.7653 24.6745 48.1654 27.7287 49.5193 31.2779C50.8733 34.8271 51.1173 38.7038 50.219 42.3948C49.3207 46.0857 47.3226 49.4168 44.4891 51.9469H44.4875Z" fill="#07B4B9"/>
<path d="M32 16.125C27.6735 16.125 23.4442 17.4079 19.8469 19.8116C16.2496 22.2153 13.4458 25.6317 11.7901 29.6288C10.1345 33.6259 9.70128 38.0243 10.5453 42.2676C11.3894 46.5109 13.4728 50.4087 16.532 53.468C19.5913 56.5272 23.4891 58.6106 27.7324 59.4547C31.9757 60.2987 36.3741 59.8655 40.3712 58.2099C44.3683 56.5542 47.7848 53.7504 50.1884 50.1531C52.5921 46.5558 53.875 42.3265 53.875 38C53.8684 32.2004 51.5616 26.6403 47.4607 22.5393C43.3597 18.4384 37.7996 16.1316 32 16.125ZM22.625 54.2141V52.0625C22.6263 50.8197 23.1205 49.6281 23.9993 48.7493C24.8781 47.8705 26.0697 47.3762 27.3125 47.375H36.6875C37.9303 47.3762 39.1219 47.8705 40.0007 48.7493C40.8795 49.6281 41.3738 50.8197 41.375 52.0625V54.2141C38.53 55.8753 35.2946 56.7508 32 56.7508C28.7055 56.7508 25.4701 55.8753 22.625 54.2141ZM44.4875 51.9469C44.4564 49.8974 43.6213 47.9422 42.1624 46.5025C40.7034 45.0628 38.7372 44.2539 36.6875 44.25H27.3125C25.2628 44.2539 23.2966 45.0628 21.8376 46.5025C20.3787 47.9422 19.5436 49.8974 19.5125 51.9469C16.679 49.4168 14.6808 46.0857 13.7826 42.3948C12.8843 38.7038 13.1283 34.8271 14.4823 31.2779C15.8362 27.7287 18.2363 24.6745 21.3647 22.5196C24.493 20.3648 28.2021 19.211 32.0008 19.211C35.7995 19.211 39.5086 20.3648 42.6369 22.5196C45.7653 24.6745 48.1654 27.7287 49.5193 31.2779C50.8733 34.8271 51.1173 38.7038 50.219 42.3948C49.3207 46.0857 47.3226 49.4168 44.4891 51.9469H44.4875Z" fill="#07B4B9"/>
<path d="M35 725.5C33.4548 725.5 31.9444 725.958 30.6596 726.817C29.3749 727.675 28.3735 728.895 27.7822 730.323C27.1909 731.75 27.0362 733.321 27.3376 734.837C27.6391 736.352 28.3831 737.744 29.4757 738.837C30.5683 739.929 31.9604 740.673 33.4759 740.975C34.9913 741.276 36.5622 741.122 37.9897 740.53C39.4173 739.939 40.6374 738.938 41.4959 737.653C42.3543 736.368 42.8125 734.858 42.8125 733.313C42.8125 731.24 41.9894 729.253 40.5243 727.788C39.0591 726.323 37.072 725.5 35 725.5ZM35 738C34.0729 738 33.1666 737.725 32.3958 737.21C31.6249 736.695 31.0241 735.963 30.6693 735.106C30.3145 734.25 30.2217 733.307 30.4026 732.398C30.5834 731.489 31.0299 730.653 31.6854 729.998C32.341 729.342 33.1762 728.896 34.0855 728.715C34.9948 728.534 35.9373 728.627 36.7938 728.982C37.6504 729.337 38.3824 729.937 38.8975 730.708C39.4126 731.479 39.6875 732.385 39.6875 733.313C39.6863 734.555 39.192 735.747 38.3132 736.626C37.4344 737.505 36.2428 737.999 35 738Z" fill="#07B4B9"/>
<path d="M35 716.125C30.6735 716.125 26.4442 717.408 22.8469 719.812C19.2496 722.215 16.4458 725.632 14.7901 729.629C13.1345 733.626 12.7013 738.024 13.5453 742.268C14.3894 746.511 16.4728 750.409 19.532 753.468C22.5913 756.527 26.4891 758.611 30.7324 759.455C34.9757 760.299 39.3741 759.866 43.3712 758.21C47.3683 756.554 50.7848 753.75 53.1884 750.153C55.5921 746.556 56.875 742.326 56.875 738C56.8684 732.2 54.5616 726.64 50.4607 722.539C46.3597 718.438 40.7996 716.132 35 716.125V716.125ZM25.625 754.214V752.062C25.6263 750.82 26.1205 749.628 26.9993 748.749C27.8781 747.87 29.0697 747.376 30.3125 747.375H39.6875C40.9303 747.376 42.1219 747.87 43.0007 748.749C43.8795 749.628 44.3738 750.82 44.375 752.062V754.214C41.53 755.875 38.2946 756.751 35 756.751C31.7055 756.751 28.4701 755.875 25.625 754.214V754.214ZM47.4875 751.947C47.4564 749.897 46.6214 747.942 45.1624 746.502C43.7034 745.063 41.7372 744.254 39.6875 744.25H30.3125C28.2628 744.254 26.2966 745.063 24.8376 746.502C23.3787 747.942 22.5436 749.897 22.5125 751.947C19.679 749.417 17.6808 746.086 16.7826 742.395C15.8843 738.704 16.1283 734.827 17.4823 731.278C18.8362 727.729 21.2363 724.674 24.3647 722.52C27.493 720.365 31.2021 719.211 35.0008 719.211C38.7995 719.211 42.5086 720.365 45.6369 722.52C48.7653 724.674 51.1654 727.729 52.5193 731.278C53.8733 734.827 54.1173 738.704 53.219 742.395C52.3207 746.086 50.3226 749.417 47.4891 751.947H47.4875Z" fill="#07B4B9"/>
<path d="M35 716.125C30.6735 716.125 26.4442 717.408 22.8469 719.812C19.2496 722.215 16.4458 725.632 14.7901 729.629C13.1345 733.626 12.7013 738.024 13.5453 742.268C14.3894 746.511 16.4728 750.409 19.532 753.468C22.5913 756.527 26.4891 758.611 30.7324 759.455C34.9757 760.299 39.3741 759.866 43.3712 758.21C47.3683 756.554 50.7848 753.75 53.1884 750.153C55.5921 746.556 56.875 742.326 56.875 738C56.8684 732.2 54.5616 726.64 50.4607 722.539C46.3597 718.438 40.7996 716.132 35 716.125ZM25.625 754.214V752.062C25.6263 750.82 26.1205 749.628 26.9993 748.749C27.8781 747.87 29.0697 747.376 30.3125 747.375H39.6875C40.9303 747.376 42.1219 747.87 43.0007 748.749C43.8795 749.628 44.3738 750.82 44.375 752.062V754.214C41.53 755.875 38.2946 756.751 35 756.751C31.7055 756.751 28.4701 755.875 25.625 754.214ZM47.4875 751.947C47.4564 749.897 46.6213 747.942 45.1624 746.502C43.7034 745.063 41.7372 744.254 39.6875 744.25H30.3125C28.2628 744.254 26.2966 745.063 24.8376 746.502C23.3787 747.942 22.5436 749.897 22.5125 751.947C19.679 749.417 17.6808 746.086 16.7826 742.395C15.8843 738.704 16.1283 734.827 17.4823 731.278C18.8362 727.729 21.2363 724.674 24.3647 722.52C27.493 720.365 31.2021 719.211 35.0008 719.211C38.7995 719.211 42.5086 720.365 45.6369 722.52C48.7653 724.674 51.1654 727.729 52.5193 731.278C53.8733 734.827 54.1173 738.704 53.219 742.395C52.3207 746.086 50.3226 749.417 47.4891 751.947H47.4875Z" fill="#07B4B9"/>
<path d="M32 263.5C30.4548 263.5 28.9444 263.958 27.6596 264.817C26.3749 265.675 25.3735 266.895 24.7822 268.323C24.1909 269.75 24.0362 271.321 24.3376 272.837C24.6391 274.352 25.3831 275.744 26.4757 276.837C27.5683 277.929 28.9604 278.673 30.4759 278.975C31.9913 279.276 33.5622 279.122 34.9897 278.53C36.4173 277.939 37.6374 276.938 38.4959 275.653C39.3543 274.368 39.8125 272.858 39.8125 271.313C39.8125 269.24 38.9894 267.253 37.5243 265.788C36.0591 264.323 34.072 263.5 32 263.5ZM32 276C31.0729 276 30.1666 275.725 29.3958 275.21C28.6249 274.695 28.0241 273.963 27.6693 273.106C27.3145 272.25 27.2217 271.307 27.4026 270.398C27.5834 269.489 28.0299 268.653 28.6854 267.998C29.341 267.342 30.1762 266.896 31.0855 266.715C31.9948 266.534 32.9373 266.627 33.7938 266.982C34.6504 267.337 35.3824 267.937 35.8975 268.708C36.4126 269.479 36.6875 270.385 36.6875 271.313C36.6863 272.555 36.192 273.747 35.3132 274.626C34.4344 275.505 33.2428 275.999 32 276Z" fill="#FBD561"/>
<path d="M32 254.125C27.6735 254.125 23.4442 255.408 19.8469 257.812C16.2496 260.215 13.4458 263.632 11.7901 267.629C10.1345 271.626 9.70128 276.024 10.5453 280.268C11.3894 284.511 13.4728 288.409 16.532 291.468C19.5913 294.527 23.4891 296.611 27.7324 297.455C31.9757 298.299 36.3741 297.866 40.3712 296.21C44.3683 294.554 47.7848 291.75 50.1884 288.153C52.5921 284.556 53.875 280.326 53.875 276C53.8684 270.2 51.5616 264.64 47.4607 260.539C43.3597 256.438 37.7996 254.132 32 254.125V254.125ZM22.625 292.214V290.062C22.6263 288.82 23.1205 287.628 23.9993 286.749C24.8781 285.87 26.0697 285.376 27.3125 285.375H36.6875C37.9303 285.376 39.1219 285.87 40.0007 286.749C40.8795 287.628 41.3738 288.82 41.375 290.062V292.214C38.53 293.875 35.2946 294.751 32 294.751C28.7055 294.751 25.4701 293.875 22.625 292.214V292.214ZM44.4875 289.947C44.4564 287.897 43.6214 285.942 42.1624 284.502C40.7034 283.063 38.7372 282.254 36.6875 282.25H27.3125C25.2628 282.254 23.2966 283.063 21.8376 284.502C20.3787 285.942 19.5436 287.897 19.5125 289.947C16.679 287.417 14.6808 284.086 13.7826 280.395C12.8843 276.704 13.1283 272.827 14.4823 269.278C15.8362 265.729 18.2363 262.674 21.3647 260.52C24.493 258.365 28.2021 257.211 32.0008 257.211C35.7995 257.211 39.5086 258.365 42.6369 260.52C45.7653 262.674 48.1654 265.729 49.5193 269.278C50.8733 272.827 51.1173 276.704 50.219 280.395C49.3207 284.086 47.3226 287.417 44.4891 289.947H44.4875Z" fill="#FBD561"/>
<path d="M32 254.125C27.6735 254.125 23.4442 255.408 19.8469 257.812C16.2496 260.215 13.4458 263.632 11.7901 267.629C10.1345 271.626 9.70128 276.024 10.5453 280.268C11.3894 284.511 13.4728 288.409 16.532 291.468C19.5913 294.527 23.4891 296.611 27.7324 297.455C31.9757 298.299 36.3741 297.866 40.3712 296.21C44.3683 294.554 47.7848 291.75 50.1884 288.153C52.5921 284.556 53.875 280.326 53.875 276C53.8684 270.2 51.5616 264.64 47.4607 260.539C43.3597 256.438 37.7996 254.132 32 254.125ZM22.625 292.214V290.062C22.6263 288.82 23.1205 287.628 23.9993 286.749C24.8781 285.87 26.0697 285.376 27.3125 285.375H36.6875C37.9303 285.376 39.1219 285.87 40.0007 286.749C40.8795 287.628 41.3738 288.82 41.375 290.062V292.214C38.53 293.875 35.2946 294.751 32 294.751C28.7055 294.751 25.4701 293.875 22.625 292.214ZM44.4875 289.947C44.4564 287.897 43.6213 285.942 42.1624 284.502C40.7034 283.063 38.7372 282.254 36.6875 282.25H27.3125C25.2628 282.254 23.2966 283.063 21.8376 284.502C20.3787 285.942 19.5436 287.897 19.5125 289.947C16.679 287.417 14.6808 284.086 13.7826 280.395C12.8843 276.704 13.1283 272.827 14.4823 269.278C15.8362 265.729 18.2363 262.674 21.3647 260.52C24.493 258.365 28.2021 257.211 32.0008 257.211C35.7995 257.211 39.5086 258.365 42.6369 260.52C45.7653 262.674 48.1654 265.729 49.5193 269.278C50.8733 272.827 51.1173 276.704 50.219 280.395C49.3207 284.086 47.3226 287.417 44.4891 289.947H44.4875Z" fill="#FBD561"/>
<path d="M69.49 27C69.4153 27 69.3453 26.972 69.28 26.916C69.224 26.86 69.196 26.79 69.196 26.706L69.224 26.58L72.598 17.55C72.6633 17.3167 72.8267 17.2 73.088 17.2H74.614C74.8567 17.2 75.02 17.3167 75.104 17.55L78.478 26.58C78.4873 26.608 78.492 26.65 78.492 26.706C78.492 26.79 78.464 26.86 78.408 26.916C78.352 26.972 78.2867 27 78.212 27H76.994C76.8727 27 76.7793 26.972 76.714 26.916C76.6487 26.86 76.6067 26.7993 76.588 26.734L75.93 25.026H71.772L71.114 26.734C71.0393 26.9113 70.904 27 70.708 27H69.49ZM75.44 23.416L73.844 19.09L72.262 23.416H75.44ZM79.981 27C79.8877 27 79.8084 26.9673 79.743 26.902C79.6777 26.8367 79.645 26.7573 79.645 26.664V17.396C79.645 17.2933 79.6777 17.214 79.743 17.158C79.8084 17.0927 79.8877 17.06 79.981 17.06H81.143C81.2457 17.06 81.325 17.0927 81.381 17.158C81.4464 17.214 81.479 17.2933 81.479 17.396V26.664C81.479 26.7573 81.4464 26.8367 81.381 26.902C81.325 26.9673 81.2457 27 81.143 27H79.981ZM83.6161 18.516C83.5228 18.516 83.4434 18.4833 83.3781 18.418C83.3128 18.3527 83.2801 18.2733 83.2801 18.18V17.172C83.2801 17.0787 83.3128 16.9993 83.3781 16.934C83.4434 16.8687 83.5228 16.836 83.6161 16.836H84.8901C84.9834 16.836 85.0628 16.8687 85.1281 16.934C85.2028 16.9993 85.2401 17.0787 85.2401 17.172V18.18C85.2401 18.2733 85.2074 18.3527 85.1421 18.418C85.0768 18.4833 84.9928 18.516 84.8901 18.516H83.6161ZM83.6721 27C83.5788 27 83.4994 26.9673 83.4341 26.902C83.3688 26.8367 83.3361 26.7573 83.3361 26.664V20.056C83.3361 19.9627 83.3688 19.8833 83.4341 19.818C83.4994 19.7527 83.5788 19.72 83.6721 19.72H84.8341C84.9368 19.72 85.0161 19.7527 85.0721 19.818C85.1374 19.874 85.1701 19.9533 85.1701 20.056V26.664C85.1701 26.7573 85.1374 26.8367 85.0721 26.902C85.0161 26.9673 84.9368 27 84.8341 27H83.6721ZM90.1775 27.14C89.1508 27.14 88.3295 26.8553 87.7135 26.286C87.1068 25.7167 86.7848 24.928 86.7475 23.92L86.7335 23.36L86.7475 22.8C86.7848 21.792 87.1068 21.0033 87.7135 20.434C88.3295 19.8647 89.1508 19.58 90.1775 19.58C90.9055 19.58 91.5215 19.7107 92.0255 19.972C92.5388 20.2333 92.9168 20.5553 93.1595 20.938C93.4115 21.3113 93.5468 21.666 93.5655 22.002C93.5748 22.0953 93.5422 22.1747 93.4675 22.24C93.4022 22.3053 93.3228 22.338 93.2295 22.338H91.9975C91.9042 22.338 91.8295 22.3193 91.7735 22.282C91.7268 22.2353 91.6802 22.1607 91.6335 22.058C91.4935 21.694 91.3068 21.4327 91.0735 21.274C90.8495 21.1153 90.5602 21.036 90.2055 21.036C89.7295 21.036 89.3562 21.19 89.0855 21.498C88.8148 21.7967 88.6702 22.254 88.6515 22.87L88.6375 23.388L88.6515 23.85C88.6888 25.0727 89.2068 25.684 90.2055 25.684C90.5695 25.684 90.8635 25.6047 91.0875 25.446C91.3115 25.2873 91.4935 25.026 91.6335 24.662C91.6802 24.5593 91.7268 24.4893 91.7735 24.452C91.8295 24.4053 91.9042 24.382 91.9975 24.382H93.2295C93.3228 24.382 93.4022 24.4147 93.4675 24.48C93.5422 24.5453 93.5748 24.6247 93.5655 24.718C93.5468 25.0447 93.4162 25.3947 93.1735 25.768C92.9308 26.1413 92.5575 26.4633 92.0535 26.734C91.5495 27.0047 90.9242 27.14 90.1775 27.14ZM98.1616 27.14C97.1256 27.14 96.2996 26.8413 95.6836 26.244C95.0769 25.6373 94.7549 24.788 94.7176 23.696L94.7036 23.346L94.7176 22.996C94.7642 21.932 95.0909 21.0967 95.6976 20.49C96.3136 19.8833 97.1349 19.58 98.1616 19.58C99.2629 19.58 100.112 19.916 100.71 20.588C101.316 21.26 101.62 22.156 101.62 23.276V23.57C101.62 23.6633 101.587 23.7427 101.522 23.808C101.456 23.8733 101.372 23.906 101.27 23.906H96.6216V24.018C96.6402 24.5313 96.7802 24.9653 97.0416 25.32C97.3122 25.6653 97.6809 25.838 98.1476 25.838C98.6982 25.838 99.1416 25.6233 99.4776 25.194C99.5616 25.0913 99.6269 25.026 99.6736 24.998C99.7296 24.97 99.8089 24.956 99.9116 24.956H101.116C101.2 24.956 101.27 24.984 101.326 25.04C101.391 25.0867 101.424 25.1473 101.424 25.222C101.424 25.446 101.288 25.712 101.018 26.02C100.756 26.3187 100.378 26.58 99.8836 26.804C99.3889 27.028 98.8149 27.14 98.1616 27.14ZM99.7156 22.73V22.688C99.7156 22.1373 99.5756 21.694 99.2956 21.358C99.0249 21.022 98.6469 20.854 98.1616 20.854C97.6762 20.854 97.2982 21.022 97.0276 21.358C96.7569 21.694 96.6216 22.1373 96.6216 22.688V22.73H99.7156Z" fill="#062D56"/>
<path d="M72.49 727C72.4153 727 72.3453 726.972 72.28 726.916C72.224 726.86 72.196 726.79 72.196 726.706L72.224 726.58L75.598 717.55C75.6633 717.317 75.8267 717.2 76.088 717.2H77.614C77.8567 717.2 78.02 717.317 78.104 717.55L81.478 726.58C81.4873 726.608 81.492 726.65 81.492 726.706C81.492 726.79 81.464 726.86 81.408 726.916C81.352 726.972 81.2867 727 81.212 727H79.994C79.8727 727 79.7793 726.972 79.714 726.916C79.6487 726.86 79.6067 726.799 79.588 726.734L78.93 725.026H74.772L74.114 726.734C74.0393 726.911 73.904 727 73.708 727H72.49ZM78.44 723.416L76.844 719.09L75.262 723.416H78.44ZM82.981 727C82.8877 727 82.8084 726.967 82.743 726.902C82.6777 726.837 82.645 726.757 82.645 726.664V717.396C82.645 717.293 82.6777 717.214 82.743 717.158C82.8084 717.093 82.8877 717.06 82.981 717.06H84.143C84.2457 717.06 84.325 717.093 84.381 717.158C84.4464 717.214 84.479 717.293 84.479 717.396V726.664C84.479 726.757 84.4464 726.837 84.381 726.902C84.325 726.967 84.2457 727 84.143 727H82.981ZM86.6161 718.516C86.5228 718.516 86.4434 718.483 86.3781 718.418C86.3128 718.353 86.2801 718.273 86.2801 718.18V717.172C86.2801 717.079 86.3128 716.999 86.3781 716.934C86.4434 716.869 86.5228 716.836 86.6161 716.836H87.8901C87.9834 716.836 88.0628 716.869 88.1281 716.934C88.2028 716.999 88.2401 717.079 88.2401 717.172V718.18C88.2401 718.273 88.2074 718.353 88.1421 718.418C88.0768 718.483 87.9928 718.516 87.8901 718.516H86.6161ZM86.6721 727C86.5788 727 86.4994 726.967 86.4341 726.902C86.3688 726.837 86.3361 726.757 86.3361 726.664V720.056C86.3361 719.963 86.3688 719.883 86.4341 719.818C86.4994 719.753 86.5788 719.72 86.6721 719.72H87.8341C87.9368 719.72 88.0161 719.753 88.0721 719.818C88.1374 719.874 88.1701 719.953 88.1701 720.056V726.664C88.1701 726.757 88.1374 726.837 88.0721 726.902C88.0161 726.967 87.9368 727 87.8341 727H86.6721ZM93.1775 727.14C92.1508 727.14 91.3295 726.855 90.7135 726.286C90.1068 725.717 89.7848 724.928 89.7475 723.92L89.7335 723.36L89.7475 722.8C89.7848 721.792 90.1068 721.003 90.7135 720.434C91.3295 719.865 92.1508 719.58 93.1775 719.58C93.9055 719.58 94.5215 719.711 95.0255 719.972C95.5388 720.233 95.9168 720.555 96.1595 720.938C96.4115 721.311 96.5468 721.666 96.5655 722.002C96.5748 722.095 96.5422 722.175 96.4675 722.24C96.4022 722.305 96.3228 722.338 96.2295 722.338H94.9975C94.9042 722.338 94.8295 722.319 94.7735 722.282C94.7268 722.235 94.6802 722.161 94.6335 722.058C94.4935 721.694 94.3068 721.433 94.0735 721.274C93.8495 721.115 93.5602 721.036 93.2055 721.036C92.7295 721.036 92.3562 721.19 92.0855 721.498C91.8148 721.797 91.6702 722.254 91.6515 722.87L91.6375 723.388L91.6515 723.85C91.6888 725.073 92.2068 725.684 93.2055 725.684C93.5695 725.684 93.8635 725.605 94.0875 725.446C94.3115 725.287 94.4935 725.026 94.6335 724.662C94.6802 724.559 94.7268 724.489 94.7735 724.452C94.8295 724.405 94.9042 724.382 94.9975 724.382H96.2295C96.3228 724.382 96.4022 724.415 96.4675 724.48C96.5422 724.545 96.5748 724.625 96.5655 724.718C96.5468 725.045 96.4162 725.395 96.1735 725.768C95.9308 726.141 95.5575 726.463 95.0535 726.734C94.5495 727.005 93.9242 727.14 93.1775 727.14ZM101.162 727.14C100.126 727.14 99.2996 726.841 98.6836 726.244C98.0769 725.637 97.7549 724.788 97.7176 723.696L97.7036 723.346L97.7176 722.996C97.7642 721.932 98.0909 721.097 98.6976 720.49C99.3136 719.883 100.135 719.58 101.162 719.58C102.263 719.58 103.112 719.916 103.71 720.588C104.316 721.26 104.62 722.156 104.62 723.276V723.57C104.62 723.663 104.587 723.743 104.522 723.808C104.456 723.873 104.372 723.906 104.27 723.906H99.6216V724.018C99.6402 724.531 99.7802 724.965 100.042 725.32C100.312 725.665 100.681 725.838 101.148 725.838C101.698 725.838 102.142 725.623 102.478 725.194C102.562 725.091 102.627 725.026 102.674 724.998C102.73 724.97 102.809 724.956 102.912 724.956H104.116C104.2 724.956 104.27 724.984 104.326 725.04C104.391 725.087 104.424 725.147 104.424 725.222C104.424 725.446 104.288 725.712 104.018 726.02C103.756 726.319 103.378 726.58 102.884 726.804C102.389 727.028 101.815 727.14 101.162 727.14ZM102.716 722.73V722.688C102.716 722.137 102.576 721.694 102.296 721.358C102.025 721.022 101.647 720.854 101.162 720.854C100.676 720.854 100.298 721.022 100.028 721.358C99.7569 721.694 99.6216 722.137 99.6216 722.688V722.73H102.716Z" fill="#062D56"/>
<path d="M70.428 265C70.3347 265 70.2553 264.967 70.19 264.902C70.1247 264.837 70.092 264.757 70.092 264.664V255.55C70.092 255.447 70.12 255.363 70.176 255.298C70.2413 255.233 70.3253 255.2 70.428 255.2H74.488C75.58 255.2 76.392 255.443 76.924 255.928C77.4653 256.404 77.736 257.057 77.736 257.888C77.736 258.373 77.6147 258.789 77.372 259.134C77.1387 259.47 76.8633 259.713 76.546 259.862C76.938 260.039 77.2647 260.329 77.526 260.73C77.7967 261.131 77.932 261.589 77.932 262.102C77.932 262.97 77.638 263.67 77.05 264.202C76.4713 264.734 75.6547 265 74.6 265H70.428ZM74.236 259.218C74.7213 259.218 75.09 259.101 75.342 258.868C75.594 258.635 75.72 258.322 75.72 257.93C75.72 257.529 75.594 257.221 75.342 257.006C75.09 256.782 74.7213 256.67 74.236 256.67H72.038V259.218H74.236ZM74.376 263.516C74.8613 263.516 75.2393 263.385 75.51 263.124C75.7807 262.853 75.916 262.513 75.916 262.102C75.916 261.682 75.7807 261.341 75.51 261.08C75.2393 260.809 74.8613 260.674 74.376 260.674H72.038V263.516H74.376ZM82.7417 265.14C81.6497 265.14 80.805 264.86 80.2077 264.3C79.6103 263.731 79.2883 262.956 79.2417 261.976L79.2277 261.36L79.2417 260.744C79.2883 259.773 79.615 259.003 80.2217 258.434C80.8283 257.865 81.6683 257.58 82.7417 257.58C83.815 257.58 84.655 257.865 85.2617 258.434C85.8683 259.003 86.195 259.773 86.2417 260.744C86.251 260.856 86.2557 261.061 86.2557 261.36C86.2557 261.659 86.251 261.864 86.2417 261.976C86.195 262.956 85.873 263.731 85.2757 264.3C84.6783 264.86 83.8337 265.14 82.7417 265.14ZM82.7417 263.754C83.2363 263.754 83.619 263.6 83.8897 263.292C84.1603 262.975 84.3097 262.513 84.3377 261.906C84.347 261.813 84.3517 261.631 84.3517 261.36C84.3517 261.089 84.347 260.907 84.3377 260.814C84.3097 260.207 84.1603 259.75 83.8897 259.442C83.619 259.125 83.2363 258.966 82.7417 258.966C82.247 258.966 81.8643 259.125 81.5937 259.442C81.323 259.75 81.1737 260.207 81.1457 260.814L81.1317 261.36L81.1457 261.906C81.1737 262.513 81.323 262.975 81.5937 263.292C81.8643 263.6 82.247 263.754 82.7417 263.754ZM91.8388 265.14C90.8775 265.14 90.1308 264.809 89.5988 264.146V264.664C89.5988 264.757 89.5661 264.837 89.5008 264.902C89.4448 264.967 89.3655 265 89.2628 265H88.1568C88.0635 265 87.9841 264.967 87.9188 264.902C87.8535 264.837 87.8208 264.757 87.8208 264.664V255.396C87.8208 255.293 87.8535 255.214 87.9188 255.158C87.9841 255.093 88.0635 255.06 88.1568 255.06H89.3468C89.4495 255.06 89.5288 255.093 89.5848 255.158C89.6501 255.214 89.6828 255.293 89.6828 255.396V258.504C90.2148 257.888 90.9335 257.58 91.8388 257.58C92.7815 257.58 93.5048 257.888 94.0088 258.504C94.5128 259.12 94.7835 259.918 94.8208 260.898C94.8301 261.01 94.8348 261.159 94.8348 261.346C94.8348 261.542 94.8301 261.696 94.8208 261.808C94.7835 262.816 94.5128 263.623 94.0088 264.23C93.5048 264.837 92.7815 265.14 91.8388 265.14ZM91.3208 263.642C92.3288 263.642 92.8655 263.021 92.9308 261.78C92.9401 261.687 92.9448 261.547 92.9448 261.36C92.9448 261.173 92.9401 261.033 92.9308 260.94C92.8655 259.699 92.3288 259.078 91.3208 259.078C90.7981 259.078 90.3968 259.246 90.1168 259.582C89.8461 259.909 89.7015 260.305 89.6828 260.772L89.6688 261.304L89.6828 261.85C89.7108 262.354 89.8555 262.779 90.1168 263.124C90.3781 263.469 90.7795 263.642 91.3208 263.642Z" fill="#062D56"/>
<path d="M71.8574 55.8545L76.0068 45.0469H74.8789L70.7227 55.8545H71.8574ZM83.458 55H84.7773V54.8906C84.6953 54.6855 84.6315 54.4463 84.5859 54.1729C84.5404 53.8949 84.5176 53.6328 84.5176 53.3867V49.9482C84.5176 49.5335 84.4424 49.1712 84.292 48.8613C84.1416 48.5514 83.9365 48.2917 83.6768 48.082C83.4124 47.877 83.1003 47.7243 82.7402 47.624C82.3802 47.5192 81.9906 47.4668 81.5713 47.4668C81.111 47.4668 80.6986 47.5306 80.334 47.6582C79.974 47.7858 79.6686 47.9521 79.418 48.1572C79.1628 48.3669 78.9668 48.6016 78.8301 48.8613C78.6979 49.1211 78.6296 49.3854 78.625 49.6543H79.8965C79.8965 49.4993 79.9329 49.3512 80.0059 49.21C80.0833 49.0641 80.1904 48.9388 80.3271 48.834C80.4639 48.7292 80.6302 48.6449 80.8262 48.5811C81.0267 48.5173 81.2523 48.4854 81.5029 48.4854C81.7718 48.4854 82.0133 48.5195 82.2275 48.5879C82.4463 48.6562 82.6309 48.752 82.7812 48.875C82.9316 49.0026 83.0479 49.1553 83.1299 49.333C83.2119 49.5107 83.2529 49.7113 83.2529 49.9346V50.5156H81.8721C81.3571 50.5156 80.89 50.5658 80.4707 50.666C80.056 50.7663 79.7005 50.9167 79.4043 51.1172C79.1081 51.3223 78.8779 51.5775 78.7139 51.8828C78.5544 52.1882 78.4746 52.5436 78.4746 52.9492C78.4746 53.2591 78.5339 53.5485 78.6523 53.8174C78.7754 54.0817 78.9486 54.3096 79.1719 54.501C79.3906 54.6969 79.6572 54.8519 79.9717 54.9658C80.2907 55.0798 80.6462 55.1367 81.0381 55.1367C81.2796 55.1367 81.5075 55.1117 81.7217 55.0615C81.9359 55.0114 82.1387 54.943 82.3301 54.8564C82.5169 54.7699 82.6878 54.6696 82.8428 54.5557C83.0023 54.4417 83.1458 54.321 83.2734 54.1934C83.2871 54.3483 83.3076 54.4987 83.335 54.6445C83.3669 54.7858 83.4079 54.9043 83.458 55ZM81.2227 54.0361C80.9766 54.0361 80.7601 54.0042 80.5732 53.9404C80.3864 53.8766 80.2314 53.7878 80.1084 53.6738C79.9854 53.5645 79.8919 53.4323 79.8281 53.2773C79.7689 53.1224 79.7393 52.9538 79.7393 52.7715C79.7393 52.5801 79.7734 52.4092 79.8418 52.2588C79.9147 52.1084 80.0195 51.9785 80.1562 51.8691C80.3477 51.7142 80.6051 51.6003 80.9287 51.5273C81.2568 51.4499 81.6396 51.4111 82.0771 51.4111H83.2529V52.9082C83.18 53.054 83.0798 53.1953 82.9521 53.332C82.8245 53.4642 82.6742 53.5827 82.501 53.6875C82.3232 53.7923 82.1273 53.8766 81.9131 53.9404C81.6989 54.0042 81.4688 54.0361 81.2227 54.0361ZM86.7666 51.2402V51.3838C86.7666 51.9124 86.8372 52.4069 86.9785 52.8672C87.1198 53.3229 87.318 53.7194 87.5732 54.0566C87.8285 54.3939 88.1361 54.6582 88.4961 54.8496C88.8607 55.041 89.2663 55.1367 89.7129 55.1367C90.1686 55.1367 90.5674 55.0592 90.9092 54.9043C91.251 54.7493 91.5449 54.5215 91.791 54.2207L91.8457 55H93.0078V44.5H91.7432V48.335C91.5016 48.0524 91.2145 47.8382 90.8818 47.6924C90.5537 47.542 90.1686 47.4668 89.7266 47.4668C89.2754 47.4668 88.8675 47.5602 88.5029 47.7471C88.1383 47.9339 87.8285 48.1937 87.5732 48.5264C87.3135 48.859 87.113 49.2578 86.9717 49.7227C86.835 50.1829 86.7666 50.6888 86.7666 51.2402ZM88.0312 51.3838V51.2402C88.0312 50.8802 88.07 50.5384 88.1475 50.2148C88.2249 49.8867 88.3457 49.5973 88.5098 49.3467C88.6693 49.1006 88.8743 48.9046 89.125 48.7588C89.3802 48.613 89.6855 48.54 90.041 48.54C90.4557 48.54 90.8021 48.638 91.0801 48.834C91.3581 49.0254 91.5791 49.2715 91.7432 49.5723V53.0039C91.5791 53.3275 91.3581 53.585 91.0801 53.7764C90.8021 53.9678 90.4512 54.0635 90.0273 54.0635C89.6764 54.0635 89.3757 53.9928 89.125 53.8516C88.8743 53.7057 88.6693 53.5098 88.5098 53.2637C88.3457 53.0176 88.2249 52.7327 88.1475 52.4092C88.07 52.0856 88.0312 51.7438 88.0312 51.3838ZM95.1748 51.2402V51.3838C95.1748 51.9124 95.2454 52.4069 95.3867 52.8672C95.528 53.3229 95.7262 53.7194 95.9814 54.0566C96.2367 54.3939 96.5443 54.6582 96.9043 54.8496C97.2689 55.041 97.6745 55.1367 98.1211 55.1367C98.5768 55.1367 98.9756 55.0592 99.3174 54.9043C99.6592 54.7493 99.9531 54.5215 100.199 54.2207L100.254 55H101.416V44.5H100.151V48.335C99.9098 48.0524 99.6227 47.8382 99.29 47.6924C98.9619 47.542 98.5768 47.4668 98.1348 47.4668C97.6836 47.4668 97.2757 47.5602 96.9111 47.7471C96.5465 47.9339 96.2367 48.1937 95.9814 48.5264C95.7217 48.859 95.5212 49.2578 95.3799 49.7227C95.2432 50.1829 95.1748 50.6888 95.1748 51.2402ZM96.4395 51.3838V51.2402C96.4395 50.8802 96.4782 50.5384 96.5557 50.2148C96.6331 49.8867 96.7539 49.5973 96.918 49.3467C97.0775 49.1006 97.2826 48.9046 97.5332 48.7588C97.7884 48.613 98.0938 48.54 98.4492 48.54C98.8639 48.54 99.2103 48.638 99.4883 48.834C99.7663 49.0254 99.9873 49.2715 100.151 49.5723V53.0039C99.9873 53.3275 99.7663 53.585 99.4883 53.7764C99.2103 53.9678 98.8594 54.0635 98.4355 54.0635C98.0846 54.0635 97.7839 53.9928 97.5332 53.8516C97.2826 53.7057 97.0775 53.5098 96.918 53.2637C96.7539 53.0176 96.6331 52.7327 96.5557 52.4092C96.4782 52.0856 96.4395 51.7438 96.4395 51.3838ZM118 53.6602V52.3203L113.816 50.707L113.454 50.584L113.816 50.4678L118 48.8271V47.4873L112.203 50.0713V51.0693L118 53.6602ZM120.639 55H121.903V49.6953C121.99 49.5358 122.09 49.39 122.204 49.2578C122.323 49.1257 122.45 49.0094 122.587 48.9092C122.756 48.7952 122.94 48.7064 123.141 48.6426C123.341 48.Line truncated
<path d="M71.8574 55.8545L76.0068 45.0469H74.8789L70.7227 55.8545H71.8574ZM81.749 54.1113C81.3525 54.1113 81.0199 54.0339 80.751 53.8789C80.4867 53.7194 80.2747 53.512 80.1152 53.2568C79.9512 53.0062 79.8327 52.7236 79.7598 52.4092C79.6914 52.0902 79.6572 51.7689 79.6572 51.4453V51.1582C79.6572 50.8392 79.6914 50.5225 79.7598 50.208C79.8327 49.8936 79.9512 49.6087 80.1152 49.3535C80.2793 49.1029 80.4935 48.9001 80.7578 48.7451C81.0267 48.5856 81.3571 48.5059 81.749 48.5059C82.0042 48.5059 82.2412 48.5492 82.46 48.6357C82.6833 48.7223 82.8747 48.8408 83.0342 48.9912C83.1937 49.1416 83.319 49.3171 83.4102 49.5176C83.5059 49.7135 83.556 49.9232 83.5605 50.1465H84.7568C84.7568 49.7728 84.6816 49.4219 84.5312 49.0938C84.3809 48.7656 84.1735 48.4808 83.9092 48.2393C83.6403 48.0023 83.3213 47.8154 82.9521 47.6787C82.5876 47.5374 82.1865 47.4668 81.749 47.4668C81.1885 47.4668 80.6986 47.5671 80.2793 47.7676C79.86 47.9681 79.5114 48.237 79.2334 48.5742C78.9508 48.916 78.7389 49.3102 78.5977 49.7568C78.4564 50.2035 78.3857 50.6706 78.3857 51.1582V51.4453C78.3857 51.9375 78.4564 52.4069 78.5977 52.8535C78.7389 53.2956 78.9508 53.6852 79.2334 54.0225C79.5114 54.3643 79.86 54.6354 80.2793 54.8359C80.6986 55.0365 81.1885 55.1367 81.749 55.1367C82.141 55.1367 82.5169 55.0706 82.877 54.9385C83.237 54.8018 83.556 54.6195 83.834 54.3916C84.112 54.1683 84.333 53.9085 84.4971 53.6123C84.6657 53.3115 84.7523 52.9971 84.7568 52.6689H83.5605C83.556 52.874 83.5013 53.0654 83.3965 53.2432C83.2962 53.4163 83.1618 53.5667 82.9932 53.6943C82.8245 53.8265 82.6309 53.929 82.4121 54.002C82.1979 54.0749 81.9769 54.1113 81.749 54.1113Z" fill="#062D56"/>
<path d="M79.9229 749.606C79.9411 748.918 79.8773 748.294 79.7314 747.733C79.5856 747.168 79.3669 746.685 79.0752 746.284C78.779 745.883 78.4144 745.576 77.9814 745.361C77.5485 745.143 77.054 745.033 76.498 745.033C75.9284 745.033 75.4066 745.163 74.9326 745.423C74.4632 745.683 74.0553 746.04 73.709 746.496C73.3444 746.975 73.0527 747.542 72.834 748.198C72.6198 748.854 72.499 749.547 72.4717 750.276C72.4489 750.974 72.5036 751.616 72.6357 752.204C72.7725 752.787 72.9935 753.291 73.2988 753.715C73.5996 754.139 73.9893 754.469 74.4678 754.706C74.9508 754.938 75.5273 755.055 76.1973 755.055C76.3431 755.055 76.498 755.043 76.6621 755.021C76.8262 755.002 76.988 754.97 77.1475 754.925C77.307 754.884 77.4596 754.831 77.6055 754.768C77.7513 754.704 77.8812 754.629 77.9951 754.542L77.7764 753.742C77.6761 753.811 77.5645 753.872 77.4414 753.927C77.3184 753.981 77.1885 754.027 77.0518 754.063C76.915 754.104 76.776 754.136 76.6348 754.159C76.4935 754.177 76.3545 754.187 76.2178 754.187C75.7074 754.187 75.263 754.1 74.8848 753.927C74.5111 753.749 74.2035 753.492 73.9619 753.154C73.7204 752.822 73.5449 752.414 73.4355 751.931C73.3262 751.448 73.2829 750.896 73.3057 750.276C73.3239 749.616 73.4173 749.009 73.5859 748.458C73.7546 747.902 73.9915 747.428 74.2969 747.036C74.584 746.672 74.9076 746.391 75.2676 746.195C75.6322 745.995 76.0355 745.895 76.4775 745.895C76.915 745.895 77.3047 745.979 77.6465 746.147C77.9883 746.316 78.2777 746.56 78.5146 746.879C78.7471 747.198 78.9202 747.588 79.0342 748.048C79.1481 748.508 79.196 749.028 79.1777 749.606C79.1732 749.939 79.1481 750.254 79.1025 750.55C79.057 750.846 78.9909 751.104 78.9043 751.322C78.8177 751.546 78.7083 751.723 78.5762 751.855C78.4486 751.983 78.3005 752.047 78.1318 752.047C78.0589 752.047 77.9906 752.035 77.9268 752.013C77.863 751.99 77.8105 751.944 77.7695 751.876C77.724 751.812 77.6898 751.723 77.667 751.609C77.6442 751.491 77.6396 751.338 77.6533 751.151L77.9541 747.706C77.8356 747.542 77.6761 747.401 77.4756 747.282C77.2751 747.159 77.0221 747.098 76.7168 747.098C76.3932 747.098 76.097 747.175 75.8281 747.33C75.5592 747.48 75.3245 747.697 75.124 747.979C74.9189 748.267 74.7526 748.615 74.625 749.025C74.4974 749.431 74.4131 749.887 74.3721 750.393C74.3447 750.748 74.3493 751.074 74.3857 751.37C74.4268 751.666 74.4997 751.922 74.6045 752.136C74.7048 752.35 74.8369 752.516 75.001 752.635C75.165 752.753 75.3587 752.812 75.582 752.812C75.737 752.812 75.8851 752.79 76.0264 752.744C76.1676 752.699 76.2998 752.635 76.4229 752.553C76.5231 752.48 76.6165 752.396 76.7031 752.3C76.7943 752.204 76.8763 752.099 76.9492 751.985C76.9811 752.095 77.0221 752.195 77.0723 752.286C77.1224 752.373 77.1816 752.45 77.25 752.519C77.3457 752.614 77.4596 752.687 77.5918 752.737C77.724 752.787 77.8721 752.812 78.0361 752.812C78.3734 752.812 78.6582 752.715 78.8906 752.519C79.123 752.323 79.3145 752.07 79.4648 751.76C79.6107 751.45 79.7201 751.106 79.793 750.728C79.8659 750.345 79.9092 749.971 79.9229 749.606ZM75.2129 750.393C75.2493 750.019 75.304 749.682 75.377 749.381C75.4544 749.076 75.5547 748.816 75.6777 748.602C75.8008 748.392 75.9512 748.23 76.1289 748.116C76.3112 747.998 76.5231 747.938 76.7646 747.938C76.833 747.938 76.8991 747.945 76.9629 747.959C77.0312 747.973 77.0973 747.995 77.1611 748.027L76.9014 751.001L76.8945 751.069C76.8444 751.179 76.7897 751.277 76.7305 751.363C76.6712 751.445 76.6097 751.518 76.5459 751.582C76.4411 751.682 76.3249 751.755 76.1973 751.801C76.0742 751.846 75.9443 751.869 75.8076 751.869C75.6982 751.869 75.6025 751.837 75.5205 751.773C75.443 751.705 75.3792 751.607 75.3291 751.479C75.279 751.356 75.2448 751.204 75.2266 751.021C75.2083 750.835 75.2038 750.625 75.2129 750.393ZM87.3672 753.66V752.32L83.1836 750.707L82.8213 750.584L83.1836 750.468L87.3672 748.827V747.487L81.5703 750.071V751.069L87.3672 753.66ZM90.0059 755H91.2705V749.695C91.3571 749.536 91.4574 749.39 91.5713 749.258C91.6898 749.126 91.8174 749.009 91.9541 748.909C92.1227 748.795 92.3073 748.706 92.5078 748.643C92.7083 748.574 92.9248 748.54 93.1572 748.54C93.4261 748.54 93.6631 748.572 93.8682 748.636C94.0778 748.7 94.2555 748.802 94.4014 748.943C94.5426 749.085 94.6497 749.269 94.7227 749.497C94.7956 749.725 94.832 750.003 94.832 750.331V755H96.0967V750.304C96.0967 749.812 96.0352 749.388 95.9121 749.032C95.7936 748.672 95.6227 748.376 95.3994 748.144C95.1761 747.911 94.9049 747.74 94.5859 747.631C94.2715 747.521 93.9206 747.467 93.5332 747.467C93.2461 747.471 92.9727 747.515 92.7129 747.597C92.4577 747.674 92.2207 747.786 92.002 747.932C91.8561 748.027 91.7171 748.141 91.585 748.273C91.4574 748.401 91.3389 748.542 91.2295 748.697L91.1406 747.604H90.0059V755ZM103.274 755H104.594V754.891C104.512 754.686 104.448 754.446 104.402 754.173C104.357 753.895 104.334 753.633 104.334 753.387V749.948C104.334 749.534 104.259 749.171 104.108 748.861C103.958 748.551 103.753 748.292 103.493 748.082C103.229 747.877 102.917 747.724 102.557 747.624C102.197 747.519 101.807 747.467 101.388 747.467C100.927Line truncated
<path d="M71.8574 294.854L76.0068 284.047H74.8789L70.7227 294.854H71.8574ZM81.749 293.111C81.3525 293.111 81.0199 293.034 80.751 292.879C80.4867 292.719 80.2747 292.512 80.1152 292.257C79.9512 292.006 79.8327 291.724 79.7598 291.409C79.6914 291.09 79.6572 290.769 79.6572 290.445V290.158C79.6572 289.839 79.6914 289.522 79.7598 289.208C79.8327 288.894 79.9512 288.609 80.1152 288.354C80.2793 288.103 80.4935 287.9 80.7578 287.745C81.0267 287.586 81.3571 287.506 81.749 287.506C82.0042 287.506 82.2412 287.549 82.46 287.636C82.6833 287.722 82.8747 287.841 83.0342 287.991C83.1937 288.142 83.319 288.317 83.4102 288.518C83.5059 288.714 83.556 288.923 83.5605 289.146H84.7568C84.7568 288.773 84.6816 288.422 84.5312 288.094C84.3809 287.766 84.1735 287.481 83.9092 287.239C83.6403 287.002 83.3213 286.815 82.9521 286.679C82.5876 286.537 82.1865 286.467 81.749 286.467C81.1885 286.467 80.6986 286.567 80.2793 286.768C79.86 286.968 79.5114 287.237 79.2334 287.574C78.9508 287.916 78.7389 288.31 78.5977 288.757C78.4564 289.203 78.3857 289.671 78.3857 290.158V290.445C78.3857 290.938 78.4564 291.407 78.5977 291.854C78.7389 292.296 78.9508 292.685 79.2334 293.022C79.5114 293.364 79.86 293.635 80.2793 293.836C80.6986 294.036 81.1885 294.137 81.749 294.137C82.141 294.137 82.5169 294.071 82.877 293.938C83.237 293.802 83.556 293.619 83.834 293.392C84.112 293.168 84.333 292.909 84.4971 292.612C84.6657 292.312 84.7523 291.997 84.7568 291.669H83.5605C83.556 291.874 83.5013 292.065 83.3965 292.243C83.2962 292.416 83.1618 292.567 82.9932 292.694C82.8245 292.826 82.6309 292.929 82.4121 293.002C82.1979 293.075 81.9769 293.111 81.749 293.111ZM86.6504 290.233V290.384C86.6504 290.917 86.7279 291.411 86.8828 291.867C87.0378 292.323 87.2611 292.719 87.5527 293.057C87.8398 293.394 88.1908 293.658 88.6055 293.85C89.0247 294.041 89.4964 294.137 90.0205 294.137C90.54 294.137 91.0072 294.041 91.4219 293.85C91.8366 293.658 92.1898 293.394 92.4814 293.057C92.7686 292.719 92.9896 292.323 93.1445 291.867C93.2995 291.411 93.377 290.917 93.377 290.384V290.233C93.377 289.7 93.2995 289.206 93.1445 288.75C92.9896 288.29 92.7686 287.891 92.4814 287.554C92.1898 287.216 91.8343 286.952 91.415 286.761C91.0003 286.565 90.5309 286.467 90.0068 286.467C89.4873 286.467 89.0202 286.565 88.6055 286.761C88.1908 286.952 87.8398 287.216 87.5527 287.554C87.2611 287.891 87.0378 288.29 86.8828 288.75C86.7279 289.206 86.6504 289.7 86.6504 290.233ZM87.915 290.384V290.233C87.915 289.873 87.9583 289.529 88.0449 289.201C88.1315 288.868 88.2637 288.577 88.4414 288.326C88.6146 288.076 88.8311 287.877 89.0908 287.731C89.3506 287.581 89.6559 287.506 90.0068 287.506C90.3577 287.506 90.6631 287.581 90.9229 287.731C91.1872 287.877 91.4082 288.076 91.5859 288.326C91.7591 288.577 91.889 288.868 91.9756 289.201C92.0667 289.529 92.1123 289.873 92.1123 290.233V290.384C92.1123 290.748 92.069 291.097 91.9824 291.43C91.8958 291.758 91.766 292.047 91.5928 292.298C91.415 292.549 91.194 292.747 90.9297 292.893C90.6699 293.038 90.3669 293.111 90.0205 293.111C89.6696 293.111 89.362 293.038 89.0977 292.893C88.8333 292.747 88.6146 292.549 88.4414 292.298C88.2637 292.047 88.1315 291.758 88.0449 291.43C87.9583 291.097 87.915 290.748 87.915 290.384ZM95.4141 294H96.6787V288.695C96.7653 288.536 96.8656 288.39 96.9795 288.258C97.098 288.126 97.2256 288.009 97.3623 287.909C97.5309 287.795 97.7155 287.706 97.916 287.643C98.1165 287.574 98.333 287.54 98.5654 287.54C98.8343 287.54 99.0713 287.572 99.2764 287.636C99.486 287.7 99.6637 287.802 99.8096 287.943C99.9508 288.085 100.058 288.269 100.131 288.497C100.204 288.725 100.24 289.003 100.24 289.331V294H101.505V289.304C101.505 288.812 101.443 288.388 101.32 288.032C101.202 287.672 101.031 287.376 100.808 287.144C100.584 286.911 100.313 286.74 99.9941 286.631C99.6797 286.521 99.3288 286.467 98.9414 286.467C98.6543 286.471 98.3809 286.515 98.1211 286.597C97.8659 286.674 97.6289 286.786 97.4102 286.932C97.2643 287.027 97.1253 287.141 96.9932 287.273C96.8656 287.401 96.7471 287.542 96.6377 287.697L96.5488 286.604H95.4141V294ZM103.822 294H105.087V288.695C105.174 288.536 105.274 288.39 105.388 288.258C105.506 288.126 105.634 288.009 105.771 287.909C105.939 287.795 106.124 287.706 106.324 287.643C106.525 287.574 106.741 287.54 106.974 287.54C107.243 287.54 107.479 287.572 107.685 287.636C107.894 287.7 108.072 287.802 108.218 287.943C108.359 288.085 108.466 288.269 108.539 288.497C108.612 288.725 108.648 289.003 108.648 289.331V294H109.913V289.304C109.913 288.812 109.852 288.388 109.729 288.032C109.61 287.672 109.439 287.376 109.216 287.144C108.993 286.911 108.721 286.74 108.402 286.631C108.088 286.521 107.737 286.467 107.35 286.467C107.062 286.471 106.789 286.515 106.529 286.597C106.274 286.674 106.037 286.786 105.818 286.932C105.673 287.027 105.534 287.141 105.401 287.273C105.274 287.401 105.155 287.542 105.046 287.697L104.957 286.604H103.822V294ZM115.498 294.137C116.218 294.137 116.822 293.993 117.31 293.706C117.802 293.414 118.171 293.082 118.417 292.708L117.645 292.1Line truncated
<path d="M72.388 76.194H73.732L76.686 85H75.538L74.782 82.76H71.282L70.526 85H69.364L72.388 76.194ZM71.576 81.892H74.502L73.046 77.552L71.576 81.892ZM78.4667 75.466H79.5727V85H78.4667V75.466ZM82.4606 78.294H83.5666V85H82.4606V78.294ZM83.0066 76.726C82.7826 76.726 82.6052 76.6653 82.4746 76.544C82.3532 76.4133 82.2926 76.2453 82.2926 76.04C82.2926 75.8253 82.3532 75.6573 82.4746 75.536C82.6052 75.4053 82.7826 75.34 83.0066 75.34C83.2306 75.34 83.4079 75.4053 83.5386 75.536C83.6786 75.6573 83.7486 75.8253 83.7486 76.04C83.7486 76.2453 83.6786 76.4133 83.5386 76.544C83.4079 76.6653 83.2306 76.726 83.0066 76.726ZM88.8002 78.14C89.5935 78.14 90.2235 78.3453 90.6902 78.756C91.1568 79.1573 91.4602 79.6613 91.6002 80.268L90.4802 80.366C90.3588 79.974 90.1628 79.6707 89.8922 79.456C89.6215 79.232 89.3228 79.12 88.9962 79.12C88.3988 79.12 87.9135 79.344 87.5402 79.792C87.1762 80.24 86.9942 80.8513 86.9942 81.626C86.9942 82.3913 87.1715 83.0073 87.5262 83.474C87.8902 83.9407 88.3382 84.174 88.8702 84.174C89.4115 84.174 89.8128 84.0527 90.0742 83.81C90.3448 83.558 90.4802 83.2033 90.4802 82.746H91.6142C91.6142 83.4647 91.3622 84.048 90.8582 84.496C90.3635 84.9347 89.7148 85.154 88.9122 85.154C88.0628 85.154 87.3395 84.832 86.7422 84.188C86.1542 83.544 85.8602 82.69 85.8602 81.626C85.8602 80.5527 86.1542 79.7033 86.7422 79.078C87.3302 78.4527 88.0162 78.14 88.8002 78.14ZM96.0892 84.258C97.0132 84.258 97.5406 83.852 97.6712 83.04H98.8052C98.7026 83.712 98.4039 84.2347 97.9092 84.608C97.4239 84.972 96.8172 85.154 96.0892 85.154C95.1932 85.154 94.4652 84.8367 93.9052 84.202C93.3452 83.558 93.0652 82.704 93.0652 81.64C93.0652 80.576 93.3452 79.7267 93.9052 79.092C94.4746 78.4573 95.2259 78.14 96.1592 78.14C97.1019 78.14 97.8019 78.504 98.2592 79.232C98.7259 79.96 98.8892 80.8467 98.7492 81.892H94.1712C94.1712 82.5827 94.3392 83.152 94.6752 83.6C95.0112 84.0387 95.4826 84.258 96.0892 84.258ZM96.9012 79.19C96.6866 79.078 96.4252 79.022 96.1172 79.022C95.5479 79.022 95.0952 79.218 94.7592 79.61C94.4326 79.9927 94.2412 80.4733 94.1852 81.052H97.7552C97.7552 80.1187 97.4706 79.498 96.9012 79.19ZM108.87 83.67C108.413 84.6407 107.671 85.126 106.644 85.126C105.888 85.126 105.277 84.916 104.81 84.496C104.353 84.076 104.124 83.4273 104.124 82.55V78.294H105.23V82.466C105.23 83.5953 105.753 84.16 106.798 84.16C107.405 84.16 107.895 83.9267 108.268 83.46C108.651 82.9933 108.852 82.396 108.87 81.668V78.294H109.976V85H108.87V83.67ZM112.46 79.946C112.46 79.3953 112.694 78.9567 113.16 78.63C113.636 78.3033 114.276 78.14 115.078 78.14C115.881 78.14 116.506 78.308 116.954 78.644C117.412 78.98 117.65 79.4047 117.668 79.918H116.59C116.506 79.3113 115.993 79.008 115.05 79.008C114.593 79.008 114.238 79.1107 113.986 79.316C113.744 79.5213 113.622 79.7453 113.622 79.988C113.622 80.2213 113.716 80.422 113.902 80.59C114.089 80.7487 114.388 80.8887 114.798 81.01L116.142 81.458C116.712 81.6353 117.146 81.864 117.444 82.144C117.752 82.4147 117.906 82.7927 117.906 83.278C117.906 83.754 117.659 84.188 117.164 84.58C116.67 84.9627 115.979 85.154 115.092 85.154C114.206 85.154 113.515 84.958 113.02 84.566C112.526 84.1647 112.264 83.6513 112.236 83.026H113.3C113.319 83.446 113.487 83.7633 113.804 83.978C114.131 84.1833 114.537 84.286 115.022 84.286C115.508 84.286 115.909 84.1833 116.226 83.978C116.544 83.7727 116.702 83.53 116.702 83.25C116.702 82.9607 116.609 82.7413 116.422 82.592C116.236 82.4427 115.932 82.312 115.512 82.2L114.21 81.766C113.044 81.4207 112.46 80.814 112.46 79.946ZM122.49 84.258C123.414 84.258 123.941 83.852 124.072 83.04H125.206C125.103 83.712 124.804 84.2347 124.31 84.608C123.824 84.972 123.218 85.154 122.49 85.154C121.594 85.154 120.866 84.8367 120.306 84.202C119.746 83.558 119.466 82.704 119.466 81.64C119.466 80.576 119.746 79.7267 120.306 79.092C120.875 78.4573 121.626 78.14 122.56 78.14C123.502 78.14 124.202 78.504 124.66 79.232C125.126 79.96 125.29 80.8467 125.15 81.892H120.572C120.572 82.5827 120.74 83.152 121.076 83.6C121.412 84.0387 121.883 84.258 122.49 84.258ZM123.302 79.19C123.087 79.078 122.826 79.022 122.518 79.022C121.948 79.022 121.496 79.218 121.16 79.61C120.833 79.9927 120.642 80.4733 120.586 81.052H124.156C124.156 80.1187 123.871 79.498 123.302 79.19ZM127.035 79.946C127.035 79.3953 127.268 78.9567 127.735 78.63C128.211 78.3033 128.85 78.14 129.653 78.14C130.455 78.14 131.081 78.308 131.529 78.644C131.986 78.98 132.224 79.4047 132.243 79.918H131.165C131.081 79.3113 130.567 79.008 129.625 79.008C129.167 79.008 128.813 79.1107 128.561 79.316C128.318 79.5213 128.197 79.7453 128.197 79.988C128.197 80.2213 128.29 80.422 128.477 80.59C128.663 80.7487 128.962 80.8887 129.373 81.01L130.717 81.458C131.286 81.6353 131.72 81.864 132.019 82.144C132.327 82.4147 132.481 82.7927 132.481 83.278C132.481 83.754 132.233 84.188 131.739 84.58C131.244 84.9627 130.553 85.154 129.667 85.154C128.78 85.154 128.089 84.958 127.595 84.566C127.1 84.1647 126.839 83.6513 126.811 83.026H127.875C127.893 83.446 128.061 83.7633 128.379 83.978C128.705 84.18Line truncated
<path d="M71.8574 294.854L76.0068 284.047H74.8789L70.7227 294.854H71.8574ZM81.749 293.111C81.3525 293.111 81.0199 293.034 80.751 292.879C80.4867 292.719 80.2747 292.512 80.1152 292.257C79.9512 292.006 79.8327 291.724 79.7598 291.409C79.6914 291.09 79.6572 290.769 79.6572 290.445V290.158C79.6572 289.839 79.6914 289.522 79.7598 289.208C79.8327 288.894 79.9512 288.609 80.1152 288.354C80.2793 288.103 80.4935 287.9 80.7578 287.745C81.0267 287.586 81.3571 287.506 81.749 287.506C82.0042 287.506 82.2412 287.549 82.46 287.636C82.6833 287.722 82.8747 287.841 83.0342 287.991C83.1937 288.142 83.319 288.317 83.4102 288.518C83.5059 288.714 83.556 288.923 83.5605 289.146H84.7568C84.7568 288.773 84.6816 288.422 84.5312 288.094C84.3809 287.766 84.1735 287.481 83.9092 287.239C83.6403 287.002 83.3213 286.815 82.9521 286.679C82.5876 286.537 82.1865 286.467 81.749 286.467C81.1885 286.467 80.6986 286.567 80.2793 286.768C79.86 286.968 79.5114 287.237 79.2334 287.574C78.9508 287.916 78.7389 288.31 78.5977 288.757C78.4564 289.203 78.3857 289.671 78.3857 290.158V290.445C78.3857 290.938 78.4564 291.407 78.5977 291.854C78.7389 292.296 78.9508 292.685 79.2334 293.022C79.5114 293.364 79.86 293.635 80.2793 293.836C80.6986 294.036 81.1885 294.137 81.749 294.137C82.141 294.137 82.5169 294.071 82.877 293.938C83.237 293.802 83.556 293.619 83.834 293.392C84.112 293.168 84.333 292.909 84.4971 292.612C84.6657 292.312 84.7523 291.997 84.7568 291.669H83.5605C83.556 291.874 83.5013 292.065 83.3965 292.243C83.2962 292.416 83.1618 292.567 82.9932 292.694C82.8245 292.826 82.6309 292.929 82.4121 293.002C82.1979 293.075 81.9769 293.111 81.749 293.111ZM101.184 292.66V291.32L97 289.707L96.6377 289.584L97 289.468L101.184 287.827V286.487L95.3867 289.071V290.069L101.184 292.66ZM104.021 286.604V287.704H106.536V292.906H104.021V294H110.214V292.906H107.801V286.604H104.021ZM106.372 284.662C106.372 284.867 106.434 285.038 106.557 285.175C106.684 285.312 106.876 285.38 107.131 285.38C107.382 285.38 107.571 285.312 107.698 285.175C107.826 285.038 107.89 284.867 107.89 284.662C107.89 284.548 107.871 284.443 107.835 284.348C107.799 284.252 107.744 284.172 107.671 284.108C107.612 284.049 107.536 284.004 107.445 283.972C107.354 283.935 107.249 283.917 107.131 283.917C107.012 283.917 106.905 283.935 106.81 283.972C106.718 284.004 106.643 284.049 106.584 284.108C106.511 284.177 106.456 284.259 106.42 284.354C106.388 284.45 106.372 284.553 106.372 284.662ZM112.23 294H113.495V288.695C113.582 288.536 113.682 288.39 113.796 288.258C113.914 288.126 114.042 288.009 114.179 287.909C114.347 287.795 114.532 287.706 114.732 287.643C114.933 287.574 115.149 287.54 115.382 287.54C115.651 287.54 115.888 287.572 116.093 287.636C116.302 287.7 116.48 287.802 116.626 287.943C116.767 288.085 116.874 288.269 116.947 288.497C117.02 288.725 117.057 289.003 117.057 289.331V294H118.321V289.304C118.321 288.812 118.26 288.388 118.137 288.032C118.018 287.672 117.847 287.376 117.624 287.144C117.401 286.911 117.13 286.74 116.811 286.631C116.496 286.521 116.145 286.467 115.758 286.467C115.471 286.471 115.197 286.515 114.938 286.597C114.682 286.674 114.445 286.786 114.227 286.932C114.081 287.027 113.942 287.141 113.81 287.273C113.682 287.401 113.563 287.542 113.454 287.697L113.365 286.604H112.23V294ZM123.161 294H124.125L127.14 286.604H125.848L123.776 292.182L123.653 292.64L123.537 292.182L121.418 286.604H120.119L123.161 294ZM129.245 286.604V287.704H131.761V292.906H129.245V294H135.438V292.906H133.025V286.604H129.245ZM131.597 284.662C131.597 284.867 131.658 285.038 131.781 285.175C131.909 285.312 132.1 285.38 132.355 285.38C132.606 285.38 132.795 285.312 132.923 285.175C133.05 285.038 133.114 284.867 133.114 284.662C133.114 284.548 133.096 284.443 133.06 284.348C133.023 284.252 132.968 284.172 132.896 284.108C132.836 284.049 132.761 284.004 132.67 283.972C132.579 283.935 132.474 283.917 132.355 283.917C132.237 283.917 132.13 283.935 132.034 283.972C131.943 284.004 131.868 284.049 131.809 284.108C131.736 284.177 131.681 284.259 131.645 284.354C131.613 284.45 131.597 284.553 131.597 284.662ZM140.449 284.812H139.178V286.604H137.236V287.581H139.178V291.601C139.178 292.056 139.237 292.446 139.355 292.77C139.479 293.089 139.645 293.348 139.854 293.549C140.064 293.754 140.31 293.904 140.593 294C140.88 294.091 141.188 294.137 141.516 294.137C141.712 294.137 141.908 294.128 142.104 294.109C142.304 294.091 142.493 294.064 142.671 294.027C142.849 293.995 143.013 293.957 143.163 293.911C143.313 293.861 143.441 293.804 143.546 293.74L143.368 292.845C143.291 292.863 143.19 292.886 143.067 292.913C142.949 292.936 142.821 292.959 142.685 292.981C142.543 293.004 142.4 293.025 142.254 293.043C142.108 293.057 141.967 293.063 141.83 293.063C141.643 293.063 141.465 293.041 141.297 292.995C141.133 292.95 140.987 292.87 140.859 292.756C140.732 292.646 140.632 292.498 140.559 292.312C140.486 292.125 140.449 291.888 140.449 291.601V287.581H143.266V286.604H140.449V284.812ZM150.724 294H152.043V293.891C151.961 293.686 151.897 293Line truncated
<path d="M72.388 76.194H73.732L76.686 85H75.538L74.782 82.76H71.282L70.526 85H69.364L72.388 76.194ZM71.576 81.892H74.502L73.046 77.552L71.576 81.892ZM78.4667 75.466H79.5727V85H78.4667V75.466ZM82.4606 78.294H83.5666V85H82.4606V78.294ZM83.0066 76.726C82.7826 76.726 82.6052 76.6653 82.4746 76.544C82.3532 76.4133 82.2926 76.2453 82.2926 76.04C82.2926 75.8253 82.3532 75.6573 82.4746 75.536C82.6052 75.4053 82.7826 75.34 83.0066 75.34C83.2306 75.34 83.4079 75.4053 83.5386 75.536C83.6786 75.6573 83.7486 75.8253 83.7486 76.04C83.7486 76.2453 83.6786 76.4133 83.5386 76.544C83.4079 76.6653 83.2306 76.726 83.0066 76.726ZM88.8002 78.14C89.5935 78.14 90.2235 78.3453 90.6902 78.756C91.1568 79.1573 91.4602 79.6613 91.6002 80.268L90.4802 80.366C90.3588 79.974 90.1628 79.6707 89.8922 79.456C89.6215 79.232 89.3228 79.12 88.9962 79.12C88.3988 79.12 87.9135 79.344 87.5402 79.792C87.1762 80.24 86.9942 80.8513 86.9942 81.626C86.9942 82.3913 87.1715 83.0073 87.5262 83.474C87.8902 83.9407 88.3382 84.174 88.8702 84.174C89.4115 84.174 89.8128 84.0527 90.0742 83.81C90.3448 83.558 90.4802 83.2033 90.4802 82.746H91.6142C91.6142 83.4647 91.3622 84.048 90.8582 84.496C90.3635 84.9347 89.7148 85.154 88.9122 85.154C88.0628 85.154 87.3395 84.832 86.7422 84.188C86.1542 83.544 85.8602 82.69 85.8602 81.626C85.8602 80.5527 86.1542 79.7033 86.7422 79.078C87.3302 78.4527 88.0162 78.14 88.8002 78.14ZM96.0892 84.258C97.0132 84.258 97.5406 83.852 97.6712 83.04H98.8052C98.7026 83.712 98.4039 84.2347 97.9092 84.608C97.4239 84.972 96.8172 85.154 96.0892 85.154C95.1932 85.154 94.4652 84.8367 93.9052 84.202C93.3452 83.558 93.0652 82.704 93.0652 81.64C93.0652 80.576 93.3452 79.7267 93.9052 79.092C94.4746 78.4573 95.2259 78.14 96.1592 78.14C97.1019 78.14 97.8019 78.504 98.2592 79.232C98.7259 79.96 98.8892 80.8467 98.7492 81.892H94.1712C94.1712 82.5827 94.3392 83.152 94.6752 83.6C95.0112 84.0387 95.4826 84.258 96.0892 84.258ZM96.9012 79.19C96.6866 79.078 96.4252 79.022 96.1172 79.022C95.5479 79.022 95.0952 79.218 94.7592 79.61C94.4326 79.9927 94.2412 80.4733 94.1852 81.052H97.7552C97.7552 80.1187 97.4706 79.498 96.9012 79.19ZM108.87 83.67C108.413 84.6407 107.671 85.126 106.644 85.126C105.888 85.126 105.277 84.916 104.81 84.496C104.353 84.076 104.124 83.4273 104.124 82.55V78.294H105.23V82.466C105.23 83.5953 105.753 84.16 106.798 84.16C107.405 84.16 107.895 83.9267 108.268 83.46C108.651 82.9933 108.852 82.396 108.87 81.668V78.294H109.976V85H108.87V83.67ZM112.46 79.946C112.46 79.3953 112.694 78.9567 113.16 78.63C113.636 78.3033 114.276 78.14 115.078 78.14C115.881 78.14 116.506 78.308 116.954 78.644C117.412 78.98 117.65 79.4047 117.668 79.918H116.59C116.506 79.3113 115.993 79.008 115.05 79.008C114.593 79.008 114.238 79.1107 113.986 79.316C113.744 79.5213 113.622 79.7453 113.622 79.988C113.622 80.2213 113.716 80.422 113.902 80.59C114.089 80.7487 114.388 80.8887 114.798 81.01L116.142 81.458C116.712 81.6353 117.146 81.864 117.444 82.144C117.752 82.4147 117.906 82.7927 117.906 83.278C117.906 83.754 117.659 84.188 117.164 84.58C116.67 84.9627 115.979 85.154 115.092 85.154C114.206 85.154 113.515 84.958 113.02 84.566C112.526 84.1647 112.264 83.6513 112.236 83.026H113.3C113.319 83.446 113.487 83.7633 113.804 83.978C114.131 84.1833 114.537 84.286 115.022 84.286C115.508 84.286 115.909 84.1833 116.226 83.978C116.544 83.7727 116.702 83.53 116.702 83.25C116.702 82.9607 116.609 82.7413 116.422 82.592C116.236 82.4427 115.932 82.312 115.512 82.2L114.21 81.766C113.044 81.4207 112.46 80.814 112.46 79.946ZM122.49 84.258C123.414 84.258 123.941 83.852 124.072 83.04H125.206C125.103 83.712 124.804 84.2347 124.31 84.608C123.824 84.972 123.218 85.154 122.49 85.154C121.594 85.154 120.866 84.8367 120.306 84.202C119.746 83.558 119.466 82.704 119.466 81.64C119.466 80.576 119.746 79.7267 120.306 79.092C120.875 78.4573 121.626 78.14 122.56 78.14C123.502 78.14 124.202 78.504 124.66 79.232C125.126 79.96 125.29 80.8467 125.15 81.892H120.572C120.572 82.5827 120.74 83.152 121.076 83.6C121.412 84.0387 121.883 84.258 122.49 84.258ZM123.302 79.19C123.087 79.078 122.826 79.022 122.518 79.022C121.948 79.022 121.496 79.218 121.16 79.61C120.833 79.9927 120.642 80.4733 120.586 81.052H124.156C124.156 80.1187 123.871 79.498 123.302 79.19ZM127.035 79.946C127.035 79.3953 127.268 78.9567 127.735 78.63C128.211 78.3033 128.85 78.14 129.653 78.14C130.455 78.14 131.081 78.308 131.529 78.644C131.986 78.98 132.224 79.4047 132.243 79.918H131.165C131.081 79.3113 130.567 79.008 129.625 79.008C129.167 79.008 128.813 79.1107 128.561 79.316C128.318 79.5213 128.197 79.7453 128.197 79.988C128.197 80.2213 128.29 80.422 128.477 80.59C128.663 80.7487 128.962 80.8887 129.373 81.01L130.717 81.458C131.286 81.6353 131.72 81.864 132.019 82.144C132.327 82.4147 132.481 82.7927 132.481 83.278C132.481 83.754 132.233 84.188 131.739 84.58C131.244 84.9627 130.553 85.154 129.667 85.154C128.78 85.154 128.089 84.958 127.595 84.566C127.1 84.1647 126.839 83.6513 126.811 83.026H127.875C127.893 83.446 128.061 83.7633 128.379 83.978C128.705 84.18Line truncated
<path d="M76.522 776.04C77.6607 776.04 78.58 776.432 79.28 777.216C79.9893 777.991 80.344 779.125 80.344 780.618C80.344 782.102 79.994 783.231 79.294 784.006C78.594 784.771 77.67 785.154 76.522 785.154C75.374 785.154 74.45 784.767 73.75 783.992C73.0593 783.208 72.714 782.079 72.714 780.604C72.714 779.12 73.0593 777.991 73.75 777.216C74.45 776.432 75.374 776.04 76.522 776.04ZM76.522 777.034C75.7007 777.034 75.052 777.342 74.576 777.958C74.1 778.574 73.862 779.461 73.862 780.618C73.862 781.775 74.1 782.653 74.576 783.25C75.052 783.847 75.7007 784.146 76.522 784.146C77.3433 784.146 77.992 783.847 78.468 783.25C78.9533 782.653 79.196 781.775 79.196 780.618C79.196 779.461 78.9533 778.574 78.468 777.958C77.992 777.342 77.3433 777.034 76.522 777.034ZM83.5288 779.596C83.9674 778.625 84.7188 778.14 85.7828 778.14C86.5761 778.14 87.1921 778.401 87.6308 778.924C88.0788 779.447 88.3028 780.161 88.3028 781.066V785H87.2108V781.066C87.2108 780.422 87.0568 779.937 86.7488 779.61C86.4501 779.283 86.0208 779.12 85.4608 779.12C84.9008 779.12 84.4481 779.349 84.1028 779.806C83.7574 780.263 83.5754 780.898 83.5568 781.71V785H82.4508V778.308H83.4028L83.5288 779.596ZM93.1263 778.14C93.9197 778.14 94.5497 778.345 95.0163 778.756C95.483 779.157 95.7863 779.661 95.9263 780.268L94.8063 780.366C94.685 779.974 94.489 779.671 94.2183 779.456C93.9477 779.232 93.649 779.12 93.3223 779.12C92.725 779.12 92.2397 779.344 91.8663 779.792C91.5023 780.24 91.3203 780.851 91.3203 781.626C91.3203 782.391 91.4977 783.007 91.8523 783.474C92.2163 783.941 92.6643 784.174 93.1963 784.174C93.7377 784.174 94.139 784.053 94.4003 783.81C94.671 783.558 94.8063 783.203 94.8063 782.746H95.9403C95.9403 783.465 95.6883 784.048 95.1843 784.496C94.6897 784.935 94.041 785.154 93.2383 785.154C92.389 785.154 91.6657 784.832 91.0683 784.188C90.4803 783.544 90.1863 782.69 90.1863 781.626C90.1863 780.553 90.4803 779.703 91.0683 779.078C91.6563 778.453 92.3423 778.14 93.1263 778.14ZM100.415 784.258C101.339 784.258 101.867 783.852 101.997 783.04H103.131C103.029 783.712 102.73 784.235 102.235 784.608C101.75 784.972 101.143 785.154 100.415 785.154C99.5194 785.154 98.7914 784.837 98.2314 784.202C97.6714 783.558 97.3914 782.704 97.3914 781.64C97.3914 780.576 97.6714 779.727 98.2314 779.092C98.8007 778.457 99.5521 778.14 100.485 778.14C101.428 778.14 102.128 778.504 102.585 779.232C103.052 779.96 103.215 780.847 103.075 781.892H98.4974C98.4974 782.583 98.6654 783.152 99.0014 783.6C99.3374 784.039 99.8087 784.258 100.415 784.258ZM101.227 779.19C101.013 779.078 100.751 779.022 100.443 779.022C99.8741 779.022 99.4214 779.218 99.0854 779.61C98.7587 779.993 98.5674 780.473 98.5114 781.052H102.081C102.081 780.119 101.797 779.498 101.227 779.19ZM112.146 784.804C111.344 785.177 110.611 785.257 109.948 785.042C109.472 784.893 109.136 784.58 108.94 784.104C108.838 783.871 108.786 783.591 108.786 783.264V779.148H107.708V778.308H108.786V776.446H109.878V778.308H111.978V779.148H109.878V783.25C109.878 783.931 110.196 784.272 110.83 784.272C111.176 784.272 111.563 784.188 111.992 784.02L112.146 784.804ZM115.016 779.54C115.464 778.607 116.206 778.14 117.242 778.14C118.035 778.14 118.651 778.401 119.09 778.924C119.538 779.447 119.762 780.161 119.762 781.066V785H118.67V781.066C118.67 780.422 118.516 779.937 118.208 779.61C117.909 779.283 117.475 779.12 116.906 779.12C116.337 779.12 115.879 779.363 115.534 779.848C115.189 780.324 115.016 780.987 115.016 781.836V785H113.91V775.466H115.016V779.54ZM124.669 784.258C125.593 784.258 126.121 783.852 126.251 783.04H127.385C127.283 783.712 126.984 784.235 126.489 784.608C126.004 784.972 125.397 785.154 124.669 785.154C123.773 785.154 123.045 784.837 122.485 784.202C121.925 783.558 121.645 782.704 121.645 781.64C121.645 780.576 121.925 779.727 122.485 779.092C123.055 778.457 123.806 778.14 124.739 778.14C125.682 778.14 126.382 778.504 126.839 779.232C127.306 779.96 127.469 780.847 127.329 781.892H122.751C122.751 782.583 122.919 783.152 123.255 783.6C123.591 784.039 124.063 784.258 124.669 784.258ZM125.481 779.19C125.267 779.078 125.005 779.022 124.697 779.022C124.128 779.022 123.675 779.218 123.339 779.61C123.013 779.993 122.821 780.473 122.765 781.052H126.335C126.335 780.119 126.051 779.498 125.481 779.19ZM135.126 778.14C135.92 778.14 136.55 778.345 137.016 778.756C137.483 779.157 137.786 779.661 137.926 780.268L136.806 780.366C136.685 779.974 136.489 779.671 136.218 779.456C135.948 779.232 135.649 779.12 135.322 779.12C134.725 779.12 134.24 779.344 133.866 779.792C133.502 780.24 133.32 780.851 133.32 781.626C133.32 782.391 133.498 783.007 133.852 783.474C134.216 783.941 134.664 784.174 135.196 784.174C135.738 784.174 136.139 784.053 136.4 783.81C136.671 783.558 136.806 783.203 136.806 782.746H137.94C137.94 783.465 137.688 784.048 137.184 784.496C136.69 784.935 136.041 785.154 135.238 785.154C134.389 785.154 133.666 784.832 133.068 784.188C132.48 783.544 132.186 782.69 132.186 781.626C132.186 780.553 132.48 779.703 133.068 779.078C133.656 778.453 134.342Line truncated
<path d="M70.428 315.194L72.57 322.516L74.74 316.104H75.482L77.638 322.516L80.102 315.194H81.32L78.212 324H77.05L75.132 318.358L73.144 324H71.982L69.196 315.194H70.428ZM84.0434 318.54C84.4914 317.607 85.2334 317.14 86.2694 317.14C87.0628 317.14 87.6788 317.401 88.1174 317.924C88.5654 318.447 88.7894 319.161 88.7894 320.066V324H87.6974V320.066C87.6974 319.422 87.5434 318.937 87.2354 318.61C86.9368 318.283 86.5028 318.12 85.9334 318.12C85.3641 318.12 84.9068 318.363 84.5614 318.848C84.2161 319.324 84.0434 319.987 84.0434 320.836V324H82.9374V314.466H84.0434V318.54ZM93.6967 323.258C94.6207 323.258 95.148 322.852 95.2787 322.04H96.4127C96.31 322.712 96.0113 323.235 95.5167 323.608C95.0313 323.972 94.4247 324.154 93.6967 324.154C92.8007 324.154 92.0727 323.837 91.5127 323.202C90.9527 322.558 90.6727 321.704 90.6727 320.64C90.6727 319.576 90.9527 318.727 91.5127 318.092C92.082 317.457 92.8333 317.14 93.7667 317.14C94.7093 317.14 95.4093 317.504 95.8667 318.232C96.3333 318.96 96.4967 319.847 96.3567 320.892H91.7787C91.7787 321.583 91.9467 322.152 92.2827 322.6C92.6187 323.039 93.09 323.258 93.6967 323.258ZM94.5087 318.19C94.294 318.078 94.0327 318.022 93.7247 318.022C93.1553 318.022 92.7027 318.218 92.3667 318.61C92.04 318.993 91.8487 319.473 91.7927 320.052H95.3627C95.3627 319.119 95.078 318.498 94.5087 318.19ZM99.6557 318.596C100.094 317.625 100.846 317.14 101.91 317.14C102.703 317.14 103.319 317.401 103.758 317.924C104.206 318.447 104.43 319.161 104.43 320.066V324H103.338V320.066C103.338 319.422 103.184 318.937 102.876 318.61C102.577 318.283 102.148 318.12 101.588 318.12C101.028 318.12 100.575 318.349 100.23 318.806C99.8844 319.263 99.7024 319.898 99.6837 320.71V324H98.5777V317.308H99.5297L99.6557 318.596ZM110.363 315.194H113.653C114.577 315.194 115.287 315.413 115.781 315.852C116.285 316.291 116.537 316.841 116.537 317.504C116.537 318.008 116.397 318.447 116.117 318.82C115.847 319.193 115.431 319.445 114.871 319.576C115.422 319.669 115.861 319.907 116.187 320.29C116.523 320.673 116.691 321.107 116.691 321.592C116.691 322.675 116.164 323.407 115.109 323.79C114.717 323.93 114.237 324 113.667 324H110.363V315.194ZM113.639 323.034C114.311 323.034 114.792 322.899 115.081 322.628C115.371 322.357 115.515 321.998 115.515 321.55C115.515 321.102 115.357 320.747 115.039 320.486C114.722 320.215 114.255 320.08 113.639 320.08H111.469V323.034H113.639ZM111.469 319.128H113.625C114.167 319.128 114.596 318.997 114.913 318.736C115.24 318.465 115.403 318.097 115.403 317.63C115.403 317.163 115.245 316.799 114.927 316.538C114.619 316.277 114.185 316.146 113.625 316.146H111.469V319.128ZM121.48 317.14C122.414 317.14 123.165 317.443 123.734 318.05C124.313 318.657 124.602 319.525 124.602 320.654C124.602 321.774 124.313 322.637 123.734 323.244C123.165 323.851 122.414 324.154 121.48 324.154C120.547 324.154 119.791 323.851 119.212 323.244C118.643 322.637 118.358 321.774 118.358 320.654C118.358 319.525 118.643 318.657 119.212 318.05C119.791 317.443 120.547 317.14 121.48 317.14ZM123.482 320.654C123.482 319.851 123.314 319.226 122.978 318.778C122.642 318.321 122.148 318.092 121.494 318.092C120.85 318.092 120.356 318.321 120.01 318.778C119.665 319.226 119.492 319.851 119.492 320.654C119.492 321.447 119.656 322.073 119.982 322.53C120.309 322.978 120.794 323.202 121.438 323.202C122.092 323.202 122.596 322.978 122.95 322.53C123.305 322.073 123.482 321.447 123.482 320.654ZM127.821 318.302C128.269 317.527 128.922 317.14 129.781 317.14C130.639 317.14 131.353 317.462 131.923 318.106C132.492 318.741 132.777 319.585 132.777 320.64C132.777 321.685 132.487 322.535 131.909 323.188C131.33 323.832 130.625 324.154 129.795 324.154C129.347 324.154 128.941 324.042 128.577 323.818C128.222 323.594 127.942 323.263 127.737 322.824L127.485 324H126.715V314.466H127.821V318.302ZM129.711 318.12C129.179 318.12 128.735 318.293 128.381 318.638C128.026 318.974 127.839 319.445 127.821 320.052V321.144C127.821 321.76 128.003 322.255 128.367 322.628C128.74 322.992 129.188 323.174 129.711 323.174C130.233 323.174 130.686 322.945 131.069 322.488C131.451 322.021 131.643 321.405 131.643 320.64C131.643 319.875 131.451 319.263 131.069 318.806C130.695 318.349 130.243 318.12 129.711 318.12ZM140.957 318.246C139.902 318.246 139.356 319.077 139.319 320.738V324H138.213V317.294H139.319V318.582C139.655 317.649 140.247 317.182 141.097 317.182C141.367 317.182 141.624 317.224 141.867 317.308L141.811 318.386C141.531 318.293 141.246 318.246 140.957 318.246ZM145.869 323.258C146.793 323.258 147.32 322.852 147.451 322.04H148.585C148.482 322.712 148.183 323.235 147.689 323.608C147.203 323.972 146.597 324.154 145.869 324.154C144.973 324.154 144.245 323.837 143.685 323.202C143.125 322.558 142.845 321.704 142.845 320.64C142.845 319.576 143.125 318.727 143.685 318.092C144.254 317.457 145.005 317.14 145.939 317.14C146.881 317.14 147.581 317.504 148.039 318.232C148.505 318.96 148.669 319.847 148.529 320.892H143.951C143.951 321.583 144.119 322.152 144.455 322.6C144.791 323.039 145.262 323.258 145.869 323.258ZLine truncated
<path d="M70.428 315.194L72.57 322.516L74.74 316.104H75.482L77.638 322.516L80.102 315.194H81.32L78.212 324H77.05L75.132 318.358L73.144 324H71.982L69.196 315.194H70.428ZM84.0434 318.54C84.4914 317.607 85.2334 317.14 86.2694 317.14C87.0628 317.14 87.6788 317.401 88.1174 317.924C88.5654 318.447 88.7894 319.161 88.7894 320.066V324H87.6974V320.066C87.6974 319.422 87.5434 318.937 87.2354 318.61C86.9368 318.283 86.5028 318.12 85.9334 318.12C85.3641 318.12 84.9068 318.363 84.5614 318.848C84.2161 319.324 84.0434 319.987 84.0434 320.836V324H82.9374V314.466H84.0434V318.54ZM93.6967 323.258C94.6207 323.258 95.148 322.852 95.2787 322.04H96.4127C96.31 322.712 96.0113 323.235 95.5167 323.608C95.0313 323.972 94.4247 324.154 93.6967 324.154C92.8007 324.154 92.0727 323.837 91.5127 323.202C90.9527 322.558 90.6727 321.704 90.6727 320.64C90.6727 319.576 90.9527 318.727 91.5127 318.092C92.082 317.457 92.8333 317.14 93.7667 317.14C94.7093 317.14 95.4093 317.504 95.8667 318.232C96.3333 318.96 96.4967 319.847 96.3567 320.892H91.7787C91.7787 321.583 91.9467 322.152 92.2827 322.6C92.6187 323.039 93.09 323.258 93.6967 323.258ZM94.5087 318.19C94.294 318.078 94.0327 318.022 93.7247 318.022C93.1553 318.022 92.7027 318.218 92.3667 318.61C92.04 318.993 91.8487 319.473 91.7927 320.052H95.3627C95.3627 319.119 95.078 318.498 94.5087 318.19ZM99.6557 318.596C100.094 317.625 100.846 317.14 101.91 317.14C102.703 317.14 103.319 317.401 103.758 317.924C104.206 318.447 104.43 319.161 104.43 320.066V324H103.338V320.066C103.338 319.422 103.184 318.937 102.876 318.61C102.577 318.283 102.148 318.12 101.588 318.12C101.028 318.12 100.575 318.349 100.23 318.806C99.8844 319.263 99.7024 319.898 99.6837 320.71V324H98.5777V317.308H99.5297L99.6557 318.596ZM110.363 315.194H113.653C114.577 315.194 115.287 315.413 115.781 315.852C116.285 316.291 116.537 316.841 116.537 317.504C116.537 318.008 116.397 318.447 116.117 318.82C115.847 319.193 115.431 319.445 114.871 319.576C115.422 319.669 115.861 319.907 116.187 320.29C116.523 320.673 116.691 321.107 116.691 321.592C116.691 322.675 116.164 323.407 115.109 323.79C114.717 323.93 114.237 324 113.667 324H110.363V315.194ZM113.639 323.034C114.311 323.034 114.792 322.899 115.081 322.628C115.371 322.357 115.515 321.998 115.515 321.55C115.515 321.102 115.357 320.747 115.039 320.486C114.722 320.215 114.255 320.08 113.639 320.08H111.469V323.034H113.639ZM111.469 319.128H113.625C114.167 319.128 114.596 318.997 114.913 318.736C115.24 318.465 115.403 318.097 115.403 317.63C115.403 317.163 115.245 316.799 114.927 316.538C114.619 316.277 114.185 316.146 113.625 316.146H111.469V319.128ZM121.48 317.14C122.414 317.14 123.165 317.443 123.734 318.05C124.313 318.657 124.602 319.525 124.602 320.654C124.602 321.774 124.313 322.637 123.734 323.244C123.165 323.851 122.414 324.154 121.48 324.154C120.547 324.154 119.791 323.851 119.212 323.244C118.643 322.637 118.358 321.774 118.358 320.654C118.358 319.525 118.643 318.657 119.212 318.05C119.791 317.443 120.547 317.14 121.48 317.14ZM123.482 320.654C123.482 319.851 123.314 319.226 122.978 318.778C122.642 318.321 122.148 318.092 121.494 318.092C120.85 318.092 120.356 318.321 120.01 318.778C119.665 319.226 119.492 319.851 119.492 320.654C119.492 321.447 119.656 322.073 119.982 322.53C120.309 322.978 120.794 323.202 121.438 323.202C122.092 323.202 122.596 322.978 122.95 322.53C123.305 322.073 123.482 321.447 123.482 320.654ZM127.821 318.302C128.269 317.527 128.922 317.14 129.781 317.14C130.639 317.14 131.353 317.462 131.923 318.106C132.492 318.741 132.777 319.585 132.777 320.64C132.777 321.685 132.487 322.535 131.909 323.188C131.33 323.832 130.625 324.154 129.795 324.154C129.347 324.154 128.941 324.042 128.577 323.818C128.222 323.594 127.942 323.263 127.737 322.824L127.485 324H126.715V314.466H127.821V318.302ZM129.711 318.12C129.179 318.12 128.735 318.293 128.381 318.638C128.026 318.974 127.839 319.445 127.821 320.052V321.144C127.821 321.76 128.003 322.255 128.367 322.628C128.74 322.992 129.188 323.174 129.711 323.174C130.233 323.174 130.686 322.945 131.069 322.488C131.451 322.021 131.643 321.405 131.643 320.64C131.643 319.875 131.451 319.263 131.069 318.806C130.695 318.349 130.243 318.12 129.711 318.12ZM140.957 318.246C139.902 318.246 139.356 319.077 139.319 320.738V324H138.213V317.294H139.319V318.582C139.655 317.649 140.247 317.182 141.097 317.182C141.367 317.182 141.624 317.224 141.867 317.308L141.811 318.386C141.531 318.293 141.246 318.246 140.957 318.246ZM145.869 323.258C146.793 323.258 147.32 322.852 147.451 322.04H148.585C148.482 322.712 148.183 323.235 147.689 323.608C147.203 323.972 146.597 324.154 145.869 324.154C144.973 324.154 144.245 323.837 143.685 323.202C143.125 322.558 142.845 321.704 142.845 320.64C142.845 319.576 143.125 318.727 143.685 318.092C144.254 317.457 145.005 317.14 145.939 317.14C146.881 317.14 147.581 317.504 148.039 318.232C148.505 318.96 148.669 319.847 148.529 320.892H143.951C143.951 321.583 144.119 322.152 144.455 322.6C144.791 323.039 145.262 323.258 145.869 323.258ZLine truncated
<path d="M176.375 506.812V505.25H173.25V506.812C173.25 509.713 174.402 512.495 176.454 514.546C178.505 516.598 181.287 517.75 184.188 517.75H188.875V514.625H184.188C182.115 514.625 180.128 513.802 178.663 512.337C177.198 510.872 176.375 508.885 176.375 506.812Z" fill="#062D56"/>
<path d="M204.5 491.188V492.75H207.625V491.188C207.625 488.287 206.473 485.505 204.421 483.454C202.37 481.402 199.588 480.25 196.688 480.25H192V483.375H196.688C197.713 483.375 198.729 483.577 199.677 483.97C200.625 484.362 201.486 484.938 202.212 485.663C202.937 486.389 203.513 487.25 203.905 488.198C204.298 489.146 204.5 490.162 204.5 491.188V491.188Z" fill="#062D56"/>
<path d="M184.188 491.188H174.812C173.569 491.188 172.377 491.681 171.498 492.56C170.619 493.44 170.125 494.632 170.125 495.875V499H173.25V495.875C173.25 495.461 173.415 495.063 173.708 494.77C174.001 494.477 174.398 494.312 174.812 494.312H184.188C184.602 494.312 184.999 494.477 185.292 494.77C185.585 495.063 185.75 495.461 185.75 495.875V499H188.875V495.875C188.875 494.632 188.381 493.44 187.502 492.56C186.623 491.681 185.431 491.188 184.188 491.188V491.188Z" fill="#062D56"/>
<path d="M179.5 489.625C180.736 489.625 181.945 489.258 182.972 488.572C184 487.885 184.801 486.909 185.274 485.767C185.747 484.625 185.871 483.368 185.63 482.156C185.389 480.943 184.793 479.83 183.919 478.956C183.045 478.082 181.932 477.486 180.719 477.245C179.507 477.004 178.25 477.128 177.108 477.601C175.966 478.074 174.99 478.875 174.303 479.903C173.617 480.93 173.25 482.139 173.25 483.375C173.25 485.033 173.908 486.622 175.081 487.794C176.253 488.967 177.842 489.625 179.5 489.625ZM179.5 480.25C180.118 480.25 180.722 480.433 181.236 480.777C181.75 481.12 182.151 481.608 182.387 482.179C182.624 482.75 182.686 483.378 182.565 483.985C182.444 484.591 182.147 485.148 181.71 485.585C181.273 486.022 180.716 486.319 180.11 486.44C179.503 486.561 178.875 486.499 178.304 486.262C177.733 486.026 177.245 485.625 176.902 485.111C176.558 484.597 176.375 483.993 176.375 483.375C176.375 482.546 176.704 481.751 177.29 481.165C177.876 480.579 178.671 480.25 179.5 480.25V480.25Z" fill="#062D56"/>
<path d="M204.5 491.188V492.75H207.625V491.188C207.625 488.287 206.473 485.505 204.421 483.454C202.37 481.402 199.588 480.25 196.688 480.25H192V483.375H196.688C197.713 483.375 198.729 483.577 199.677 483.97C200.625 484.362 201.486 484.938 202.212 485.663C202.937 486.389 203.513 487.25 203.905 488.198C204.298 489.146 204.5 490.162 204.5 491.188Z" fill="#062D56"/>
<path d="M184.188 491.188H174.812C173.569 491.188 172.377 491.681 171.498 492.56C170.619 493.44 170.125 494.632 170.125 495.875V499H173.25V495.875C173.25 495.461 173.415 495.063 173.708 494.77C174.001 494.477 174.398 494.312 174.812 494.312H184.188C184.602 494.312 184.999 494.477 185.292 494.77C185.585 495.063 185.75 495.461 185.75 495.875V499H188.875V495.875C188.875 494.632 188.381 493.44 187.502 492.56C186.623 491.681 185.431 491.188 184.188 491.188Z" fill="#062D56"/>
<path d="M179.5 489.625C180.736 489.625 181.945 489.258 182.972 488.572C184 487.885 184.801 486.909 185.274 485.767C185.747 484.625 185.871 483.368 185.63 482.156C185.389 480.943 184.793 479.83 183.919 478.956C183.045 478.082 181.932 477.486 180.719 477.245C179.507 477.004 178.25 477.128 177.108 477.601C175.966 478.074 174.99 478.875 174.303 479.903C173.617 480.93 173.25 482.139 173.25 483.375C173.25 485.033 173.908 486.622 175.081 487.794C176.253 488.967 177.842 489.625 179.5 489.625ZM179.5 480.25C180.118 480.25 180.722 480.433 181.236 480.777C181.75 481.12 182.151 481.608 182.387 482.179C182.624 482.75 182.686 483.378 182.565 483.985C182.444 484.591 182.147 485.148 181.71 485.585C181.273 486.022 180.716 486.319 180.11 486.44C179.503 486.561 178.875 486.499 178.304 486.262C177.733 486.026 177.245 485.625 176.902 485.111C176.558 484.597 176.375 483.993 176.375 483.375C176.375 482.546 176.704 481.751 177.29 481.165C177.876 480.579 178.671 480.25 179.5 480.25Z" fill="#062D56"/>
<path d="M209.188 513.062H199.812C198.569 513.062 197.377 513.556 196.498 514.435C195.619 515.315 195.125 516.507 195.125 517.75V520.875H198.25V517.75C198.25 517.336 198.415 516.938 198.708 516.645C199.001 516.352 199.398 516.188 199.812 516.188H209.188C209.602 516.188 209.999 516.352 210.292 516.645C210.585 516.938 210.75 517.336 210.75 517.75V520.875H213.875V517.75C213.875 516.507 213.381 515.315 212.502 514.435C211.623 513.556 210.431 513.062 209.188 513.062Z" fill="#062D56"/>
<path d="M198.25 505.25C198.25 506.486 198.617 507.695 199.303 508.722C199.99 509.75 200.966 510.551 202.108 511.024C203.25 511.497 204.507 511.621 205.719 511.38C206.932 511.139 208.045 510.543 208.919 509.669C209.793 508.795 210.389 507.682 210.63 506.469C210.871 505.257 210.747 504 210.274 502.858C209.801 501.716 209 500.74 207.972 500.053C206.945 499.367 205.736 499 204.5 499C202.842 499 201.253 499.658 200.081 500.831C198.908 502.003 198.25 503.592 198.25 505.25ZM207.625 505.25C207.625 505.868 207.442 506.472 207.098 506.986C206.755 507.5 206.267 507.901 205.696 508.137C205.125 508.374 204.497 508.436 203.89 508.315C203.284 508.194 202.727 507.897 202.29 507.46C201.853 507.023 201.556 506.466 201.435 505.86C201.314 505.253 201.376 504.625 201.613 504.054C201.849 503.483 202.25 502.995 202.764 502.652C203.278 502.308 203.882 502.125 204.5 502.125C205.329 502.125 206.124 502.454 206.71 503.04C207.296 503.626 207.625 504.421 207.625 505.25Z" fill="#062D56"/>
<path d="M191 178V239" stroke="#E5E5E5" stroke-width="2"/>

Before

Width:  |  Height:  |  Size: 376 KiB

After

Width:  |  Height:  |  Size: 332 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 MiB

-3
View File
@@ -1,3 +0,0 @@
<svg width="1015" height="48" viewBox="0 0 1015 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.253063 4.848H19.8851V9.744H5.91706V17.952H18.6851V22.8H5.91706V36H0.253063V4.848ZM41.2282 15.456C42.0282 16.48 42.6202 17.664 43.0042 19.008C43.4202 20.352 43.6282 21.584 43.6282 22.704C43.6282 23.824 43.5642 24.832 43.4362 25.728H28.3642C28.4282 27.616 28.8922 29.152 29.7562 30.336C30.6202 31.52 31.9322 32.112 33.6922 32.112C36.0282 32.112 37.4202 31.088 37.8682 29.04H43.5802C43.1962 31.376 42.1242 33.216 40.3642 34.56C38.5402 35.968 36.3162 36.672 33.6922 36.672C30.6202 36.672 28.0442 35.552 25.9642 33.312C23.8202 30.976 22.7482 27.984 22.7482 24.336C22.7482 20.592 23.8202 17.584 25.9642 15.312C28.0122 13.136 30.5882 12.048 33.6922 12.048C36.9242 12.048 39.4362 13.184 41.2282 15.456ZM33.7402 16.56C32.1402 16.56 30.8922 17.088 29.9962 18.144C29.1002 19.168 28.5722 20.496 28.4122 22.128H38.3482C38.3482 19.6 37.5482 17.904 35.9482 17.04C35.3402 16.72 34.6042 16.56 33.7402 16.56ZM65.6253 32.4C64.1853 35.248 61.9773 36.672 59.0013 36.672C56.0253 36.672 53.5293 35.536 51.5133 33.264C49.4333 30.896 48.3933 27.888 48.3933 24.24C48.3933 20.592 49.3853 17.632 51.3693 15.36C53.3213 13.152 55.7533 12.048 58.6653 12.048C61.5773 12.048 63.7693 13.216 65.2413 15.552V3.072H70.9533V36H66.2973L65.6253 32.4ZM59.7213 17.136C58.1213 17.136 56.7773 17.792 55.6893 19.104C54.6333 20.384 54.1053 22.112 54.1053 24.288C54.1053 26.464 54.6493 28.224 55.7373 29.568C56.8253 30.88 58.2013 31.536 59.8653 31.536C61.2413 31.536 62.4733 30.992 63.5613 29.904C64.6813 28.784 65.2413 27.376 65.2413 25.68V22.656C65.1773 20.992 64.6173 19.632 63.5613 18.576C62.6013 17.616 61.3213 17.136 59.7213 17.136ZM96.1657 15.456C96.9657 16.48 97.5577 17.664 97.9417 19.008C98.3577 20.352 98.5657 21.584 98.5657 22.704C98.5657 23.824 98.5017 24.832 98.3737 25.728H83.3017C83.3657 27.616 83.8297 29.152 84.6937 30.336C85.5577 31.52 86.8697 32.112 88.6297 32.112C90.9657 32.112 92.3577 31.088 92.8057 29.04H98.5177C98.1337 31.376 97.0617 33.216 95.3017 34.56C93.4777 35.968 91.2537 36.672 88.6297 36.672C85.5577 36.672 82.9817 35.552 80.9017 33.312C78.7577 30.976 77.6857 27.984 77.6857 24.336C77.6857 20.592 78.7577 17.584 80.9017 15.312C82.9497 13.136 85.5257 12.048 88.6297 12.048C91.8617 12.048 94.3737 13.184 96.1657 15.456ZM88.6777 16.56C87.0777 16.56 85.8297 17.088 84.9337 18.144C84.0377 19.168 83.5097 20.496 83.3497 22.128H93.2857C93.2857 19.6 92.4857 17.904 90.8857 17.04C90.2777 16.72 89.5417 16.56 88.6777 16.56ZM111.011 17.28C112.419 13.92 114.531 12.24 117.347 12.24C117.891 12.24 118.579 12.352 119.411 12.576L119.315 18.24C118.419 18.048 117.539 17.952 116.675 17.952C112.899 17.952 111.011 20.56 111.011 25.776V36H105.347V12.624H111.011V17.28ZM132.996 22.368C134.852 22.368 136.996 22.672 139.428 23.28V20.976C139.428 19.344 139.092 18.144 138.42 17.376C137.78 16.576 136.708 16.176 135.204 16.176C133.732 16.176 132.596 16.48 131.796 17.088C130.996 17.664 130.596 18.496 130.596 19.584H124.404C124.404 16.928 125.332 15.008 127.188 13.824C129.076 12.64 131.7 12.048 135.06 12.048C139.86 12.048 142.964 13.728 144.372 17.088C144.852 18.24 145.092 19.6 145.092 21.168V36H140.148L139.716 32.88C138.212 35.408 135.908 36.672 132.804 36.672C129.796 36.672 127.46 35.936 125.796 34.464C124.26 33.056 123.492 31.28 123.492 29.136C123.492 26.96 124.34 25.296 126.036 24.144C127.732 22.96 130.052 22.368 132.996 22.368ZM139.428 26.88C137.54 26.368 135.78 26.112 134.148 26.112C131.076 26.112 129.54 27.136 129.54 29.184C129.54 30.048 129.892 30.8 130.596 31.44C131.3 32.048 132.42 32.352 133.956 32.352C135.524 32.352 136.804 31.84 137.796 30.816C138.82 29.76 139.364 28.448 139.428 26.88ZM166.499 35.424C164.387 36.256 162.723 36.672 161.507 36.672C160.291 36.672 159.219 36.528 158.291 36.24C157.395 35.952 156.595 35.52 155.891 34.944C154.419 33.632 153.683 31.824 153.683 29.52V16.464H150.419V12.672H153.683V6.528H159.347V12.672H165.683V16.464H159.347V29.328C159.347 31.248 160.259 32.208 162.083 32.208C163.011 32.208 164.211 31.952 165.683 31.44L166.499 35.424ZM188.556 15.456C189.356 16.48 189.948 17.664 190.332 19.008C190.748 20.352 190.956 21.584 190.956 22.704C190.956 23.824 190.892 24.832 190.764 25.728H175.692C175.756 27.616 176.22 29.152 177.084 30.336C177.948 31.52 179.26 32.112 181.02 32.112C183.356 32.112 184.748 31.088 185.196 29.04H190.908C190.524 31.376 189.452 33.216 187.692 34.56C185.868 35.968 183.644 36.672 181.02 36.672C177.948 36.672 175.372 35.552 173.292 33.312C171.148 30.976 170.076 27.984 170.076 24.336C170.076 20.592 171.148 17.584 173.292 15.312C175.34 13.136 177.916 12.048 181.02 12.048C184.252 12.048 186.764 13.184 188.556 15.456ZM181.068 16.56C179.468 16.56 178.22 17.088 177.324 18.144C176.428 19.168 175.9 20.496 175.74 22.128H185.676C185.676 19.6 184.876 17.904 183.276 17.04C182.668 16.72 181.932 16.56 181.068 16.56ZM212.953 32.4C211.513 35.248 209.305 36.672 206.329 36.672C203.353 36.672 200.857 35.536 198.841 33.264C196.761 30.896 195.721 27.888 195.721 24.24C195.721 20.592 196.713 17.632 198.697 15.36C200.649 13.152 203.081 12.048 205.993 12.048Line truncated
</svg>

Before

Width:  |  Height:  |  Size: 23 KiB

+278
View File
@@ -0,0 +1,278 @@
CREATE TABLE contact_profiles ( -- remote user profile
contact_profile_id INTEGER PRIMARY KEY,
display_name TEXT NOT NULL, -- contact name set by remote user (not unique), this name must not contain spaces
full_name TEXT NOT NULL,
properties TEXT NOT NULL DEFAULT '{}' -- JSON with contact profile properties
);
CREATE INDEX contact_profiles_index ON contact_profiles (display_name, full_name);
CREATE TABLE users (
user_id INTEGER PRIMARY KEY,
contact_id INTEGER NOT NULL UNIQUE REFERENCES contacts ON DELETE CASCADE
DEFERRABLE INITIALLY DEFERRED,
local_display_name TEXT NOT NULL UNIQUE,
active_user INTEGER NOT NULL DEFAULT 0, -- 1 for active user
FOREIGN KEY (user_id, local_display_name)
REFERENCES display_names (user_id, local_display_name)
ON DELETE RESTRICT
ON UPDATE CASCADE
DEFERRABLE INITIALLY DEFERRED
);
CREATE TABLE display_names (
user_id INTEGER NOT NULL REFERENCES users,
local_display_name TEXT NOT NULL,
ldn_base TEXT NOT NULL,
ldn_suffix INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (user_id, local_display_name) ON CONFLICT FAIL,
UNIQUE (user_id, ldn_base, ldn_suffix) ON CONFLICT FAIL
) WITHOUT ROWID;
CREATE TABLE contacts (
contact_id INTEGER PRIMARY KEY,
contact_profile_id INTEGER REFERENCES contact_profiles, -- NULL if it's an incognito profile
user_id INTEGER NOT NULL REFERENCES users,
local_display_name TEXT NOT NULL,
is_user INTEGER NOT NULL DEFAULT 0, -- 1 if this contact is a user
via_group INTEGER REFERENCES groups (group_id) ON DELETE SET NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
FOREIGN KEY (user_id, local_display_name)
REFERENCES display_names (user_id, local_display_name)
ON DELETE RESTRICT
ON UPDATE CASCADE,
UNIQUE (user_id, local_display_name),
UNIQUE (user_id, contact_profile_id)
);
CREATE TABLE sent_probes (
sent_probe_id INTEGER PRIMARY KEY,
contact_id INTEGER NOT NULL UNIQUE REFERENCES contacts ON DELETE CASCADE,
probe BLOB NOT NULL,
user_id INTEGER NOT NULL REFERENCES users,
UNIQUE (user_id, probe)
);
CREATE TABLE sent_probe_hashes (
sent_probe_hash_id INTEGER PRIMARY KEY,
sent_probe_id INTEGER NOT NULL REFERENCES sent_probes ON DELETE CASCADE,
contact_id INTEGER NOT NULL REFERENCES contacts ON DELETE CASCADE,
user_id INTEGER NOT NULL REFERENCES users,
UNIQUE (sent_probe_id, contact_id)
);
CREATE TABLE received_probes (
received_probe_id INTEGER PRIMARY KEY,
contact_id INTEGER NOT NULL REFERENCES contacts ON DELETE CASCADE,
probe BLOB,
probe_hash BLOB NOT NULL,
user_id INTEGER NOT NULL REFERENCES users
);
CREATE TABLE known_servers(
server_id INTEGER PRIMARY KEY,
host TEXT NOT NULL,
port TEXT NOT NULL,
key_hash BLOB,
user_id INTEGER NOT NULL REFERENCES users,
UNIQUE (user_id, host, port)
) WITHOUT ROWID;
CREATE TABLE group_profiles ( -- shared group profiles
group_profile_id INTEGER PRIMARY KEY,
display_name TEXT NOT NULL, -- this name must not contain spaces
full_name TEXT NOT NULL,
properties TEXT NOT NULL DEFAULT '{}' -- JSON with user or contact profile
);
CREATE TABLE groups (
group_id INTEGER PRIMARY KEY, -- local group ID
user_id INTEGER NOT NULL REFERENCES users,
local_display_name TEXT NOT NULL, -- local group name without spaces
group_profile_id INTEGER REFERENCES group_profiles, -- shared group profile
inv_queue_info BLOB,
FOREIGN KEY (user_id, local_display_name)
REFERENCES display_names (user_id, local_display_name)
ON DELETE RESTRICT
ON UPDATE CASCADE,
UNIQUE (user_id, local_display_name),
UNIQUE (user_id, group_profile_id)
);
CREATE TABLE group_members ( -- group members, excluding the local user
group_member_id INTEGER PRIMARY KEY,
group_id INTEGER NOT NULL REFERENCES groups ON DELETE RESTRICT,
member_id BLOB NOT NULL, -- shared member ID, unique per group
member_role TEXT NOT NULL, -- owner, admin, member
member_category TEXT NOT NULL, -- see GroupMemberCategory
member_status TEXT NOT NULL, -- see GroupMemberStatus
invited_by INTEGER REFERENCES contacts (contact_id) ON DELETE RESTRICT, -- NULL for the members who joined before the current user and for the group creator
group_queue_info BLOB,
direct_queue_info BLOB,
user_id INTEGER NOT NULL REFERENCES users,
local_display_name TEXT NOT NULL, -- should be the same as contact
contact_profile_id INTEGER NOT NULL REFERENCES contact_profiles ON DELETE RESTRICT,
contact_id INTEGER REFERENCES contacts ON DELETE RESTRICT,
FOREIGN KEY (user_id, local_display_name)
REFERENCES display_names (user_id, local_display_name)
ON DELETE RESTRICT
ON UPDATE CASCADE,
UNIQUE (group_id, member_id)
);
CREATE TABLE group_member_intros (
group_member_intro_id INTEGER PRIMARY KEY,
re_group_member_id INTEGER NOT NULL REFERENCES group_members (group_member_id) ON DELETE CASCADE,
to_group_member_id INTEGER NOT NULL REFERENCES group_members (group_member_id) ON DELETE CASCADE,
group_queue_info BLOB,
direct_queue_info BLOB,
intro_status TEXT NOT NULL, -- see GroupMemberIntroStatus
UNIQUE (re_group_member_id, to_group_member_id)
);
CREATE TABLE files (
file_id INTEGER PRIMARY KEY,
contact_id INTEGER REFERENCES contacts ON DELETE RESTRICT,
group_id INTEGER REFERENCES groups ON DELETE RESTRICT,
file_name TEXT NOT NULL,
file_path TEXT,
file_size INTEGER NOT NULL,
chunk_size INTEGER NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
user_id INTEGER NOT NULL REFERENCES users
);
CREATE TABLE snd_files (
file_id INTEGER NOT NULL REFERENCES files ON DELETE RESTRICT,
connection_id INTEGER NOT NULL REFERENCES connections ON DELETE RESTRICT,
file_status TEXT NOT NULL, -- new, accepted, connected, completed
group_member_id INTEGER REFERENCES group_members ON DELETE RESTRICT,
PRIMARY KEY (file_id, connection_id)
) WITHOUT ROWID;
CREATE TABLE rcv_files (
file_id INTEGER PRIMARY KEY REFERENCES files ON DELETE RESTRICT,
file_status TEXT NOT NULL, -- new, accepted, connected, completed
group_member_id INTEGER REFERENCES group_members ON DELETE RESTRICT,
file_queue_info BLOB
);
CREATE TABLE snd_file_chunks (
file_id INTEGER NOT NULL,
connection_id INTEGER NOT NULL,
chunk_number INTEGER NOT NULL,
chunk_agent_msg_id INTEGER,
chunk_sent INTEGER NOT NULL DEFAULT 0, -- 0 (sent to agent), 1 (sent to server)
FOREIGN KEY (file_id, connection_id) REFERENCES snd_files ON DELETE CASCADE,
PRIMARY KEY (file_id, connection_id, chunk_number)
) WITHOUT ROWID;
CREATE TABLE rcv_file_chunks (
file_id INTEGER NOT NULL REFERENCES rcv_files,
chunk_number INTEGER NOT NULL,
chunk_agent_msg_id INTEGER NOT NULL,
chunk_stored INTEGER NOT NULL DEFAULT 0, -- 0 (received), 1 (appended to file)
PRIMARY KEY (file_id, chunk_number)
) WITHOUT ROWID;
CREATE TABLE connections ( -- all SMP agent connections
connection_id INTEGER PRIMARY KEY,
agent_conn_id BLOB NOT NULL UNIQUE,
conn_level INTEGER NOT NULL DEFAULT 0,
via_contact INTEGER REFERENCES contacts (contact_id),
conn_status TEXT NOT NULL,
conn_type TEXT NOT NULL, -- contact, member, rcv_file, snd_file
contact_id INTEGER REFERENCES contacts ON DELETE RESTRICT,
group_member_id INTEGER REFERENCES group_members ON DELETE RESTRICT,
snd_file_id INTEGER,
rcv_file_id INTEGER REFERENCES rcv_files (file_id) ON DELETE RESTRICT,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
user_id INTEGER NOT NULL REFERENCES users,
FOREIGN KEY (snd_file_id, connection_id)
REFERENCES snd_files (file_id, connection_id)
ON DELETE RESTRICT
DEFERRABLE INITIALLY DEFERRED
);
CREATE TABLE events ( -- messages received by the agent, append only
event_id INTEGER PRIMARY KEY,
agent_msg_id INTEGER NOT NULL, -- internal message ID
external_msg_id INTEGER NOT NULL, -- external message ID (sent or received)
agent_meta TEXT NOT NULL, -- JSON with timestamps etc. sent in MSG
connection_id INTEGER NOT NULL REFERENCES connections,
received INTEGER NOT NULL, -- 0 for received, 1 for sent
chat_event_id INTEGER,
continuation_of INTEGER, -- references chat_event_id, but can be incorrect
event_type TEXT NOT NULL, -- event type - see protocol/types.ts
event_encoding INTEGER NOT NULL, -- format of event_body: 0 - binary, 1 - text utf8, 2 - JSON (utf8)
content_type TEXT NOT NULL, -- content type - see protocol/types.ts
event_body BLOB, -- agent message body as sent
event_hash BLOB NOT NULL,
integrity TEXT NOT NULL DEFAULT '',
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX events_external_msg_id_index ON events (connection_id, external_msg_id);
CREATE TABLE event_body_parts (
event_body_part_id INTEGER PRIMARY KEY,
event_id REFERENCES events,
full_size INTEGER NOT NULL,
part_status TEXT, -- full, partial
content_type TEXT NOT NULL,
event_part BLOB
);
CREATE TABLE contact_profile_events (
event_id INTEGER NOT NULL UNIQUE REFERENCES events,
contact_profile_id INTEGER NOT NULL REFERENCES contact_profiles
);
CREATE TABLE group_profile_events (
event_id INTEGER NOT NULL UNIQUE REFERENCES events,
group_profile_id INTEGER NOT NULL REFERENCES group_profiles
);
CREATE TABLE group_events (
event_id INTEGER NOT NULL UNIQUE REFERENCES events,
group_id INTEGER NOT NULL REFERENCES groups ON DELETE RESTRICT,
group_member_id INTEGER REFERENCES group_members -- NULL for current user
);
CREATE TABLE group_event_parents (
group_event_parent_id INTEGER PRIMARY KEY,
event_id INTEGER NOT NULL REFERENCES group_events (event_id),
parent_group_member_id INTEGER REFERENCES group_members (group_member_id), -- can be NULL if parent_member_id is incorrect
parent_member_id BLOB, -- shared member ID, unique per group
parent_event_id INTEGER REFERENCES events (event_id) ON DELETE CASCADE, -- this can be NULL if received event references another event that's not received yet
parent_chat_event_id INTEGER NOT NULL,
parent_event_hash BLOB NOT NULL
);
CREATE INDEX group_event_parents_parent_chat_event_id_index
ON group_event_parents (parent_member_id, parent_chat_event_id);
CREATE TABLE messages ( -- mutable messages presented to user
message_id INTEGER PRIMARY KEY,
contact_id INTEGER NOT NULL REFERENCES contacts ON DELETE RESTRICT, -- 1 for sent messages
group_id INTEGER REFERENCES groups ON DELETE RESTRICT, -- NULL for direct messages
deleted INTEGER NOT NULL, -- 1 for deleted
msg_type TEXT NOT NULL,
content_type TEXT NOT NULL,
msg_text TEXT NOT NULL, -- textual representation
msg_props TEXT NOT NULL -- JSON
);
CREATE TABLE message_content (
message_content_id INTEGER PRIMARY KEY,
message_id INTEGER REFERENCES messages ON DELETE CASCADE,
content_type TEXT NOT NULL,
content_size INTEGER, -- full expected content size
content_status TEXT, -- empty, part, full
content BLOB NOT NULL
);
CREATE TABLE message_events (
event_id INTEGER NOT NULL UNIQUE REFERENCES events,
message_id INTEGER NOT NULL REFERENCES messages
);
+26 -16
View File
@@ -1,5 +1,5 @@
name: simplex-chat
version: 0.3.1
version: 0.4.0
#synopsis:
#description:
homepage: https://github.com/simplex-chat/simplex-chat#readme
@@ -12,34 +12,41 @@ extra-source-files:
- README.md
dependencies:
- aeson == 1.5.*
- ansi-terminal == 0.10.*
- attoparsec == 0.13.*
- base >= 4.7 && < 5
- base64-bytestring >= 1.0 && < 1.3
- bytestring == 0.10.*
- composition == 1.0.*
- containers == 0.6.*
- cryptonite >= 0.27 && < 0.30
- directory == 1.3.*
- exceptions == 0.10.*
- file-embed == 0.0.14.*
- filepath == 1.4.*
- mtl == 2.2.*
- optparse-applicative == 0.15.*
- process == 1.6.*
- simple-logger == 0.1.*
- simplexmq == 0.4.*
- sqlite-simple == 0.4.*
- stm == 2.5.*
- terminal == 0.2.*
- text == 1.2.*
- time == 1.9.*
- unliftio == 0.2.*
- unliftio-core == 0.2.*
library:
source-dirs: src
executables:
dog-food:
source-dirs: apps/dog-food
simplex-chat:
source-dirs: apps/simplex-chat
main: Main.hs
dependencies:
- simplex-chat
- async == 2.2.*
- bytestring == 0.10.*
- directory == 1.3.*
- filepath == 1.4.*
- mtl == 2.2.*
- optparse-applicative == 0.15.*
- process == 1.6.*
- simple-logger == 0.1.*
- simplexmq == 0.3.*
- stm == 2.5.*
- terminal == 0.2.*
- time == 1.9.*
- unliftio == 0.2.*
ghc-options:
- -threaded
@@ -49,7 +56,10 @@ tests:
main: Test.hs
dependencies:
- simplex-chat
- async == 2.2.*
- hspec == 2.7.*
- network == 3.1.*
- stm == 2.5.*
ghc-options:
# - -haddock
+74
View File
@@ -0,0 +1,74 @@
// x. namespace is for chat messages transmitted inside SMP agent MSG
type MemberMessageType =
| "x.grp.info" // group profile information or update
| "x.grp.off" // disable group
| "x.grp.del" // group deleted
| "x.grp.mem.new" // new group member
| "x.grp.mem.acl" // group member permissions (ACL)
| "x.grp.mem.leave" // group member left
| "x.grp.mem.off" // suspend group member
| "x.grp.mem.on" // enable group member
| "x.grp.mem.del" // group member removed
type ProfileMessageType =
| "x.info" // profile information or update
| "x.info.grp" // information about group in profile
| "x.info.con" // information about contact in profile
type NotificationMessageType = "x.msg.read"
type OpenConnMessageType =
| "x.open.grp" // open invitation to the group
| "x.open.con" // open invitation to the contact
type ContentMessageType =
| "x.msg.new" // new message
| "x.msg.append" // additional part of the message
| "x.msg.del" // delete message
| "x.msg.update" // update message
| "x.msg.fwd" // forward message
| "x.msg.reply" // reply to message
// TODO namespace for chat messages transmitted as other agent messages
type DirectMessageType =
| ProfileMessageType
| NotificationMessageType
| OpenConnMessageType
| ContentMessageType
type GroupMessageType = MemberMessageType | DirectMessageType
type ContentType =
| "c.text"
| "c.html"
| "c.image"
| "c.audio"
| "c.video"
| "c.doc"
| "c.sticker"
| "c.file"
| "c.link"
| "c.form"
| "c.poll"
| "c.applet"
// the type of message data transmitted inside SMP agent MSG
interface MessageData<T extends GroupMessageType> {
type: T
sent: Date
data: unknown
}
interface DirectMessageData<T extends DirectMessageType> extends MessageData<T> {}
interface GroupMessageData<T extends GroupMessageType> extends MessageData<T> {
msgId: number
parents: ParentMessage[]
}
interface ParentMessage {
memberId: Uint8Array
msgId: number
msgHash: Uint8Array
}
+1132
View File
File diff suppressed because it is too large. Load diff
+87
View File
@@ -0,0 +1,87 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module Simplex.Chat.Controller where
import Control.Exception
import Control.Monad.Except
import Control.Monad.IO.Unlift
import Control.Monad.Reader
import Crypto.Random (ChaChaDRG)
import Data.Int (Int64)
import Data.Map.Strict (Map)
import Numeric.Natural
import Simplex.Chat.Notification
import Simplex.Chat.Store (StoreError)
import Simplex.Chat.Terminal
import Simplex.Chat.Types
import Simplex.Messaging.Agent (AgentClient)
import Simplex.Messaging.Agent.Env.SQLite (AgentConfig)
import Simplex.Messaging.Agent.Protocol (AgentErrorType)
import Simplex.Messaging.Agent.Store.SQLite (SQLiteStore)
import System.IO (Handle)
import UnliftIO.STM
data ChatConfig = ChatConfig
{ agentConfig :: AgentConfig,
dbPoolSize :: Int,
tbqSize :: Natural,
fileChunkSize :: Integer
}
data ChatController = ChatController
{ currentUser :: TVar User,
smpAgent :: AgentClient,
chatTerminal :: ChatTerminal,
chatStore :: SQLiteStore,
idsDrg :: TVar ChaChaDRG,
inputQ :: TBQueue InputEvent,
notifyQ :: TBQueue Notification,
sendNotification :: Notification -> IO (),
chatLock :: TMVar (),
sndFiles :: TVar (Map Int64 Handle),
rcvFiles :: TVar (Map Int64 Handle),
config :: ChatConfig
}
data InputEvent = InputCommand String | InputControl Char
data ChatError
= ChatError ChatErrorType
| ChatErrorMessage String
| ChatErrorAgent AgentErrorType
| ChatErrorStore StoreError
deriving (Show, Exception)
data ChatErrorType
= CEGroupUserRole
| CEGroupContactRole ContactName
| CEGroupDuplicateMember ContactName
| CEGroupDuplicateMemberId
| CEGroupNotJoined GroupName
| CEGroupMemberNotActive
| CEGroupMemberUserRemoved
| CEGroupMemberNotFound ContactName
| CEGroupInternal String
| CEFileNotFound String
| CEFileAlreadyReceiving String
| CEFileAlreadyExists FilePath
| CEFileRead FilePath SomeException
| CEFileWrite FilePath SomeException
| CEFileSend Int64 AgentErrorType
| CEFileRcvChunk String
| CEFileInternal String
deriving (Show, Exception)
type ChatMonad m = (MonadUnliftIO m, MonadReader ChatController m, MonadError ChatError m)
setActive :: (MonadUnliftIO m, MonadReader ChatController m) => ActiveTo -> m ()
setActive to = asks (activeTo . chatTerminal) >>= atomically . (`writeTVar` to)
unsetActive :: (MonadUnliftIO m, MonadReader ChatController m) => ActiveTo -> m ()
unsetActive a = asks (activeTo . chatTerminal) >>= atomically . (`modifyTVar` unset)
where
unset a' = if a == a' then ActiveNone else a'
+109
View File
@@ -0,0 +1,109 @@
{-# LANGUAGE OverloadedStrings #-}
module Simplex.Chat.Help
( chatHelpInfo,
filesHelpInfo,
groupsHelpInfo,
markdownInfo,
)
where
import Data.List (intersperse)
import Data.Text (Text)
import Simplex.Chat.Markdown
import Simplex.Chat.Styled
import System.Console.ANSI.Types
highlight :: Text -> Markdown
highlight = Markdown (Colored Cyan)
green :: Text -> Markdown
green = Markdown (Colored Green)
indent :: Markdown
indent = " "
listHighlight :: [Text] -> Markdown
listHighlight = mconcat . intersperse ", " . map highlight
chatHelpInfo :: [StyledString]
chatHelpInfo =
map
styleMarkdown
[ highlight "Using SimpleX chat prototype",
"Follow these steps to set up a connection:",
"",
green "Step 1: " <> highlight "/connect" <> " - Alice adds a contact.",
indent <> "Alice should send the invitation printed by the /add command",
indent <> "to her contact, Bob, out-of-band, via any trusted channel.",
"",
green "Step 2: " <> highlight "/connect <invitation>" <> " - Bob accepts the invitation.",
indent <> "Bob should use the invitation he received out-of-band.",
"",
green "Step 3: " <> "Bob and Alice are notified that the connection is set up,",
indent <> "both can now send messages:",
indent <> highlight "@bob Hello, Bob!" <> " - Alice messages Bob (assuming Bob has display name 'bob').",
indent <> highlight "@alice Hey, Alice!" <> " - Bob replies to Alice.",
"",
green "To send file:",
indent <> highlight "/file bob ./photo.jpg" <> " - Alice sends file to Bob",
indent <> "File commands: " <> highlight "/help files",
"",
green "To create group:",
indent <> highlight "/group team" <> " - create group #team",
indent <> "Group commands: " <> highlight "/help groups",
"",
green "Other commands:",
indent <> highlight "/profile " <> " - show user profile",
indent <> highlight "/profile <name> [<full_name>]" <> " - update user profile",
indent <> highlight "/delete <contact>" <> " - delete contact and all messages with them",
indent <> highlight "/markdown " <> " - show supported markdown syntax",
indent <> highlight "/quit " <> " - quit chat",
"",
"The commands may be abbreviated to a single letter: " <> listHighlight ["/c", "/f", "/g", "/p", "/h"] <> ", etc."
]
filesHelpInfo :: [StyledString]
filesHelpInfo =
map
styleMarkdown
[ green "File transfer commands:",
indent <> highlight "/file @<contact> <file_path> " <> " - send file to contact",
indent <> highlight "/file #<group> <file_path> " <> " - send file to group",
indent <> highlight "/freceive <file_id> [<file_path>]" <> " - accept to receive file",
indent <> highlight "/fcancel <file_id> " <> " - cancel sending / receiving file",
indent <> highlight "/fstatus <file_id> " <> " - show file transfer status",
"",
"The commands may be abbreviated: " <> listHighlight ["/f", "/fr", "/fc", "/fs"]
]
groupsHelpInfo :: [StyledString]
groupsHelpInfo =
map
styleMarkdown
[ green "Group management commands:",
indent <> highlight "/group <group> [<full_name>] " <> " - create group",
indent <> highlight "/add <group> <contact> [<role>]" <> " - add contact to group, roles: " <> highlight "owner" <> ", " <> highlight "admin" <> " (default), " <> highlight "member",
indent <> highlight "/join <group> " <> " - accept group invitation",
indent <> highlight "/remove <group> <member> " <> " - remove member from group",
indent <> highlight "/leave <group> " <> " - leave group",
indent <> highlight "/delete <group> " <> " - delete group",
indent <> highlight "/members <group> " <> " - list group members",
indent <> highlight "#<group> <message> " <> " - send message to group",
"",
"The commands may be abbreviated: " <> listHighlight ["/g", "/a", "/j", "/rm", "/l", "/d", "/ms"]
]
markdownInfo :: [StyledString]
markdownInfo =
map
styleMarkdown
[ green "Markdown:",
indent <> highlight "*bold* " <> " - " <> Markdown Bold "bold text",
indent <> highlight "_italic_ " <> " - " <> Markdown Italic "italic text" <> " (shown as underlined)",
indent <> highlight "+underlined+ " <> " - " <> Markdown Underline "underlined text",
indent <> highlight "~strikethrough~" <> " - " <> Markdown StrikeThrough "strikethrough text" <> " (shown as inverse)",
indent <> highlight "`code snippet` " <> " - " <> Markdown Snippet "a + b // no *markdown* here",
indent <> highlight "!1 text! " <> " - " <> Markdown (Colored Red) "red text" <> " (1-6: red, green, blue, yellow, cyan, magenta)",
indent <> highlight "#secret# " <> " - " <> Markdown Secret "secret text" <> " (can be copy-pasted)"
]
@@ -1,50 +1,51 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module ChatTerminal.Core where
module Simplex.Chat.Input where
import Control.Concurrent.STM
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Control.Monad.IO.Unlift
import Control.Monad.Reader
import Data.List (dropWhileEnd)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding
import Simplex.Chat.Markdown
import Styled
import System.Console.ANSI.Types
import Simplex.Chat.Controller
import Simplex.Chat.Terminal
import System.Exit (exitSuccess)
import System.Terminal hiding (insertChars)
import Types
import UnliftIO.STM
data ActiveTo = ActiveNone | ActiveC Contact | ActiveG Group
deriving (Eq)
getKey :: MonadTerminal m => m (Key, Modifiers)
getKey =
flush >> awaitEvent >>= \case
Left Interrupt -> liftIO exitSuccess
Right (KeyEvent key ms) -> pure (key, ms)
_ -> getKey
data ChatTerminal = ChatTerminal
{ inputQ :: TBQueue String,
outputQ :: TBQueue [StyledString],
activeTo :: TVar ActiveTo,
termMode :: TermMode,
termState :: TVar TerminalState,
termSize :: Size,
nextMessageRow :: TVar Int,
termLock :: TMVar ()
}
runTerminalInput :: (MonadUnliftIO m, MonadReader ChatController m) => m ()
runTerminalInput = do
ChatController {inputQ, chatTerminal = ct} <- ask
liftIO $
withChatTerm ct $ do
updateInput ct
receiveFromTTY inputQ ct
data TerminalState = TerminalState
{ inputPrompt :: String,
inputString :: String,
inputPosition :: Int,
previousInput :: String
}
receiveFromTTY :: MonadTerminal m => TBQueue InputEvent -> ChatTerminal -> m ()
receiveFromTTY inputQ ct@ChatTerminal {activeTo, termSize, termState} =
forever $ getKey >>= processKey >> withTermLock ct (updateInput ct)
where
processKey :: MonadTerminal m => (Key, Modifiers) -> m ()
processKey = \case
(EnterKey, _) -> submitInput
key -> atomically $ do
ac <- readTVar activeTo
modifyTVar termState $ updateTermState ac (width termSize) key
inputHeight :: TerminalState -> ChatTerminal -> Int
inputHeight ts ct = length (inputPrompt ts <> inputString ts) `div` width (termSize ct) + 1
positionRowColumn :: Int -> Int -> Position
positionRowColumn wid pos =
let row = pos `div` wid
col = pos - row * wid
in Position {row, col}
submitInput :: MonadTerminal m => m ()
submitInput = atomically $ do
ts <- readTVar termState
let s = inputString ts
writeTVar termState $ ts {inputString = "", inputPosition = 0, previousInput = s}
writeTBQueue inputQ $ InputCommand s
updateTermState :: ActiveTo -> Int -> (Key, Modifiers) -> TerminalState -> TerminalState
updateTermState ac tw (key, ms) ts@TerminalState {inputString = s, inputPosition = p} = case key of
@@ -79,8 +80,8 @@ updateTermState ac tw (key, ms) ts@TerminalState {inputString = s, inputPosition
insert cs = let (b, a) = splitAt p s in (b <> cs <> a, p + length cs)
contactPrefix = case ac of
ActiveNone -> ""
ActiveC (Contact c) -> "@" <> B.unpack c <> " "
ActiveG (Group g) -> "#" <> B.unpack g <> " "
ActiveC c -> "@" <> T.unpack c <> " "
ActiveG g -> "#" <> T.unpack g <> " "
backDeleteChar
| p == 0 || null s = ts
| p >= length s = ts' (init s, length s - 1)
@@ -115,38 +116,3 @@ updateTermState ac tw (key, ms) ts@TerminalState {inputString = s, inputPosition
afterWord = dropWhile (/= ' ') $ dropWhile (== ' ') after
in min (length s) $ p + length after - length afterWord
ts' (s', p') = ts {inputString = s', inputPosition = p'}
styleMessage :: String -> String -> StyledString
styleMessage time msg = do
case msg of
"" -> ""
s@('@' : _) -> sentMessage s
s@('#' : _) -> sentMessage s
s -> markdown s
where
sentMessage :: String -> StyledString
sentMessage s =
let (c, rest) = span (/= ' ') s
in styleTime time <> " " <> styled (Colored Cyan) c <> markdown rest
markdown :: String -> StyledString
markdown = styleMarkdownText . T.pack
styleTime :: String -> StyledString
styleTime = Styled [SetColor Foreground Vivid Black]
safeDecodeUtf8 :: ByteString -> Text
safeDecodeUtf8 = decodeUtf8With onError
where
onError _ _ = Just '?'
ttyContact :: Contact -> StyledString
ttyContact (Contact a) = styled (Colored Green) a
ttyFromContact :: Contact -> StyledString
ttyFromContact (Contact a) = styled (Colored Yellow) $ a <> "> "
ttyGroup :: Group -> StyledString
ttyGroup (Group g) = styled (Colored Blue) $ "#" <> g
ttyFromGroup :: Group -> Contact -> StyledString
ttyFromGroup (Group g) (Contact a) = styled (Colored Yellow) $ "#" <> g <> " " <> a <> "> "
@@ -2,11 +2,9 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module Notification (Notification (..), initializeNotifications) where
module Simplex.Chat.Notification (Notification (..), initializeNotifications) where
import ChatTerminal.Core (safeDecodeUtf8)
import Control.Monad (void)
import Data.ByteString.Char8 (ByteString)
import Data.List (isInfixOf)
import Data.Map (Map, fromList)
import qualified Data.Map as M
@@ -18,7 +16,7 @@ import System.FilePath (combine)
import System.Info (os)
import System.Process (readCreateProcess, shell)
data Notification = Notification {title :: ByteString, text :: ByteString}
data Notification = Notification {title :: Text, text :: Text}
initializeNotifications :: IO (Notification -> IO ())
initializeNotifications = case os of
@@ -39,13 +37,13 @@ notify script notification =
void $ readCreateProcess (shell . T.unpack $ script notification) ""
linuxScript :: Notification -> Text
linuxScript Notification {title, text} = "notify-send '" <> linuxEscape (safeDecodeUtf8 title) <> "' '" <> linuxEscape (safeDecodeUtf8 text) <> "'"
linuxScript Notification {title, text} = "notify-send '" <> linuxEscape title <> "' '" <> linuxEscape text <> "'"
linuxEscape :: Text -> Text
linuxEscape = replaceAll $ fromList [('\'', "'\\''")]
macScript :: Notification -> Text
macScript Notification {title, text} = "osascript -e 'display notification \"" <> macEscape (safeDecodeUtf8 text) <> "\" with title \"" <> macEscape (safeDecodeUtf8 title) <> "\"'"
macScript Notification {title, text} = "osascript -e 'display notification \"" <> macEscape text <> "\" with title \"" <> macEscape title <> "\"'"
macEscape :: Text -> Text
macEscape = replaceAll $ fromList [('"', "\\\"")]
@@ -54,7 +52,7 @@ initWslNotify :: IO (Notification -> IO ())
initWslNotify = notify . wslScript <$> savePowershellScript
wslScript :: FilePath -> Notification -> Text
wslScript path Notification {title, text} = "powershell.exe \"" <> T.pack path <> " \\\"" <> wslEscape (safeDecodeUtf8 title) <> "\\\" \\\"" <> wslEscape (safeDecodeUtf8 text) <> "\\\"\""
wslScript path Notification {title, text} = "powershell.exe \"" <> T.pack path <> " \\\"" <> wslEscape title <> "\\\" \\\"" <> wslEscape text <> "\\\"\""
wslEscape :: Text -> Text
wslEscape = replaceAll $ fromList [('`', "\\`\\`"), ('\\', "\\\\"), ('"', "\\`\\\"")]
@@ -63,7 +61,7 @@ initWinNotify :: IO (Notification -> IO ())
initWinNotify = notify . winScript <$> savePowershellScript
winScript :: FilePath -> Notification -> Text
winScript path Notification {title, text} = "powershell.exe \"" <> T.pack path <> " '" <> winRemoveQuotes (safeDecodeUtf8 title) <> "' '" <> winRemoveQuotes (safeDecodeUtf8 text) <> "'\""
winScript path Notification {title, text} = "powershell.exe \"" <> T.pack path <> " '" <> winRemoveQuotes title <> "' '" <> winRemoveQuotes text <> "'\""
winRemoveQuotes :: Text -> Text
winRemoveQuotes = replaceAll $ fromList [('`', ""), ('\'', ""), ('"', "")]
@@ -1,7 +1,6 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module ChatOptions (getChatOpts, ChatOpts (..)) where
module Simplex.Chat.Options (getChatOpts, ChatOpts (..)) where
import qualified Data.Attoparsec.ByteString.Char8 as A
import qualified Data.ByteString.Char8 as B
@@ -11,12 +10,10 @@ import Options.Applicative
import Simplex.Messaging.Agent.Protocol (SMPServer (..), smpServerP)
import Simplex.Messaging.Parsers (parseAll)
import System.FilePath (combine)
import Types
data ChatOpts = ChatOpts
{ dbFile :: String,
smpServers :: NonEmpty SMPServer,
termMode :: TermMode
smpServers :: NonEmpty SMPServer
}
chatOpts :: FilePath -> Parser ChatOpts
@@ -34,31 +31,25 @@ chatOpts appDir =
( long "server"
<> short 's'
<> metavar "SERVER"
<> help "SMP server(s) to use (smp1.simplex.im#pLdiGvm0jD1CMblnov6Edd/391OrYsShw+RgdfR0ChA=)"
<> value (L.fromList ["smp1.simplex.im#pLdiGvm0jD1CMblnov6Edd/391OrYsShw+RgdfR0ChA="])
)
<*> option
parseTermMode
( long "term"
<> short 't'
<> metavar "TERM"
<> help ("terminal mode: editor or basic (" <> termModeName TermModeEditor <> ")")
<> value TermModeEditor
<> help
( "SMP server(s) to use"
<> "\n(smp2.simplex.im,smp3.simplex.im)"
)
<> value
( L.fromList
[ "smp2.simplex.im#z5W2QLQ1Br3Yd6CoWg7bIq1bHdwK7Y8bEiEXBs/WfAg=", -- London, UK
"smp3.simplex.im#nxc7HnrnM8dOKgkMp008ub/9o9LXJlxlMrMpR+mfMQw=" -- Fremont, CA
]
)
)
where
defaultDbFilePath = combine appDir "smp-chat.db"
defaultDbFilePath = combine appDir "simplex"
parseSMPServer :: ReadM (NonEmpty SMPServer)
parseSMPServer = eitherReader $ parseAll servers . B.pack
where
servers = L.fromList <$> smpServerP `A.sepBy1` A.char ','
parseTermMode :: ReadM TermMode
parseTermMode = maybeReader $ \case
"basic" -> Just TermModeBasic
"editor" -> Just TermModeEditor
_ -> Nothing
getChatOpts :: FilePath -> IO ChatOpts
getChatOpts appDir = execParser opts
where
-13
View File
@@ -1,13 +0,0 @@
module Simplex.Chat.Protocol where
data Profile = Profile
{ displayName :: Text,
fullName :: Text
}
data Contact = Contact
{ profile :: Profile,
connection :: ConnAlias
}
data ChatMessage = ContentMessage | ReadNotification | FileTransfer
+383
View File
@@ -0,0 +1,383 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TupleSections #-}
module Simplex.Chat.Protocol where
import Control.Applicative (optional)
import Control.Monad ((<=<))
import Data.Aeson (FromJSON, ToJSON)
import qualified Data.Aeson as J
import Data.Attoparsec.ByteString.Char8 (Parser)
import qualified Data.Attoparsec.ByteString.Char8 as A
import qualified Data.ByteString.Base64 as B64
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as LB
import Data.Int (Int64)
import Data.List (find)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import Simplex.Chat.Types
import Simplex.Chat.Util (safeDecodeUtf8)
import Simplex.Messaging.Agent.Protocol
import Simplex.Messaging.Parsers (parseAll)
import Simplex.Messaging.Util (bshow)
data ChatDirection (p :: AParty) where
ReceivedDirectMessage :: Connection -> Maybe Contact -> ChatDirection 'Agent
SentDirectMessage :: Contact -> ChatDirection 'Client
ReceivedGroupMessage :: Connection -> GroupName -> GroupMember -> ChatDirection 'Agent
SentGroupMessage :: GroupName -> ChatDirection 'Client
SndFileConnection :: Connection -> SndFileTransfer -> ChatDirection 'Agent
RcvFileConnection :: Connection -> RcvFileTransfer -> ChatDirection 'Agent
deriving instance Eq (ChatDirection p)
deriving instance Show (ChatDirection p)
fromConnection :: ChatDirection 'Agent -> Connection
fromConnection = \case
ReceivedDirectMessage conn _ -> conn
ReceivedGroupMessage conn _ _ -> conn
SndFileConnection conn _ -> conn
RcvFileConnection conn _ -> conn
data ChatMsgEvent
= XMsgNew MsgContent
| XFile FileInvitation
| XFileAcpt String
| XInfo Profile
| XGrpInv GroupInvitation
| XGrpAcpt MemberId
| XGrpMemNew MemberInfo
| XGrpMemIntro MemberInfo
| XGrpMemInv MemberId IntroInvitation
| XGrpMemFwd MemberInfo IntroInvitation
| XGrpMemInfo MemberId Profile
| XGrpMemCon MemberId
| XGrpMemConAll MemberId
| XGrpMemDel MemberId
| XGrpLeave
| XGrpDel
| XInfoProbe ByteString
| XInfoProbeCheck ByteString
| XInfoProbeOk ByteString
| XOk
deriving (Eq, Show)
data MessageType = MTText | MTImage deriving (Eq, Show)
data MsgContent = MsgContent
{ messageType :: MessageType,
files :: [(ContentType, Int)],
content :: [MsgContentBody]
}
deriving (Eq, Show)
toMsgType :: ByteString -> Either String MessageType
toMsgType = \case
"c.text" -> Right MTText
"c.image" -> Right MTImage
t -> Left $ "invalid message type " <> B.unpack t
rawMsgType :: MessageType -> ByteString
rawMsgType = \case
MTText -> "c.text"
MTImage -> "c.image"
data ChatMessage = ChatMessage
{ chatMsgId :: Maybe Int64,
chatMsgEvent :: ChatMsgEvent,
chatDAG :: Maybe ByteString
}
deriving (Eq, Show)
toChatMessage :: RawChatMessage -> Either String ChatMessage
toChatMessage RawChatMessage {chatMsgId, chatMsgEvent, chatMsgParams, chatMsgBody} = do
(chatDAG, body) <- getDAG <$> mapM toMsgBodyContent chatMsgBody
let chatMsg msg = pure ChatMessage {chatMsgId, chatMsgEvent = msg, chatDAG}
case (chatMsgEvent, chatMsgParams) of
("x.msg.new", mt : rawFiles) -> do
t <- toMsgType mt
files <- mapM (toContentInfo <=< parseAll contentInfoP) rawFiles
chatMsg . XMsgNew $ MsgContent {messageType = t, files, content = body}
("x.file", [name, size, qInfo]) -> do
let fileName = T.unpack $ safeDecodeUtf8 name
fileSize <- parseAll A.decimal size
fileQInfo <- parseAll smpQueueInfoP qInfo
chatMsg . XFile $ FileInvitation {fileName, fileSize, fileQInfo}
("x.file.acpt", [name]) ->
chatMsg . XFileAcpt . T.unpack $ safeDecodeUtf8 name
("x.info", []) -> do
profile <- getJSON body
chatMsg $ XInfo profile
("x.grp.inv", [fromMemId, fromRole, memId, role, qInfo]) -> do
fromMem <- (,) <$> B64.decode fromMemId <*> toMemberRole fromRole
invitedMem <- (,) <$> B64.decode memId <*> toMemberRole role
groupQInfo <- parseAll smpQueueInfoP qInfo
profile <- getJSON body
chatMsg . XGrpInv $ GroupInvitation fromMem invitedMem groupQInfo profile
("x.grp.acpt", [memId]) ->
chatMsg . XGrpAcpt =<< B64.decode memId
("x.grp.mem.new", [memId, role]) -> do
chatMsg . XGrpMemNew =<< toMemberInfo memId role body
("x.grp.mem.intro", [memId, role]) ->
chatMsg . XGrpMemIntro =<< toMemberInfo memId role body
("x.grp.mem.inv", [memId, groupQInfo, directQInfo]) ->
chatMsg =<< (XGrpMemInv <$> B64.decode memId <*> toIntroInv groupQInfo directQInfo)
("x.grp.mem.fwd", [memId, role, groupQInfo, directQInfo]) -> do
chatMsg =<< (XGrpMemFwd <$> toMemberInfo memId role body <*> toIntroInv groupQInfo directQInfo)
("x.grp.mem.info", [memId]) ->
chatMsg =<< (XGrpMemInfo <$> B64.decode memId <*> getJSON body)
("x.grp.mem.con", [memId]) ->
chatMsg . XGrpMemCon =<< B64.decode memId
("x.grp.mem.con.all", [memId]) ->
chatMsg . XGrpMemConAll =<< B64.decode memId
("x.grp.mem.del", [memId]) ->
chatMsg . XGrpMemDel =<< B64.decode memId
("x.grp.leave", []) ->
chatMsg XGrpLeave
("x.grp.del", []) ->
chatMsg XGrpDel
("x.info.probe", [probe]) -> do
chatMsg . XInfoProbe =<< B64.decode probe
("x.info.probe.check", [probeHash]) -> do
chatMsg =<< (XInfoProbeCheck <$> B64.decode probeHash)
("x.info.probe.ok", [probe]) -> do
chatMsg =<< (XInfoProbeOk <$> B64.decode probe)
("x.ok", []) ->
chatMsg XOk
_ -> Left $ "bad syntax or unsupported event " <> B.unpack chatMsgEvent
where
getDAG :: [MsgContentBody] -> (Maybe ByteString, [MsgContentBody])
getDAG body = case break (isContentType SimplexDAG) body of
(b, MsgContentBody SimplexDAG dag : a) -> (Just dag, b <> a)
_ -> (Nothing, body)
toMemberInfo :: ByteString -> ByteString -> [MsgContentBody] -> Either String MemberInfo
toMemberInfo memId role body = MemberInfo <$> B64.decode memId <*> toMemberRole role <*> getJSON body
toIntroInv :: ByteString -> ByteString -> Either String IntroInvitation
toIntroInv groupQInfo directQInfo = IntroInvitation <$> parseAll smpQueueInfoP groupQInfo <*> parseAll smpQueueInfoP directQInfo
toContentInfo :: (RawContentType, Int) -> Either String (ContentType, Int)
toContentInfo (rawType, size) = (,size) <$> toContentType rawType
getJSON :: FromJSON a => [MsgContentBody] -> Either String a
getJSON = J.eitherDecodeStrict' <=< getSimplexContentType XCJson
isContentType :: ContentType -> MsgContentBody -> Bool
isContentType t MsgContentBody {contentType = t'} = t == t'
isSimplexContentType :: XContentType -> MsgContentBody -> Bool
isSimplexContentType = isContentType . SimplexContentType
getContentType :: ContentType -> [MsgContentBody] -> Either String ByteString
getContentType t body = case find (isContentType t) body of
Just MsgContentBody {contentData} -> Right contentData
Nothing -> Left "no required content type"
getSimplexContentType :: XContentType -> [MsgContentBody] -> Either String ByteString
getSimplexContentType = getContentType . SimplexContentType
rawChatMessage :: ChatMessage -> RawChatMessage
rawChatMessage ChatMessage {chatMsgId, chatMsgEvent, chatDAG} =
case chatMsgEvent of
XMsgNew MsgContent {messageType = t, files, content} ->
let rawFiles = map (serializeContentInfo . rawContentInfo) files
in rawMsg "x.msg.new" (rawMsgType t : rawFiles) content
XFile FileInvitation {fileName, fileSize, fileQInfo} ->
rawMsg "x.file" [encodeUtf8 $ T.pack fileName, bshow fileSize, serializeSmpQueueInfo fileQInfo] []
XFileAcpt fileName ->
rawMsg "x.file.acpt" [encodeUtf8 $ T.pack fileName] []
XInfo profile ->
rawMsg "x.info" [] [jsonBody profile]
XGrpInv (GroupInvitation (fromMemId, fromRole) (memId, role) qInfo groupProfile) ->
let params =
[ B64.encode fromMemId,
serializeMemberRole fromRole,
B64.encode memId,
serializeMemberRole role,
serializeSmpQueueInfo qInfo
]
in rawMsg "x.grp.inv" params [jsonBody groupProfile]
XGrpAcpt memId ->
rawMsg "x.grp.acpt" [B64.encode memId] []
XGrpMemNew (MemberInfo memId role profile) ->
let params = [B64.encode memId, serializeMemberRole role]
in rawMsg "x.grp.mem.new" params [jsonBody profile]
XGrpMemIntro (MemberInfo memId role profile) ->
rawMsg "x.grp.mem.intro" [B64.encode memId, serializeMemberRole role] [jsonBody profile]
XGrpMemInv memId IntroInvitation {groupQInfo, directQInfo} ->
let params = [B64.encode memId, serializeSmpQueueInfo groupQInfo, serializeSmpQueueInfo directQInfo]
in rawMsg "x.grp.mem.inv" params []
XGrpMemFwd (MemberInfo memId role profile) IntroInvitation {groupQInfo, directQInfo} ->
let params =
[ B64.encode memId,
serializeMemberRole role,
serializeSmpQueueInfo groupQInfo,
serializeSmpQueueInfo directQInfo
]
in rawMsg "x.grp.mem.fwd" params [jsonBody profile]
XGrpMemInfo memId profile ->
rawMsg "x.grp.mem.info" [B64.encode memId] [jsonBody profile]
XGrpMemCon memId ->
rawMsg "x.grp.mem.con" [B64.encode memId] []
XGrpMemConAll memId ->
rawMsg "x.grp.mem.con.all" [B64.encode memId] []
XGrpMemDel memId ->
rawMsg "x.grp.mem.del" [B64.encode memId] []
XGrpLeave ->
rawMsg "x.grp.leave" [] []
XGrpDel ->
rawMsg "x.grp.del" [] []
XInfoProbe probe ->
rawMsg "x.info.probe" [B64.encode probe] []
XInfoProbeCheck probeHash ->
rawMsg "x.info.probe.check" [B64.encode probeHash] []
XInfoProbeOk probe ->
rawMsg "x.info.probe.ok" [B64.encode probe] []
XOk ->
rawMsg "x.ok" [] []
where
rawMsg :: ByteString -> [ByteString] -> [MsgContentBody] -> RawChatMessage
rawMsg event chatMsgParams body =
RawChatMessage {chatMsgId, chatMsgEvent = event, chatMsgParams, chatMsgBody = rawWithDAG body}
rawContentInfo :: (ContentType, Int) -> (RawContentType, Int)
rawContentInfo (t, size) = (rawContentType t, size)
jsonBody :: ToJSON a => a -> MsgContentBody
jsonBody x =
let json = LB.toStrict $ J.encode x
in MsgContentBody {contentType = SimplexContentType XCJson, contentData = json}
rawWithDAG :: [MsgContentBody] -> [RawMsgBodyContent]
rawWithDAG body = map rawMsgBodyContent $ case chatDAG of
Nothing -> body
Just dag -> MsgContentBody {contentType = SimplexDAG, contentData = dag} : body
toMsgBodyContent :: RawMsgBodyContent -> Either String MsgContentBody
toMsgBodyContent RawMsgBodyContent {contentType, contentData} = do
cType <- toContentType contentType
pure MsgContentBody {contentType = cType, contentData}
rawMsgBodyContent :: MsgContentBody -> RawMsgBodyContent
rawMsgBodyContent MsgContentBody {contentType = t, contentData} =
RawMsgBodyContent {contentType = rawContentType t, contentData}
data MsgContentBody = MsgContentBody
{ contentType :: ContentType,
contentData :: ByteString
}
deriving (Eq, Show)
data ContentType
= SimplexContentType XContentType
| MimeContentType MContentType
| SimplexDAG
deriving (Eq, Show)
data XContentType = XCText | XCImage | XCJson deriving (Eq, Show)
data MContentType = MCImageJPG | MCImagePNG deriving (Eq, Show)
toContentType :: RawContentType -> Either String ContentType
toContentType (RawContentType ns cType) = case ns of
"x" -> case cType of
"text" -> Right $ SimplexContentType XCText
"image" -> Right $ SimplexContentType XCImage
"json" -> Right $ SimplexContentType XCJson
"dag" -> Right SimplexDAG
_ -> err
"m" -> case cType of
"image/jpg" -> Right $ MimeContentType MCImageJPG
"image/png" -> Right $ MimeContentType MCImagePNG
_ -> err
_ -> err
where
err = Left . B.unpack $ "invalid content type " <> ns <> "." <> cType
rawContentType :: ContentType -> RawContentType
rawContentType t = case t of
SimplexContentType t' -> RawContentType "x" $ case t' of
XCText -> "text"
XCImage -> "image"
XCJson -> "json"
MimeContentType t' -> RawContentType "m" $ case t' of
MCImageJPG -> "image/jpg"
MCImagePNG -> "image/png"
SimplexDAG -> RawContentType "x" "dag"
newtype ContentMsg = NewContentMsg ContentData
newtype ContentData = ContentText Text
data RawChatMessage = RawChatMessage
{ chatMsgId :: Maybe Int64,
chatMsgEvent :: ByteString,
chatMsgParams :: [ByteString],
chatMsgBody :: [RawMsgBodyContent]
}
deriving (Eq, Show)
data RawMsgBodyContent = RawMsgBodyContent
{ contentType :: RawContentType,
contentData :: ByteString
}
deriving (Eq, Show)
data RawContentType = RawContentType NameSpace ByteString
deriving (Eq, Show)
type NameSpace = ByteString
newtype MsgData = MsgData ByteString
deriving (Eq, Show)
class DataLength a where
dataLength :: a -> Int
rawChatMessageP :: Parser RawChatMessage
rawChatMessageP = do
chatMsgId <- optional A.decimal <* A.space
chatMsgEvent <- B.intercalate "." <$> identifierP `A.sepBy1'` A.char '.' <* A.space
chatMsgParams <- A.takeWhile1 (not . A.inClass ", ") `A.sepBy'` A.char ',' <* A.space
chatMsgBody <- msgBodyContent =<< contentInfoP `A.sepBy'` A.char ',' <* A.space
pure RawChatMessage {chatMsgId, chatMsgEvent, chatMsgParams, chatMsgBody}
where
msgBodyContent :: [(RawContentType, Int)] -> Parser [RawMsgBodyContent]
msgBodyContent [] = pure []
msgBodyContent ((contentType, size) : ps) = do
contentData <- A.take size <* A.space
((RawMsgBodyContent {contentType, contentData}) :) <$> msgBodyContent ps
contentInfoP :: Parser (RawContentType, Int)
contentInfoP = do
contentType <- RawContentType <$> identifierP <* A.char '.' <*> A.takeTill (A.inClass ":, ")
size <- A.char ':' *> A.decimal
pure (contentType, size)
identifierP :: Parser ByteString
identifierP = B.cons <$> A.letter_ascii <*> A.takeWhile (\c -> A.isAlpha_ascii c || A.isDigit c)
serializeRawChatMessage :: RawChatMessage -> ByteString
serializeRawChatMessage RawChatMessage {chatMsgId, chatMsgEvent, chatMsgParams, chatMsgBody} =
B.unwords
[ maybe "" bshow chatMsgId,
chatMsgEvent,
B.intercalate "," chatMsgParams,
B.unwords $ map serializeBodyContentInfo chatMsgBody,
B.unwords $ map msgContentData chatMsgBody
]
serializeBodyContentInfo :: RawMsgBodyContent -> ByteString
serializeBodyContentInfo RawMsgBodyContent {contentType = t, contentData} =
serializeContentInfo (t, B.length contentData)
serializeContentInfo :: (RawContentType, Int) -> ByteString
serializeContentInfo (RawContentType ns cType, size) = ns <> "." <> cType <> ":" <> bshow size
msgContentData :: RawMsgBodyContent -> ByteString
msgContentData RawMsgBodyContent {contentData} = contentData <> " "
File diff suppressed because it is too large. Load diff
@@ -1,14 +1,13 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
module Styled
module Simplex.Chat.Styled
( StyledString (..),
bPlain,
plain,
StyledFormat (..),
styleMarkdown,
styleMarkdownText,
styled,
sLength,
sShow,
)
where
@@ -28,12 +27,6 @@ instance Monoid StyledString where mempty = plain ""
instance IsString StyledString where fromString = plain
plain :: String -> StyledString
plain = Styled []
bPlain :: ByteString -> StyledString
bPlain = Styled [] . B.unpack
styleMarkdownText :: Text -> StyledString
styleMarkdownText = styleMarkdown . parseMarkdown
@@ -48,12 +41,22 @@ wrap c s = plain [c] <> s <> plain [c]
class StyledFormat a where
styled :: Format -> a -> StyledString
plain :: a -> StyledString
instance StyledFormat String where styled = Styled . sgr
instance StyledFormat String where
styled = Styled . sgr
plain = Styled []
instance StyledFormat ByteString where styled f = styled f . B.unpack
instance StyledFormat ByteString where
styled f = styled f . B.unpack
plain = Styled [] . B.unpack
instance StyledFormat Text where styled f = styled f . T.unpack
instance StyledFormat Text where
styled f = styled f . T.unpack
plain = Styled [] . T.unpack
sShow :: Show a => a -> StyledString
sShow = plain . show
sgr :: Format -> [SGR]
sgr = \case
+176
View File
@@ -0,0 +1,176 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Simplex.Chat.Terminal where
import Control.Monad.Catch (MonadMask)
import Control.Monad.IO.Class (MonadIO)
import Simplex.Chat.Styled
import Simplex.Chat.Types
import System.Console.ANSI.Types
import System.Terminal
import System.Terminal.Internal (LocalTerminal, Terminal, VirtualTerminal)
import UnliftIO.STM
data ActiveTo = ActiveNone | ActiveC ContactName | ActiveG GroupName
deriving (Eq)
data ChatTerminal = ChatTerminal
{ activeTo :: TVar ActiveTo,
termDevice :: TerminalDevice,
termState :: TVar TerminalState,
termSize :: Size,
nextMessageRow :: TVar Int,
termLock :: TMVar ()
}
data TerminalState = TerminalState
{ inputPrompt :: String,
inputString :: String,
inputPosition :: Int,
previousInput :: String
}
class Terminal t => WithTerminal t where
withTerm :: (MonadIO m, MonadMask m) => t -> (t -> m a) -> m a
data TerminalDevice = forall t. WithTerminal t => TerminalDevice t
instance WithTerminal LocalTerminal where
withTerm _ = withTerminal
instance WithTerminal VirtualTerminal where
withTerm t = ($ t)
withChatTerm :: (MonadIO m, MonadMask m) => ChatTerminal -> (forall t. WithTerminal t => TerminalT t m a) -> m a
withChatTerm ChatTerminal {termDevice = TerminalDevice t} action = withTerm t $ runTerminalT action
newChatTerminal :: WithTerminal t => t -> IO ChatTerminal
newChatTerminal t = do
activeTo <- newTVarIO ActiveNone
termSize <- withTerm t . runTerminalT $ getWindowSize
let lastRow = height termSize - 1
termState <- newTVarIO newTermState
termLock <- newTMVarIO ()
nextMessageRow <- newTVarIO lastRow
-- threadDelay 500000 -- this delay is the same as timeout in getTerminalSize
return ChatTerminal {activeTo, termDevice = TerminalDevice t, termState, termSize, nextMessageRow, termLock}
newTermState :: TerminalState
newTermState =
TerminalState
{ inputString = "",
inputPosition = 0,
inputPrompt = "> ",
previousInput = ""
}
withTermLock :: MonadTerminal m => ChatTerminal -> m () -> m ()
withTermLock ChatTerminal {termLock} action = do
_ <- atomically $ takeTMVar termLock
action
atomically $ putTMVar termLock ()
printToTerminal :: ChatTerminal -> [StyledString] -> IO ()
printToTerminal ct s =
withChatTerm ct $
withTermLock ct $ do
printMessage ct s
updateInput ct
updateInput :: forall m. MonadTerminal m => ChatTerminal -> m ()
updateInput ChatTerminal {termSize = Size {height, width}, termState, nextMessageRow} = do
hideCursor
ts <- readTVarIO termState
nmr <- readTVarIO nextMessageRow
let ih = inputHeight ts
iStart = height - ih
prompt = inputPrompt ts
Position {row, col} = positionRowColumn width $ length prompt + inputPosition ts
if nmr >= iStart
then atomically $ writeTVar nextMessageRow iStart
else clearLines nmr iStart
setCursorPosition $ Position {row = max nmr iStart, col = 0}
putString $ prompt <> inputString ts <> " "
eraseInLine EraseForward
setCursorPosition $ Position {row = iStart + row, col}
showCursor
flush
where
clearLines :: Int -> Int -> m ()
clearLines from till
| from >= till = return ()
| otherwise = do
setCursorPosition $ Position {row = from, col = 0}
eraseInLine EraseForward
clearLines (from + 1) till
inputHeight :: TerminalState -> Int
inputHeight ts = length (inputPrompt ts <> inputString ts) `div` width + 1
positionRowColumn :: Int -> Int -> Position
positionRowColumn wid pos =
let row = pos `div` wid
col = pos - row * wid
in Position {row, col}
printMessage :: forall m. MonadTerminal m => ChatTerminal -> [StyledString] -> m ()
printMessage ChatTerminal {termSize = Size {height, width}, nextMessageRow} msg = do
nmr <- readTVarIO nextMessageRow
setCursorPosition $ Position {row = nmr, col = 0}
mapM_ printStyled msg
flush
let lc = sum $ map lineCount msg
atomically . writeTVar nextMessageRow $ min (height - 1) (nmr + lc)
where
lineCount :: StyledString -> Int
lineCount s = sLength s `div` width + 1
printStyled :: StyledString -> m ()
printStyled s = do
putStyled s
eraseInLine EraseForward
putLn
-- Currently it is assumed that the message does not have internal line breaks.
-- Previous implementation "kind of" supported them,
-- but it was not determining the number of printed lines correctly
-- because of accounting for control sequences in length
putStyled :: MonadTerminal m => StyledString -> m ()
putStyled (s1 :<>: s2) = putStyled s1 >> putStyled s2
putStyled (Styled [] s) = putString s
putStyled (Styled sgr s) = setSGR sgr >> putString s >> resetAttributes
setSGR :: MonadTerminal m => [SGR] -> m ()
setSGR = mapM_ $ \case
Reset -> resetAttributes
SetConsoleIntensity BoldIntensity -> setAttribute bold
SetConsoleIntensity _ -> resetAttribute bold
SetItalicized True -> setAttribute italic
SetItalicized _ -> resetAttribute italic
SetUnderlining NoUnderline -> resetAttribute underlined
SetUnderlining _ -> setAttribute underlined
SetSwapForegroundBackground True -> setAttribute inverted
SetSwapForegroundBackground _ -> resetAttribute inverted
SetColor l i c -> setAttribute . layer l . intensity i $ color c
SetBlinkSpeed _ -> pure ()
SetVisible _ -> pure ()
SetRGBColor _ _ -> pure ()
SetPaletteColor _ _ -> pure ()
SetDefaultColor _ -> pure ()
where
layer = \case
Foreground -> foreground
Background -> background
intensity = \case
Dull -> id
Vivid -> bright
color = \case
Black -> black
Red -> red
Green -> green
Yellow -> yellow
Blue -> blue
Magenta -> magenta
Cyan -> cyan
White -> white
+497
View File
@@ -0,0 +1,497 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module Simplex.Chat.Types where
import Data.Aeson (FromJSON, ToJSON)
import qualified Data.Aeson as J
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Int (Int64)
import Data.Text (Text)
import Data.Time.Clock (UTCTime)
import Data.Typeable (Typeable)
import Database.SQLite.Simple (ResultError (..), SQLData (..))
import Database.SQLite.Simple.FromField (FieldParser, FromField (..), returnError)
import Database.SQLite.Simple.Internal (Field (..))
import Database.SQLite.Simple.Ok (Ok (Ok))
import Database.SQLite.Simple.ToField (ToField (..))
import GHC.Generics
import Simplex.Messaging.Agent.Protocol (ConnId, SMPQueueInfo)
import Simplex.Messaging.Agent.Store.SQLite (fromTextField_)
class IsContact a where
contactId' :: a -> Int64
profile' :: a -> Profile
localDisplayName' :: a -> ContactName
instance IsContact User where
contactId' = userContactId
profile' = profile
localDisplayName' = localDisplayName
instance IsContact Contact where
contactId' = contactId
profile' = profile
localDisplayName' = localDisplayName
data User = User
{ userId :: UserId,
userContactId :: Int64,
localDisplayName :: ContactName,
profile :: Profile,
activeUser :: Bool
}
type UserId = Int64
data Contact = Contact
{ contactId :: Int64,
localDisplayName :: ContactName,
profile :: Profile,
activeConn :: Connection,
viaGroup :: Maybe Int64
}
deriving (Eq, Show)
contactConnId :: Contact -> ConnId
contactConnId Contact {activeConn = Connection {agentConnId}} = agentConnId
type ContactName = Text
type GroupName = Text
data Group = Group
{ groupId :: Int64,
localDisplayName :: GroupName,
groupProfile :: GroupProfile,
members :: [GroupMember],
membership :: GroupMember
}
deriving (Eq, Show)
data Profile = Profile
{ displayName :: ContactName,
fullName :: Text
}
deriving (Generic, Eq, Show)
instance ToJSON Profile where toEncoding = J.genericToEncoding J.defaultOptions
instance FromJSON Profile
data GroupProfile = GroupProfile
{ displayName :: GroupName,
fullName :: Text
}
deriving (Generic, Eq, Show)
instance ToJSON GroupProfile where toEncoding = J.genericToEncoding J.defaultOptions
instance FromJSON GroupProfile
data GroupInvitation = GroupInvitation
{ fromMember :: (MemberId, GroupMemberRole),
invitedMember :: (MemberId, GroupMemberRole),
queueInfo :: SMPQueueInfo,
groupProfile :: GroupProfile
}
deriving (Eq, Show)
data IntroInvitation = IntroInvitation
{ groupQInfo :: SMPQueueInfo,
directQInfo :: SMPQueueInfo
}
deriving (Eq, Show)
data MemberInfo = MemberInfo MemberId GroupMemberRole Profile
deriving (Eq, Show)
memberInfo :: GroupMember -> MemberInfo
memberInfo m = MemberInfo (memberId m) (memberRole m) (memberProfile m)
data ReceivedGroupInvitation = ReceivedGroupInvitation
{ fromMember :: GroupMember,
userMember :: GroupMember,
queueInfo :: SMPQueueInfo,
groupProfile :: GroupProfile
}
deriving (Eq, Show)
data GroupMember = GroupMember
{ groupMemberId :: Int64,
groupId :: Int64,
memberId :: MemberId,
memberRole :: GroupMemberRole,
memberCategory :: GroupMemberCategory,
memberStatus :: GroupMemberStatus,
invitedBy :: InvitedBy,
localDisplayName :: ContactName,
memberProfile :: Profile,
memberContactId :: Maybe Int64,
activeConn :: Maybe Connection
}
deriving (Eq, Show)
memberConnId :: GroupMember -> Maybe ConnId
memberConnId GroupMember {activeConn} = case activeConn of
Just Connection {agentConnId} -> Just agentConnId
Nothing -> Nothing
data NewGroupMember = NewGroupMember
{ memInfo :: MemberInfo,
memCategory :: GroupMemberCategory,
memStatus :: GroupMemberStatus,
memInvitedBy :: InvitedBy,
localDisplayName :: ContactName,
memProfileId :: Int64,
memContactId :: Maybe Int64
}
type MemberId = ByteString
data InvitedBy = IBContact Int64 | IBUser | IBUnknown
deriving (Eq, Show)
toInvitedBy :: Int64 -> Maybe Int64 -> InvitedBy
toInvitedBy userCtId (Just ctId)
| userCtId == ctId = IBUser
| otherwise = IBContact ctId
toInvitedBy _ Nothing = IBUnknown
fromInvitedBy :: Int64 -> InvitedBy -> Maybe Int64
fromInvitedBy userCtId = \case
IBUnknown -> Nothing
IBContact ctId -> Just ctId
IBUser -> Just userCtId
data GroupMemberRole = GRMember | GRAdmin | GROwner
deriving (Eq, Show, Ord)
instance FromField GroupMemberRole where fromField = fromBlobField_ toMemberRole
instance ToField GroupMemberRole where toField = toField . serializeMemberRole
toMemberRole :: ByteString -> Either String GroupMemberRole
toMemberRole = \case
"owner" -> Right GROwner
"admin" -> Right GRAdmin
"member" -> Right GRMember
r -> Left $ "invalid group member role " <> B.unpack r
serializeMemberRole :: GroupMemberRole -> ByteString
serializeMemberRole = \case
GROwner -> "owner"
GRAdmin -> "admin"
GRMember -> "member"
fromBlobField_ :: Typeable k => (ByteString -> Either String k) -> FieldParser k
fromBlobField_ p = \case
f@(Field (SQLBlob b) _) ->
case p b of
Right k -> Ok k
Left e -> returnError ConversionFailed f ("could not parse field: " ++ e)
f -> returnError ConversionFailed f "expecting SQLBlob column type"
data GroupMemberCategory
= GCUserMember
| GCInviteeMember -- member invited by the user
| GCHostMember -- member who invited the user
| GCPreMember -- member who joined before the user and was introduced to the user (user receives x.grp.mem.intro about such members)
| GCPostMember -- member who joined after the user to whom the user was introduced (user receives x.grp.mem.new announcing these members and then x.grp.mem.fwd with invitation from these members)
deriving (Eq, Show)
instance FromField GroupMemberCategory where fromField = fromTextField_ memberCategoryT
instance ToField GroupMemberCategory where toField = toField . serializeMemberCategory
memberCategoryT :: Text -> Maybe GroupMemberCategory
memberCategoryT = \case
"user" -> Just GCUserMember
"invitee" -> Just GCInviteeMember
"host" -> Just GCHostMember
"pre" -> Just GCPreMember
"post" -> Just GCPostMember
_ -> Nothing
serializeMemberCategory :: GroupMemberCategory -> Text
serializeMemberCategory = \case
GCUserMember -> "user"
GCInviteeMember -> "invitee"
GCHostMember -> "host"
GCPreMember -> "pre"
GCPostMember -> "post"
data GroupMemberStatus
= GSMemRemoved -- member who was removed from the group
| GSMemLeft -- member who left the group
| GSMemGroupDeleted -- user member of the deleted group
| GSMemInvited -- member is sent to or received invitation to join the group
| GSMemIntroduced -- user received x.grp.mem.intro for this member (only with GCPreMember)
| GSMemIntroInvited -- member is sent to or received from intro invitation
| GSMemAccepted -- member accepted invitation (only User and Invitee)
| GSMemAnnounced -- host announced (x.grp.mem.new) a member (Invitee and PostMember) to the group - at this point this member can send messages and invite other members (if they have sufficient permissions)
| GSMemConnected -- member created the group connection with the inviting member
| GSMemComplete -- host confirmed (x.grp.mem.all) that a member (User, Invitee and PostMember) created group connections with all previous members
| GSMemCreator -- user member that created the group (only GCUserMember)
deriving (Eq, Show, Ord)
instance FromField GroupMemberStatus where fromField = fromTextField_ memberStatusT
instance ToField GroupMemberStatus where toField = toField . serializeMemberStatus
memberActive :: GroupMember -> Bool
memberActive m = case memberStatus m of
GSMemRemoved -> False
GSMemLeft -> False
GSMemGroupDeleted -> False
GSMemInvited -> False
GSMemIntroduced -> False
GSMemIntroInvited -> False
GSMemAccepted -> False
GSMemAnnounced -> False
GSMemConnected -> True
GSMemComplete -> True
GSMemCreator -> True
memberCurrent :: GroupMember -> Bool
memberCurrent m = case memberStatus m of
GSMemRemoved -> False
GSMemLeft -> False
GSMemGroupDeleted -> False
GSMemInvited -> False
GSMemIntroduced -> True
GSMemIntroInvited -> True
GSMemAccepted -> True
GSMemAnnounced -> True
GSMemConnected -> True
GSMemComplete -> True
GSMemCreator -> True
memberStatusT :: Text -> Maybe GroupMemberStatus
memberStatusT = \case
"removed" -> Just GSMemRemoved
"left" -> Just GSMemLeft
"deleted" -> Just GSMemGroupDeleted
"invited" -> Just GSMemInvited
"introduced" -> Just GSMemIntroduced
"intro-inv" -> Just GSMemIntroInvited
"accepted" -> Just GSMemAccepted
"announced" -> Just GSMemAnnounced
"connected" -> Just GSMemConnected
"complete" -> Just GSMemComplete
"creator" -> Just GSMemCreator
_ -> Nothing
serializeMemberStatus :: GroupMemberStatus -> Text
serializeMemberStatus = \case
GSMemRemoved -> "removed"
GSMemLeft -> "left"
GSMemGroupDeleted -> "deleted"
GSMemInvited -> "invited"
GSMemIntroduced -> "introduced"
GSMemIntroInvited -> "intro-inv"
GSMemAccepted -> "accepted"
GSMemAnnounced -> "announced"
GSMemConnected -> "connected"
GSMemComplete -> "complete"
GSMemCreator -> "creator"
data SndFileTransfer = SndFileTransfer
{ fileId :: Int64,
fileName :: String,
filePath :: String,
fileSize :: Integer,
chunkSize :: Integer,
recipientDisplayName :: ContactName,
connId :: Int64,
agentConnId :: ConnId,
fileStatus :: FileStatus
}
deriving (Eq, Show)
data FileInvitation = FileInvitation
{ fileName :: String,
fileSize :: Integer,
fileQInfo :: SMPQueueInfo
}
deriving (Eq, Show)
data RcvFileTransfer = RcvFileTransfer
{ fileId :: Int64,
fileInvitation :: FileInvitation,
fileStatus :: RcvFileStatus,
senderDisplayName :: ContactName,
chunkSize :: Integer
}
deriving (Eq, Show)
data RcvFileStatus
= RFSNew
| RFSAccepted RcvFileInfo
| RFSConnected RcvFileInfo
| RFSComplete RcvFileInfo
| RFSCancelled RcvFileInfo
deriving (Eq, Show)
data RcvFileInfo = RcvFileInfo
{ filePath :: FilePath,
connId :: Int64,
agentConnId :: ConnId
}
deriving (Eq, Show)
data FileTransfer = FTSnd [SndFileTransfer] | FTRcv RcvFileTransfer
data FileStatus = FSNew | FSAccepted | FSConnected | FSComplete | FSCancelled deriving (Eq, Ord, Show)
instance FromField FileStatus where fromField = fromTextField_ fileStatusT
instance ToField FileStatus where toField = toField . serializeFileStatus
fileStatusT :: Text -> Maybe FileStatus
fileStatusT = \case
"new" -> Just FSNew
"accepted" -> Just FSAccepted
"connected" -> Just FSConnected
"complete" -> Just FSComplete
"cancelled" -> Just FSCancelled
_ -> Nothing
serializeFileStatus :: FileStatus -> Text
serializeFileStatus = \case
FSNew -> "new"
FSAccepted -> "accepted"
FSConnected -> "connected"
FSComplete -> "complete"
FSCancelled -> "cancelled"
data RcvChunkStatus = RcvChunkOk | RcvChunkFinal | RcvChunkDuplicate | RcvChunkError
deriving (Eq, Show)
data Connection = Connection
{ connId :: Int64,
agentConnId :: ConnId,
connLevel :: Int,
viaContact :: Maybe Int64,
connType :: ConnType,
connStatus :: ConnStatus,
entityId :: Maybe Int64, -- contact, group member or file ID
createdAt :: UTCTime
}
deriving (Eq, Show)
data ConnStatus
= -- | connection is created by initiating party with agent NEW command (createConnection)
ConnNew
| -- | connection is joined by joining party with agent JOIN command (joinConnection)
ConnJoined
| -- | initiating party received CONF notification (to be renamed to REQ)
ConnRequested
| -- | initiating party accepted connection with agent LET command (to be renamed to ACPT) (allowConnection)
ConnAccepted
| -- | connection can be sent messages to (after joining party received INFO notification)
ConnSndReady
| -- | connection is ready for both parties to send and receive messages
ConnReady
| -- | connection deleted
ConnDeleted
deriving (Eq, Show)
instance FromField ConnStatus where fromField = fromTextField_ connStatusT
instance ToField ConnStatus where toField = toField . serializeConnStatus
connStatusT :: Text -> Maybe ConnStatus
connStatusT = \case
"new" -> Just ConnNew
"joined" -> Just ConnJoined
"requested" -> Just ConnRequested
"accepted" -> Just ConnAccepted
"snd-ready" -> Just ConnSndReady
"ready" -> Just ConnReady
"deleted" -> Just ConnDeleted
_ -> Nothing
serializeConnStatus :: ConnStatus -> Text
serializeConnStatus = \case
ConnNew -> "new"
ConnJoined -> "joined"
ConnRequested -> "requested"
ConnAccepted -> "accepted"
ConnSndReady -> "snd-ready"
ConnReady -> "ready"
ConnDeleted -> "deleted"
data ConnType = ConnContact | ConnMember | ConnSndFile | ConnRcvFile
deriving (Eq, Show)
instance FromField ConnType where fromField = fromTextField_ connTypeT
instance ToField ConnType where toField = toField . serializeConnType
connTypeT :: Text -> Maybe ConnType
connTypeT = \case
"contact" -> Just ConnContact
"member" -> Just ConnMember
"snd_file" -> Just ConnSndFile
"rcv_file" -> Just ConnRcvFile
_ -> Nothing
serializeConnType :: ConnType -> Text
serializeConnType = \case
ConnContact -> "contact"
ConnMember -> "member"
ConnSndFile -> "snd_file"
ConnRcvFile -> "rcv_file"
data NewConnection = NewConnection
{ agentConnId :: ByteString,
connLevel :: Int,
viaConn :: Maybe Int64
}
data GroupMemberIntro = GroupMemberIntro
{ introId :: Int64,
reMember :: GroupMember,
toMember :: GroupMember,
introStatus :: GroupMemberIntroStatus,
introInvitation :: Maybe IntroInvitation
}
data GroupMemberIntroStatus
= GMIntroPending
| GMIntroSent
| GMIntroInvReceived
| GMIntroInvForwarded
| GMIntroReConnected
| GMIntroToConnected
| GMIntroConnected
instance FromField GroupMemberIntroStatus where fromField = fromTextField_ introStatusT
instance ToField GroupMemberIntroStatus where toField = toField . serializeIntroStatus
introStatusT :: Text -> Maybe GroupMemberIntroStatus
introStatusT = \case
"new" -> Just GMIntroPending
"sent" -> Just GMIntroSent
"rcv" -> Just GMIntroInvReceived
"fwd" -> Just GMIntroInvForwarded
"re-con" -> Just GMIntroReConnected
"to-con" -> Just GMIntroToConnected
"con" -> Just GMIntroConnected
_ -> Nothing
serializeIntroStatus :: GroupMemberIntroStatus -> Text
serializeIntroStatus = \case
GMIntroPending -> "new"
GMIntroSent -> "sent"
GMIntroInvReceived -> "rcv"
GMIntroInvForwarded -> "fwd"
GMIntroReConnected -> "re-con"
GMIntroToConnected -> "to-con"
GMIntroConnected -> "con"
+16
View File
@@ -0,0 +1,16 @@
module Simplex.Chat.Util where
import Data.ByteString.Char8 (ByteString)
import Data.Text (Text)
import Data.Text.Encoding (decodeUtf8With)
safeDecodeUtf8 :: ByteString -> Text
safeDecodeUtf8 = decodeUtf8With onError
where
onError _ _ = Just '?'
ifM :: Monad m => m Bool -> m a -> m a -> m a
ifM ba t f = ba >>= \b -> if b then t else f
unlessM :: Monad m => m Bool -> m () -> m ()
unlessM b = ifM b $ pure ()
+687
View File
@@ -0,0 +1,687 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module Simplex.Chat.View
( printToView,
showInvitation,
showChatError,
showContactDeleted,
showContactGroups,
showContactConnected,
showContactDisconnected,
showContactAnotherClient,
showContactSubscribed,
showContactSubError,
showGroupSubscribed,
showGroupEmpty,
showGroupRemoved,
showMemberSubError,
showReceivedMessage,
showReceivedGroupMessage,
showSentMessage,
showSentGroupMessage,
showSentFileInvitation,
showSentGroupFileInvitation,
showSentFileInfo,
showSndFileStart,
showSndFileComplete,
showSndFileCancelled,
showSndGroupFileCancelled,
showSndFileRcvCancelled,
receivedFileInvitation,
showRcvFileAccepted,
showRcvFileStart,
showRcvFileComplete,
showRcvFileCancelled,
showRcvFileSndCancelled,
showFileTransferStatus,
showSndFileSubError,
showRcvFileSubError,
showGroupCreated,
showGroupDeletedUser,
showGroupDeleted,
showSentGroupInvitation,
showReceivedGroupInvitation,
showJoinedGroupMember,
showUserJoinedGroup,
showJoinedGroupMemberConnecting,
showConnectedToGroupMember,
showDeletedMember,
showDeletedMemberUser,
showLeftMemberUser,
showLeftMember,
showGroupMembers,
showContactsMerged,
showUserProfile,
showUserProfileUpdated,
showContactUpdated,
showMessageError,
safeDecodeUtf8,
msgPlain,
)
where
import Control.Monad.IO.Unlift
import Control.Monad.Reader
import Data.ByteString.Char8 (ByteString)
import Data.Composition ((.:), (.:.))
import Data.Function (on)
import Data.Int (Int64)
import Data.List (groupBy, intersperse, sortOn)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Time.Clock (DiffTime, UTCTime)
import Data.Time.Format (defaultTimeLocale, formatTime)
import Data.Time.LocalTime (TimeZone, ZonedTime, getCurrentTimeZone, getZonedTime, localDay, localTimeOfDay, timeOfDayToTime, utcToLocalTime, zonedTimeToLocalTime)
import Numeric (showFFloat)
import Simplex.Chat.Controller
import Simplex.Chat.Markdown
import Simplex.Chat.Store (StoreError (..))
import Simplex.Chat.Styled
import Simplex.Chat.Terminal (printToTerminal)
import Simplex.Chat.Types
import Simplex.Chat.Util (safeDecodeUtf8)
import Simplex.Messaging.Agent.Protocol
import System.Console.ANSI.Types
type ChatReader m = (MonadUnliftIO m, MonadReader ChatController m)
showInvitation :: ChatReader m => SMPQueueInfo -> m ()
showInvitation = printToView . invitation
showChatError :: ChatReader m => ChatError -> m ()
showChatError = printToView . chatError
showContactDeleted :: ChatReader m => ContactName -> m ()
showContactDeleted = printToView . contactDeleted
showContactGroups :: ChatReader m => ContactName -> [GroupName] -> m ()
showContactGroups = printToView .: contactGroups
showContactConnected :: ChatReader m => Contact -> m ()
showContactConnected = printToView . contactConnected
showContactDisconnected :: ChatReader m => ContactName -> m ()
showContactDisconnected = printToView . contactDisconnected
showContactAnotherClient :: ChatReader m => ContactName -> m ()
showContactAnotherClient = printToView . contactAnotherClient
showContactSubscribed :: ChatReader m => ContactName -> m ()
showContactSubscribed = printToView . contactSubscribed
showContactSubError :: ChatReader m => ContactName -> ChatError -> m ()
showContactSubError = printToView .: contactSubError
showGroupSubscribed :: ChatReader m => GroupName -> m ()
showGroupSubscribed = printToView . groupSubscribed
showGroupEmpty :: ChatReader m => GroupName -> m ()
showGroupEmpty = printToView . groupEmpty
showGroupRemoved :: ChatReader m => GroupName -> m ()
showGroupRemoved = printToView . groupRemoved
showMemberSubError :: ChatReader m => GroupName -> ContactName -> ChatError -> m ()
showMemberSubError = printToView .:. memberSubError
showReceivedMessage :: ChatReader m => ContactName -> UTCTime -> [StyledString] -> MsgIntegrity -> m ()
showReceivedMessage = showReceivedMessage_ . ttyFromContact
showReceivedGroupMessage :: ChatReader m => GroupName -> ContactName -> UTCTime -> [StyledString] -> MsgIntegrity -> m ()
showReceivedGroupMessage = showReceivedMessage_ .: ttyFromGroup
showReceivedMessage_ :: ChatReader m => StyledString -> UTCTime -> [StyledString] -> MsgIntegrity -> m ()
showReceivedMessage_ from utcTime msg mOk = printToView =<< liftIO (receivedMessage from utcTime msg mOk)
showSentMessage :: ChatReader m => ContactName -> ByteString -> m ()
showSentMessage = showSentMessage_ . ttyToContact
showSentGroupMessage :: ChatReader m => GroupName -> ByteString -> m ()
showSentGroupMessage = showSentMessage_ . ttyToGroup
showSentMessage_ :: ChatReader m => StyledString -> ByteString -> m ()
showSentMessage_ to msg = printToView =<< liftIO (sentMessage to msg)
showSentFileInvitation :: ChatReader m => ContactName -> FilePath -> m ()
showSentFileInvitation = showSentFileInvitation_ . ttyToContact
showSentGroupFileInvitation :: ChatReader m => GroupName -> FilePath -> m ()
showSentGroupFileInvitation = showSentFileInvitation_ . ttyToGroup
showSentFileInvitation_ :: ChatReader m => StyledString -> FilePath -> m ()
showSentFileInvitation_ to filePath = printToView =<< liftIO (sentFileInvitation to filePath)
showSentFileInfo :: ChatReader m => Int64 -> m ()
showSentFileInfo = printToView . sentFileInfo
showSndFileStart :: ChatReader m => SndFileTransfer -> m ()
showSndFileStart = printToView . sndFileStart
showSndFileComplete :: ChatReader m => SndFileTransfer -> m ()
showSndFileComplete = printToView . sndFileComplete
showSndFileCancelled :: ChatReader m => SndFileTransfer -> m ()
showSndFileCancelled = printToView . sndFileCancelled
showSndGroupFileCancelled :: ChatReader m => [SndFileTransfer] -> m ()
showSndGroupFileCancelled = printToView . sndGroupFileCancelled
showSndFileRcvCancelled :: ChatReader m => SndFileTransfer -> m ()
showSndFileRcvCancelled = printToView . sndFileRcvCancelled
showRcvFileAccepted :: ChatReader m => RcvFileTransfer -> FilePath -> m ()
showRcvFileAccepted = printToView .: rcvFileAccepted
showRcvFileStart :: ChatReader m => RcvFileTransfer -> m ()
showRcvFileStart = printToView . rcvFileStart
showRcvFileComplete :: ChatReader m => RcvFileTransfer -> m ()
showRcvFileComplete = printToView . rcvFileComplete
showRcvFileCancelled :: ChatReader m => RcvFileTransfer -> m ()
showRcvFileCancelled = printToView . rcvFileCancelled
showRcvFileSndCancelled :: ChatReader m => RcvFileTransfer -> m ()
showRcvFileSndCancelled = printToView . rcvFileSndCancelled
showFileTransferStatus :: ChatReader m => (FileTransfer, [Integer]) -> m ()
showFileTransferStatus = printToView . fileTransferStatus
showSndFileSubError :: ChatReader m => SndFileTransfer -> ChatError -> m ()
showSndFileSubError = printToView .: sndFileSubError
showRcvFileSubError :: ChatReader m => RcvFileTransfer -> ChatError -> m ()
showRcvFileSubError = printToView .: rcvFileSubError
showGroupCreated :: ChatReader m => Group -> m ()
showGroupCreated = printToView . groupCreated
showGroupDeletedUser :: ChatReader m => GroupName -> m ()
showGroupDeletedUser = printToView . groupDeletedUser
showGroupDeleted :: ChatReader m => GroupName -> GroupMember -> m ()
showGroupDeleted = printToView .: groupDeleted
showSentGroupInvitation :: ChatReader m => GroupName -> ContactName -> m ()
showSentGroupInvitation = printToView .: sentGroupInvitation
showReceivedGroupInvitation :: ChatReader m => Group -> ContactName -> GroupMemberRole -> m ()
showReceivedGroupInvitation = printToView .:. receivedGroupInvitation
showJoinedGroupMember :: ChatReader m => GroupName -> GroupMember -> m ()
showJoinedGroupMember = printToView .: joinedGroupMember
showUserJoinedGroup :: ChatReader m => GroupName -> m ()
showUserJoinedGroup = printToView . userJoinedGroup
showJoinedGroupMemberConnecting :: ChatReader m => GroupName -> GroupMember -> GroupMember -> m ()
showJoinedGroupMemberConnecting = printToView .:. joinedGroupMemberConnecting
showConnectedToGroupMember :: ChatReader m => GroupName -> GroupMember -> m ()
showConnectedToGroupMember = printToView .: connectedToGroupMember
showDeletedMember :: ChatReader m => GroupName -> Maybe GroupMember -> Maybe GroupMember -> m ()
showDeletedMember = printToView .:. deletedMember
showDeletedMemberUser :: ChatReader m => GroupName -> GroupMember -> m ()
showDeletedMemberUser = printToView .: deletedMemberUser
showLeftMemberUser :: ChatReader m => GroupName -> m ()
showLeftMemberUser = printToView . leftMemberUser
showLeftMember :: ChatReader m => GroupName -> GroupMember -> m ()
showLeftMember = printToView .: leftMember
showGroupMembers :: ChatReader m => Group -> m ()
showGroupMembers = printToView . groupMembers
showContactsMerged :: ChatReader m => Contact -> Contact -> m ()
showContactsMerged = printToView .: contactsMerged
showUserProfile :: ChatReader m => Profile -> m ()
showUserProfile = printToView . userProfile
showUserProfileUpdated :: ChatReader m => User -> User -> m ()
showUserProfileUpdated = printToView .: userProfileUpdated
showContactUpdated :: ChatReader m => Contact -> Contact -> m ()
showContactUpdated = printToView .: contactUpdated
showMessageError :: ChatReader m => Text -> Text -> m ()
showMessageError = printToView .: messageError
invitation :: SMPQueueInfo -> [StyledString]
invitation qInfo =
[ "pass this invitation to your contact (via another channel): ",
"",
(plain . serializeSmpQueueInfo) qInfo,
"",
"and ask them to connect: " <> highlight' "/c <invitation_above>"
]
contactDeleted :: ContactName -> [StyledString]
contactDeleted c = [ttyContact c <> ": contact is deleted"]
contactGroups :: ContactName -> [GroupName] -> [StyledString]
contactGroups c gNames = [ttyContact c <> ": contact cannot be deleted, it is a member of the group(s) " <> ttyGroups gNames]
where
ttyGroups :: [GroupName] -> StyledString
ttyGroups [] = ""
ttyGroups [g] = ttyGroup g
ttyGroups (g : gs) = ttyGroup g <> ", " <> ttyGroups gs
contactConnected :: Contact -> [StyledString]
contactConnected ct = [ttyFullContact ct <> ": contact is connected"]
contactDisconnected :: ContactName -> [StyledString]
contactDisconnected c = [ttyContact c <> ": disconnected from server (messages will be queued)"]
contactAnotherClient :: ContactName -> [StyledString]
contactAnotherClient c = [ttyContact c <> ": contact is connected to another client"]
contactSubscribed :: ContactName -> [StyledString]
contactSubscribed c = [ttyContact c <> ": connected to server"]
contactSubError :: ContactName -> ChatError -> [StyledString]
contactSubError c e = [ttyContact c <> ": contact error " <> sShow e]
groupSubscribed :: GroupName -> [StyledString]
groupSubscribed g = [ttyGroup g <> ": connected to server(s)"]
groupEmpty :: GroupName -> [StyledString]
groupEmpty g = [ttyGroup g <> ": group is empty"]
groupRemoved :: GroupName -> [StyledString]
groupRemoved g = [ttyGroup g <> ": you are no longer a member or group deleted"]
memberSubError :: GroupName -> ContactName -> ChatError -> [StyledString]
memberSubError g c e = [ttyGroup g <> " member " <> ttyContact c <> " error: " <> sShow e]
groupCreated :: Group -> [StyledString]
groupCreated g@Group {localDisplayName} =
[ "group " <> ttyFullGroup g <> " is created",
"use " <> highlight ("/a " <> localDisplayName <> " <name>") <> " to add members"
]
groupDeletedUser :: GroupName -> [StyledString]
groupDeletedUser g = groupDeleted_ g Nothing
groupDeleted :: GroupName -> GroupMember -> [StyledString]
groupDeleted g m = groupDeleted_ g (Just m) <> ["use " <> highlight ("/d #" <> g) <> " to delete the local copy of the group"]
groupDeleted_ :: GroupName -> Maybe GroupMember -> [StyledString]
groupDeleted_ g m = [ttyGroup g <> ": " <> memberOrUser m <> " deleted the group"]
sentGroupInvitation :: GroupName -> ContactName -> [StyledString]
sentGroupInvitation g c = ["invitation to join the group " <> ttyGroup g <> " sent to " <> ttyContact c]
receivedGroupInvitation :: Group -> ContactName -> GroupMemberRole -> [StyledString]
receivedGroupInvitation g@Group {localDisplayName} c role =
[ ttyFullGroup g <> ": " <> ttyContact c <> " invites you to join the group as " <> plain (serializeMemberRole role),
"use " <> highlight ("/j " <> localDisplayName) <> " to accept"
]
joinedGroupMember :: GroupName -> GroupMember -> [StyledString]
joinedGroupMember g m = [ttyGroup g <> ": " <> ttyMember m <> " joined the group "]
userJoinedGroup :: GroupName -> [StyledString]
userJoinedGroup g = [ttyGroup g <> ": you joined the group"]
joinedGroupMemberConnecting :: GroupName -> GroupMember -> GroupMember -> [StyledString]
joinedGroupMemberConnecting g host m = [ttyGroup g <> ": " <> ttyMember host <> " added " <> ttyFullMember m <> " to the group (connecting...)"]
connectedToGroupMember :: GroupName -> GroupMember -> [StyledString]
connectedToGroupMember g m = [ttyGroup g <> ": " <> connectedMember m <> " is connected"]
deletedMember :: GroupName -> Maybe GroupMember -> Maybe GroupMember -> [StyledString]
deletedMember g by m = [ttyGroup g <> ": " <> memberOrUser by <> " removed " <> memberOrUser m <> " from the group"]
deletedMemberUser :: GroupName -> GroupMember -> [StyledString]
deletedMemberUser g by = deletedMember g (Just by) Nothing <> groupPreserved g
leftMemberUser :: GroupName -> [StyledString]
leftMemberUser g = leftMember_ g Nothing <> groupPreserved g
leftMember :: GroupName -> GroupMember -> [StyledString]
leftMember g m = leftMember_ g (Just m)
leftMember_ :: GroupName -> Maybe GroupMember -> [StyledString]
leftMember_ g m = [ttyGroup g <> ": " <> memberOrUser m <> " left the group"]
groupPreserved :: GroupName -> [StyledString]
groupPreserved g = ["use " <> highlight ("/d #" <> g) <> " to delete the group"]
memberOrUser :: Maybe GroupMember -> StyledString
memberOrUser = maybe "you" ttyMember
connectedMember :: GroupMember -> StyledString
connectedMember m = case memberCategory m of
GCPreMember -> "member " <> ttyFullMember m
GCPostMember -> "new member " <> ttyMember m -- without fullName as as it was shown in joinedGroupMemberConnecting
_ -> "member " <> ttyMember m -- these case is not used
groupMembers :: Group -> [StyledString]
groupMembers Group {membership, members} = map groupMember . filter (not . removedOrLeft) $ membership : members
where
removedOrLeft m = let s = memberStatus m in s == GSMemRemoved || s == GSMemLeft
groupMember m = ttyFullMember m <> ": " <> role m <> ", " <> category m <> status m
role = plain . serializeMemberRole . memberRole
category m = case memberCategory m of
GCUserMember -> "you, "
GCInviteeMember -> "invited, "
GCHostMember -> "host, "
_ -> ""
status m = case memberStatus m of
GSMemRemoved -> "removed"
GSMemLeft -> "left"
GSMemInvited -> "not yet joined"
GSMemConnected -> "connected"
GSMemComplete -> "connected"
GSMemCreator -> "created group"
_ -> ""
contactsMerged :: Contact -> Contact -> [StyledString]
contactsMerged _to@Contact {localDisplayName = c1} _from@Contact {localDisplayName = c2} =
[ "contact " <> ttyContact c2 <> " is merged into " <> ttyContact c1,
"use " <> ttyToContact c1 <> highlight' "<message>" <> " to send messages"
]
userProfile :: Profile -> [StyledString]
userProfile Profile {displayName, fullName} =
[ "user profile: " <> ttyFullName displayName fullName,
"use " <> highlight' "/p <display name> [<full name>]" <> " to change it",
"(the updated profile will be sent to all your contacts)"
]
userProfileUpdated :: User -> User -> [StyledString]
userProfileUpdated
User {localDisplayName = n, profile = Profile {fullName}}
User {localDisplayName = n', profile = Profile {fullName = fullName'}}
| n == n' && fullName == fullName' = []
| n == n' = ["user full name " <> (if T.null fullName' || fullName' == n' then "removed" else "changed to " <> plain fullName') <> notified]
| otherwise = ["user profile is changed to " <> ttyFullName n' fullName' <> notified]
where
notified = " (your contacts are notified)"
contactUpdated :: Contact -> Contact -> [StyledString]
contactUpdated
Contact {localDisplayName = n, profile = Profile {fullName}}
Contact {localDisplayName = n', profile = Profile {fullName = fullName'}}
| n == n' && fullName == fullName' = []
| n == n' = ["contact " <> ttyContact n <> fullNameUpdate]
| otherwise =
[ "contact " <> ttyContact n <> " changed to " <> ttyFullName n' fullName',
"use " <> ttyToContact n' <> highlight' "<message>" <> " to send messages"
]
where
fullNameUpdate = if T.null fullName' || fullName' == n' then " removed full name" else " updated full name: " <> plain fullName'
messageError :: Text -> Text -> [StyledString]
messageError prefix err = [plain prefix <> ": " <> plain err]
receivedMessage :: StyledString -> UTCTime -> [StyledString] -> MsgIntegrity -> IO [StyledString]
receivedMessage from utcTime msg mOk = do
t <- formatUTCTime <$> getCurrentTimeZone <*> getZonedTime
pure $ prependFirst (t <> " " <> from) msg ++ showIntegrity mOk
where
formatUTCTime :: TimeZone -> ZonedTime -> StyledString
formatUTCTime localTz currentTime =
let localTime = utcToLocalTime localTz utcTime
format =
if (localDay localTime < localDay (zonedTimeToLocalTime currentTime))
&& (timeOfDayToTime (localTimeOfDay localTime) > (6 * 60 * 60 :: DiffTime))
then "%m-%d" -- if message is from yesterday or before and 6 hours has passed since midnight
else "%H:%M"
in styleTime $ formatTime defaultTimeLocale format localTime
showIntegrity :: MsgIntegrity -> [StyledString]
showIntegrity MsgOk = []
showIntegrity (MsgError err) = msgError $ case err of
MsgSkipped fromId toId ->
"skipped message ID " <> show fromId
<> if fromId == toId then "" else ".." <> show toId
MsgBadId msgId -> "unexpected message ID " <> show msgId
MsgBadHash -> "incorrect message hash"
MsgDuplicate -> "duplicate message ID"
msgError :: String -> [StyledString]
msgError s = [styled (Colored Red) s]
sentMessage :: StyledString -> ByteString -> IO [StyledString]
sentMessage to msg = sendWithTime_ to . msgPlain $ safeDecodeUtf8 msg
sentFileInvitation :: StyledString -> FilePath -> IO [StyledString]
sentFileInvitation to f = sendWithTime_ ("/f " <> to) [ttyFilePath f]
sendWithTime_ :: StyledString -> [StyledString] -> IO [StyledString]
sendWithTime_ to styledMsg = do
time <- formatTime defaultTimeLocale "%H:%M" <$> getZonedTime
pure $ prependFirst (styleTime time <> " " <> to) styledMsg
prependFirst :: StyledString -> [StyledString] -> [StyledString]
prependFirst s [] = [s]
prependFirst s (s' : ss) = (s <> s') : ss
msgPlain :: Text -> [StyledString]
msgPlain = map styleMarkdownText . T.lines
sentFileInfo :: Int64 -> [StyledString]
sentFileInfo fileId =
["use " <> highlight ("/fc " <> show fileId) <> " to cancel sending"]
sndFileStart :: SndFileTransfer -> [StyledString]
sndFileStart = sendingFile_ "started"
sndFileComplete :: SndFileTransfer -> [StyledString]
sndFileComplete = sendingFile_ "completed"
sndFileCancelled :: SndFileTransfer -> [StyledString]
sndFileCancelled = sendingFile_ "cancelled"
sndGroupFileCancelled :: [SndFileTransfer] -> [StyledString]
sndGroupFileCancelled fts =
case filter (\SndFileTransfer {fileStatus = s} -> s /= FSCancelled && s /= FSComplete) fts of
[] -> ["sending file can't be cancelled"]
ts@(ft : _) -> ["cancelled sending " <> sndFile ft <> " to " <> listMembers ts]
sendingFile_ :: StyledString -> SndFileTransfer -> [StyledString]
sendingFile_ status ft@SndFileTransfer {recipientDisplayName = c} =
[status <> " sending " <> sndFile ft <> " to " <> ttyContact c]
sndFileRcvCancelled :: SndFileTransfer -> [StyledString]
sndFileRcvCancelled ft@SndFileTransfer {recipientDisplayName = c} =
[ttyContact c <> " cancelled receiving " <> sndFile ft]
sndFile :: SndFileTransfer -> StyledString
sndFile SndFileTransfer {fileId, fileName} = fileTransfer fileId fileName
receivedFileInvitation :: RcvFileTransfer -> [StyledString]
receivedFileInvitation RcvFileTransfer {fileId, fileInvitation = FileInvitation {fileName, fileSize}} =
[ "sends file " <> ttyFilePath fileName <> " (" <> humanReadableSize fileSize <> " / " <> sShow fileSize <> " bytes)",
"use " <> highlight ("/fr " <> show fileId <> " [<dir>/ | <path>]") <> " to receive it"
]
humanReadableSize :: Integer -> StyledString
humanReadableSize size
| size < kB = sShow size <> " bytes"
| size < mB = hrSize kB "KiB"
| size < gB = hrSize mB "MiB"
| otherwise = hrSize gB "GiB"
where
hrSize sB name = plain $ unwords [showFFloat (Just 1) (fromIntegral size / (fromIntegral sB :: Double)) "", name]
kB = 1024
mB = kB * 1024
gB = mB * 1024
rcvFileAccepted :: RcvFileTransfer -> FilePath -> [StyledString]
rcvFileAccepted RcvFileTransfer {fileId, senderDisplayName = c} filePath =
["saving file " <> sShow fileId <> " from " <> ttyContact c <> " to " <> plain filePath]
rcvFileStart :: RcvFileTransfer -> [StyledString]
rcvFileStart = receivingFile_ "started"
rcvFileComplete :: RcvFileTransfer -> [StyledString]
rcvFileComplete = receivingFile_ "completed"
rcvFileCancelled :: RcvFileTransfer -> [StyledString]
rcvFileCancelled = receivingFile_ "cancelled"
receivingFile_ :: StyledString -> RcvFileTransfer -> [StyledString]
receivingFile_ status ft@RcvFileTransfer {senderDisplayName = c} =
[status <> " receiving " <> rcvFile ft <> " from " <> ttyContact c]
rcvFileSndCancelled :: RcvFileTransfer -> [StyledString]
rcvFileSndCancelled ft@RcvFileTransfer {senderDisplayName = c} =
[ttyContact c <> " cancelled sending " <> rcvFile ft]
rcvFile :: RcvFileTransfer -> StyledString
rcvFile RcvFileTransfer {fileId, fileInvitation = FileInvitation {fileName}} = fileTransfer fileId fileName
fileTransfer :: Int64 -> String -> StyledString
fileTransfer fileId fileName = "file " <> sShow fileId <> " (" <> ttyFilePath fileName <> ")"
fileTransferStatus :: (FileTransfer, [Integer]) -> [StyledString]
fileTransferStatus (FTSnd [ft@SndFileTransfer {fileStatus, fileSize, chunkSize}], chunksNum) =
["sending " <> sndFile ft <> " " <> sndStatus]
where
sndStatus = case fileStatus of
FSNew -> "not accepted yet"
FSAccepted -> "just started"
FSConnected -> "progress " <> fileProgress chunksNum chunkSize fileSize
FSComplete -> "complete"
FSCancelled -> "cancelled"
fileTransferStatus (FTSnd [], _) = ["no file transfers (empty group)"]
fileTransferStatus (FTSnd fts@(ft : _), chunksNum) =
case concatMap membersTransferStatus $ groupBy ((==) `on` fs) $ sortOn fs fts of
[membersStatus] -> ["sending " <> sndFile ft <> " " <> membersStatus]
membersStatuses -> ("sending " <> sndFile ft <> ": ") : map (" " <>) membersStatuses
where
fs = fileStatus :: SndFileTransfer -> FileStatus
membersTransferStatus [] = []
membersTransferStatus ts@(SndFileTransfer {fileStatus, fileSize, chunkSize} : _) = [sndStatus <> ": " <> listMembers ts]
where
sndStatus = case fileStatus of
FSNew -> "not accepted"
FSAccepted -> "just started"
FSConnected -> "in progress (" <> sShow (sum chunksNum * chunkSize * 100 `div` (toInteger (length chunksNum) * fileSize)) <> "%)"
FSComplete -> "complete"
FSCancelled -> "cancelled"
fileTransferStatus (FTRcv ft@RcvFileTransfer {fileId, fileInvitation = FileInvitation {fileSize}, fileStatus, chunkSize}, chunksNum) =
["receiving " <> rcvFile ft <> " " <> rcvStatus]
where
rcvStatus = case fileStatus of
RFSNew -> "not accepted yet, use " <> highlight ("/fr " <> show fileId) <> " to receive file"
RFSAccepted _ -> "just started"
RFSConnected _ -> "progress " <> fileProgress chunksNum chunkSize fileSize
RFSComplete RcvFileInfo {filePath} -> "complete, path: " <> plain filePath
RFSCancelled RcvFileInfo {filePath} -> "cancelled, received part path: " <> plain filePath
listMembers :: [SndFileTransfer] -> StyledString
listMembers = mconcat . intersperse ", " . map (ttyContact . recipientDisplayName)
fileProgress :: [Integer] -> Integer -> Integer -> StyledString
fileProgress chunksNum chunkSize fileSize =
sShow (sum chunksNum * chunkSize * 100 `div` fileSize) <> "% of " <> humanReadableSize fileSize
sndFileSubError :: SndFileTransfer -> ChatError -> [StyledString]
sndFileSubError SndFileTransfer {fileId, fileName} e =
["sent file " <> sShow fileId <> " (" <> plain fileName <> ") error: " <> sShow e]
rcvFileSubError :: RcvFileTransfer -> ChatError -> [StyledString]
rcvFileSubError RcvFileTransfer {fileId, fileInvitation = FileInvitation {fileName}} e =
["received file " <> sShow fileId <> " (" <> plain fileName <> ") error: " <> sShow e]
chatError :: ChatError -> [StyledString]
chatError = \case
ChatError err -> case err of
CEGroupDuplicateMember c -> ["contact " <> ttyContact c <> " is already in the group"]
CEGroupDuplicateMemberId -> ["cannot add member - duplicate member ID"]
CEGroupUserRole -> ["you have insufficient permissions for this group command"]
CEGroupContactRole c -> ["contact " <> ttyContact c <> " has insufficient permissions for this group action"]
CEGroupNotJoined g -> ["you did not join this group, use " <> highlight ("/join #" <> g)]
CEGroupMemberNotActive -> ["you cannot invite other members yet, try later"]
CEGroupMemberUserRemoved -> ["you are no longer the member of the group"]
CEGroupMemberNotFound c -> ["contact " <> ttyContact c <> " is not a group member"]
CEGroupInternal s -> ["chat group bug: " <> plain s]
CEFileNotFound f -> ["file not found: " <> plain f]
CEFileAlreadyReceiving f -> ["file is already accepted: " <> plain f]
CEFileAlreadyExists f -> ["file already exists: " <> plain f]
CEFileRead f e -> ["cannot read file " <> plain f, sShow e]
CEFileWrite f e -> ["cannot write file " <> plain f, sShow e]
CEFileSend fileId e -> ["error sending file " <> sShow fileId <> ": " <> sShow e]
CEFileRcvChunk e -> ["error receiving file: " <> plain e]
CEFileInternal e -> ["file error: " <> plain e]
-- e -> ["chat error: " <> sShow e]
ChatErrorStore err -> case err of
SEDuplicateName -> ["this display name is already used by user, contact or group"]
SEContactNotFound c -> ["no contact " <> ttyContact c]
SEContactNotReady c -> ["contact " <> ttyContact c <> " is not active yet"]
SEGroupNotFound g -> ["no group " <> ttyGroup g]
SEGroupAlreadyJoined -> ["you already joined this group"]
SEFileNotFound fileId -> fileNotFound fileId
SESndFileNotFound fileId -> fileNotFound fileId
SERcvFileNotFound fileId -> fileNotFound fileId
e -> ["chat db error: " <> sShow e]
ChatErrorAgent e -> ["smp agent error: " <> sShow e]
ChatErrorMessage e -> ["chat message error: " <> sShow e]
where
fileNotFound fileId = ["file " <> sShow fileId <> " not found"]
printToView :: (MonadUnliftIO m, MonadReader ChatController m) => [StyledString] -> m ()
printToView s = asks chatTerminal >>= liftIO . (`printToTerminal` s)
ttyContact :: ContactName -> StyledString
ttyContact = styled (Colored Green)
ttyFullContact :: Contact -> StyledString
ttyFullContact Contact {localDisplayName, profile = Profile {fullName}} =
ttyFullName localDisplayName fullName
ttyMember :: GroupMember -> StyledString
ttyMember GroupMember {localDisplayName} = ttyContact localDisplayName
ttyFullMember :: GroupMember -> StyledString
ttyFullMember GroupMember {localDisplayName, memberProfile = Profile {fullName}} =
ttyFullName localDisplayName fullName
ttyFullName :: ContactName -> Text -> StyledString
ttyFullName c fullName = ttyContact c <> optFullName c fullName
ttyToContact :: ContactName -> StyledString
ttyToContact c = styled (Colored Cyan) $ "@" <> c <> " "
ttyFromContact :: ContactName -> StyledString
ttyFromContact c = styled (Colored Yellow) $ c <> "> "
ttyGroup :: GroupName -> StyledString
ttyGroup g = styled (Colored Blue) $ "#" <> g
ttyFullGroup :: Group -> StyledString
ttyFullGroup Group {localDisplayName, groupProfile = GroupProfile {fullName}} =
ttyGroup localDisplayName <> optFullName localDisplayName fullName
ttyFromGroup :: GroupName -> ContactName -> StyledString
ttyFromGroup g c = styled (Colored Yellow) $ "#" <> g <> " " <> c <> "> "
ttyToGroup :: GroupName -> StyledString
ttyToGroup g = styled (Colored Cyan) $ "#" <> g <> " "
ttyFilePath :: FilePath -> StyledString
ttyFilePath = plain
optFullName :: ContactName -> Text -> StyledString
optFullName localDisplayName fullName
| T.null fullName || localDisplayName == fullName = ""
| otherwise = plain (" (" <> fullName <> ")")
highlight :: StyledFormat a => a -> StyledString
highlight = styled (Colored Cyan)
highlight' :: String -> StyledString
highlight' = highlight
styleTime :: String -> StyledString
styleTime = Styled [SetColor Foreground Vivid Black]
+168
View File
@@ -0,0 +1,168 @@
# Chat protocol
## Design constraints
- the transport message has a fixed size (8 or 16kb), but the SMP agent will be updated to support sending messages up to maximum configured size (TBC - 64-256kb) in 8-16Kb blocks.
- the chat message can have multiple content parts, but it should fit the agent message of the variable size.
- one of the chat message types should support transmitting large binaries in chunks that could potentially be interleaved with other messages. For example, image preview would fit the message, but the full size image will be transmitted in chunks later - same for large files.
- using object storage can be effective for large groups, but we will postpone it until content channels are implemented.
## Questions
- should content types be:
- limited to MIME-types
- separate content types vocabulary
- both MIME types and extensions (currently we support MIME (m.) and Simplex (x.) namespaces)
- allow additional content types namespaces
## Message syntax
The syntax of the message inside agent MSG:
```abnf
agentMessageBody = [chatMsgId] SP msgEvent SP [parameters] SP [contentParts [SP msgBodyParts]]
chatMsgId = 1*DIGIT ; used to refer to previous message;
; in the group should only be used in messages sent to all members,
; which is the main reason not to use external agent ID -
; some messages are sent only to one member
msgEvent = protocolNamespace 1*("." msgTypeName)
protocolNamespace = 1*ALPHA ; "x" for all events defined in the protocol
msgTypeName = 1*ALPHA
parameters = parameter *("," parameter)
parameter = 1*(%x21-2B / %x2D-7E) ; exclude control characters, space, comma (%x2C)
contentParts = contentPart *("," contentPart)
contentPart = contentTypeNamespace "." contentType ":" contentSize [":" contentHash]
contentType = "i." <mime-type> / contentTypeNamespace "." 1*("." contentTypeName)
contentTypeNamespace = 1*ALPHA
contentTypeName = 1*ALPHA
contentHash = <base64>
msgBodyParts = msgBodyPart *(SP msgBodyPart)
msgEventParents = msgEventParent *msgEventParent ; binary body part for content type "x.dag"
msgEventParent = memberId refMsgId refMsgHash
memberId = 8*8(OCTET) ; shared member ID
refMsgId = 8*8(OCTET) ; sequential message number - external agent message ID
refMsgHash = 16*16(OCTET) ; SHA256 of agent message body
```
### Example: messages, updates, groups
```
"3 x.msg.new c.text x.text:5 hello "
"4 x.msg.new c.image i.image/jpg:256,i.image/png:4096 abcd abcd "
"4 x.msg.new c.image x.dag:32,i.image/jpg:8000,i.image/png:16000 binary1"
"5 x.msg.new c.image,i.image/jpg:150000 i.image/jpg:256 abcd "
"6 x.msg.file 5,1.1 x.file:60000 abcd "
"7 x.msg.file 5,1.2 x.file:60000 abcd "
"8 x.msg.file 5,1.3 x.file:30000 abcd "
'8 x.msg.update 3 x.text:11,x.dag:16 hello there abcd '
'9 x.msg.delete 3'
'10 x.msg.new app/v1 i.text/html:NNN,i.text/css:NNN,c.js:NNN,c.json:NNN ... ... ... {...} '
'11 x.msg.eval 8 c.json:NNN {...} '
'12 x.msg.new c.text x.text:16,x.dag:32 hello there @123 abcd '
' x.grp.mem.inv 23456,123 x.json:NNN {...} '
' x.grp.mem.acpt 23456 x.text:NNN <invitation> '
' x.grp.mem.intro 23456,234 x.json:NNN {...} '
' x.grp.mem.inv 23456,234 x.text:NNN <invitation> '
' x.grp.mem.req 23456,123 x.json:NNN {...} '
' x.grp.mem.direct.inv 23456,234 x.text:NNN <invitation> '
' x.file name,size x.text:NNN <invitation> '
```
### Group protocol
#### Add group member
A -> B: invite to group - `MSG: x.grp.inv G_MEM_ID_A,G_MEM_ROLE_A,G_MEM_ID_B,G_MEM_ROLE_B,<invitation> x.json:NNN <group_profile>`
user B confirms
B -> A: establish group connection (B: JOIN, A: LET)
B -> Ag: join group - `in SMP confirmation: x.grp.acpt G_MEM_ID_B`
A -> group (including B)): announce group member: `MSG: N x.grp.mem.new G_MEM_ID_B,G_MEM_ROLE_B,G_MEM_ID_M,... x.json:NNN <B_profile>`
In the message `x.grp.mem.new` A sends the sorted list of all members to whom A is connected followed by the new member ID, role and profile. The following introductions will be sent about/to all members A "knows about" (includes members introduced to A and members who accepted group invitation but not connected yet), once they are connected, so it can be a bigger list than sent in `x.grp.mem.new`.
All members who received `x.grp.mem.new` from A should check the list of connected members and if any connected members that recipients invited to the group are not in this list, they should introduce them to this new member (the last ID, role and profile in `x.grp.mem.new`). That might lead to double introductions that would provide a stronger consistency of group membership at a cost of extra connection between some members that will be unused.
subsequent messages between A and B are via group connection
A -> Bg: intro member - `MSG: x.grp.mem.intro G_MEM_ID_M,G_MEM_ROLE_M x.json:NNN <M_profile>`
B -> Ag: inv for mem - `MSG: x.grp.mem.inv G_MEM_ID_M,<gr_invitation>,<dm_invitation>,<probe>`
M is an existing member, messages are via group connection
A -> Mg: fwd inv - `MSG: x.grp.mem.fwd G_MEM_ID_B,<gr_invitation>,<dm_invitation>,<probe>`
M -> Bg: establish group connection (M: JOIN, B: LET)
M -> B: establish direct connection (M: JOIN, B: LET)
M -> Bg: confirm profile and role - `CONF: x.grp.mem.info G_MEM_ID_M,G_MEM_ROLE x.json:NNN <M_profile>`
B -> Mg: send profile probe - `MSG: x.info.probe <probe>` - it should always be send, even when there is no profile match.
if M is a known contact (profile match) send probe to M:
B -> M (via old DM conn): profile match probe: `MSG: x.info.probe.check <probe_hash>`
M -> B (via old DM conn): probe confirm: `MSG: x.info.probe.ok <probe>`
link to the same contact
B -> Ag: connected to M: `MSG: x.grp.mem.con G_MEM_ID_M`
M -> Ag: connected to M: `MSG: x.grp.mem.con G_MEM_ID_B`
once all members connected
A -> group: `MSG: N x.grp.mem.con.all G_MEM_ID_B`
#### Send group message
Example:
`MSG: N x.msg.new c.text x.text:5 hello `
#### Group member statuses
1. Me
- invited
- accepted
- connected to member who invited me
- announced to group
- x.grp.mem.new to group
- confirmed as connected to group
- this happens once member who invited me sends x.grp.mem.ok to group
1. Member that I invited:
- invited
- accepted
- connected to me
- announced to group
- this happens after x.grp.mem.new but before introductions are sent.
This message is used to determine which members should be additionally introduced if they were announced before (or in "parallel").
- confirmed as connected to group
2. Member who invited me
- invited_me
- connected to me
- I won't know whether this member was announced or confirmed to group - with the correctly functioning clients it must have happened.
3. Prior member introduced to me after I joined (x.grp.mem.intro)
- introduced
- sent invitation
- connected
- connected directly (or confirmed existing contact)
4. Member I was introduced to after that member joined (via x.grp.mem.fwd)
- announced via x.grp.mem.new
- received invitation
- connected
- connected directly (or confirmed existing contact)
#### Introductions
1. Introductions I sent to members I invited
- the time of joining is determined by the time of creating the connection and sending the x.grp.mem.new message to the group.
- introductions of the members who were connected before the new member should be sent - how to determine which members were connected before?
- use time stamp of creating connection, possibly in the member record - not very reliable, as time can change.
- use record ID - requires changing the schema, as currently members are added as invited, not as connected. So possibly invited members should be tracked in a separate table, and all members should still be tracked together to ensure that memberId is unique.
- record ID is also not 100% sufficient, as there can be forks in message history and I may need to intro the member I invited to the member that was announced after my member in my chronology, but in another graph branch.
- some other mechanism that allows to establish who should be connected to whom and whether I should introduce or another member (in case of forks - although maybe we both can introduce and eventually two group connections will be created between these members and they would just ignore the first one - although in cases of multiple branches in the graph it can be N connections).
- introductions/member connection statuses:
- created introduction
- sent to the member I invited
- received the invitation from the member I invited
- forwarded this invitation to previously connected member
- received confirmation from member I invited
- received confirmation from member I forwarded to
- completed introduction and recorded that these members are now fully connected to each other
2. Introductions I received from the member who invited me
- if somebody else sends such introduction - this is an error (can be logged or ignored)
- duplicate memberId is an error (e.g. it is a member that was announced in the group broadcast - I should be introduced to this member, and not the other way around? Although it can happen in case of fork and maybe I should establish the connection anyway).
- member connection status in this case is just a member status from part 3, so maybe no need to track invitations separately and just put SMPQueueInfo on member record.
3. Invitation forwarded to me by any prior member
- any admin/owner can add members, so they can forward their queue invitations - I should just check forwarding member permission
- duplicate memberId is an error
- unannounced memberId is an error - I should have seen member announcement prior to receiving this forwarded invitation. Fork would not happen here as it is the same member that announces and forwards the invitation, so they should be in order.
- member connection status in this case is just a member status from part 4, so maybe no need to track invitations separately and just put SMPQueueInfo on member record.
+3 -3
View File
@@ -40,10 +40,10 @@ extra-deps:
- simple-logger-0.1.0@sha256:be8ede4bd251a9cac776533bae7fb643369ebd826eb948a9a18df1a8dd252ff8,1079
- sqlite-simple-0.4.18.0@sha256:3ceea56375c0a3590c814e411a4eb86943f8d31b93b110ca159c90689b6b39e5,3002
- terminal-0.2.0.0@sha256:de6770ecaae3197c66ac1f0db5a80cf5a5b1d3b64a66a05b50f442de5ad39570,2977
# - simplexmq-0.3.1@sha256:f247aaff3c16c5d3974a4ab4d5882ab50ac78073110997c0bceb05a74d10a325,6688
- simplexmq-0.4.1@sha256:3a1bc40d85e4e398458e5b9b79757e0af4fe27b8ef44eb3157f7f1e07412a8e8,7640
# - ../simplexmq
- github: simplex-chat/simplexmq
commit: dffa7a61006aa5c4050c954857aaf1357fe33242
# - github: simplex-chat/simplexmq
# commit: 35e6593581e68f7b444e0f8f4fb6a2e2cc59a5ea
#
# extra-deps: []
+199
View File
@@ -0,0 +1,199 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module ChatClient where
import Control.Concurrent (ThreadId, forkIOWithUnmask, killThread)
import Control.Concurrent.Async
import Control.Concurrent.STM
import Control.Exception (bracket, bracket_)
import Control.Monad.Except
import Data.List (dropWhileEnd)
import Network.Socket
import Simplex.Chat
import Simplex.Chat.Controller (ChatConfig (..), ChatController (..))
import Simplex.Chat.Options
import Simplex.Chat.Store
import Simplex.Chat.Types (Profile)
import Simplex.Messaging.Agent.Env.SQLite
import Simplex.Messaging.Agent.RetryInterval
import Simplex.Messaging.Server (runSMPServerBlocking)
import Simplex.Messaging.Server.Env.STM
import Simplex.Messaging.Transport
import System.Directory (createDirectoryIfMissing, removeDirectoryRecursive)
import qualified System.Terminal as C
import System.Terminal.Internal (VirtualTerminal (..), VirtualTerminalSettings (..), withVirtualTerminal)
import System.Timeout (timeout)
testDBPrefix :: FilePath
testDBPrefix = "tests/tmp/test"
serverPort :: ServiceName
serverPort = "5000"
opts :: ChatOpts
opts =
ChatOpts
{ dbFile = undefined,
smpServers = ["localhost:5000"]
}
termSettings :: VirtualTerminalSettings
termSettings =
VirtualTerminalSettings
{ virtualType = "xterm",
virtualWindowSize = pure C.Size {height = 24, width = 1000},
virtualEvent = retry,
virtualInterrupt = retry
}
data TestCC = TestCC
{ chatController :: ChatController,
virtualTerminal :: VirtualTerminal,
chatAsync :: Async (),
termAsync :: Async (),
termQ :: TQueue String
}
aCfg :: AgentConfig
aCfg = agentConfig defaultChatConfig
cfg :: ChatConfig
cfg =
defaultChatConfig
{ agentConfig =
aCfg {retryInterval = (retryInterval aCfg) {initialInterval = 50000}}
}
virtualSimplexChat :: FilePath -> Profile -> IO TestCC
virtualSimplexChat dbFile profile = do
st <- createStore (dbFile <> ".chat.db") 1
void . runExceptT $ createUser st profile True
t <- withVirtualTerminal termSettings pure
cc <- newChatController cfg opts {dbFile} t . const $ pure () -- no notifications
chatAsync <- async $ runSimplexChat cc
termQ <- newTQueueIO
termAsync <- async $ readTerminalOutput t termQ
pure TestCC {chatController = cc, virtualTerminal = t, chatAsync, termAsync, termQ}
readTerminalOutput :: VirtualTerminal -> TQueue String -> IO ()
readTerminalOutput t termQ = do
let w = virtualWindow t
winVar <- atomically $ newTVar . init =<< readTVar w
forever . atomically $ do
win <- readTVar winVar
win' <- init <$> readTVar w
if win' == win
then retry
else do
let diff = getDiff win' win
forM_ diff $ writeTQueue termQ
writeTVar winVar win'
where
getDiff :: [String] -> [String] -> [String]
getDiff win win' = getDiff_ 1 (length win) win win'
getDiff_ :: Int -> Int -> [String] -> [String] -> [String]
getDiff_ n len win' win =
let diff = drop (len - n) win'
in if drop n win <> diff == win'
then map (dropWhileEnd (== ' ')) diff
else getDiff_ (n + 1) len win' win
testChatN :: [Profile] -> ([TestCC] -> IO ()) -> IO ()
testChatN ps test =
bracket_
(createDirectoryIfMissing False "tests/tmp")
(removeDirectoryRecursive "tests/tmp")
$ do
let envs = zip ps $ map ((testDBPrefix <>) . show) [(1 :: Int) ..]
tcs <- getTestCCs envs []
test tcs
where
getTestCCs [] tcs = pure tcs
getTestCCs ((p, db) : envs') tcs = (:) <$> virtualSimplexChat db p <*> getTestCCs envs' tcs
testChat2 :: Profile -> Profile -> (TestCC -> TestCC -> IO ()) -> IO ()
testChat2 p1 p2 test = testChatN [p1, p2] test_
where
test_ :: [TestCC] -> IO ()
test_ [tc1, tc2] = test tc1 tc2
test_ _ = error "expected 2 chat clients"
testChat3 :: Profile -> Profile -> Profile -> (TestCC -> TestCC -> TestCC -> IO ()) -> IO ()
testChat3 p1 p2 p3 test = testChatN [p1, p2, p3] test_
where
test_ :: [TestCC] -> IO ()
test_ [tc1, tc2, tc3] = test tc1 tc2 tc3
test_ _ = error "expected 3 chat clients"
testChat4 :: Profile -> Profile -> Profile -> Profile -> (TestCC -> TestCC -> TestCC -> TestCC -> IO ()) -> IO ()
testChat4 p1 p2 p3 p4 test = testChatN [p1, p2, p3, p4] test_
where
test_ :: [TestCC] -> IO ()
test_ [tc1, tc2, tc3, tc4] = test tc1 tc2 tc3 tc4
test_ _ = error "expected 4 chat clients"
concurrentlyN_ :: [IO a] -> IO ()
concurrentlyN_ = mapConcurrently_ id
serverCfg :: ServerConfig
serverCfg =
ServerConfig
{ transports = [(serverPort, transport @TCP)],
tbqSize = 1,
msgQueueQuota = 4,
queueIdBytes = 12,
msgIdBytes = 6,
storeLog = Nothing,
blockSize = 4096,
serverPrivateKey =
-- full RSA private key (only for tests)
"MIIFIwIBAAKCAQEArZyrri/NAwt5buvYjwu+B/MQeJUszDBpRgVqNddlI9kNwDXu\
\kaJ8chEhrtaUgXeSWGooWwqjXEUQE6RVbCC6QVo9VEBSP4xFwVVd9Fj7OsgfcXXh\
\AqWxfctDcBZQ5jTUiJpdBc+Vz2ZkumVNl0W+j9kWm9nfkMLQj8c0cVSDxz4OKpZb\
\qFuj0uzHkis7e7wsrKSKWLPg3M5ZXPZM1m9qn7SfJzDRDfJifamxWI7uz9XK2+Dp\
\NkUQlGQgFJEv1cKN88JAwIqZ1s+TAQMQiB+4QZ2aNfSqGEzRJN7FMCKRK7pM0A9A\
\PCnijyuImvKFxTdk8Bx1q+XNJzsY6fBrLWJZ+QKBgQCySG4tzlcEm+tOVWRcwrWh\
\6zsczGZp9mbf9c8itRx6dlldSYuDG1qnddL70wuAZF2AgS1JZgvcRZECoZRoWP5q\
\Kq2wvpTIYjFPpC39lxgUoA/DXKVKZZdan+gwaVPAPT54my1CS32VrOiAY4gVJ3LJ\
\Mn1/FqZXUFQA326pau3loQKCAQEAoljmJMp88EZoy3HlHUbOjl5UEhzzVsU1TnQi\
\QmPm+aWRe2qelhjW4aTvSVE5mAUJsN6UWTeMf4uvM69Z9I5pfw2pEm8x4+GxRibY\
\iiwF2QNaLxxmzEHm1zQQPTgb39o8mgklhzFPill0JsnL3f6IkVwjFJofWSmpqEGs\
\dFSMRSXUTVXh1p/o7QZrhpwO/475iWKVS7o48N/0Xp513re3aXw+DRNuVnFEaBIe\
\TLvWM9Czn16ndAu1HYiTBuMvtRbAWnGZxU8ewzF4wlWK5tdIL5PTJDd1VhZJAKtB\
\npDvJpwxzKmjAhcTmjx0ckMIWtdVaOVm/2gWCXDty2FEdg7koQKBgQDOUUguJ/i7\
\q0jldWYRnVkotKnpInPdcEaodrehfOqYEHnvro9xlS6OeAS4Vz5AdH45zQ/4J3bV\
\2cH66tNr18ebM9nL//t5G69i89R9W7szyUxCI3LmAIdi3oSEbmz5GQBaw4l6h9Wi\
\n4FmFQaAXZrjQfO2qJcAHvWRsMp2pmqAGwKBgQDXaza0DRsKWywWznsHcmHa0cx8\
\I4jxqGaQmLO7wBJRP1NSFrywy1QfYrVX9CTLBK4V3F0PCgZ01Qv94751CzN43TgF\
\ebd/O9r5NjNTnOXzdWqETbCffLGd6kLgCMwPQWpM9ySVjXHWCGZsRAnF2F6M1O32\
\43StIifvwJQFqSM3ewKBgCaW6y7sRY90Ua7283RErezd9EyT22BWlDlACrPu3FNC\
\LtBf1j43uxBWBQrMLsHe2GtTV0xt9m0MfwZsm2gSsXcm4Xi4DJgfN+Z7rIlyy9UY\
\PCDSdZiU1qSr+NrffDrXlfiAM1cUmCdUX7eKjp/ltkUHNaOGfSn5Pdr3MkAiD/Hf\
\AoGBAKIdKCuOwuYlwjS9J+IRGuSSM4o+OxQdwGmcJDTCpyWb5dEk68e7xKIna3zf\
\jc+H+QdMXv1nkRK9bZgYheXczsXaNZUSTwpxaEldzVD3hNvsXSgJRy9fqHwA4PBq\
\vqiBHoO3RNbqg+2rmTMfDuXreME3S955ZiPZm4Z+T8Hj52mPAoGAQm5QH/gLFtY5\
\+znqU/0G8V6BKISCQMxbbmTQVcTgGySrP2gVd+e4MWvUttaZykhWqs8rpr7mgpIY\
\hul7Swx0SHFN3WpXu8uj+B6MLpRcCbDHO65qU4kQLs+IaXXsuuTjMvJ5LwjkZVrQ\
\TmKzSAw7iVWwEUZR/PeiEKazqrpp9VU="
}
withSmpServer :: IO a -> IO a
withSmpServer = serverBracket (`runSMPServerBlocking` serverCfg) (pure ()) . const
serverBracket :: (TMVar Bool -> IO ()) -> IO () -> (ThreadId -> IO a) -> IO a
serverBracket process afterProcess f = do
started <- newEmptyTMVarIO
bracket
(forkIOWithUnmask ($ process started))
(\t -> killThread t >> afterProcess >> waitFor started "stop")
(\t -> waitFor started "start" >> f t)
where
waitFor started s =
5000000 `timeout` atomically (takeTMVar started) >>= \case
Nothing -> error $ "server did not " <> s
_ -> pure ()
+643
View File
@@ -0,0 +1,643 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PostfixOperators #-}
module ChatTests where
import ChatClient
import Control.Concurrent.Async (concurrently_)
import Control.Concurrent.STM
import qualified Data.ByteString as B
import Data.Char (isDigit)
import qualified Data.Text as T
import Simplex.Chat.Controller
import Simplex.Chat.Types (Profile (..), User (..))
import Simplex.Chat.Util (unlessM)
import System.Directory (doesFileExist)
import System.Timeout (timeout)
import Test.Hspec
aliceProfile :: Profile
aliceProfile = Profile {displayName = "alice", fullName = "Alice"}
bobProfile :: Profile
bobProfile = Profile {displayName = "bob", fullName = "Bob"}
cathProfile :: Profile
cathProfile = Profile {displayName = "cath", fullName = "Catherine"}
danProfile :: Profile
danProfile = Profile {displayName = "dan", fullName = "Daniel"}
chatTests :: Spec
chatTests = do
describe "direct messages" $
it "add contact and send/receive message" testAddContact
describe "chat groups" $ do
it "add contacts, create group and send/receive messages" testGroup
it "create and join group with 4 members" testGroup2
it "create and delete group" testGroupDelete
it "remove contact from group and add again" testGroupRemoveAdd
describe "user profiles" $
it "update user profiles and notify contacts" testUpdateProfile
describe "sending and receiving files" $ do
it "send and receive file" testFileTransfer
it "sender cancelled file transfer" testFileSndCancel
it "recipient cancelled file transfer" testFileRcvCancel
it "send and receive file to group" testGroupFileTransfer
testAddContact :: IO ()
testAddContact =
testChat2 aliceProfile bobProfile $
\alice bob -> do
alice ##> "/c"
inv <- getInvitation alice
bob ##> ("/c " <> inv)
concurrently_
(bob <## "alice (Alice): contact is connected")
(alice <## "bob (Bob): contact is connected")
alice #> "@bob hello"
bob <# "alice> hello"
bob #> "@alice hi"
alice <# "bob> hi"
-- test adding the same contact one more time - local name will be different
alice ##> "/c"
inv' <- getInvitation alice
bob ##> ("/c " <> inv')
concurrently_
(bob <## "alice_1 (Alice): contact is connected")
(alice <## "bob_1 (Bob): contact is connected")
alice #> "@bob_1 hello"
bob <# "alice_1> hello"
bob #> "@alice_1 hi"
alice <# "bob_1> hi"
-- test deleting contact
alice ##> "/d bob_1"
alice <## "bob_1: contact is deleted"
alice #> "@bob_1 hey"
alice <## "no contact bob_1"
testGroup :: IO ()
testGroup =
testChat3 aliceProfile bobProfile cathProfile $
\alice bob cath -> do
connectUsers alice bob
connectUsers alice cath
alice ##> "/g team"
alice <## "group #team is created"
alice <## "use /a team <name> to add members"
alice ##> "/a team bob"
concurrentlyN_
[ alice <## "invitation to join the group #team sent to bob",
do
bob <## "#team: alice invites you to join the group as admin"
bob <## "use /j team to accept"
]
bob ##> "/j team"
concurrently_
(alice <## "#team: bob joined the group")
(bob <## "#team: you joined the group")
alice ##> "/a team cath"
concurrentlyN_
[ alice <## "invitation to join the group #team sent to cath",
do
cath <## "#team: alice invites you to join the group as admin"
cath <## "use /j team to accept"
]
cath ##> "/j team"
concurrentlyN_
[ alice <## "#team: cath joined the group",
do
cath <## "#team: you joined the group"
cath <## "#team: member bob (Bob) is connected",
do
bob <## "#team: alice added cath (Catherine) to the group (connecting...)"
bob <## "#team: new member cath is connected"
]
alice #> "#team hello"
concurrently_
(bob <# "#team alice> hello")
(cath <# "#team alice> hello")
bob #> "#team hi there"
concurrently_
(alice <# "#team bob> hi there")
(cath <# "#team bob> hi there")
cath #> "#team hey"
concurrently_
(alice <# "#team cath> hey")
(bob <# "#team cath> hey")
bob <##> cath
-- remove member
bob ##> "/rm team cath"
concurrentlyN_
[ bob <## "#team: you removed cath from the group",
alice <## "#team: bob removed cath from the group",
do
cath <## "#team: bob removed you from the group"
cath <## "use /d #team to delete the group"
]
bob #> "#team hi"
concurrently_
(alice <# "#team bob> hi")
(cath </)
alice #> "#team hello"
concurrently_
(bob <# "#team alice> hello")
(cath </)
cath #> "#team hello"
cath <## "you are no longer the member of the group"
bob <##> cath
testGroup2 :: IO ()
testGroup2 =
testChat4 aliceProfile bobProfile cathProfile danProfile $
\alice bob cath dan -> do
connectUsers alice bob
connectUsers alice cath
connectUsers bob dan
connectUsers alice dan
alice ##> "/g club"
alice <## "group #club is created"
alice <## "use /a club <name> to add members"
alice ##> "/a club bob"
concurrentlyN_
[ alice <## "invitation to join the group #club sent to bob",
do
bob <## "#club: alice invites you to join the group as admin"
bob <## "use /j club to accept"
]
alice ##> "/a club cath"
concurrentlyN_
[ alice <## "invitation to join the group #club sent to cath",
do
cath <## "#club: alice invites you to join the group as admin"
cath <## "use /j club to accept"
]
bob ##> "/j club"
concurrently_
(alice <## "#club: bob joined the group")
(bob <## "#club: you joined the group")
cath ##> "/j club"
concurrentlyN_
[ alice <## "#club: cath joined the group",
do
cath <## "#club: you joined the group"
cath <## "#club: member bob (Bob) is connected",
do
bob <## "#club: alice added cath (Catherine) to the group (connecting...)"
bob <## "#club: new member cath is connected"
]
bob ##> "/a club dan"
concurrentlyN_
[ bob <## "invitation to join the group #club sent to dan",
do
dan <## "#club: bob invites you to join the group as admin"
dan <## "use /j club to accept"
]
dan ##> "/j club"
concurrentlyN_
[ bob <## "#club: dan joined the group",
do
dan <## "#club: you joined the group"
dan
<### [ "#club: member alice_1 (Alice) is connected",
"contact alice_1 is merged into alice",
"use @alice <message> to send messages",
"#club: member cath (Catherine) is connected"
],
do
alice <## "#club: bob added dan_1 (Daniel) to the group (connecting...)"
alice <## "#club: new member dan_1 is connected"
alice <## "contact dan_1 is merged into dan"
alice <## "use @dan <message> to send messages",
do
cath <## "#club: bob added dan (Daniel) to the group (connecting...)"
cath <## "#club: new member dan is connected"
]
alice #> "#club hello"
concurrentlyN_
[ bob <# "#club alice> hello",
cath <# "#club alice> hello",
dan <# "#club alice> hello"
]
bob #> "#club hi there"
concurrentlyN_
[ alice <# "#club bob> hi there",
cath <# "#club bob> hi there",
dan <# "#club bob> hi there"
]
cath #> "#club hey"
concurrentlyN_
[ alice <# "#club cath> hey",
bob <# "#club cath> hey",
dan <# "#club cath> hey"
]
dan #> "#club how is it going?"
concurrentlyN_
[ alice <# "#club dan> how is it going?",
bob <# "#club dan> how is it going?",
cath <# "#club dan> how is it going?"
]
bob <##> cath
dan <##> cath
dan <##> alice
-- remove member
cath ##> "/rm club dan"
concurrentlyN_
[ cath <## "#club: you removed dan from the group",
alice <## "#club: cath removed dan from the group",
bob <## "#club: cath removed dan from the group",
do
dan <## "#club: cath removed you from the group"
dan <## "use /d #club to delete the group"
]
alice #> "#club hello"
concurrentlyN_
[ bob <# "#club alice> hello",
cath <# "#club alice> hello",
(dan </)
]
bob #> "#club hi there"
concurrentlyN_
[ alice <# "#club bob> hi there",
cath <# "#club bob> hi there",
(dan </)
]
cath #> "#club hey"
concurrentlyN_
[ alice <# "#club cath> hey",
bob <# "#club cath> hey",
(dan </)
]
dan #> "#club how is it going?"
dan <## "you are no longer the member of the group"
dan <##> cath
dan <##> alice
-- member leaves
bob ##> "/l club"
concurrentlyN_
[ do
bob <## "#club: you left the group"
bob <## "use /d #club to delete the group",
alice <## "#club: bob left the group",
cath <## "#club: bob left the group"
]
alice #> "#club hello"
concurrently_
(cath <# "#club alice> hello")
(bob </)
cath #> "#club hey"
concurrently_
(alice <# "#club cath> hey")
(bob </)
bob #> "#club how is it going?"
bob <## "you are no longer the member of the group"
bob <##> cath
bob <##> alice
testGroupDelete :: IO ()
testGroupDelete =
testChat3 aliceProfile bobProfile cathProfile $
\alice bob cath -> do
createGroup3 "team" alice bob cath
alice ##> "/d #team"
concurrentlyN_
[ alice <## "#team: you deleted the group",
do
bob <## "#team: alice deleted the group"
bob <## "use /d #team to delete the local copy of the group",
do
cath <## "#team: alice deleted the group"
cath <## "use /d #team to delete the local copy of the group"
]
bob ##> "/d #team"
bob <## "#team: you deleted the group"
cath #> "#team hi"
cath <## "you are no longer the member of the group"
testGroupRemoveAdd :: IO ()
testGroupRemoveAdd =
testChat3 aliceProfile bobProfile cathProfile $
\alice bob cath -> do
createGroup3 "team" alice bob cath
-- remove member
alice ##> "/rm team bob"
concurrentlyN_
[ alice <## "#team: you removed bob from the group",
do
bob <## "#team: alice removed you from the group"
bob <## "use /d #team to delete the group",
cath <## "#team: alice removed bob from the group"
]
alice ##> "/a team bob"
alice <## "invitation to join the group #team sent to bob"
bob <## "#team_1 (team): alice invites you to join the group as admin"
bob <## "use /j team_1 to accept"
bob ##> "/j team_1"
concurrentlyN_
[ alice <## "#team: bob joined the group",
do
bob <## "#team_1: you joined the group"
bob <## "#team_1: member cath_1 (Catherine) is connected"
bob <## "contact cath_1 is merged into cath"
bob <## "use @cath <message> to send messages",
do
cath <## "#team: alice added bob_1 (Bob) to the group (connecting...)"
cath <## "#team: new member bob_1 is connected"
cath <## "contact bob_1 is merged into bob"
cath <## "use @bob <message> to send messages"
]
alice #> "#team hi"
concurrently_
(bob <# "#team_1 alice> hi")
(cath <# "#team alice> hi")
bob #> "#team_1 hey"
concurrently_
(alice <# "#team bob> hey")
(cath <# "#team bob> hey")
cath #> "#team hello"
concurrently_
(alice <# "#team cath> hello")
(bob <# "#team_1 cath> hello")
testUpdateProfile :: IO ()
testUpdateProfile =
testChat3 aliceProfile bobProfile cathProfile $
\alice bob cath -> do
createGroup3 "team" alice bob cath
alice ##> "/p"
alice <## "user profile: alice (Alice)"
alice <## "use /p <display name> [<full name>] to change it"
alice <## "(the updated profile will be sent to all your contacts)"
alice ##> "/p alice"
concurrentlyN_
[ alice <## "user full name removed (your contacts are notified)",
bob <## "contact alice removed full name",
cath <## "contact alice removed full name"
]
alice ##> "/p alice Alice Jones"
concurrentlyN_
[ alice <## "user full name changed to Alice Jones (your contacts are notified)",
bob <## "contact alice updated full name: Alice Jones",
cath <## "contact alice updated full name: Alice Jones"
]
cath ##> "/p cate"
concurrentlyN_
[ cath <## "user profile is changed to cate (your contacts are notified)",
do
alice <## "contact cath changed to cate"
alice <## "use @cate <message> to send messages",
do
bob <## "contact cath changed to cate"
bob <## "use @cate <message> to send messages"
]
cath ##> "/p cat Cate"
concurrentlyN_
[ cath <## "user profile is changed to cat (Cate) (your contacts are notified)",
do
alice <## "contact cate changed to cat (Cate)"
alice <## "use @cat <message> to send messages",
do
bob <## "contact cate changed to cat (Cate)"
bob <## "use @cat <message> to send messages"
]
testFileTransfer :: IO ()
testFileTransfer =
testChat2 aliceProfile bobProfile $
\alice bob -> do
connectUsers alice bob
startFileTransfer alice bob
concurrentlyN_
[ do
bob #> "@alice receiving here..."
bob <## "completed receiving file 1 (test.jpg) from alice",
do
alice <# "bob> receiving here..."
alice <## "completed sending file 1 (test.jpg) to bob"
]
src <- B.readFile "./tests/fixtures/test.jpg"
dest <- B.readFile "./tests/tmp/test.jpg"
dest `shouldBe` src
testFileSndCancel :: IO ()
testFileSndCancel =
testChat2 aliceProfile bobProfile $
\alice bob -> do
connectUsers alice bob
startFileTransfer alice bob
alice ##> "/fc 1"
concurrentlyN_
[ do
alice <## "cancelled sending file 1 (test.jpg) to bob"
alice ##> "/fs 1"
alice <## "sending file 1 (test.jpg) cancelled",
do
bob <## "alice cancelled sending file 1 (test.jpg)"
bob ##> "/fs 1"
bob <## "receiving file 1 (test.jpg) cancelled, received part path: ./tests/tmp/test.jpg"
]
checkPartialTransfer
testFileRcvCancel :: IO ()
testFileRcvCancel =
testChat2 aliceProfile bobProfile $
\alice bob -> do
connectUsers alice bob
startFileTransfer alice bob
bob ##> "/fs 1"
getTermLine bob >>= (`shouldStartWith` "receiving file 1 (test.jpg) progress")
waitFileExists "./tests/tmp/test.jpg"
bob ##> "/fc 1"
concurrentlyN_
[ do
bob <## "cancelled receiving file 1 (test.jpg) from alice"
bob ##> "/fs 1"
bob <## "receiving file 1 (test.jpg) cancelled, received part path: ./tests/tmp/test.jpg",
do
alice <## "bob cancelled receiving file 1 (test.jpg)"
alice ##> "/fs 1"
alice <## "sending file 1 (test.jpg) cancelled"
]
checkPartialTransfer
where
waitFileExists f = unlessM (doesFileExist f) $ waitFileExists f
testGroupFileTransfer :: IO ()
testGroupFileTransfer =
testChat3 aliceProfile bobProfile cathProfile $
\alice bob cath -> do
createGroup3 "team" alice bob cath
alice #> "/f #team ./tests/fixtures/test.jpg"
alice <## "use /fc 1 to cancel sending"
concurrentlyN_
[ do
bob <# "#team alice> sends file test.jpg (136.5 KiB / 139737 bytes)"
bob <## "use /fr 1 [<dir>/ | <path>] to receive it",
do
cath <# "#team alice> sends file test.jpg (136.5 KiB / 139737 bytes)"
cath <## "use /fr 1 [<dir>/ | <path>] to receive it"
]
alice ##> "/fs 1"
getTermLine alice >>= (`shouldStartWith` "sending file 1 (test.jpg) not accepted")
bob ##> "/fr 1 ./tests/tmp/"
bob <## "saving file 1 from alice to ./tests/tmp/test.jpg"
concurrentlyN_
[ do
alice <## "started sending file 1 (test.jpg) to bob"
alice <## "completed sending file 1 (test.jpg) to bob"
alice ##> "/fs 1"
alice <## "sending file 1 (test.jpg):"
alice <### [" complete: bob", " not accepted: cath"],
do
bob <## "started receiving file 1 (test.jpg) from alice"
bob <## "completed receiving file 1 (test.jpg) from alice"
]
cath ##> "/fr 1 ./tests/tmp/"
cath <## "saving file 1 from alice to ./tests/tmp/test_1.jpg"
concurrentlyN_
[ do
alice <## "started sending file 1 (test.jpg) to cath"
alice <## "completed sending file 1 (test.jpg) to cath"
alice ##> "/fs 1"
getTermLine alice >>= (`shouldStartWith` "sending file 1 (test.jpg) complete"),
do
cath <## "started receiving file 1 (test.jpg) from alice"
cath <## "completed receiving file 1 (test.jpg) from alice"
]
startFileTransfer :: TestCC -> TestCC -> IO ()
startFileTransfer alice bob = do
alice #> "/f @bob ./tests/fixtures/test.jpg"
alice <## "use /fc 1 to cancel sending"
bob <# "alice> sends file test.jpg (136.5 KiB / 139737 bytes)"
bob <## "use /fr 1 [<dir>/ | <path>] to receive it"
bob ##> "/fr 1 ./tests/tmp"
bob <## "saving file 1 from alice to ./tests/tmp/test.jpg"
concurrently_
(bob <## "started receiving file 1 (test.jpg) from alice")
(alice <## "started sending file 1 (test.jpg) to bob")
checkPartialTransfer :: IO ()
checkPartialTransfer = do
src <- B.readFile "./tests/fixtures/test.jpg"
dest <- B.readFile "./tests/tmp/test.jpg"
B.unpack src `shouldStartWith` B.unpack dest
B.length src > B.length dest `shouldBe` True
connectUsers :: TestCC -> TestCC -> IO ()
connectUsers cc1 cc2 = do
name1 <- showName cc1
name2 <- showName cc2
cc1 ##> "/c"
inv <- getInvitation cc1
cc2 ##> ("/c " <> inv)
concurrently_
(cc2 <## (name1 <> ": contact is connected"))
(cc1 <## (name2 <> ": contact is connected"))
showName :: TestCC -> IO String
showName (TestCC ChatController {currentUser} _ _ _ _) = do
User {localDisplayName, profile = Profile {fullName}} <- readTVarIO currentUser
pure . T.unpack $ localDisplayName <> " (" <> fullName <> ")"
createGroup3 :: String -> TestCC -> TestCC -> TestCC -> IO ()
createGroup3 gName cc1 cc2 cc3 = do
connectUsers cc1 cc2
connectUsers cc1 cc3
name2 <- userName cc2
name3 <- userName cc3
sName2 <- showName cc2
sName3 <- showName cc3
cc1 ##> ("/g " <> gName)
cc1 <## ("group #" <> gName <> " is created")
cc1 <## ("use /a " <> gName <> " <name> to add members")
addMember cc2
cc2 ##> ("/j " <> gName)
concurrently_
(cc1 <## ("#" <> gName <> ": " <> name2 <> " joined the group"))
(cc2 <## ("#" <> gName <> ": you joined the group"))
addMember cc3
cc3 ##> ("/j " <> gName)
concurrentlyN_
[ cc1 <## ("#" <> gName <> ": " <> name3 <> " joined the group"),
do
cc3 <## ("#" <> gName <> ": you joined the group")
cc3 <## ("#" <> gName <> ": member " <> sName2 <> " is connected"),
do
cc2 <## ("#" <> gName <> ": alice added " <> sName3 <> " to the group (connecting...)")
cc2 <## ("#" <> gName <> ": new member " <> name3 <> " is connected")
]
where
addMember :: TestCC -> IO ()
addMember mem = do
name1 <- userName cc1
memName <- userName mem
cc1 ##> ("/a " <> gName <> " " <> memName)
concurrentlyN_
[ cc1 <## ("invitation to join the group #" <> gName <> " sent to " <> memName),
do
mem <## ("#" <> gName <> ": " <> name1 <> " invites you to join the group as admin")
mem <## ("use /j " <> gName <> " to accept")
]
-- | test sending direct messages
(<##>) :: TestCC -> TestCC -> IO ()
cc1 <##> cc2 = do
name1 <- userName cc1
name2 <- userName cc2
cc1 #> ("@" <> name2 <> " hi")
cc2 <# (name1 <> "> hi")
cc2 #> ("@" <> name1 <> " hey")
cc1 <# (name2 <> "> hey")
userName :: TestCC -> IO [Char]
userName (TestCC ChatController {currentUser} _ _ _ _) = T.unpack . localDisplayName <$> readTVarIO currentUser
(##>) :: TestCC -> String -> IO ()
cc ##> cmd = do
cc `send` cmd
cc <## cmd
(#>) :: TestCC -> String -> IO ()
cc #> cmd = do
cc `send` cmd
cc <# cmd
send :: TestCC -> String -> IO ()
send TestCC {chatController = cc} cmd = atomically $ writeTBQueue (inputQ cc) $ InputCommand cmd
(<##) :: TestCC -> String -> Expectation
cc <## line = getTermLine cc `shouldReturn` line
(<###) :: TestCC -> [String] -> Expectation
_ <### [] = pure ()
cc <### ls = do
line <- getTermLine cc
if line `elem` ls
then cc <### filter (/= line) ls
else error $ "unexpected output: " <> line
(<#) :: TestCC -> String -> Expectation
cc <# line = (dropTime <$> getTermLine cc) `shouldReturn` line
(</) :: TestCC -> Expectation
(</) cc = timeout 500000 (getTermLine cc) `shouldReturn` Nothing
dropTime :: String -> String
dropTime msg = case splitAt 6 msg of
([m, m', ':', s, s', ' '], text) ->
if all isDigit [m, m', s, s'] then text else error "invalid time"
_ -> error "invalid time"
getTermLine :: TestCC -> IO String
getTermLine = atomically . readTQueue . termQ
getInvitation :: TestCC -> IO String
getInvitation cc = do
cc <## "pass this invitation to your contact (via another channel):"
cc <## ""
inv <- getTermLine cc
cc <## ""
cc <## "and ask them to connect: /c <invitation_above>"
pure inv
+47
View File
@@ -0,0 +1,47 @@
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
module ProtocolTests where
import Data.ByteString.Char8 (ByteString)
import Simplex.Chat.Protocol
import Simplex.Messaging.Parsers (parseAll)
import Test.Hspec
protocolTests :: Spec
protocolTests = do
parseChatMessageTest
(#==) :: ByteString -> RawChatMessage -> Expectation
s #== msg = parseAll rawChatMessageP s `shouldBe` Right msg
parseChatMessageTest :: Spec
parseChatMessageTest = describe "Raw chat message format" $ do
it "no parameters and content" $
"5 x.grp.mem.leave " #== RawChatMessage (Just 5) "x.grp.mem.leave" [] []
it "one parameter, no content" $
"6 x.msg.del 3 " #== RawChatMessage (Just 6) "x.msg.del" ["3"] []
it "with content that fits the message" $
"7 x.msg.new c.text x.text:11 hello there "
#== RawChatMessage
(Just 7)
"x.msg.new"
["c.text"]
[RawMsgBodyContent (RawContentType "x" "text") "hello there"]
it "with DAG reference and partial content" $
"8 x.msg.new c.image x.dag:16,x.text:7,m.image/jpg:6 0123456789012345 picture abcdef "
#== RawChatMessage
(Just 8)
"x.msg.new"
["c.image"]
[ RawMsgBodyContent (RawContentType "x" "dag") "0123456789012345",
RawMsgBodyContent (RawContentType "x" "text") "picture",
RawMsgBodyContent (RawContentType "m" "image/jpg") "abcdef"
]
it "without message id" $
" x.grp.mem.inv 23456,123 x.json:46 {\"contactRef\":\"john\",\"displayName\":\"John Doe\"} "
#== RawChatMessage
Nothing
"x.grp.mem.inv"
["23456", "123"]
[RawMsgBodyContent (RawContentType "x" "json") "{\"contactRef\":\"john\",\"displayName\":\"John Doe\"}"]
+7 -3
View File
@@ -1,7 +1,11 @@
import ChatClient
import ChatTests
import MarkdownTests
import ProtocolTests
import Test.Hspec
main :: IO ()
main = do
hspec $ do
describe "SimpleX chat markdown" markdownTests
main = withSmpServer . hspec $ do
describe "SimpleX chat markdown" markdownTests
describe "SimpleX chat protocol" protocolTests
describe "SimpleX chat client" chatTests
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB