switch to * for chat type sigil

This commit is contained in:
IC Rainbow
2024-01-04 18:14:35 +02:00
parent 8e3df00c62
commit 65bb3d2bbd
7 changed files with 66 additions and 66 deletions

View File

@@ -6294,7 +6294,7 @@ chatCommandP =
"/_get items " *> (APIGetChatItems <$> chatPaginationP <*> optional (" search=" *> stringP)),
"/_get item info " *> (APIGetChatItemInfo <$> chatRefP <* A.space <*> A.decimal),
"/_send " *> (APISendMessage <$> chatRefP <*> liveMessageP <*> sendMessageTTLP <*> (" json " *> jsonP <|> " text " *> (ComposedMessage Nothing Nothing <$> mcTextP))),
"/_create -" *> (APICreateChatItem <$> A.decimal <*> (" json " *> jsonP <|> " text " *> (ComposedMessage Nothing Nothing <$> mcTextP))),
"/_create *" *> (APICreateChatItem <$> A.decimal <*> (" json " *> jsonP <|> " text " *> (ComposedMessage Nothing Nothing <$> mcTextP))),
"/_update item " *> (APIUpdateChatItem <$> chatRefP <* A.space <*> A.decimal <*> liveMessageP <* A.space <*> msgContentP),
"/_delete item " *> (APIDeleteChatItem <$> chatRefP <* A.space <*> A.decimal <* A.space <*> ciDeleteMode),
"/_delete member item #" *> (APIDeleteMemberChatItem <$> A.decimal <* A.space <*> A.decimal <* A.space <*> A.decimal),
@@ -6403,7 +6403,7 @@ chatCommandP =
("/leave " <|> "/l ") *> char_ '#' *> (LeaveGroup <$> displayName),
("/delete #" <|> "/d #") *> (DeleteGroup <$> displayName),
("/delete " <|> "/d ") *> char_ '@' *> (DeleteContact <$> displayName),
"/clear -" $> ClearNoteFolder "",
"/clear *" $> ClearNoteFolder "",
"/clear #" *> (ClearGroup <$> displayName),
"/clear " *> char_ '@' *> (ClearContact <$> displayName),
("/members " <|> "/ms ") *> char_ '#' *> (ListMembers <$> displayName),
@@ -6437,7 +6437,7 @@ chatCommandP =
("/connect" <|> "/c") *> (Connect <$> incognitoP <* A.space <*> ((Just <$> strP) <|> A.takeTill isSpace $> Nothing)),
("/connect" <|> "/c") *> (AddContact <$> incognitoP),
SendMessage <$> chatNameP <* A.space <*> msgTextP,
"/- " *> (SendMessage (ChatName CTLocal "") <$> msgTextP),
"/* " *> (SendMessage (ChatName CTLocal "") <$> msgTextP),
"@#" *> (SendMemberContactMessage <$> displayName <* A.space <* char_ '@' <*> displayName <* A.space <*> msgTextP),
"/live " *> (SendLiveMessage <$> chatNameP <*> (A.space *> msgTextP <|> pure "")),
(">@" <|> "> @") *> sendMsgQuote (AMsgDirection SMDRcv),
@@ -6528,7 +6528,7 @@ chatCommandP =
incognitoOnOffP = (A.space *> "incognito=" *> onOffP) <|> pure False
imagePrefix = (<>) <$> "data:" <*> ("image/png;base64," <|> "image/jpg;base64,")
imageP = safeDecodeUtf8 <$> ((<>) <$> imagePrefix <*> (B64.encode <$> base64P))
chatTypeP = A.char '@' $> CTDirect <|> A.char '#' $> CTGroup <|> A.char '-' $> CTLocal <|> A.char ':' $> CTContactConnection
chatTypeP = A.char '@' $> CTDirect <|> A.char '#' $> CTGroup <|> A.char '*' $> CTLocal <|> A.char ':' $> CTContactConnection
chatPaginationP =
(CPLast <$ "count=" <*> A.decimal)
<|> (CPAfter <$ "after=" <*> A.decimal <* A.space <* "count=" <*> A.decimal)

