2021-06-25 18:18:24 +01:00
|
|
|
{-# LANGUAGE ConstraintKinds #-}
|
2022-01-11 08:50:44 +00:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2021-07-12 19:00:03 +01:00
|
|
|
{-# LANGUAGE DuplicateRecordFields #-}
|
2021-06-25 18:18:24 +01:00
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
|
{-# LANGUAGE LambdaCase #-}
|
2021-07-12 19:00:03 +01:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
2021-06-25 18:18:24 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
2021-07-05 20:05:07 +01:00
|
|
|
module Simplex.Chat.View
|
2022-01-21 11:09:33 +00:00
|
|
|
( safeDecodeUtf8,
|
2021-09-05 14:08:29 +01:00
|
|
|
msgPlain,
|
2021-11-07 21:57:05 +00:00
|
|
|
clientVersionInfo,
|
2022-01-21 11:09:33 +00:00
|
|
|
viewConnReqInvitation,
|
|
|
|
|
viewSentConfirmation,
|
|
|
|
|
viewSentInvitation,
|
|
|
|
|
viewInvalidConnReq,
|
|
|
|
|
viewContactDeleted,
|
|
|
|
|
viewContactGroups,
|
|
|
|
|
viewContactsList,
|
|
|
|
|
viewUserContactLinkCreated,
|
|
|
|
|
viewUserContactLinkDeleted,
|
|
|
|
|
viewUserContactLink,
|
|
|
|
|
viewAcceptingContactRequest,
|
|
|
|
|
viewContactRequestRejected,
|
|
|
|
|
viewGroupCreated,
|
|
|
|
|
viewSentGroupInvitation,
|
|
|
|
|
viewCannotResendInvitation,
|
|
|
|
|
viewDeletedMember,
|
|
|
|
|
viewLeftMemberUser,
|
|
|
|
|
viewGroupDeletedUser,
|
|
|
|
|
viewGroupMembers,
|
|
|
|
|
viewSentFileInfo,
|
|
|
|
|
viewRcvFileAccepted,
|
|
|
|
|
viewRcvFileSndCancelled,
|
|
|
|
|
viewSndGroupFileCancelled,
|
|
|
|
|
viewRcvFileCancelled,
|
|
|
|
|
viewFileTransferStatus,
|
|
|
|
|
viewUserProfileUpdated,
|
|
|
|
|
viewUserProfile,
|
|
|
|
|
viewChatError,
|
|
|
|
|
viewSentMessage,
|
|
|
|
|
viewSentGroupMessage,
|
|
|
|
|
viewSentGroupFileInvitation,
|
|
|
|
|
viewSentFileInvitation,
|
|
|
|
|
viewGroupsList,
|
|
|
|
|
viewContactSubscribed,
|
|
|
|
|
viewContactSubError,
|
|
|
|
|
viewGroupInvitation,
|
|
|
|
|
viewGroupEmpty,
|
|
|
|
|
viewGroupRemoved,
|
|
|
|
|
viewMemberSubError,
|
|
|
|
|
viewGroupSubscribed,
|
|
|
|
|
viewSndFileSubError,
|
|
|
|
|
viewRcvFileSubError,
|
|
|
|
|
viewUserContactLinkSubscribed,
|
|
|
|
|
viewUserContactLinkSubError,
|
|
|
|
|
viewContactConnected,
|
|
|
|
|
viewContactDisconnected,
|
|
|
|
|
viewContactAnotherClient,
|
|
|
|
|
viewJoinedGroupMember,
|
|
|
|
|
viewUserJoinedGroup,
|
|
|
|
|
viewJoinedGroupMemberConnecting,
|
|
|
|
|
viewConnectedToGroupMember,
|
|
|
|
|
viewReceivedGroupInvitation,
|
|
|
|
|
viewDeletedMemberUser,
|
|
|
|
|
viewLeftMember,
|
|
|
|
|
viewSndFileStart,
|
|
|
|
|
viewSndFileComplete,
|
|
|
|
|
viewSndFileCancelled,
|
|
|
|
|
viewSndFileRcvCancelled,
|
|
|
|
|
viewRcvFileStart,
|
|
|
|
|
viewRcvFileComplete,
|
|
|
|
|
viewReceivedContactRequest,
|
|
|
|
|
viewMessageError,
|
|
|
|
|
viewReceivedMessage,
|
|
|
|
|
viewReceivedGroupMessage,
|
|
|
|
|
viewReceivedFileInvitation,
|
|
|
|
|
viewReceivedGroupFileInvitation,
|
|
|
|
|
viewContactUpdated,
|
|
|
|
|
viewContactsMerged,
|
|
|
|
|
viewGroupDeleted,
|
2021-06-25 18:18:24 +01:00
|
|
|
)
|
|
|
|
|
where
|
|
|
|
|
|
|
|
|
|
import Data.ByteString.Char8 (ByteString)
|
2022-01-21 11:09:33 +00:00
|
|
|
import Data.Composition ((.:))
|
2021-09-05 14:08:29 +01:00
|
|
|
import Data.Function (on)
|
2021-09-04 07:32:56 +01:00
|
|
|
import Data.Int (Int64)
|
2021-12-11 12:57:12 +00:00
|
|
|
import Data.List (groupBy, intersperse, sort, sortOn)
|
2021-07-04 18:42:24 +01:00
|
|
|
import Data.Text (Text)
|
2021-06-25 18:18:24 +01:00
|
|
|
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)
|
2021-09-04 07:32:56 +01:00
|
|
|
import Numeric (showFFloat)
|
2021-06-25 18:18:24 +01:00
|
|
|
import Simplex.Chat.Controller
|
|
|
|
|
import Simplex.Chat.Markdown
|
2021-07-12 19:00:03 +01:00
|
|
|
import Simplex.Chat.Store (StoreError (..))
|
2021-06-25 18:18:24 +01:00
|
|
|
import Simplex.Chat.Styled
|
2021-07-04 18:42:24 +01:00
|
|
|
import Simplex.Chat.Types
|
2021-07-05 20:05:07 +01:00
|
|
|
import Simplex.Chat.Util (safeDecodeUtf8)
|
2021-06-25 18:18:24 +01:00
|
|
|
import Simplex.Messaging.Agent.Protocol
|
2022-01-11 08:50:44 +00:00
|
|
|
import Simplex.Messaging.Encoding.String
|
2021-12-08 13:09:51 +00:00
|
|
|
import qualified Simplex.Messaging.Protocol as SMP
|
2021-06-25 18:18:24 +01:00
|
|
|
import System.Console.ANSI.Types
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSentConfirmation :: [StyledString]
|
|
|
|
|
viewSentConfirmation = ["confirmation sent!"]
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSentInvitation :: [StyledString]
|
|
|
|
|
viewSentInvitation = ["connection request sent!"]
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewInvalidConnReq :: [StyledString]
|
|
|
|
|
viewInvalidConnReq =
|
|
|
|
|
[ "",
|
|
|
|
|
"Connection link is invalid, possibly it was created in a previous version.",
|
|
|
|
|
"Please ask your contact to check " <> highlight' "/version" <> " and update if needed.",
|
|
|
|
|
plain updateStr
|
|
|
|
|
]
|
2021-08-22 15:56:36 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewUserContactLinkSubscribed :: [StyledString]
|
|
|
|
|
viewUserContactLinkSubscribed = ["Your address is active! To show: " <> highlight' "/sa"]
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewConnReqInvitation :: ConnReqInvitation -> [StyledString]
|
|
|
|
|
viewConnReqInvitation cReq =
|
2021-12-08 13:09:51 +00:00
|
|
|
[ "pass this invitation link to your contact (via another channel): ",
|
2021-06-25 18:18:24 +01:00
|
|
|
"",
|
2022-01-11 08:50:44 +00:00
|
|
|
(plain . strEncode) cReq,
|
2021-06-25 18:18:24 +01:00
|
|
|
"",
|
2021-12-08 13:09:51 +00:00
|
|
|
"and ask them to connect: " <> highlight' "/c <invitation_link_above>"
|
2021-06-25 18:18:24 +01:00
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactDeleted :: ContactName -> [StyledString]
|
|
|
|
|
viewContactDeleted c = [ttyContact c <> ": contact is deleted"]
|
2021-08-02 20:10:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactGroups :: ContactName -> [GroupName] -> [StyledString]
|
|
|
|
|
viewContactGroups c gNames = [ttyContact c <> ": contact cannot be deleted, it is a member of the group(s) " <> ttyGroups gNames]
|
2021-08-02 20:10:24 +01:00
|
|
|
where
|
|
|
|
|
ttyGroups :: [GroupName] -> StyledString
|
|
|
|
|
ttyGroups [] = ""
|
|
|
|
|
ttyGroups [g] = ttyGroup g
|
|
|
|
|
ttyGroups (g : gs) = ttyGroup g <> ", " <> ttyGroups gs
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactsList :: [Contact] -> [StyledString]
|
|
|
|
|
viewContactsList =
|
2021-12-10 11:45:58 +00:00
|
|
|
let ldn = T.toLower . (localDisplayName :: Contact -> ContactName)
|
|
|
|
|
in map ttyFullContact . sortOn ldn
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactConnected :: Contact -> [StyledString]
|
|
|
|
|
viewContactConnected ct = [ttyFullContact ct <> ": contact is connected"]
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactDisconnected :: ContactName -> [StyledString]
|
|
|
|
|
viewContactDisconnected c = [ttyContact c <> ": disconnected from server (messages will be queued)"]
|
2021-08-14 21:04:51 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactAnotherClient :: ContactName -> [StyledString]
|
|
|
|
|
viewContactAnotherClient c = [ttyContact c <> ": contact is connected to another client"]
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactSubscribed :: ContactName -> [StyledString]
|
|
|
|
|
viewContactSubscribed c = [ttyContact c <> ": connected to server"]
|
2021-07-25 20:23:52 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactSubError :: ContactName -> ChatError -> [StyledString]
|
|
|
|
|
viewContactSubError c e = [ttyContact c <> ": contact error " <> sShow e]
|
2021-07-25 20:23:52 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewUserContactLinkCreated :: ConnReqContact -> [StyledString]
|
|
|
|
|
viewUserContactLinkCreated = connReqContact_ "Your new chat address is created!"
|
2021-12-08 13:09:51 +00:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewUserContactLinkDeleted :: [StyledString]
|
|
|
|
|
viewUserContactLinkDeleted =
|
2021-12-08 13:09:51 +00:00
|
|
|
[ "Your chat address is deleted - accepted contacts will remain connected.",
|
|
|
|
|
"To create a new chat address use " <> highlight' "/ad"
|
|
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewUserContactLink :: ConnReqContact -> [StyledString]
|
|
|
|
|
viewUserContactLink = connReqContact_ "Your chat address:"
|
2021-12-08 13:09:51 +00:00
|
|
|
|
|
|
|
|
connReqContact_ :: StyledString -> ConnReqContact -> [StyledString]
|
|
|
|
|
connReqContact_ intro cReq =
|
|
|
|
|
[ intro,
|
|
|
|
|
"",
|
2022-01-11 08:50:44 +00:00
|
|
|
(plain . strEncode) cReq,
|
2021-12-08 13:09:51 +00:00
|
|
|
"",
|
|
|
|
|
"Anybody can send you contact requests with: " <> highlight' "/c <contact_link_above>",
|
|
|
|
|
"to show it again: " <> highlight' "/sa",
|
|
|
|
|
"to delete it: " <> highlight' "/da" <> " (accepted contacts will remain connected)"
|
|
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewReceivedContactRequest :: ContactName -> Profile -> [StyledString]
|
|
|
|
|
viewReceivedContactRequest c Profile {fullName} =
|
2021-12-08 13:09:51 +00:00
|
|
|
[ ttyFullName c fullName <> " wants to connect to you!",
|
|
|
|
|
"to accept: " <> highlight ("/ac " <> c),
|
|
|
|
|
"to reject: " <> highlight ("/rc " <> c) <> " (the sender will NOT be notified)"
|
|
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewAcceptingContactRequest :: ContactName -> [StyledString]
|
|
|
|
|
viewAcceptingContactRequest c = [ttyContact c <> ": accepting contact request..."]
|
2021-12-08 13:09:51 +00:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactRequestRejected :: ContactName -> [StyledString]
|
|
|
|
|
viewContactRequestRejected c = [ttyContact c <> ": contact request rejected"]
|
2021-12-08 13:09:51 +00:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewUserContactLinkSubError :: ChatError -> [StyledString]
|
|
|
|
|
viewUserContactLinkSubError e =
|
2021-12-08 13:09:51 +00:00
|
|
|
[ "user address error: " <> sShow e,
|
|
|
|
|
"to delete your address: " <> highlight' "/da"
|
|
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewGroupSubscribed :: Group -> [StyledString]
|
|
|
|
|
viewGroupSubscribed g = [ttyFullGroup g <> ": connected to server(s)"]
|
2021-08-02 20:10:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewGroupEmpty :: Group -> [StyledString]
|
|
|
|
|
viewGroupEmpty g = [ttyFullGroup g <> ": group is empty"]
|
2021-08-02 20:10:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewGroupRemoved :: Group -> [StyledString]
|
|
|
|
|
viewGroupRemoved g = [ttyFullGroup g <> ": you are no longer a member or group deleted"]
|
2021-07-25 20:23:52 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewMemberSubError :: GroupName -> ContactName -> ChatError -> [StyledString]
|
|
|
|
|
viewMemberSubError g c e = [ttyGroup g <> " member " <> ttyContact c <> " error: " <> sShow e]
|
2021-07-25 20:23:52 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewGroupCreated :: Group -> [StyledString]
|
|
|
|
|
viewGroupCreated g@Group {localDisplayName} =
|
2021-07-16 07:40:55 +01:00
|
|
|
[ "group " <> ttyFullGroup g <> " is created",
|
2021-07-24 10:26:28 +01:00
|
|
|
"use " <> highlight ("/a " <> localDisplayName <> " <name>") <> " to add members"
|
2021-07-16 07:40:55 +01:00
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewGroupDeletedUser :: GroupName -> [StyledString]
|
|
|
|
|
viewGroupDeletedUser g = groupDeleted_ g Nothing
|
2021-08-02 20:10:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewGroupDeleted :: GroupName -> GroupMember -> [StyledString]
|
|
|
|
|
viewGroupDeleted g m = groupDeleted_ g (Just m) <> ["use " <> highlight ("/d #" <> g) <> " to delete the local copy of the group"]
|
2021-08-02 20:10:24 +01:00
|
|
|
|
|
|
|
|
groupDeleted_ :: GroupName -> Maybe GroupMember -> [StyledString]
|
|
|
|
|
groupDeleted_ g m = [ttyGroup g <> ": " <> memberOrUser m <> " deleted the group"]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSentGroupInvitation :: GroupName -> ContactName -> [StyledString]
|
|
|
|
|
viewSentGroupInvitation g c = ["invitation to join the group " <> ttyGroup g <> " sent to " <> ttyContact c]
|
2021-07-16 07:40:55 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewCannotResendInvitation :: GroupName -> ContactName -> [StyledString]
|
|
|
|
|
viewCannotResendInvitation g c =
|
2022-01-06 23:39:58 +04:00
|
|
|
[ ttyContact c <> " is already invited to group " <> ttyGroup g,
|
|
|
|
|
"to re-send invitation: " <> highlight ("/rm " <> g <> " " <> c) <> ", " <> highlight ("/a " <> g <> " " <> c)
|
|
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewReceivedGroupInvitation :: Group -> ContactName -> GroupMemberRole -> [StyledString]
|
|
|
|
|
viewReceivedGroupInvitation g@Group {localDisplayName} c role =
|
2022-01-11 08:50:44 +00:00
|
|
|
[ ttyFullGroup g <> ": " <> ttyContact c <> " invites you to join the group as " <> plain (strEncode role),
|
2021-07-24 10:26:28 +01:00
|
|
|
"use " <> highlight ("/j " <> localDisplayName) <> " to accept"
|
2021-07-16 07:40:55 +01:00
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewJoinedGroupMember :: GroupName -> GroupMember -> [StyledString]
|
|
|
|
|
viewJoinedGroupMember g m = [ttyGroup g <> ": " <> ttyMember m <> " joined the group "]
|
2021-07-24 10:26:28 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewUserJoinedGroup :: GroupName -> [StyledString]
|
|
|
|
|
viewUserJoinedGroup g = [ttyGroup g <> ": you joined the group"]
|
2021-07-24 10:26:28 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewJoinedGroupMemberConnecting :: GroupName -> GroupMember -> GroupMember -> [StyledString]
|
|
|
|
|
viewJoinedGroupMemberConnecting g host m = [ttyGroup g <> ": " <> ttyMember host <> " added " <> ttyFullMember m <> " to the group (connecting...)"]
|
2021-07-16 07:40:55 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewConnectedToGroupMember :: GroupName -> GroupMember -> [StyledString]
|
|
|
|
|
viewConnectedToGroupMember g m = [ttyGroup g <> ": " <> connectedMember m <> " is connected"]
|
2021-07-12 19:00:03 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewDeletedMember :: GroupName -> Maybe GroupMember -> Maybe GroupMember -> [StyledString]
|
|
|
|
|
viewDeletedMember g by m = [ttyGroup g <> ": " <> memberOrUser by <> " removed " <> memberOrUser m <> " from the group"]
|
2021-08-02 20:10:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewDeletedMemberUser :: GroupName -> GroupMember -> [StyledString]
|
|
|
|
|
viewDeletedMemberUser g by = viewDeletedMember g (Just by) Nothing <> groupPreserved g
|
2021-08-02 20:10:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewLeftMemberUser :: GroupName -> [StyledString]
|
|
|
|
|
viewLeftMemberUser g = leftMember_ g Nothing <> groupPreserved g
|
2021-08-02 20:10:24 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewLeftMember :: GroupName -> GroupMember -> [StyledString]
|
|
|
|
|
viewLeftMember g m = leftMember_ g (Just m)
|
2021-08-02 20:10:24 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2021-07-24 10:26:28 +01:00
|
|
|
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
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewGroupMembers :: Group -> [StyledString]
|
|
|
|
|
viewGroupMembers Group {membership, members} = map groupMember . filter (not . removedOrLeft) $ membership : members
|
2021-07-27 08:08:05 +01:00
|
|
|
where
|
|
|
|
|
removedOrLeft m = let s = memberStatus m in s == GSMemRemoved || s == GSMemLeft
|
|
|
|
|
groupMember m = ttyFullMember m <> ": " <> role m <> ", " <> category m <> status m
|
2022-01-11 08:50:44 +00:00
|
|
|
role m = plain . strEncode $ memberRole (m :: GroupMember)
|
2021-07-27 08:08:05 +01:00
|
|
|
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"
|
|
|
|
|
_ -> ""
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewGroupsList :: [(GroupName, Text, GroupMemberStatus)] -> [StyledString]
|
|
|
|
|
viewGroupsList [] = ["you have no groups!", "to create: " <> highlight' "/g <name>"]
|
|
|
|
|
viewGroupsList gs = map groupSS $ sort gs
|
2021-12-18 10:23:47 +00:00
|
|
|
where
|
2022-01-06 23:39:58 +04:00
|
|
|
groupSS (displayName, fullName, GSMemInvited) = groupInvitation displayName fullName
|
2022-01-06 14:24:33 +04:00
|
|
|
groupSS (displayName, fullName, _) = ttyGroup displayName <> optFullName displayName fullName
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewGroupInvitation :: Group -> [StyledString]
|
|
|
|
|
viewGroupInvitation Group {localDisplayName = ldn, groupProfile = GroupProfile {fullName}} =
|
|
|
|
|
[groupInvitation ldn fullName]
|
|
|
|
|
|
2022-01-06 23:39:58 +04:00
|
|
|
groupInvitation :: GroupName -> Text -> StyledString
|
|
|
|
|
groupInvitation displayName fullName =
|
2022-01-06 14:24:33 +04:00
|
|
|
highlight ("#" <> displayName)
|
|
|
|
|
<> optFullName displayName fullName
|
|
|
|
|
<> " - you are invited ("
|
|
|
|
|
<> highlight ("/j " <> displayName)
|
|
|
|
|
<> " to join, "
|
|
|
|
|
<> highlight ("/d #" <> displayName)
|
|
|
|
|
<> " to delete invitation)"
|
2021-12-10 11:45:58 +00:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactsMerged :: Contact -> Contact -> [StyledString]
|
|
|
|
|
viewContactsMerged _to@Contact {localDisplayName = c1} _from@Contact {localDisplayName = c2} =
|
2021-07-27 08:08:05 +01:00
|
|
|
[ "contact " <> ttyContact c2 <> " is merged into " <> ttyContact c1,
|
|
|
|
|
"use " <> ttyToContact c1 <> highlight' "<message>" <> " to send messages"
|
|
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewUserProfile :: Profile -> [StyledString]
|
|
|
|
|
viewUserProfile Profile {displayName, fullName} =
|
2021-08-22 15:56:36 +01:00
|
|
|
[ "user profile: " <> ttyFullName displayName fullName,
|
2021-09-04 07:32:56 +01:00
|
|
|
"use " <> highlight' "/p <display name> [<full name>]" <> " to change it",
|
2021-08-22 15:56:36 +01:00
|
|
|
"(the updated profile will be sent to all your contacts)"
|
|
|
|
|
]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewUserProfileUpdated :: User -> User -> [StyledString]
|
|
|
|
|
viewUserProfileUpdated
|
2021-08-22 15:56:36 +01:00
|
|
|
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)"
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewContactUpdated :: Contact -> Contact -> [StyledString]
|
|
|
|
|
viewContactUpdated
|
2021-08-22 15:56:36 +01:00
|
|
|
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'
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewMessageError :: Text -> Text -> [StyledString]
|
|
|
|
|
viewMessageError prefix err = [plain prefix <> ": " <> plain err]
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewReceivedMessage :: ContactName -> UTCTime -> [StyledString] -> MsgIntegrity -> IO [StyledString]
|
|
|
|
|
viewReceivedMessage = viewReceivedMessage_ . ttyFromContact
|
|
|
|
|
|
|
|
|
|
viewReceivedGroupMessage :: GroupName -> ContactName -> UTCTime -> [StyledString] -> MsgIntegrity -> IO [StyledString]
|
|
|
|
|
viewReceivedGroupMessage = viewReceivedMessage_ .: ttyFromGroup
|
|
|
|
|
|
|
|
|
|
viewReceivedMessage_ :: StyledString -> UTCTime -> [StyledString] -> MsgIntegrity -> IO [StyledString]
|
|
|
|
|
viewReceivedMessage_ from utcTime msg mOk = do
|
2021-06-25 18:18:24 +01:00
|
|
|
t <- formatUTCTime <$> getCurrentTimeZone <*> getZonedTime
|
2021-09-05 14:08:29 +01:00
|
|
|
pure $ prependFirst (t <> " " <> from) msg ++ showIntegrity mOk
|
2021-06-25 18:18:24 +01:00
|
|
|
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]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSentMessage :: ContactName -> ByteString -> IO [StyledString]
|
|
|
|
|
viewSentMessage = viewSentMessage_ . ttyToContact
|
|
|
|
|
|
|
|
|
|
viewSentGroupMessage :: GroupName -> ByteString -> IO [StyledString]
|
|
|
|
|
viewSentGroupMessage = viewSentMessage_ . ttyToGroup
|
|
|
|
|
|
|
|
|
|
viewSentMessage_ :: StyledString -> ByteString -> IO [StyledString]
|
|
|
|
|
viewSentMessage_ to msg = sentWithTime_ to . msgPlain $ safeDecodeUtf8 msg
|
|
|
|
|
|
|
|
|
|
viewSentFileInvitation :: ContactName -> FilePath -> IO [StyledString]
|
|
|
|
|
viewSentFileInvitation = viewSentFileInvitation_ . ttyToContact
|
2021-09-05 14:08:29 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSentGroupFileInvitation :: GroupName -> FilePath -> IO [StyledString]
|
|
|
|
|
viewSentGroupFileInvitation = viewSentFileInvitation_ . ttyToGroup
|
2021-09-05 14:08:29 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSentFileInvitation_ :: StyledString -> FilePath -> IO [StyledString]
|
|
|
|
|
viewSentFileInvitation_ to f = sentWithTime_ ("/f " <> to) [ttyFilePath f]
|
|
|
|
|
|
|
|
|
|
sentWithTime_ :: StyledString -> [StyledString] -> IO [StyledString]
|
|
|
|
|
sentWithTime_ to styledMsg = do
|
2021-06-25 18:18:24 +01:00
|
|
|
time <- formatTime defaultTimeLocale "%H:%M" <$> getZonedTime
|
2021-09-05 14:08:29 +01:00
|
|
|
pure $ prependFirst (styleTime time <> " " <> to) styledMsg
|
2021-06-25 18:18:24 +01:00
|
|
|
|
|
|
|
|
prependFirst :: StyledString -> [StyledString] -> [StyledString]
|
|
|
|
|
prependFirst s [] = [s]
|
|
|
|
|
prependFirst s (s' : ss) = (s <> s') : ss
|
|
|
|
|
|
2021-07-04 18:42:24 +01:00
|
|
|
msgPlain :: Text -> [StyledString]
|
|
|
|
|
msgPlain = map styleMarkdownText . T.lines
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSentFileInfo :: Int64 -> [StyledString]
|
|
|
|
|
viewSentFileInfo fileId =
|
2021-09-05 14:08:29 +01:00
|
|
|
["use " <> highlight ("/fc " <> show fileId) <> " to cancel sending"]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSndFileStart :: SndFileTransfer -> [StyledString]
|
|
|
|
|
viewSndFileStart = sendingFile_ "started"
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSndFileComplete :: SndFileTransfer -> [StyledString]
|
|
|
|
|
viewSndFileComplete = sendingFile_ "completed"
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSndFileCancelled :: SndFileTransfer -> [StyledString]
|
|
|
|
|
viewSndFileCancelled = sendingFile_ "cancelled"
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSndGroupFileCancelled :: [SndFileTransfer] -> [StyledString]
|
|
|
|
|
viewSndGroupFileCancelled fts =
|
2021-09-05 14:08:29 +01:00
|
|
|
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]
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2021-09-05 14:08:29 +01:00
|
|
|
sendingFile_ :: StyledString -> SndFileTransfer -> [StyledString]
|
|
|
|
|
sendingFile_ status ft@SndFileTransfer {recipientDisplayName = c} =
|
|
|
|
|
[status <> " sending " <> sndFile ft <> " to " <> ttyContact c]
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSndFileRcvCancelled :: SndFileTransfer -> [StyledString]
|
|
|
|
|
viewSndFileRcvCancelled ft@SndFileTransfer {recipientDisplayName = c} =
|
2021-09-05 14:08:29 +01:00
|
|
|
[ttyContact c <> " cancelled receiving " <> sndFile ft]
|
|
|
|
|
|
|
|
|
|
sndFile :: SndFileTransfer -> StyledString
|
|
|
|
|
sndFile SndFileTransfer {fileId, fileName} = fileTransfer fileId fileName
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewReceivedFileInvitation :: ContactName -> UTCTime -> RcvFileTransfer -> MsgIntegrity -> IO [StyledString]
|
|
|
|
|
viewReceivedFileInvitation c ts = viewReceivedMessage c ts . receivedFileInvitation_
|
|
|
|
|
|
|
|
|
|
viewReceivedGroupFileInvitation :: GroupName -> ContactName -> UTCTime -> RcvFileTransfer -> MsgIntegrity -> IO [StyledString]
|
|
|
|
|
viewReceivedGroupFileInvitation g c ts = viewReceivedGroupMessage g c ts . receivedFileInvitation_
|
|
|
|
|
|
|
|
|
|
receivedFileInvitation_ :: RcvFileTransfer -> [StyledString]
|
|
|
|
|
receivedFileInvitation_ RcvFileTransfer {fileId, fileInvitation = FileInvitation {fileName, fileSize}} =
|
2021-09-05 14:08:29 +01:00
|
|
|
[ "sends file " <> ttyFilePath fileName <> " (" <> humanReadableSize fileSize <> " / " <> sShow fileSize <> " bytes)",
|
2021-09-04 07:32:56 +01:00
|
|
|
"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
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewRcvFileAccepted :: RcvFileTransfer -> FilePath -> [StyledString]
|
|
|
|
|
viewRcvFileAccepted RcvFileTransfer {fileId, senderDisplayName = c} filePath =
|
2021-09-05 14:08:29 +01:00
|
|
|
["saving file " <> sShow fileId <> " from " <> ttyContact c <> " to " <> plain filePath]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewRcvFileStart :: RcvFileTransfer -> [StyledString]
|
|
|
|
|
viewRcvFileStart = receivingFile_ "started"
|
2021-09-05 14:08:29 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewRcvFileComplete :: RcvFileTransfer -> [StyledString]
|
|
|
|
|
viewRcvFileComplete = receivingFile_ "completed"
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewRcvFileCancelled :: RcvFileTransfer -> [StyledString]
|
|
|
|
|
viewRcvFileCancelled = receivingFile_ "cancelled"
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2021-09-05 14:08:29 +01:00
|
|
|
receivingFile_ :: StyledString -> RcvFileTransfer -> [StyledString]
|
|
|
|
|
receivingFile_ status ft@RcvFileTransfer {senderDisplayName = c} =
|
|
|
|
|
[status <> " receiving " <> rcvFile ft <> " from " <> ttyContact c]
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewRcvFileSndCancelled :: RcvFileTransfer -> [StyledString]
|
|
|
|
|
viewRcvFileSndCancelled ft@RcvFileTransfer {senderDisplayName = c} =
|
2021-09-05 14:08:29 +01:00
|
|
|
[ttyContact c <> " cancelled sending " <> rcvFile ft]
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2021-09-05 14:08:29 +01:00
|
|
|
rcvFile :: RcvFileTransfer -> StyledString
|
|
|
|
|
rcvFile RcvFileTransfer {fileId, fileInvitation = FileInvitation {fileName}} = fileTransfer fileId fileName
|
|
|
|
|
|
|
|
|
|
fileTransfer :: Int64 -> String -> StyledString
|
|
|
|
|
fileTransfer fileId fileName = "file " <> sShow fileId <> " (" <> ttyFilePath fileName <> ")"
|
2021-09-04 07:32:56 +01:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewFileTransferStatus :: (FileTransfer, [Integer]) -> [StyledString]
|
|
|
|
|
viewFileTransferStatus (FTSnd [ft@SndFileTransfer {fileStatus, fileSize, chunkSize}], chunksNum) =
|
2021-09-05 14:08:29 +01:00
|
|
|
["sending " <> sndFile ft <> " " <> sndStatus]
|
2021-09-04 07:32:56 +01:00
|
|
|
where
|
|
|
|
|
sndStatus = case fileStatus of
|
2021-09-05 14:08:29 +01:00
|
|
|
FSNew -> "not accepted yet"
|
2021-09-04 07:32:56 +01:00
|
|
|
FSAccepted -> "just started"
|
2021-09-05 14:08:29 +01:00
|
|
|
FSConnected -> "progress " <> fileProgress chunksNum chunkSize fileSize
|
|
|
|
|
FSComplete -> "complete"
|
|
|
|
|
FSCancelled -> "cancelled"
|
2022-01-21 11:09:33 +00:00
|
|
|
viewFileTransferStatus (FTSnd [], _) = ["no file transfers (empty group)"]
|
|
|
|
|
viewFileTransferStatus (FTSnd fts@(ft : _), chunksNum) =
|
2021-09-05 14:08:29 +01:00
|
|
|
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"
|
2022-01-21 11:09:33 +00:00
|
|
|
viewFileTransferStatus (FTRcv ft@RcvFileTransfer {fileId, fileInvitation = FileInvitation {fileSize}, fileStatus, chunkSize}, chunksNum) =
|
2021-09-05 14:08:29 +01:00
|
|
|
["receiving " <> rcvFile ft <> " " <> rcvStatus]
|
2021-09-04 07:32:56 +01:00
|
|
|
where
|
|
|
|
|
rcvStatus = case fileStatus of
|
2021-09-05 14:08:29 +01:00
|
|
|
RFSNew -> "not accepted yet, use " <> highlight ("/fr " <> show fileId) <> " to receive file"
|
2021-09-04 07:32:56 +01:00
|
|
|
RFSAccepted _ -> "just started"
|
2021-09-05 14:08:29 +01:00
|
|
|
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)
|
2021-09-04 07:32:56 +01:00
|
|
|
|
|
|
|
|
fileProgress :: [Integer] -> Integer -> Integer -> StyledString
|
|
|
|
|
fileProgress chunksNum chunkSize fileSize =
|
|
|
|
|
sShow (sum chunksNum * chunkSize * 100 `div` fileSize) <> "% of " <> humanReadableSize fileSize
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewSndFileSubError :: SndFileTransfer -> ChatError -> [StyledString]
|
|
|
|
|
viewSndFileSubError SndFileTransfer {fileId, fileName} e =
|
2021-09-04 07:32:56 +01:00
|
|
|
["sent file " <> sShow fileId <> " (" <> plain fileName <> ") error: " <> sShow e]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewRcvFileSubError :: RcvFileTransfer -> ChatError -> [StyledString]
|
|
|
|
|
viewRcvFileSubError RcvFileTransfer {fileId, fileInvitation = FileInvitation {fileName}} e =
|
2021-09-04 07:32:56 +01:00
|
|
|
["received file " <> sShow fileId <> " (" <> plain fileName <> ") error: " <> sShow e]
|
|
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
viewChatError :: ChatError -> [StyledString]
|
|
|
|
|
viewChatError = \case
|
2021-07-16 07:40:55 +01:00
|
|
|
ChatError err -> case err of
|
|
|
|
|
CEGroupDuplicateMember c -> ["contact " <> ttyContact c <> " is already in the group"]
|
|
|
|
|
CEGroupDuplicateMemberId -> ["cannot add member - duplicate member ID"]
|
2021-07-24 10:26:28 +01:00
|
|
|
CEGroupUserRole -> ["you have insufficient permissions for this group command"]
|
|
|
|
|
CEGroupContactRole c -> ["contact " <> ttyContact c <> " has insufficient permissions for this group action"]
|
2021-07-16 07:40:55 +01:00
|
|
|
CEGroupNotJoined g -> ["you did not join this group, use " <> highlight ("/join #" <> g)]
|
2021-07-24 10:26:28 +01:00
|
|
|
CEGroupMemberNotActive -> ["you cannot invite other members yet, try later"]
|
2022-01-05 20:46:35 +04:00
|
|
|
CEGroupMemberUserRemoved -> ["you are no longer a member of the group"]
|
2021-08-02 20:10:24 +01:00
|
|
|
CEGroupMemberNotFound c -> ["contact " <> ttyContact c <> " is not a group member"]
|
2021-07-16 07:40:55 +01:00
|
|
|
CEGroupInternal s -> ["chat group bug: " <> plain s]
|
2021-09-04 07:32:56 +01:00
|
|
|
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]
|
2022-01-11 08:50:44 +00:00
|
|
|
CEAgentVersion -> ["unsupported agent version"]
|
2021-09-04 07:32:56 +01:00
|
|
|
-- e -> ["chat error: " <> sShow e]
|
2021-07-12 19:00:03 +01:00
|
|
|
ChatErrorStore err -> case err of
|
2021-07-14 20:11:41 +01:00
|
|
|
SEDuplicateName -> ["this display name is already used by user, contact or group"]
|
2021-07-12 19:00:03 +01:00
|
|
|
SEContactNotFound c -> ["no contact " <> ttyContact c]
|
|
|
|
|
SEContactNotReady c -> ["contact " <> ttyContact c <> " is not active yet"]
|
2021-07-16 07:40:55 +01:00
|
|
|
SEGroupNotFound g -> ["no group " <> ttyGroup g]
|
|
|
|
|
SEGroupAlreadyJoined -> ["you already joined this group"]
|
2021-09-04 07:32:56 +01:00
|
|
|
SEFileNotFound fileId -> fileNotFound fileId
|
|
|
|
|
SESndFileNotFound fileId -> fileNotFound fileId
|
|
|
|
|
SERcvFileNotFound fileId -> fileNotFound fileId
|
2021-12-08 13:09:51 +00:00
|
|
|
SEDuplicateContactLink -> ["you already have chat address, to show: " <> highlight' "/sa"]
|
|
|
|
|
SEUserContactLinkNotFound -> ["no chat address, to create: " <> highlight' "/ad"]
|
|
|
|
|
SEContactRequestNotFound c -> ["no contact request from " <> ttyContact c]
|
2021-09-04 07:32:56 +01:00
|
|
|
e -> ["chat db error: " <> sShow e]
|
2021-12-08 13:09:51 +00:00
|
|
|
ChatErrorAgent err -> case err of
|
|
|
|
|
SMP SMP.AUTH -> ["error: this connection is deleted"]
|
|
|
|
|
e -> ["smp agent error: " <> sShow e]
|
2021-09-04 07:32:56 +01:00
|
|
|
ChatErrorMessage e -> ["chat message error: " <> sShow e]
|
|
|
|
|
where
|
|
|
|
|
fileNotFound fileId = ["file " <> sShow fileId <> " not found"]
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2021-07-14 20:11:41 +01:00
|
|
|
ttyContact :: ContactName -> StyledString
|
2021-07-04 18:42:24 +01:00
|
|
|
ttyContact = styled (Colored Green)
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2021-07-16 07:40:55 +01:00
|
|
|
ttyFullContact :: Contact -> StyledString
|
|
|
|
|
ttyFullContact Contact {localDisplayName, profile = Profile {fullName}} =
|
2021-07-24 10:26:28 +01:00
|
|
|
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
|
2021-07-16 07:40:55 +01:00
|
|
|
|
2021-07-14 20:11:41 +01:00
|
|
|
ttyToContact :: ContactName -> StyledString
|
2021-07-07 22:46:38 +01:00
|
|
|
ttyToContact c = styled (Colored Cyan) $ "@" <> c <> " "
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2021-07-14 20:11:41 +01:00
|
|
|
ttyFromContact :: ContactName -> StyledString
|
2021-07-04 18:42:24 +01:00
|
|
|
ttyFromContact c = styled (Colored Yellow) $ c <> "> "
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2021-07-14 20:11:41 +01:00
|
|
|
ttyGroup :: GroupName -> StyledString
|
2021-07-12 19:00:03 +01:00
|
|
|
ttyGroup g = styled (Colored Blue) $ "#" <> g
|
2021-06-25 18:18:24 +01:00
|
|
|
|
2021-07-16 07:40:55 +01:00
|
|
|
ttyFullGroup :: Group -> StyledString
|
|
|
|
|
ttyFullGroup Group {localDisplayName, groupProfile = GroupProfile {fullName}} =
|
|
|
|
|
ttyGroup localDisplayName <> optFullName localDisplayName fullName
|
|
|
|
|
|
2021-07-24 10:26:28 +01:00
|
|
|
ttyFromGroup :: GroupName -> ContactName -> StyledString
|
|
|
|
|
ttyFromGroup g c = styled (Colored Yellow) $ "#" <> g <> " " <> c <> "> "
|
|
|
|
|
|
|
|
|
|
ttyToGroup :: GroupName -> StyledString
|
|
|
|
|
ttyToGroup g = styled (Colored Cyan) $ "#" <> g <> " "
|
|
|
|
|
|
2021-09-05 14:08:29 +01:00
|
|
|
ttyFilePath :: FilePath -> StyledString
|
|
|
|
|
ttyFilePath = plain
|
|
|
|
|
|
2021-07-24 10:26:28 +01:00
|
|
|
optFullName :: ContactName -> Text -> StyledString
|
2021-07-16 07:40:55 +01:00
|
|
|
optFullName localDisplayName fullName
|
2021-07-24 10:26:28 +01:00
|
|
|
| T.null fullName || localDisplayName == fullName = ""
|
2021-07-16 07:40:55 +01:00
|
|
|
| otherwise = plain (" (" <> fullName <> ")")
|
|
|
|
|
|
|
|
|
|
highlight :: StyledFormat a => a -> StyledString
|
|
|
|
|
highlight = styled (Colored Cyan)
|
|
|
|
|
|
|
|
|
|
highlight' :: String -> StyledString
|
|
|
|
|
highlight' = highlight
|
|
|
|
|
|
2021-06-25 18:18:24 +01:00
|
|
|
styleTime :: String -> StyledString
|
|
|
|
|
styleTime = Styled [SetColor Foreground Vivid Black]
|
2021-11-07 21:57:05 +00:00
|
|
|
|
|
|
|
|
clientVersionInfo :: [StyledString]
|
2022-01-11 21:23:57 +00:00
|
|
|
clientVersionInfo = [plain versionStr, plain updateStr]
|