From 1b99cb44f12346bd8c256fe4ee4b1984e25c6510 Mon Sep 17 00:00:00 2001 From: IC Rainbow Date: Wed, 3 Jan 2024 19:38:20 +0200 Subject: [PATCH] resolve comments --- src/Simplex/Chat.hs | 4 +-- src/Simplex/Chat/Help.hs | 1 - .../Chat/Migrations/M20240102_note_folders.hs | 25 ++++++++----------- src/Simplex/Chat/Migrations/chat_schema.sql | 11 +++++--- src/Simplex/Chat/Types.hs | 1 - 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 51489ab865..8b1555aa9e 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -802,8 +802,8 @@ processChatCommand' vr = \case fileSize <- liftIO $ CF.getFileContentsSize $ CryptoFile fsFilePath cryptoArgs chunkSize <- asks $ fileChunkSize . config withStore' $ \db -> do - fileId <- createLocalFile CIFSSndComplete db user nf ciId createdAt cf fileSize chunkSize - pure CIFile {fileId, fileName = takeFileName filePath, fileSize, fileSource = Just cf, fileStatus = CIFSSndComplete, fileProtocol = FPLocal} + fileId <- createLocalFile CIFSSndStored db user nf ciId createdAt cf fileSize chunkSize + pure CIFile {fileId, fileName = takeFileName filePath, fileSize, fileSource = Just cf, fileStatus = CIFSSndStored, fileProtocol = FPLocal} ci <- liftIO $ mkChatItem cd ciId content ciFile_ Nothing Nothing Nothing False createdAt Nothing createdAt pure . CRNewChatItem user $ AChatItem SCTLocal SMDSnd (LocalChat nf) ci APIUpdateChatItem (ChatRef cType chatId) itemId live mc -> withUser $ \user -> withChatLock "updateChatItem" $ case cType of diff --git a/src/Simplex/Chat/Help.hs b/src/Simplex/Chat/Help.hs index 168dabb22f..ac93e05533 100644 --- a/src/Simplex/Chat/Help.hs +++ b/src/Simplex/Chat/Help.hs @@ -106,7 +106,6 @@ filesHelpInfo = [ green "File transfer commands:", indent <> highlight "/file @ " <> " - send file to contact", indent <> highlight "/file # " <> " - send file to group", - indent <> highlight "/file $ " <> " - add file to folder", indent <> highlight "/image [] " <> " - send file as image to @contact or #group", indent <> highlight "/freceive [] " <> " - accept to receive file", indent <> highlight "/fforward [] " <> " - forward received file to @contact or #group", diff --git a/src/Simplex/Chat/Migrations/M20240102_note_folders.hs b/src/Simplex/Chat/Migrations/M20240102_note_folders.hs index 3ea0a07f13..b5dadc6e08 100644 --- a/src/Simplex/Chat/Migrations/M20240102_note_folders.hs +++ b/src/Simplex/Chat/Migrations/M20240102_note_folders.hs @@ -11,26 +11,21 @@ m20240102_note_folders = CREATE TABLE note_folders ( note_folder_id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, - created_at TEXT NOT NULL, - updated_at TEXT NOT NULL, - chat_ts TEXT NOT NULL, + created_at TEXT NOT NULL DEFAULT(datetime('now')), + updated_at TEXT NOT NULL DEFAULT(datetime('now')), + chat_ts TEXT NOT NULL DEFAULT(datetime('now')), favorite INTEGER NOT NULL DEFAULT 0, - unread_chat INTEGER DEFAULT 0 NOT NULL + unread_chat INTEGER NOT NULL DEFAULT 0 ); ALTER TABLE chat_items ADD COLUMN note_folder_id INTEGER DEFAULT NULL REFERENCES note_folders ON DELETE CASCADE; ALTER TABLE files ADD COLUMN note_folder_id INTEGER DEFAULT NULL REFERENCES note_folders ON DELETE CASCADE; - INSERT INTO note_folders - SELECT - NULL as note_folder_id, - u.user_id as user_id, - datetime('now') as created_at, - datetime('now') as updated_at, - datetime('now') as chat_ts, - 0 as favorite, - 0 as unread_chat - FROM users u; + CREATE INDEX chat_items_note_folder_id ON chat_items(note_folder_id); + CREATE INDEX files_note_folder_id ON files(note_folder_id); + CREATE INDEX note_folders_user_id ON note_folders(user_id); + + INSERT INTO note_folders (user_id) SELECT user_id FROM users; |] down_m20240102_note_folders :: Query @@ -38,5 +33,7 @@ down_m20240102_note_folders = [sql| DROP TABLE note_folders; ALTER TABLE chat_items DROP COLUMN note_folder_id; +ALTER TABLE chat_items DROP INDEX chat_items_note_folder_id; ALTER TABLE files DROP COLUMN note_folder_id; +ALTER TABLE files DROP INDEX files_note_folder_id; |] diff --git a/src/Simplex/Chat/Migrations/chat_schema.sql b/src/Simplex/Chat/Migrations/chat_schema.sql index 1a90485ab7..c8445f8572 100644 --- a/src/Simplex/Chat/Migrations/chat_schema.sql +++ b/src/Simplex/Chat/Migrations/chat_schema.sql @@ -552,11 +552,11 @@ CREATE TABLE IF NOT EXISTS "msg_deliveries"( CREATE TABLE note_folders( note_folder_id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, - created_at TEXT NOT NULL, - updated_at TEXT NOT NULL, - chat_ts TEXT NOT NULL, + created_at TEXT NOT NULL DEFAULT(datetime('now')), + updated_at TEXT NOT NULL DEFAULT(datetime('now')), + chat_ts TEXT NOT NULL DEFAULT(datetime('now')), favorite INTEGER NOT NULL DEFAULT 0, - unread_chat INTEGER DEFAULT 0 NOT NULL + unread_chat INTEGER NOT NULL DEFAULT 0 ); CREATE INDEX contact_profiles_index ON contact_profiles( display_name, @@ -823,3 +823,6 @@ CREATE INDEX idx_msg_deliveries_agent_msg_id ON "msg_deliveries"( connection_id, agent_msg_id ); +CREATE INDEX chat_items_note_folder_id ON chat_items(note_folder_id); +CREATE INDEX files_note_folder_id ON files(note_folder_id); +CREATE INDEX note_folders_user_id ON note_folders(user_id); diff --git a/src/Simplex/Chat/Types.hs b/src/Simplex/Chat/Types.hs index ea6592093d..16ab063235 100644 --- a/src/Simplex/Chat/Types.hs +++ b/src/Simplex/Chat/Types.hs @@ -1182,7 +1182,6 @@ fileTransferCancelled (FTSnd FileTransferMeta {cancelled} _) = cancelled fileTransferCancelled (FTRcv RcvFileTransfer {cancelled}) = cancelled -- For XFTP file transfers FSConnected means "uploaded to XFTP relays" --- Local files are always FSComplete data FileStatus = FSNew | FSAccepted | FSConnected | FSComplete | FSCancelled deriving (Eq, Ord, Show) instance FromField FileStatus where fromField = fromTextField_ textDecode