mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-18 01:06:29 +00:00
plug in migrations and tests
This commit is contained in:
+2
-2
@@ -127,7 +127,7 @@ library
|
||||
Simplex.Chat.Migrations.M20231126_remote_ctrl_address
|
||||
Simplex.Chat.Migrations.M20231207_chat_list_pagination
|
||||
Simplex.Chat.Migrations.M20231214_item_content_tag
|
||||
Simplex.Chat.Migrations.M20231219_notes_folders
|
||||
Simplex.Chat.Migrations.M20231219_note_folders
|
||||
Simplex.Chat.Mobile
|
||||
Simplex.Chat.Mobile.File
|
||||
Simplex.Chat.Mobile.Shared
|
||||
@@ -540,7 +540,7 @@ test-suite simplex-chat-test
|
||||
ChatTests.Direct
|
||||
ChatTests.Files
|
||||
ChatTests.Groups
|
||||
ChatTests.Notes
|
||||
ChatTests.Local
|
||||
ChatTests.Profiles
|
||||
ChatTests.Utils
|
||||
JSONTests
|
||||
|
||||
@@ -76,7 +76,7 @@ data ChatRef = ChatRef ChatType Int64
|
||||
data ChatInfo (c :: ChatType) where
|
||||
DirectChat :: Contact -> ChatInfo 'CTDirect
|
||||
GroupChat :: GroupInfo -> ChatInfo 'CTGroup
|
||||
LocalChat :: NotesFolder -> ChatInfo 'CTLocal
|
||||
LocalChat :: NoteFolder -> ChatInfo 'CTLocal
|
||||
ContactRequest :: UserContactRequest -> ChatInfo 'CTContactRequest
|
||||
ContactConnection :: PendingContactConnection -> ChatInfo 'CTContactConnection
|
||||
|
||||
@@ -92,7 +92,7 @@ chatInfoUpdatedAt :: ChatInfo c -> UTCTime
|
||||
chatInfoUpdatedAt = \case
|
||||
DirectChat Contact {updatedAt} -> updatedAt
|
||||
GroupChat GroupInfo {updatedAt} -> updatedAt
|
||||
LocalChat NotesFolder {updatedAt} -> updatedAt
|
||||
LocalChat NoteFolder {updatedAt} -> updatedAt
|
||||
ContactRequest UserContactRequest {updatedAt} -> updatedAt
|
||||
ContactConnection PendingContactConnection {updatedAt} -> updatedAt
|
||||
|
||||
@@ -100,7 +100,7 @@ chatInfoToRef :: ChatInfo c -> ChatRef
|
||||
chatInfoToRef = \case
|
||||
DirectChat Contact {contactId} -> ChatRef CTDirect contactId
|
||||
GroupChat GroupInfo {groupId} -> ChatRef CTGroup groupId
|
||||
LocalChat NotesFolder {notesFolderId} -> ChatRef CTLocal notesFolderId
|
||||
LocalChat NoteFolder {noteFolderId} -> ChatRef CTLocal noteFolderId
|
||||
ContactRequest UserContactRequest {contactRequestId} -> ChatRef CTContactRequest contactRequestId
|
||||
ContactConnection PendingContactConnection {pccConnId} -> ChatRef CTContactConnection pccConnId
|
||||
|
||||
@@ -112,7 +112,7 @@ chatInfoMembership = \case
|
||||
data JSONChatInfo
|
||||
= JCInfoDirect {contact :: Contact}
|
||||
| JCInfoGroup {groupInfo :: GroupInfo}
|
||||
| JCInfoLocal {notesFolder :: NotesFolder}
|
||||
| JCInfoLocal {noteFolder :: NoteFolder}
|
||||
| JCInfoContactRequest {contactRequest :: UserContactRequest}
|
||||
| JCInfoContactConnection {contactConnection :: PendingContactConnection}
|
||||
|
||||
|
||||
+11
-11
@@ -1,14 +1,14 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Simplex.Chat.Migrations.M20231219_notes_folders where
|
||||
module Simplex.Chat.Migrations.M20231219_note_folders where
|
||||
|
||||
import Database.SQLite.Simple (Query)
|
||||
import Database.SQLite.Simple.QQ (sql)
|
||||
|
||||
m20231219_notes_folders :: Query
|
||||
m20231219_notes_folders =
|
||||
m20231219_note_folders :: Query
|
||||
m20231219_note_folders =
|
||||
[sql|
|
||||
CREATE TABLE notes_folders (
|
||||
CREATE TABLE note_folders (
|
||||
notes_folder_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
display_name TEXT NOT NULL,
|
||||
@@ -21,21 +21,21 @@ m20231219_notes_folders =
|
||||
FOREIGN KEY (user_id, local_display_name)
|
||||
REFERENCES display_names (user_id, local_display_name)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_notes_folders_user_id_local_display_name ON notes_folders (
|
||||
CREATE UNIQUE INDEX idx_note_folders_user_id_local_display_name ON note_folders (
|
||||
user_id,
|
||||
local_display_name
|
||||
);
|
||||
|
||||
ALTER TABLE chat_items ADD COLUMN notes_folder_id INTEGER DEFAULT NULL REFERENCES notes_folders ON DELETE CASCADE;
|
||||
ALTER TABLE chat_items ADD COLUMN notes_folder_id INTEGER DEFAULT NULL REFERENCES note_folders ON DELETE CASCADE;
|
||||
|]
|
||||
|
||||
down_m20231219_notes_folders :: Query
|
||||
down_m20231219_notes_folders =
|
||||
down_m20231219_note_folders :: Query
|
||||
down_m20231219_note_folders =
|
||||
[sql|
|
||||
DROP INDEX idx_notes_folders_user_id_local_display_name;
|
||||
DROP TABLE notes_folders;
|
||||
DROP INDEX idx_note_folders_user_id_local_display_name;
|
||||
DROP TABLE note_folders;
|
||||
ALTER TABLE chat_items DROP COLUMN notes_folder_id;
|
||||
|]
|
||||
@@ -93,6 +93,7 @@ import Simplex.Chat.Migrations.M20231114_remote_control
|
||||
import Simplex.Chat.Migrations.M20231126_remote_ctrl_address
|
||||
import Simplex.Chat.Migrations.M20231207_chat_list_pagination
|
||||
import Simplex.Chat.Migrations.M20231214_item_content_tag
|
||||
import Simplex.Chat.Migrations.M20231219_note_folders
|
||||
import Simplex.Messaging.Agent.Store.SQLite.Migrations (Migration (..))
|
||||
|
||||
schemaMigrations :: [(String, Query, Maybe Query)]
|
||||
@@ -185,7 +186,8 @@ schemaMigrations =
|
||||
("20231114_remote_control", m20231114_remote_control, Just down_m20231114_remote_control),
|
||||
("20231126_remote_ctrl_address", m20231126_remote_ctrl_address, Just down_m20231126_remote_ctrl_address),
|
||||
("20231207_chat_list_pagination", m20231207_chat_list_pagination, Just down_m20231207_chat_list_pagination),
|
||||
("20231214_item_content_tag", m20231214_item_content_tag, Just down_m20231214_item_content_tag)
|
||||
("20231214_item_content_tag", m20231214_item_content_tag, Just down_m20231214_item_content_tag),
|
||||
("20231219_note_folders", m20231219_note_folders, Just down_m20231219_note_folders)
|
||||
]
|
||||
|
||||
-- | The list of migrations in ascending order by date
|
||||
|
||||
@@ -327,7 +327,7 @@ type ContactName = Text
|
||||
|
||||
type GroupName = Text
|
||||
|
||||
type NotesFolderName = Text
|
||||
type NoteFolderName = Text
|
||||
|
||||
optionalFullName :: ContactName -> Text -> Text
|
||||
optionalFullName displayName fullName
|
||||
@@ -1523,11 +1523,11 @@ data XGrpMemIntroCont = XGrpMemIntroCont
|
||||
deriving (Show)
|
||||
|
||||
-- | An entity for local chats
|
||||
data NotesFolder = NotesFolder
|
||||
{ notesFolderId :: NotesFolderId,
|
||||
data NoteFolder = NoteFolder
|
||||
{ noteFolderId :: NoteFolderId,
|
||||
userId :: UserId,
|
||||
displayName :: NotesFolderName,
|
||||
localDisplayName :: NotesFolderName,
|
||||
displayName :: NoteFolderName,
|
||||
localDisplayName :: NoteFolderName,
|
||||
chatItemId :: Maybe Int64,
|
||||
createdAt :: UTCTime,
|
||||
updatedAt :: UTCTime,
|
||||
@@ -1537,7 +1537,7 @@ data NotesFolder = NotesFolder
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
type NotesFolderId = Int64
|
||||
type NoteFolderId = Int64
|
||||
|
||||
data ServerCfg p = ServerCfg
|
||||
{ server :: ProtoServerWithAuth p,
|
||||
@@ -1659,7 +1659,7 @@ $(JQ.deriveJSON defaultJSON ''Contact)
|
||||
|
||||
$(JQ.deriveJSON defaultJSON ''ContactRef)
|
||||
|
||||
$(JQ.deriveJSON defaultJSON ''NotesFolder)
|
||||
$(JQ.deriveJSON defaultJSON ''NoteFolder)
|
||||
|
||||
instance ProtocolTypeI p => ToJSON (ServerCfg p) where
|
||||
toEncoding = $(JQ.mkToEncoding defaultJSON ''ServerCfg)
|
||||
|
||||
@@ -393,7 +393,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 NotesFolder {localDisplayName}) items _)) = ("$" <> localDisplayName, toCIPreview items Nothing, Nothing)
|
||||
toChatView (AChat _ (Chat (LocalChat NoteFolder {localDisplayName}) items _)) = ("$" <> localDisplayName, 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
|
||||
@@ -2034,8 +2034,8 @@ ttyToGroup g = membershipIncognito g <> ttyTo ("#" <> viewGroupName g <> " ")
|
||||
ttyToGroupEdited :: GroupInfo -> StyledString
|
||||
ttyToGroupEdited g = membershipIncognito g <> ttyTo ("#" <> viewGroupName g <> " [edited] ")
|
||||
|
||||
ttyFromLocal :: NotesFolder -> StyledString
|
||||
ttyFromLocal NotesFolder {localDisplayName} = ttyFrom ("$" <> localDisplayName <> "> ")
|
||||
ttyFromLocal :: NoteFolder -> StyledString
|
||||
ttyFromLocal NoteFolder {localDisplayName} = ttyFrom ("$" <> localDisplayName <> "> ")
|
||||
|
||||
viewName :: Text -> Text
|
||||
viewName s = if T.any isSpace s then "'" <> s <> "'" else s
|
||||
|
||||
@@ -4,6 +4,7 @@ import ChatTests.ChatList
|
||||
import ChatTests.Direct
|
||||
import ChatTests.Files
|
||||
import ChatTests.Groups
|
||||
import ChatTests.Local
|
||||
import ChatTests.Profiles
|
||||
import Test.Hspec
|
||||
|
||||
@@ -11,6 +12,7 @@ chatTests :: SpecWith FilePath
|
||||
chatTests = do
|
||||
describe "direct tests" chatDirectTests
|
||||
describe "group tests" chatGroupTests
|
||||
describe "local tests" chatLocalTests
|
||||
describe "file tests" chatFileTests
|
||||
describe "profile tests" chatProfileTests
|
||||
describe "chat list pagination tests" chatListTests
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE PostfixOperators #-}
|
||||
|
||||
module ChatTests.Notes where
|
||||
module ChatTests.Local where
|
||||
|
||||
import ChatClient
|
||||
import ChatTests.Utils
|
||||
import Test.Hspec
|
||||
|
||||
chatNotesTests :: SpecWith FilePath
|
||||
chatNotesTests = do
|
||||
fdescribe "notes folders" $ do
|
||||
chatLocalTests :: SpecWith FilePath
|
||||
chatLocalTests = do
|
||||
fdescribe "note folders" $ do
|
||||
it "create folders, add notes, read, search" testNotes
|
||||
it "switch users" testUserNotes
|
||||
|
||||
testNotes :: FilePath -> IO ()
|
||||
testNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
alice ##> "/create notes folder self"
|
||||
alice <## "notes folder created, use *self to add notes"
|
||||
alice ##> "/create note folder self"
|
||||
alice <## "note folder created, write to $self to add notes"
|
||||
|
||||
alice ##> "*self keep in mind"
|
||||
alice ##> "$self keep in mind"
|
||||
alice <## "ok"
|
||||
|
||||
testUserNotes :: FilePath -> IO ()
|
||||
testUserNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
alice ##> "/create notes folder self"
|
||||
alice <## "notes folder created, use *self to add notes"
|
||||
alice ##> "/create note folder self"
|
||||
alice <## "note folder created, write to $self to add notes"
|
||||
|
||||
alice ##> "*self keep in mind"
|
||||
alice ##> "$self keep in mind"
|
||||
alice <## "ok"
|
||||
alice ##> "/contacts"
|
||||
alice <## "*self"
|
||||
alice ##> "/chats"
|
||||
alice <## "$self keep in mind"
|
||||
|
||||
alice ##> "/create user secret"
|
||||
alice <## "user profile: secret"
|
||||
alice <## "use /p <display name> to change it"
|
||||
alice <## "(the updated profile will be sent to all your contacts)"
|
||||
|
||||
alice ##> "/contacts"
|
||||
alice ##> "/chats"
|
||||
Reference in New Issue
Block a user