mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-01 00:56:05 +00:00
rename to Notes
This commit is contained in:
@@ -611,8 +611,8 @@ processChatCommand = \case
|
||||
CTGroup -> do
|
||||
groupChat <- withStore (\db -> getGroupChat db user cId pagination search)
|
||||
pure $ CRApiChat user (AChat SCTGroup groupChat)
|
||||
CTSelf -> do
|
||||
error "TODO: APIGetChat.CTSelf"
|
||||
CTNotes -> do
|
||||
error "TODO: APIGetChat.CTNotes"
|
||||
CTContactRequest -> pure $ chatCmdError (Just user) "not implemented"
|
||||
CTContactConnection -> pure $ chatCmdError (Just user) "not supported"
|
||||
APIGetChatItems pagination search -> withUser $ \user -> do
|
||||
@@ -967,8 +967,8 @@ processChatCommand = \case
|
||||
startProximateTimedItemThread user (ChatRef CTGroup chatId, itemId) deleteAt
|
||||
withStore' $ \db -> updateGroupChatItemsRead db userId chatId fromToIds
|
||||
ok user
|
||||
CTSelf -> do
|
||||
error "TODO: APIChatRead.CTSelf"
|
||||
CTNotes -> do
|
||||
error "TODO: APIChatRead.CTNotes"
|
||||
CTContactRequest -> pure $ chatCmdError Nothing "not supported"
|
||||
CTContactConnection -> pure $ chatCmdError Nothing "not supported"
|
||||
APIChatUnread (ChatRef cType chatId) unreadChat -> withUser $ \user -> case cType of
|
||||
@@ -1038,7 +1038,7 @@ processChatCommand = \case
|
||||
withStore' (\db -> setContactDeleted db user ct)
|
||||
`catchChatError` (toView . CRChatError (Just user))
|
||||
pure $ map aConnId conns
|
||||
CTSelf -> error "TODO: APIDeleteChat.CTSelf"
|
||||
CTNotes -> error "TODO: APIDeleteChat.CTNotes"
|
||||
CTContactRequest -> pure $ chatCmdError (Just user) "not supported"
|
||||
APIClearChat (ChatRef cType chatId) -> withUser $ \user -> case cType of
|
||||
CTDirect -> do
|
||||
@@ -1055,8 +1055,8 @@ processChatCommand = \case
|
||||
membersToDelete <- withStore' $ \db -> getGroupMembersForExpiration db user gInfo
|
||||
forM_ membersToDelete $ \m -> withStore' $ \db -> deleteGroupMember db user m
|
||||
pure $ CRChatCleared user (AChatInfo SCTGroup $ GroupChat gInfo)
|
||||
CTSelf -> do
|
||||
error "TODO: APIClearChat.CTSelf"
|
||||
CTNotes -> do
|
||||
error "TODO: APIClearChat.CTNotes"
|
||||
CTContactConnection -> pure $ chatCmdError (Just user) "not supported"
|
||||
CTContactRequest -> pure $ chatCmdError (Just user) "not supported"
|
||||
APIAcceptContact incognito connReqId -> withUser $ \_ -> withChatLock "acceptContact" $ do
|
||||
|
||||
@@ -47,7 +47,7 @@ import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, enumJSON, fromTextFie
|
||||
import Simplex.Messaging.Protocol (MsgBody)
|
||||
import Simplex.Messaging.Util (eitherToMaybe, safeDecodeUtf8, (<$?>))
|
||||
|
||||
data ChatType = CTDirect | CTGroup | CTContactRequest | CTContactConnection | CTSelf
|
||||
data ChatType = CTDirect | CTGroup | CTContactRequest | CTContactConnection | CTNotes
|
||||
deriving (Eq, Show, Ord)
|
||||
|
||||
data ChatName = ChatName {chatType :: ChatType, chatName :: Text}
|
||||
@@ -59,7 +59,7 @@ chatTypeStr = \case
|
||||
CTGroup -> "#"
|
||||
CTContactRequest -> "<@"
|
||||
CTContactConnection -> ":"
|
||||
CTSelf -> "~"
|
||||
CTNotes -> "~"
|
||||
|
||||
chatNameStr :: ChatName -> String
|
||||
chatNameStr (ChatName cType name) = T.unpack $ chatTypeStr cType <> if T.any isSpace name then "'" <> name <> "'" else name
|
||||
@@ -70,7 +70,7 @@ data ChatRef = ChatRef ChatType Int64
|
||||
data ChatInfo (c :: ChatType) where
|
||||
DirectChat :: Contact -> ChatInfo 'CTDirect
|
||||
GroupChat :: GroupInfo -> ChatInfo 'CTGroup
|
||||
SelfChat :: UTCTime -> ChatInfo 'CTSelf
|
||||
NotesChat :: UTCTime -> ChatInfo 'CTNotes
|
||||
ContactRequest :: UserContactRequest -> ChatInfo 'CTContactRequest
|
||||
ContactConnection :: PendingContactConnection -> ChatInfo 'CTContactConnection
|
||||
|
||||
@@ -86,7 +86,7 @@ chatInfoUpdatedAt :: ChatInfo c -> UTCTime
|
||||
chatInfoUpdatedAt = \case
|
||||
DirectChat Contact {updatedAt} -> updatedAt
|
||||
GroupChat GroupInfo {updatedAt} -> updatedAt
|
||||
SelfChat updatedAt -> updatedAt
|
||||
NotesChat updatedAt -> updatedAt
|
||||
ContactRequest UserContactRequest {updatedAt} -> updatedAt
|
||||
ContactConnection PendingContactConnection {updatedAt} -> updatedAt
|
||||
|
||||
@@ -94,7 +94,7 @@ chatInfoToRef :: ChatInfo c -> ChatRef
|
||||
chatInfoToRef = \case
|
||||
DirectChat Contact {contactId} -> ChatRef CTDirect contactId
|
||||
GroupChat GroupInfo {groupId} -> ChatRef CTGroup groupId
|
||||
SelfChat {} -> ChatRef CTSelf 0
|
||||
NotesChat {} -> ChatRef CTNotes 0
|
||||
ContactRequest UserContactRequest {contactRequestId} -> ChatRef CTContactRequest contactRequestId
|
||||
ContactConnection PendingContactConnection {pccConnId} -> ChatRef CTContactConnection pccConnId
|
||||
|
||||
@@ -106,7 +106,7 @@ chatInfoMembership = \case
|
||||
data JSONChatInfo
|
||||
= JCInfoDirect {contact :: Contact}
|
||||
| JCInfoGroup {groupInfo :: GroupInfo}
|
||||
| JCInfoSelf {updatedAt :: UTCTime}
|
||||
| JCInfoNotes {updatedAt :: UTCTime}
|
||||
| JCInfoContactRequest {contactRequest :: UserContactRequest}
|
||||
| JCInfoContactConnection {contactConnection :: PendingContactConnection}
|
||||
|
||||
@@ -123,7 +123,7 @@ jsonChatInfo :: ChatInfo c -> JSONChatInfo
|
||||
jsonChatInfo = \case
|
||||
DirectChat c -> JCInfoDirect c
|
||||
GroupChat g -> JCInfoGroup g
|
||||
SelfChat s -> JCInfoSelf s
|
||||
NotesChat s -> JCInfoNotes s
|
||||
ContactRequest g -> JCInfoContactRequest g
|
||||
ContactConnection c -> JCInfoContactConnection c
|
||||
|
||||
@@ -135,7 +135,7 @@ jsonAChatInfo :: JSONChatInfo -> AChatInfo
|
||||
jsonAChatInfo = \case
|
||||
JCInfoDirect c -> AChatInfo SCTDirect $ DirectChat c
|
||||
JCInfoGroup g -> AChatInfo SCTGroup $ GroupChat g
|
||||
JCInfoSelf s -> AChatInfo SCTSelf $ SelfChat s
|
||||
JCInfoNotes s -> AChatInfo SCTNotes $ NotesChat s
|
||||
JCInfoContactRequest g -> AChatInfo SCTContactRequest $ ContactRequest g
|
||||
JCInfoContactConnection c -> AChatInfo SCTContactConnection $ ContactConnection c
|
||||
|
||||
@@ -725,7 +725,7 @@ data SChatType (c :: ChatType) where
|
||||
SCTGroup :: SChatType 'CTGroup
|
||||
SCTContactRequest :: SChatType 'CTContactRequest
|
||||
SCTContactConnection :: SChatType 'CTContactConnection
|
||||
SCTSelf :: SChatType 'CTSelf
|
||||
SCTNotes :: SChatType 'CTNotes
|
||||
|
||||
deriving instance Show (SChatType c)
|
||||
|
||||
@@ -734,7 +734,7 @@ instance TestEquality SChatType where
|
||||
testEquality SCTGroup SCTGroup = Just Refl
|
||||
testEquality SCTContactRequest SCTContactRequest = Just Refl
|
||||
testEquality SCTContactConnection SCTContactConnection = Just Refl
|
||||
testEquality SCTSelf SCTSelf = Just Refl
|
||||
testEquality SCTNotes SCTNotes = Just Refl
|
||||
testEquality _ _ = Nothing
|
||||
|
||||
data AChatType = forall c. ChatTypeI c => ACT (SChatType c)
|
||||
@@ -750,7 +750,7 @@ instance ChatTypeI 'CTContactRequest where chatTypeI = SCTContactRequest
|
||||
|
||||
instance ChatTypeI 'CTContactConnection where chatTypeI = SCTContactConnection
|
||||
|
||||
instance ChatTypeI 'CTSelf where chatTypeI = SCTSelf
|
||||
instance ChatTypeI 'CTNotes where chatTypeI = SCTNotes
|
||||
|
||||
toChatType :: SChatType c -> ChatType
|
||||
toChatType = \case
|
||||
@@ -758,7 +758,7 @@ toChatType = \case
|
||||
SCTGroup -> CTGroup
|
||||
SCTContactRequest -> CTContactRequest
|
||||
SCTContactConnection -> CTContactConnection
|
||||
SCTSelf -> CTSelf
|
||||
SCTNotes -> CTNotes
|
||||
|
||||
aChatType :: ChatType -> AChatType
|
||||
aChatType = \case
|
||||
@@ -766,7 +766,7 @@ aChatType = \case
|
||||
CTGroup -> ACT SCTGroup
|
||||
CTContactRequest -> ACT SCTContactRequest
|
||||
CTContactConnection -> ACT SCTContactConnection
|
||||
CTSelf -> ACT SCTSelf
|
||||
CTNotes -> ACT SCTNotes
|
||||
|
||||
checkChatType :: forall t c c'. (ChatTypeI c, ChatTypeI c') => t c' -> Either String (t c)
|
||||
checkChatType x = case testEquality (chatTypeI @c) (chatTypeI @c') of
|
||||
|
||||
@@ -491,12 +491,12 @@ getChatItemQuote_ db User {userId, userContactId} chatDirection QuotedMsg {msgRe
|
||||
|
||||
getChatPreviews :: DB.Connection -> User -> Bool -> PaginationByTime -> ChatListQuery -> IO [Either StoreError AChat]
|
||||
getChatPreviews db user withPCC pagination query = do
|
||||
selfChat <- getSelfChatPreview_ db user pagination query
|
||||
notes <- getNotesChatPreview_ db user pagination query
|
||||
directChats <- findDirectChatPreviews_ db user pagination query
|
||||
groupChats <- findGroupChatPreviews_ db user pagination query
|
||||
cReqChats <- getContactRequestChatPreviews_ db user pagination query
|
||||
connChats <- if withPCC then getContactConnectionChatPreviews_ db user pagination query else pure []
|
||||
let refs = sortTake $ concat [selfChat, directChats, groupChats, cReqChats, connChats]
|
||||
let refs = sortTake $ concat [notes, directChats, groupChats, cReqChats, connChats]
|
||||
mapM (runExceptT <$> getChatPreview) refs
|
||||
where
|
||||
ts :: AChatPreviewData -> UTCTime
|
||||
@@ -505,7 +505,7 @@ getChatPreviews db user withPCC pagination query = do
|
||||
(GroupChatPD t _ _ _) -> t
|
||||
(ContactRequestPD t _) -> t
|
||||
(ContactConnectionPD t _) -> t
|
||||
(SelfChatPD t _) -> t
|
||||
(NotesChatPD t _) -> t
|
||||
sortTake = case pagination of
|
||||
PTLast count -> take count . sortBy (comparing $ Down . ts)
|
||||
PTAfter _ count -> reverse . take count . sortBy (comparing ts)
|
||||
@@ -516,14 +516,14 @@ getChatPreviews db user withPCC pagination query = do
|
||||
SCTGroup -> getGroupChatPreview_ db user cpd
|
||||
SCTContactRequest -> let (ContactRequestPD _ chat) = cpd in pure chat
|
||||
SCTContactConnection -> let (ContactConnectionPD _ chat) = cpd in pure chat
|
||||
SCTSelf -> let (SelfChatPD _ chat) = cpd in pure chat
|
||||
SCTNotes -> let (NotesChatPD _ chat) = cpd in pure chat
|
||||
|
||||
data ChatPreviewData (c :: ChatType) where
|
||||
DirectChatPD :: UTCTime -> ContactId -> Maybe ChatItemId -> ChatStats -> ChatPreviewData 'CTDirect
|
||||
GroupChatPD :: UTCTime -> GroupId -> Maybe ChatItemId -> ChatStats -> ChatPreviewData 'CTGroup
|
||||
ContactRequestPD :: UTCTime -> AChat -> ChatPreviewData 'CTContactRequest
|
||||
ContactConnectionPD :: UTCTime -> AChat -> ChatPreviewData 'CTContactConnection
|
||||
SelfChatPD :: UTCTime -> AChat -> ChatPreviewData 'CTSelf
|
||||
NotesChatPD :: UTCTime -> AChat -> ChatPreviewData 'CTNotes
|
||||
|
||||
data AChatPreviewData = forall c. ChatTypeI c => ACPD (SChatType c) (ChatPreviewData c)
|
||||
|
||||
@@ -728,8 +728,8 @@ getGroupChatPreview_ db user (GroupChatPD _ groupId lastItemId_ stats) = do
|
||||
Nothing -> pure []
|
||||
pure $ AChat SCTGroup (Chat (GroupChat groupInfo) lastItem stats)
|
||||
|
||||
getSelfChatPreview_ :: DB.Connection -> User -> PaginationByTime -> ChatListQuery -> IO [AChatPreviewData]
|
||||
getSelfChatPreview_ db User {userId} _pagination = \case
|
||||
getNotesChatPreview_ :: DB.Connection -> User -> PaginationByTime -> ChatListQuery -> IO [AChatPreviewData]
|
||||
getNotesChatPreview_ db User {userId} _pagination = \case
|
||||
CLQFilters {favorite = False, unread = False} -> query
|
||||
_ -> pure []
|
||||
where
|
||||
@@ -748,18 +748,18 @@ getSelfChatPreview_ db User {userId} _pagination = \case
|
||||
f.file_id, f.file_name, f.file_size, f.file_path, f.file_crypto_key, f.file_crypto_nonce, f.ci_file_status, f.protocol,
|
||||
FROM chat_items i
|
||||
LEFT JOIN files f ON f.chat_item_id = i.chat_item_id
|
||||
WHERE i.user_id := :user_id AND i.self_chat
|
||||
WHERE i.user_id := :user_id AND i.notes_chat
|
||||
ORDER BY ts DESC
|
||||
LIMIT 1
|
||||
|]
|
||||
[":user_id" := userId]
|
||||
toPreview :: ChatItemRow -> AChatPreviewData
|
||||
toPreview (ci :. ciMode :. ciFile_) =
|
||||
let lastItem = error "TODO: lastItem" :: CChatItem CTSelf
|
||||
let lastItem = error "TODO: lastItem" :: CChatItem CTNotes
|
||||
ts = error "TODO: ts" :: UTCTime
|
||||
stats = ChatStats {unreadCount = 0, minUnreadItemId = 0, unreadChat = False}
|
||||
aChat = AChat SCTSelf $ Chat (SelfChat ts) [lastItem] stats
|
||||
in ACPD SCTSelf $ SelfChatPD ts aChat
|
||||
aChat = AChat SCTNotes $ Chat (NotesChat ts) [lastItem] stats
|
||||
in ACPD SCTNotes $ NotesChatPD ts aChat
|
||||
|
||||
getContactRequestChatPreviews_ :: DB.Connection -> User -> PaginationByTime -> ChatListQuery -> IO [AChatPreviewData]
|
||||
getContactRequestChatPreviews_ db User {userId} pagination clq = case clq of
|
||||
|
||||
Reference in New Issue
Block a user