diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 0572b065c2..e76f951206 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -6380,7 +6380,7 @@ chatCommandP = ("/leave " <|> "/l ") *> char_ '#' *> (LeaveGroup <$> displayName), ("/delete #" <|> "/d #") *> (DeleteGroup <$> displayName), ("/delete " <|> "/d ") *> char_ '@' *> (DeleteContact <$> displayName), - "/clear $" *> (ClearNoteFolder <$> displayName), + "/clear -" $> ClearNoteFolder "-", "/clear #" *> (ClearGroup <$> displayName), "/clear " *> char_ '@' *> (ClearContact <$> displayName), ("/members " <|> "/ms ") *> char_ '#' *> (ListMembers <$> displayName), @@ -6414,22 +6414,23 @@ 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), "@#" *> (SendMemberContactMessage <$> displayName <* A.space <* char_ '@' <*> displayName <* A.space <*> msgTextP), "/live " *> (SendLiveMessage <$> chatNameP <*> (A.space *> msgTextP <|> pure "")), (">@" <|> "> @") *> sendMsgQuote (AMsgDirection SMDRcv), (">>@" <|> ">> @") *> sendMsgQuote (AMsgDirection SMDSnd), ("\\ " <|> "\\") *> (DeleteMessage <$> chatNameP <* A.space <*> textP), ("\\\\ #" <|> "\\\\#") *> (DeleteMemberMessage <$> displayName <* A.space <* char_ '@' <*> displayName <* A.space <*> textP), - ("! " <|> "!") *> (EditMessage <$> chatNameP <* A.space <*> (quotedMsg <|> pure "") <*> msgTextP), + ("! " <|> "!") *> (EditMessage <$> (notesNameP <|> chatNameP) <* A.space <*> (quotedMsg <|> pure "") <*> msgTextP), ReactToMessage <$> (("+" $> True) <|> ("-" $> False)) <*> reactionP <* A.space <*> chatNameP' <* A.space <*> textP, "/feed " *> (SendMessageBroadcast <$> msgTextP), ("/chats" <|> "/cs") *> (LastChats <$> (" all" $> Nothing <|> Just <$> (A.space *> A.decimal <|> pure 20))), - ("/tail" <|> "/t") *> (LastMessages <$> optional (A.space *> chatNameP) <*> msgCountP <*> pure Nothing), - ("/search" <|> "/?") *> (LastMessages <$> optional (A.space *> chatNameP) <*> msgCountP <*> (Just <$> (A.space *> stringP))), - "/last_item_id" *> (LastChatItemId <$> optional (A.space *> chatNameP) <*> (A.space *> A.decimal <|> pure 0)), + ("/tail" <|> "/t") *> (LastMessages <$> optional (A.space *> (notesNameP <|> chatNameP)) <*> msgCountP <*> pure Nothing), + ("/search" <|> "/?") *> (LastMessages <$> optional (A.space *> (notesNameP <|> chatNameP)) <*> msgCountP <*> (Just <$> (A.space *> stringP))), + "/last_item_id" *> (LastChatItemId <$> optional (A.space *> (notesNameP <|> chatNameP)) <*> (A.space *> A.decimal <|> pure 0)), "/show" *> (ShowLiveItems <$> (A.space *> onOffP <|> pure True)), "/show " *> (ShowChatItem . Just <$> A.decimal), - "/item info " *> (ShowChatItemInfo <$> chatNameP <* A.space <*> msgTextP), + "/item info " *> (ShowChatItemInfo <$> (notesNameP <|> chatNameP) <* A.space <*> msgTextP), ("/file " <|> "/f ") *> (SendFile <$> chatNameP' <* A.space <*> cryptoFileP), ("/image " <|> "/img ") *> (SendImage <$> chatNameP' <* A.space <*> cryptoFileP), ("/fforward " <|> "/ff ") *> (ForwardFile <$> chatNameP' <* A.space <*> A.decimal), @@ -6577,6 +6578,7 @@ chatCommandP = " member" $> GRMember, " observer" $> GRObserver ] + notesNameP = A.char '-' $> ChatName CTLocal "-" chatNameP = ChatName <$> chatTypeP <*> displayName chatNameP' = ChatName <$> (chatTypeP <|> pure CTDirect) <*> displayName chatRefP = ChatRef <$> chatTypeP <*> A.decimal diff --git a/src/Simplex/Chat/Store/NoteFolders.hs b/src/Simplex/Chat/Store/NoteFolders.hs index 13fc491fc4..2a3f7d09db 100644 --- a/src/Simplex/Chat/Store/NoteFolders.hs +++ b/src/Simplex/Chat/Store/NoteFolders.hs @@ -17,7 +17,7 @@ import qualified Simplex.Messaging.Agent.Store.SQLite.DB as DB getNoteFolderIdByName :: DB.Connection -> User -> NoteFolderName -> ExceptT StoreError IO NoteFolderId getNoteFolderIdByName db User {userId} ldn = ExceptT . firstRow fromOnly (SENoteFolderNotFoundByName ldn) $ - DB.query db [sql| SELECT note_folder_id FROM note_folders WHERE user_id = ? AND "notes" = ? |] (userId, ldn) + DB.query db [sql| SELECT note_folder_id FROM note_folders WHERE user_id = ? AND "-" = ? |] (userId, ldn) getNoteFolder :: DB.Connection -> User -> NoteFolderId -> ExceptT StoreError IO NoteFolder getNoteFolder db User {userId} noteFolderId = diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 88f47e1267..5aa7d0b088 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -394,7 +394,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 _)) = ("$notes", 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 @@ -559,14 +559,14 @@ viewChatItem chat ci@ChatItem {chatDir, meta = meta@CIMeta {forwardedByMember}, CISndGroupEvent {} -> showSndItemProhibited to _ -> showSndItem to where - to = "$notes " + 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 {} -> [] @@ -727,7 +727,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] diff --git a/tests/ChatTests/ChatList.hs b/tests/ChatTests/ChatList.hs index e4ecc79cf1..835cf446c3 100644 --- a/tests/ChatTests/ChatList.hs +++ b/tests/ChatTests/ChatList.hs @@ -194,18 +194,19 @@ testPaginationAllChatTypes = _ts6 <- iso8601Show <$> getCurrentTime -- $notes - alice #> "$notes psst" + alice `send` "/- psst" + dropTime <$> getTermLine alice `shouldReturn` "- psst" ts7 <- iso8601Show <$> getCurrentTime - getChats_ alice "count=10" [("$notes", "psst"), ("@dan", "hey"), ("#team", ""), (":3", ""), ("<@cath", ""), ("@bob", "hey")] - getChats_ alice "count=3" [("$notes", "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") [("$notes", "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") [("$notes", "psst"), ("@dan", "hey"), ("#team", ""), (":3", ""), ("<@cath", ""), ("@bob", "hey")] - getChats_ alice ("before=" <> ts7 <> " count=10") [("$notes", "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") [] diff --git a/tests/ChatTests/Local.hs b/tests/ChatTests/Local.hs index f416a69967..ad3c64ac16 100644 --- a/tests/ChatTests/Local.hs +++ b/tests/ChatTests/Local.hs @@ -7,7 +7,7 @@ import ChatClient import ChatTests.Utils import System.Directory (copyFile, doesFileExist) import Test.Hspec -import System.FilePath (takeFileName, ()) +import System.FilePath (()) import Data.Time (getCurrentTime) import ChatTests.ChatList (getChats_) import Data.Time.Format.ISO8601 (iso8601Show) @@ -25,13 +25,13 @@ testNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do alice ##> "/contacts" -- not a contact - alice #> "$notes keep in mind" + alice /- "keep in mind" alice ##> "/tail" - alice <# "$notes keep in mind" + alice <# "- keep in mind" alice ##> "/chats" - alice <# "$notes keep in mind" + alice <# "- keep in mind" alice ##> "/? keep" - alice <# "$notes keep in mind" + alice <# "- keep in mind" alice #$> ("/_read chat $1 from=1 to=100", id, "ok") alice ##> "/_unread chat $1 on" @@ -42,16 +42,16 @@ testNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do alice ##> "/tail" alice ##> "/chats" - alice #> "$notes ahoy!" + alice /- "ahoy!" alice ##> "/_update item $1 1 text Greetings." - alice ##> "/tail $notes" - alice <# "$notes Greetings." + alice ##> "/tail -" + alice <# "- Greetings." testUserNotes :: FilePath -> IO () testUserNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do - alice #> "$notes keep in mind" + alice /- "keep in mind" alice ##> "/tail" - alice <# "$notes keep in mind" + alice <# "- keep in mind" alice ##> "/create user secret" alice <## "user profile: secret" @@ -66,17 +66,17 @@ testUserNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do testPreviewsPagination :: FilePath -> IO () testPreviewsPagination tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do tsS <- iso8601Show <$> getCurrentTime - alice #> "$notes first" + alice /- "first" tsM <- iso8601Show <$> getCurrentTime - alice #> "$notes last" + alice /- "last" tsE <- iso8601Show <$> getCurrentTime -- there's only one folder that got updated after tsM and before tsE - getChats_ alice "count=3" [("$notes", "last")] + getChats_ alice "count=3" [("-", "last")] getChats_ alice ("after=" <> tsE <> " count=10") [] - getChats_ alice ("after=" <> tsS <> " count=10") [("$notes", "last")] + getChats_ alice ("after=" <> tsS <> " count=10") [("-", "last")] getChats_ alice ("before=" <> tsM <> " count=10") [] - getChats_ alice ("before=" <> tsE <> " count=10") [("$notes", "last")] + getChats_ alice ("before=" <> tsE <> " count=10") [("-", "last")] getChats_ alice ("before=" <> tsS <> " count=10") [] testFiles :: FilePath -> IO () @@ -88,15 +88,15 @@ testFiles tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do -- ui-like upload let source = "./tests/fixtures/test.jpg" - let stored = files takeFileName source + 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 <# "$notes hi myself" - alice <# "$notes file 1 (test.jpg)" + alice <# "- hi myself" + alice <# "- file 1 (test.jpg)" alice ##> "/tail" - alice <# "$notes hi myself" - alice <# "$notes file 1 (test.jpg)" + alice <# "- hi myself" + alice <# "- file 1 (test.jpg)" alice ##> "/_get chat $1 count=100" r <- chatF <$> getTermLine alice @@ -109,15 +109,20 @@ testFiles tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do 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 <# "$notes file 2 (another_test.jpg)" + alice <# "- file 2 (another_test.jpg)" alice ##> "/_delete item $1 2 internal" alice <## "message deleted" doesFileExist stored2 `shouldReturn` False doesFileExist stored `shouldReturn` True - alice ##> "/clear $notes" - alice ##> "/tail" - doesFileExist stored `shouldReturn` False + alice ##> "/clear -" alice ##> "/fs 1" alice <## "chat db error: SEChatItemNotFoundByFileId {fileId = 1}" + alice ##> "/tail" + doesFileExist stored `shouldReturn` False + +(/-) :: HasCallStack => TestCC -> String -> IO () +cc /- note = do + cc `send` ("/- " <> note) + (dropTime <$> getTermLine cc) `shouldReturn` ("- " <> note)