View File

@@ -64,7 +64,7 @@ chatTypeStr :: ChatType -> Text
chatTypeStr = \case
CTDirect -> "@"
CTGroup -> "#"
CTLocal -> "-"
CTLocal -> "*"
CTContactRequest -> "<@"
CTContactConnection -> ":"

View File

@@ -395,7 +395,7 @@ responseToView hu@(currentRH, user_) ChatConfig {logLevel, showReactions, showRe
toChatView :: AChat -> (Text, Text, Maybe ConnStatus)
toChatView (AChat _ (Chat (DirectChat Contact {localDisplayName, activeConn}) items _)) = ("@" <> localDisplayName, toCIPreview items Nothing, connStatus <$> activeConn)
toChatView (AChat _ (Chat (GroupChat GroupInfo {membership, localDisplayName}) items _)) = ("#" <> localDisplayName, toCIPreview items (Just membership), Nothing)
toChatView (AChat _ (Chat (LocalChat _) items _)) = ("-", toCIPreview items Nothing, Nothing)
toChatView (AChat _ (Chat (LocalChat _) items _)) = ("*", toCIPreview items Nothing, Nothing)
toChatView (AChat _ (Chat (ContactRequest UserContactRequest {localDisplayName}) items _)) = ("<@" <> localDisplayName, toCIPreview items Nothing, Nothing)
toChatView (AChat _ (Chat (ContactConnection PendingContactConnection {pccConnId, pccConnStatus}) items _)) = (":" <> T.pack (show pccConnId), toCIPreview items Nothing, Just pccConnStatus)
toCIPreview :: [CChatItem c] -> Maybe GroupMember -> Text
@@ -560,14 +560,14 @@ viewChatItem chat ci@ChatItem {chatDir, meta = meta@CIMeta {forwardedByMember},
CISndGroupEvent {} -> showSndItemProhibited to
_ -> showSndItem to
where
to = "- "
to = "* "
CILocalRcv -> case content of
CIRcvMsgContent mc -> withLocalFile from $ rcvMsg from quote mc
CIRcvIntegrityError err -> viewRcvIntegrityError from err ts tz meta
CIRcvGroupEvent {} -> showRcvItemProhibited from
_ -> showRcvItem from
where
from = "- "
from = "* "
where
quote = []
ContactRequest {} -> []
@@ -728,7 +728,7 @@ viewItemReaction showReactions chat CIReaction {chatDir, chatItem = CChatItem md
Just mc -> view from $ reactionMsg mc
_ -> []
where
from = "- "
from = "* "
reactionMsg mc = quoteText mc $ if toMsgDirection md == MDSnd then ">>" else ">"
(_, CIDirectSnd) -> [sentText]
(_, CIGroupSnd) -> [sentText]
@@ -2023,7 +2023,7 @@ ttyGroup' :: GroupInfo -> StyledString
ttyGroup' = ttyGroup . groupName'
ttyLocal :: NoteFolderName -> StyledString
ttyLocal l = styled (colored Green) $ "-" <> viewName l
ttyLocal l = styled (colored Green) $ "*" <> viewName l
viewContactName :: Contact -> Text
viewContactName = viewName . localDisplayName'

View File

@@ -193,20 +193,20 @@ testPaginationAllChatTypes =
_ts6 <- iso8601Show <$> getCurrentTime
-- -notes
-- * (notes)
createCCNoteFolder alice
alice /- "psst"
alice /* "psst"
ts7 <- iso8601Show <$> getCurrentTime
getChats_ alice "count=10" [("-", "psst"), ("@dan", "hey"), ("#team", ""), (":3", ""), ("<@cath", ""), ("@bob", "hey")]
getChats_ alice "count=3" [("-", "psst"), ("@dan", "hey"), ("#team", "")]
getChats_ alice "count=10" [("*", "psst"), ("@dan", "hey"), ("#team", ""), (":3", ""), ("<@cath", ""), ("@bob", "hey")]
getChats_ alice "count=3" [("*", "psst"), ("@dan", "hey"), ("#team", "")]
getChats_ alice ("after=" <> ts2 <> " count=2") [(":3", ""), ("<@cath", "")]
getChats_ alice ("before=" <> ts5 <> " count=2") [("#team", ""), (":3", "")]
getChats_ alice ("after=" <> ts3 <> " count=10") [("-", "psst"), ("@dan", "hey"), ("#team", ""), (":3", "")]
getChats_ alice ("after=" <> ts3 <> " count=10") [("*", "psst"), ("@dan", "hey"), ("#team", ""), (":3", "")]
getChats_ alice ("before=" <> ts4 <> " count=10") [(":3", ""), ("<@cath", ""), ("@bob", "hey")]
getChats_ alice ("after=" <> ts1 <> " count=10") [("-", "psst"), ("@dan", "hey"), ("#team", ""), (":3", ""), ("<@cath", ""), ("@bob", "hey")]
getChats_ alice ("before=" <> ts7 <> " count=10") [("-", "psst"), ("@dan", "hey"), ("#team", ""), (":3", ""), ("<@cath", ""), ("@bob", "hey")]
getChats_ alice ("after=" <> ts1 <> " count=10") [("*", "psst"), ("@dan", "hey"), ("#team", ""), (":3", ""), ("<@cath", ""), ("@bob", "hey")]
getChats_ alice ("before=" <> ts7 <> " count=10") [("*", "psst"), ("@dan", "hey"), ("#team", ""), (":3", ""), ("<@cath", ""), ("@bob", "hey")]
getChats_ alice ("after=" <> ts7 <> " count=10") []
getChats_ alice ("before=" <> ts1 <> " count=10") []

View File

@@ -1386,14 +1386,14 @@ testMultipleUserAddresses =
cLinkAlisa <- getContactLink alice True
bob ##> ("/c " <> cLinkAlisa)
alice <#? bob
alice #$> ("/_get chats 2 pcc=on", chats, [("<@bob", ""), ("-", "")])
alice #$> ("/_get chats 2 pcc=on", chats, [("<@bob", ""), ("*", "")])
alice ##> "/ac bob"
alice <## "bob (Bob): accepting contact request..."
concurrently_
(bob <## "alisa: contact is connected")
(alice <## "bob (Bob): contact is connected")
threadDelay 100000
alice #$> ("/_get chats 2 pcc=on", chats, [("@bob", lastChatFeature), ("-", "")])
alice #$> ("/_get chats 2 pcc=on", chats, [("@bob", lastChatFeature), ("*", "")])
alice <##> bob
bob #> "@alice hey alice"
@@ -1424,7 +1424,7 @@ testMultipleUserAddresses =
(cath <## "alisa: contact is connected")
(alice <## "cath (Catherine): contact is connected")
threadDelay 100000
alice #$> ("/_get chats 2 pcc=on", chats, [("@cath", lastChatFeature), ("@bob", "hey"), ("-", "")])
alice #$> ("/_get chats 2 pcc=on", chats, [("@cath", lastChatFeature), ("@bob", "hey"), ("*", "")])
alice <##> cath
-- first user doesn't have cath as contact

View File

@@ -28,35 +28,35 @@ testNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
alice ##> "/contacts"
-- not a contact
alice /- "keep in mind"
alice /* "keep in mind"
alice ##> "/tail"
alice <# "- keep in mind"
alice <# "* keep in mind"
alice ##> "/chats"
alice <# "- keep in mind"
alice <# "* keep in mind"
alice ##> "/? keep"
alice <# "- keep in mind"
alice <# "* keep in mind"
alice #$> ("/_read chat -1 from=1 to=100", id, "ok")
alice ##> "/_unread chat -1 on"
alice #$> ("/_read chat *1 from=1 to=100", id, "ok")
alice ##> "/_unread chat *1 on"
alice <## "ok"
alice ##> "/_delete item -1 1 internal"
alice ##> "/_delete item *1 1 internal"
alice <## "message deleted"
alice ##> "/tail"
alice ##> "/chats"
alice /- "ahoy!"
alice ##> "/_update item -1 1 text Greetings."
alice ##> "/tail -"
alice <# "- Greetings."
alice /* "ahoy!"
alice ##> "/_update item *1 1 text Greetings."
alice ##> "/tail *"
alice <# "* Greetings."
testUserNotes :: FilePath -> IO ()
testUserNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
createCCNoteFolder alice
alice /- "keep in mind"
alice /* "keep in mind"
alice ##> "/tail"
alice <# "- keep in mind"
alice <# "* keep in mind"
alice ##> "/create user secret"
alice <## "user profile: secret"
@@ -65,7 +65,7 @@ testUserNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
alice ##> "/tail"
alice ##> "/_delete item -1 1 internal"
alice ##> "/_delete item *1 1 internal"
alice <## "chat db error: SENoteFolderNotFound {noteFolderId = 1}"
testPreviewsPagination :: FilePath -> IO ()
@@ -73,38 +73,38 @@ testPreviewsPagination tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -
createCCNoteFolder alice
tsS <- iso8601Show <$> getCurrentTime
alice /- "first"
alice /* "first"
tsM <- iso8601Show <$> getCurrentTime
alice /- "last"
alice /* "last"
tsE <- iso8601Show <$> getCurrentTime
-- there's only one folder that got updated after tsM and before tsE
getChats_ alice "count=3" [("-", "last")]
getChats_ alice "count=3" [("*", "last")]
getChats_ alice ("after=" <> tsE <> " count=10") []
getChats_ alice ("after=" <> tsS <> " count=10") [("-", "last")]
getChats_ alice ("after=" <> tsS <> " count=10") [("*", "last")]
getChats_ alice ("before=" <> tsM <> " count=10") []
getChats_ alice ("before=" <> tsE <> " count=10") [("-", "last")]
getChats_ alice ("before=" <> tsE <> " count=10") [("*", "last")]
getChats_ alice ("before=" <> tsS <> " count=10") []
testChatPagination :: FilePath -> IO ()
testChatPagination tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
createCCNoteFolder alice
alice /- "hello world"
alice /- "memento mori"
alice /- "knock-knock"
alice /- "who's there?"
alice /* "hello world"
alice /* "memento mori"
alice /* "knock-knock"
alice /* "who's there?"
alice #$> ("/_get chat -1 count=100", chat, [(1, "hello world"), (1, "memento mori"), (1, "knock-knock"), (1, "who's there?")])
alice #$> ("/_get chat -1 count=1", chat, [(1, "who's there?")])
alice #$> ("/_get chat -1 after=2 count=10", chat, [(1, "knock-knock"), (1, "who's there?")])
alice #$> ("/_get chat -1 after=2 count=2", chat, [(1, "knock-knock"), (1, "who's there?")])
alice #$> ("/_get chat -1 after=1 count=2", chat, [(1, "memento mori"), (1, "knock-knock")])
alice #$> ("/_get chat -1 before=3 count=10", chat, [(1, "hello world"), (1, "memento mori")])
alice #$> ("/_get chat -1 before=3 count=2", chat, [(1, "hello world"), (1, "memento mori")])
alice #$> ("/_get chat -1 before=4 count=2", chat, [(1, "memento mori"), (1, "knock-knock")])
alice #$> ("/_get chat *1 count=100", chat, [(1, "hello world"), (1, "memento mori"), (1, "knock-knock"), (1, "who's there?")])
alice #$> ("/_get chat *1 count=1", chat, [(1, "who's there?")])
alice #$> ("/_get chat *1 after=2 count=10", chat, [(1, "knock-knock"), (1, "who's there?")])
alice #$> ("/_get chat *1 after=2 count=2", chat, [(1, "knock-knock"), (1, "who's there?")])
alice #$> ("/_get chat *1 after=1 count=2", chat, [(1, "memento mori"), (1, "knock-knock")])
alice #$> ("/_get chat *1 before=3 count=10", chat, [(1, "hello world"), (1, "memento mori")])
alice #$> ("/_get chat *1 before=3 count=2", chat, [(1, "hello world"), (1, "memento mori")])
alice #$> ("/_get chat *1 before=4 count=2", chat, [(1, "memento mori"), (1, "knock-knock")])
alice #$> ("/_get chat -1 count=10 search=k-k", chat, [(1, "knock-knock")])
alice #$> ("/_get chat *1 count=10 search=k-k", chat, [(1, "knock-knock")])
testFiles :: FilePath -> IO ()
testFiles tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
@@ -118,15 +118,15 @@ testFiles tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
let source = "./tests/fixtures/test.jpg"
let stored = files </> "test.jpg"
copyFile source stored
alice ##> "/_create -1 json {\"filePath\": \"test.jpg\", \"msgContent\": {\"text\":\"hi myself\",\"type\":\"image\",\"image\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII=\"}}"
alice <# "- hi myself"
alice <# "- file 1 (test.jpg)"
alice ##> "/_create *1 json {\"filePath\": \"test.jpg\", \"msgContent\": {\"text\":\"hi myself\",\"type\":\"image\",\"image\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII=\"}}"
alice <# "* hi myself"
alice <# "* file 1 (test.jpg)"
alice ##> "/tail"
alice <# "- hi myself"
alice <# "- file 1 (test.jpg)"
alice <# "* hi myself"
alice <# "* file 1 (test.jpg)"
alice ##> "/_get chat -1 count=100"
alice ##> "/_get chat *1 count=100"
r <- chatF <$> getTermLine alice
r `shouldBe` [((1, "hi myself"), Just "test.jpg")]
@@ -136,15 +136,15 @@ testFiles tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
-- one more file
let stored2 = files </> "another_test.jpg"
copyFile source stored2
alice ##> "/_create -1 json {\"filePath\": \"another_test.jpg\", \"msgContent\": {\"text\":\"\",\"type\":\"image\",\"image\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII=\"}}"
alice <# "- file 2 (another_test.jpg)"
alice ##> "/_create *1 json {\"filePath\": \"another_test.jpg\", \"msgContent\": {\"text\":\"\",\"type\":\"image\",\"image\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII=\"}}"
alice <# "* file 2 (another_test.jpg)"
alice ##> "/_delete item -1 2 internal"
alice ##> "/_delete item *1 2 internal"
alice <## "message deleted"
doesFileExist stored2 `shouldReturn` False
doesFileExist stored `shouldReturn` True
alice ##> "/clear -"
alice ##> "/clear *"
alice ##> "/fs 1"
alice <## "chat db error: SEChatItemNotFoundByFileId {fileId = 1}"
alice ##> "/tail"

View File

@@ -289,10 +289,10 @@ cc <##.. ls = do
unless prefix $ print ("expected to start from one of: " <> show ls, ", got: " <> l)
prefix `shouldBe` True
(/-) :: HasCallStack => TestCC -> String -> IO ()
cc /- note = do
cc `send` ("/- " <> note)
(dropTime <$> getTermLine cc) `shouldReturn` ("- " <> note)
(/*) :: HasCallStack => TestCC -> String -> IO ()
cc /* note = do
cc `send` ("/* " <> note)
(dropTime <$> getTermLine cc) `shouldReturn` ("* " <> note)
data ConsoleResponse
= ConsoleString String