mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
cover more API, implement new folders
This commit is contained in:
@@ -406,6 +406,8 @@ data ChatCommand
|
||||
| DeleteGroupLink GroupName
|
||||
| ShowGroupLink GroupName
|
||||
| SendGroupMessageQuote {groupName :: GroupName, contactName_ :: Maybe ContactName, quotedMsg :: Text, message :: Text}
|
||||
-- | APINewLocalChat UserId LocalChatProfile
|
||||
| NewNoteFolder NoteFolderName
|
||||
| LastChats (Maybe Int) -- UserId (not used in UI)
|
||||
| LastMessages (Maybe ChatName) Int (Maybe String) -- UserId (not used in UI)
|
||||
| LastChatItemId (Maybe ChatName) Int -- UserId (not used in UI)
|
||||
@@ -554,6 +556,7 @@ data ChatResponse
|
||||
| CRUserDeletedMember {user :: User, groupInfo :: GroupInfo, member :: GroupMember}
|
||||
| CRGroupsList {user :: User, groups :: [(GroupInfo, GroupSummary)]}
|
||||
| CRSentGroupInvitation {user :: User, groupInfo :: GroupInfo, contact :: Contact, member :: GroupMember}
|
||||
| CRLocalChatCreated {user :: User, noteFolder :: NoteFolder}
|
||||
| CRFileTransferStatus User (FileTransfer, [Integer]) -- TODO refactor this type to FileTransferStatus
|
||||
| CRFileTransferStatusXFTP User AChatItem
|
||||
| CRUserProfile {user :: User, profile :: Profile}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Store.NoteFolders where
|
||||
|
||||
import Control.Monad.Except (ExceptT (..), runExceptT)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Data.Text (Text)
|
||||
import Data.Time (getCurrentTime)
|
||||
import Database.SQLite.Simple.QQ (sql)
|
||||
import Simplex.Chat.Store.Shared (StoreError, insertedRowId, withLocalDisplayName)
|
||||
import Simplex.Chat.Types (NoteFolder (..))
|
||||
import Simplex.Messaging.Agent.Protocol (UserId)
|
||||
import qualified Simplex.Messaging.Agent.Store.SQLite.DB as DB
|
||||
|
||||
createNewNoteFolder :: DB.Connection -> UserId -> Text -> ExceptT StoreError IO NoteFolder
|
||||
createNewNoteFolder db userId displayName = do
|
||||
ts <- liftIO getCurrentTime
|
||||
ExceptT $ withLocalDisplayName db userId displayName $ \localDisplayName -> runExceptT $ do
|
||||
liftIO $ do
|
||||
DB.execute
|
||||
db
|
||||
[sql|
|
||||
INSERT INTO note_folders
|
||||
(user_id, display_name, local_display_name, created_at, updated_at, chat_ts, favorite, unread_chat)
|
||||
VALUES
|
||||
(?, ?, ?, ?, ?, ?, ?, ?)
|
||||
|]
|
||||
(userId, displayName, localDisplayName, ts, ts, ts, favorite, unread)
|
||||
noteFolderId <- insertedRowId db
|
||||
pure
|
||||
NoteFolder
|
||||
{ noteFolderId,
|
||||
userId,
|
||||
displayName,
|
||||
localDisplayName,
|
||||
createdAt = ts,
|
||||
updatedAt = ts,
|
||||
chatTs = ts,
|
||||
favorite,
|
||||
unread
|
||||
}
|
||||
where
|
||||
favorite = False
|
||||
unread = False
|
||||
@@ -1528,7 +1528,6 @@ data NoteFolder = NoteFolder
|
||||
userId :: UserId,
|
||||
displayName :: NoteFolderName,
|
||||
localDisplayName :: NoteFolderName,
|
||||
chatItemId :: Maybe Int64,
|
||||
createdAt :: UTCTime,
|
||||
updatedAt :: UTCTime,
|
||||
chatTs :: UTCTime,
|
||||
|
||||
@@ -262,6 +262,7 @@ responseToView hu@(currentRH, user_) ChatConfig {logLevel, showReactions, showRe
|
||||
CRMemberSubError u g m e -> ttyUser u [ttyGroup' g <> " member " <> ttyMember m <> " error: " <> sShow e]
|
||||
CRMemberSubSummary u summary -> ttyUser u $ viewErrorsSummary (filter (isJust . memberError) summary) " group member errors"
|
||||
CRGroupSubscribed u g -> ttyUser u $ viewGroupSubscribed g
|
||||
CRLocalChatCreated u NoteFolder {displayName} -> ttyUser u ["new note folder created, write to $" <> plain displayName <> " to add notes"]
|
||||
CRPendingSubSummary u _ -> ttyUser u []
|
||||
CRSndFileSubError u SndFileTransfer {fileId, fileName} e ->
|
||||
ttyUser u ["sent file " <> sShow fileId <> " (" <> plain fileName <> ") error: " <> sShow e]
|
||||
|
||||
Reference in New Issue
Block a user