diff --git a/apps/ios/Shared/Model/ChatModel.swift b/apps/ios/Shared/Model/ChatModel.swift index 23f82f437a..ce88b76d80 100644 --- a/apps/ios/Shared/Model/ChatModel.swift +++ b/apps/ios/Shared/Model/ChatModel.swift @@ -467,6 +467,8 @@ final class ChatModel: ObservableObject { var messageDelivery: Dictionary Void> = [:] + var fileUploads: Dictionary Void> = [:] + var filesToDelete: Set = [] // the banner kind the chat list showed this app session: it keeps the slot until restart, so dismissing it never puts diff --git a/apps/ios/Shared/Model/SimpleXAPI.swift b/apps/ios/Shared/Model/SimpleXAPI.swift index 65b582e275..5c99793977 100644 --- a/apps/ios/Shared/Model/SimpleXAPI.swift +++ b/apps/ios/Shared/Model/SimpleXAPI.swift @@ -581,6 +581,7 @@ private func processSendMessageCmd(toChatType: ChatType, cmd: ChatCommand) async cItem = cItemLast chatModel.messageDelivery[cItemLast.id] = endTask } + await beginFileUploadTasks(cItems) return cItems } if let networkErrorAlert = networkErrorAlert(r) { @@ -593,13 +594,38 @@ private func processSendMessageCmd(toChatType: ChatType, cmd: ChatCommand) async } else { r = await chatApiSendCmd(cmd, bgDelay: msgDelay) if case let .result(.newChatItems(_, aChatItems)) = r { - return aChatItems.map { $0.chatItem } + let cItems = aChatItems.map { $0.chatItem } + await beginFileUploadTasks(cItems) + return cItems } sendMessageErrorAlert(r.unexpected) return nil } } +@MainActor +func beginFileUploadTasks(_ items: [ChatItem]) { + let m = ChatModel.shared + for case let file? in items.map(\.file) where file.fileProtocol == .xftp { + let fileId = file.fileId + m.fileUploads[fileId] = beginBGTask { + m.fileUploads.removeValue(forKey: fileId) + } + } +} + +@MainActor +private func endFileUploadTask(_ fileId: Int64) { + ChatModel.shared.fileUploads[fileId]?() +} + +@MainActor +private func endFileUploadTasks(_ deletions: [ChatItemDeletion]) { + for case let file? in deletions.map(\.deletedChatItem.chatItem.file) { + endFileUploadTask(file.fileId) + } +} + func apiCreateChatItems(noteFolderId: Int64, composedMessages: [ComposedMessage]) async -> [ChatItem]? { let r: APIResult = await chatApiSendCmd(.apiCreateChatItems(noteFolderId: noteFolderId, composedMessages: composedMessages)) if case let .result(.newChatItems(_, aChatItems)) = r { return aChatItems.map { $0.chatItem } } @@ -659,13 +685,19 @@ func apiGetReactionMembers(groupId: Int64, itemId: Int64, reaction: MsgReaction) func apiDeleteChatItems(type: ChatType, id: Int64, scope: GroupChatScope?, itemIds: [Int64], mode: CIDeleteMode) async throws -> [ChatItemDeletion] { let r: ChatResponse1 = try await chatSendCmd(.apiDeleteChatItem(type: type, id: id, scope: scope, itemIds: itemIds, mode: mode), bgDelay: msgDelay) - if case let .chatItemsDeleted(_, items, _) = r { return items } + if case let .chatItemsDeleted(_, items, _) = r { + await endFileUploadTasks(items) + return items + } throw r.unexpected } func apiDeleteMemberChatItems(groupId: Int64, itemIds: [Int64]) async throws -> [ChatItemDeletion] { let r: ChatResponse1 = try await chatSendCmd(.apiDeleteMemberChatItem(groupId: groupId, itemIds: itemIds), bgDelay: msgDelay) - if case let .chatItemsDeleted(_, items, _) = r { return items } + if case let .chatItemsDeleted(_, items, _) = r { + await endFileUploadTasks(items) + return items + } throw r.unexpected } @@ -1732,7 +1764,9 @@ func cancelFile(user: User, fileId: Int64) async { func apiCancelFile(fileId: Int64, ctrl: chat_ctrl? = nil) async -> AChatItem? { let r: APIResult = await chatApiSendCmd(.cancelFile(fileId: fileId), ctrl: ctrl) switch r { - case let .result(.sndFileCancelled(_, chatItem, _, _)) : return chatItem + case let .result(.sndFileCancelled(_, chatItem, fileTransferMeta, _)) : + await endFileUploadTask(fileTransferMeta.fileId) + return chatItem case let .result(.rcvFileCancelled(_, chatItem, _)) : return chatItem default: logger.error("apiCancelFile error: \(responseError(r.unexpected))") @@ -2772,6 +2806,7 @@ func processReceivedMsg(_ res: ChatEvent) async { } } case let .chatItemsDeleted(user, items, _): + await endFileUploadTasks(items) if !active(user) { for item in items { let d = item.deletedChatItem @@ -3002,13 +3037,15 @@ func processReceivedMsg(_ res: ChatEvent) async { if let aChatItem = aChatItem { await chatItemSimpleUpdate(user, aChatItem) } - case let .sndFileCompleteXFTP(user, aChatItem, _): + case let .sndFileCompleteXFTP(user, aChatItem, fileTransferMeta): await chatItemSimpleUpdate(user, aChatItem) - case let .sndFileError(user, aChatItem, _, _): + await endFileUploadTask(fileTransferMeta.fileId) + case let .sndFileError(user, aChatItem, fileTransferMeta, _): if let aChatItem = aChatItem { await chatItemSimpleUpdate(user, aChatItem) Task { cleanupFile(aChatItem) } } + await endFileUploadTask(fileTransferMeta.fileId) case let .sndFileWarning(user, aChatItem, _, _): if let aChatItem = aChatItem { await chatItemSimpleUpdate(user, aChatItem) diff --git a/apps/ios/SimpleX Unit Tests/FileUploadTests.swift b/apps/ios/SimpleX Unit Tests/FileUploadTests.swift new file mode 100644 index 0000000000..9171b0f2eb --- /dev/null +++ b/apps/ios/SimpleX Unit Tests/FileUploadTests.swift @@ -0,0 +1,92 @@ +import XCTest +@testable import SimpleX +@testable import SimpleXChat + +final class FileUploadTests: XCTestCase { + private let sendCmd = sendSimpleXCmdStr + + @MainActor + override func tearDown() async throws { + ChatModel.shared.fileUploads.values.forEach { $0() } + ChatModel.shared.messageDelivery.values.forEach { $0() } + sendSimpleXCmdStr = sendCmd + } + + @MainActor + func testSentFileBeginsTask() async throws { + try replay("files/send-file") + _ = await apiSendMessages(type: .direct, id: 2, scope: nil, composedMessages: [ComposedMessage(fileSource: .plain("test.pdf"), msgContent: .file(""))]) + XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [1]) + } + + @MainActor + func testSentGroupFileBeginsTask() async throws { + try replay("files/send-group-file") + _ = await apiSendMessages(type: .group, id: 1, scope: nil, composedMessages: [ComposedMessage(fileSource: .plain("test.pdf"), msgContent: .file(""))]) + XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [1]) + } + + @MainActor + func testSentTextBeginsNoTask() async throws { + try replay("files/send-text") + _ = await apiSendMessages(type: .direct, id: 2, scope: nil, composedMessages: [ComposedMessage(msgContent: .text("hi"))]) + XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), []) + } + + @MainActor + func testCompletedUploadEndsTask() async throws { + beginUploadTask(fileId: 1) + await processReceivedMsg(try event(XCTUnwrap((try fixtureJSON("files/upload-complete") as? [Any])?.first))) + XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), []) + } + + @MainActor + func testUploadErrorEndsTask() async throws { + beginUploadTask(fileId: 1) + await processReceivedMsg(try event(XCTUnwrap((try fixtureJSON("files/upload-error") as? [Any])?.first))) + XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), []) + } + + @MainActor + func testCancelledUploadEndsTask() async throws { + beginUploadTask(fileId: 1) + try replay("files/cancel") + _ = await apiCancelFile(fileId: 1) + XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), []) + } + + @MainActor + func testDeletedItemEndsTask() async throws { + beginUploadTask(fileId: 1) + try replay("files/delete") + _ = try await apiDeleteChatItems(type: .direct, id: 2, scope: nil, itemIds: [1], mode: .cidmInternal) + XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), []) + } + + @MainActor + func testDeletedItemEventEndsTask() async throws { + beginUploadTask(fileId: 1) + await processReceivedMsg(try event(try response("files/delete"))) + XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), []) + } + + @MainActor + private func beginUploadTask(fileId: Int64) { + beginFileUploadTasks([ChatItem.getSample(1, .directSnd, .now, "", file: CIFile.getSample(fileId: fileId, fileStatus: .sndStored))]) + } + + private func response(_ fixture: String) throws -> Any { + try XCTUnwrap((try fixtureJSON(fixture) as? [String: [String: Any]])?["commands"]?.values.first) + } + + private func replay(_ fixture: String) throws { + let recorded = try response(fixture) + sendSimpleXCmdStr = { _, _, _ in try? JSONSerialization.data(withJSONObject: singleFieldJSON(recorded)) } + } + + private func event(_ json: Any) throws -> ChatEvent { + let decoded: APIResult = decodeAPIResult(try JSONSerialization.data(withJSONObject: singleFieldJSON(json))) + let event: ChatEvent? = if case let .result(r) = decoded { r } else { nil } + return try XCTUnwrap(event, "event not decoded: \(decoded.responseType)") + } +} diff --git a/apps/ios/SimpleX.xcodeproj/project.pbxproj b/apps/ios/SimpleX.xcodeproj/project.pbxproj index 3242c7ea27..d012528976 100644 --- a/apps/ios/SimpleX.xcodeproj/project.pbxproj +++ b/apps/ios/SimpleX.xcodeproj/project.pbxproj @@ -272,6 +272,7 @@ E5AEC0C22F9C000100270665 /* SnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5AEC0C12F9C000100270665 /* SnapshotTests.swift */; }; 4E57A1E70000000000000006 /* NameAlertsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E57A1E70000000000000005 /* NameAlertsTests.swift */; }; 4E57A1E70000000000000014 /* ChatItemUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E57A1E70000000000000013 /* ChatItemUpdateTests.swift */; }; + 4E57A1E70000000000000019 /* FileUploadTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E57A1E70000000000000018 /* FileUploadTests.swift */; }; 6D4F1C2A9B3E000000000002 /* MarkdownFileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4F1C2A9B3E000000000001 /* MarkdownFileTests.swift */; }; E5AEC0AF2F91A73500270665 /* ComposeChatLinkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5AEC0AE2F91A73500270665 /* ComposeChatLinkView.swift */; }; E5C0BBE82F82B45500EA7527 /* SimpleXAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E5C0BBE72F82B45500EA7527 /* SimpleXAssets.xcassets */; }; @@ -685,6 +686,7 @@ E5AEC0C32F9C000100270665 /* SimpleX Snapshots.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SimpleX Snapshots.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 4E57A1E70000000000000005 /* NameAlertsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NameAlertsTests.swift; sourceTree = ""; }; 4E57A1E70000000000000013 /* ChatItemUpdateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatItemUpdateTests.swift; sourceTree = ""; }; + 4E57A1E70000000000000018 /* FileUploadTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadTests.swift; sourceTree = ""; }; 6D4F1C2A9B3E000000000001 /* MarkdownFileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownFileTests.swift; sourceTree = ""; }; 4E57A1E70000000000000007 /* SimpleX Unit Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SimpleX Unit Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; E5AEC0AE2F91A73500270665 /* ComposeChatLinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeChatLinkView.swift; sourceTree = ""; }; @@ -1040,6 +1042,7 @@ children = ( 4E57A1E70000000000000005 /* NameAlertsTests.swift */, 4E57A1E70000000000000013 /* ChatItemUpdateTests.swift */, + 4E57A1E70000000000000018 /* FileUploadTests.swift */, 6D4F1C2A9B3E000000000001 /* MarkdownFileTests.swift */, ); path = "SimpleX Unit Tests"; @@ -1929,6 +1932,7 @@ files = ( 4E57A1E70000000000000006 /* NameAlertsTests.swift in Sources */, 4E57A1E70000000000000014 /* ChatItemUpdateTests.swift in Sources */, + 4E57A1E70000000000000019 /* FileUploadTests.swift in Sources */, 6D4F1C2A9B3E000000000002 /* MarkdownFileTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/apps/ios/product/flows/messaging.md b/apps/ios/product/flows/messaging.md index 28eddff929..7509c4558c 100644 --- a/apps/ios/product/flows/messaging.md +++ b/apps/ios/product/flows/messaging.md @@ -33,7 +33,7 @@ Complete message lifecycle in SimpleX Chat iOS: composing, sending, receiving, e 7. Internally dispatches `ChatCommand.apiSendMessages(...)` to the Haskell core. 8. Core encrypts, queues via SMP, and returns `ChatResponse1.newChatItems(user, aChatItems)`. 9. `processSendMessageCmd` extracts `[ChatItem]` from response. -10. For direct chats, a background task tracks delivery via `chatModel.messageDelivery`. +10. For direct chats, a background task tracks delivery via `chatModel.messageDelivery`. For each XFTP file, in direct and group chats, a background task tracks the upload via `chatModel.fileUploads`. 11. `ChatModel` updates, UI refreshes to show the new message. ### 2. Send Media (Image/Video/File) diff --git a/apps/ios/spec/architecture.md b/apps/ios/spec/architecture.md index 87f30b2a48..67a58fe656 100644 --- a/apps/ios/spec/architecture.md +++ b/apps/ios/spec/architecture.md @@ -134,6 +134,10 @@ func sendSimpleXCmd(_ cmd: ChatCmdProtocol, _ ctrl: chat_ctrl? All FFI calls are wrapped in [`beginBGTask()`](../Shared/Model/SimpleXAPI.swift#L54) / `endBackgroundTask()` to prevent iOS from killing the app mid-operation. The `maxTaskDuration` is 15 seconds. +Each XFTP file of a sent item has its own background task ([`beginFileUploadTasks`](../Shared/Model/SimpleXAPI.swift#L606-L615)), begun when the response to a send or a forward is received and stored in `ChatModel.fileUploads` by file ID. It is ended once, and removed, on `sndFileCompleteXFTP` or `sndFileError`, on the response to the cancellation of the file, on the deletion of its item, or on expiration ([`endFileUploadTask`](../Shared/Model/SimpleXAPI.swift#L617-L620)). + +While the chat is suspending, the agent continues the XFTP uploads started in foreground by this app process. The chat deletes the agent file of each upload after handling its completion or error, queueing the file descriptions of a completed upload first. The core sends `chatSuspended` after these deletions and the delivery of the queued messages, or at the suspend timeout. Uploads started while suspending or resumed from an earlier process are not awaited. + --- ## [3. Event Streaming](../Shared/Model/SimpleXAPI.swift#L2220-L2916) diff --git a/apps/ios/spec/services/files.md b/apps/ios/spec/services/files.md index 7e1f8a2ad1..79bea5d283 100644 --- a/apps/ios/spec/services/files.md +++ b/apps/ios/spec/services/files.md @@ -271,6 +271,10 @@ func getWallpaperDirectory() -> URL // Documents/wallpapers/ - ChatEvent.sndFileError (on failure) ``` +Each XFTP file of a sent item has a background task from the response to the send until `sndFileCompleteXFTP`, `sndFileError`, the cancellation of the file, the deletion of its item, or the task's expiration ([`beginFileUploadTasks`](../../Shared/Model/SimpleXAPI.swift#L606-L615), [`endFileUploadTask`](../../Shared/Model/SimpleXAPI.swift#L617-L620)). For a direct chat, the core sends `sndFileCompleteXFTP` after the file description is sent; for a group, after the file descriptions are queued. + +While the chat is suspending, the agent continues the XFTP uploads started in foreground by this app process. The chat deletes the agent file of each upload after handling its completion or error, queueing the file descriptions of a completed upload first. The core sends `chatSuspended` after these deletions and the delivery of the queued messages, or at the suspend timeout. Uploads started while suspending or resumed from an earlier process are not awaited. + ### Receiving ``` diff --git a/apps/ios/spec/state.md b/apps/ios/spec/state.md index a47ceb2f2a..06d4535289 100644 --- a/apps/ios/spec/state.md +++ b/apps/ios/spec/state.md @@ -162,6 +162,7 @@ ChatTagsModel (singleton -- filter state) | Property | Type | Description | Line | |----------|------|-------------|------| | `messageDelivery` | `[Int64: () -> Void]` | Pending delivery confirmation callbacks | [L426](../Shared/Model/ChatModel.swift#L426) | +| `fileUploads` | `[Int64: () -> Void]` | End functions of the background tasks of XFTP uploads, by file ID | [L470](../Shared/Model/ChatModel.swift#L470) | | `filesToDelete` | `Set` | Files queued for deletion | [L428](../Shared/Model/ChatModel.swift#L428) | | `chatListBanner` | `ChatListBanner?` | The banner kind the chat list showed this app session; `bannerSlotFree(for:)` tells whether a kind may take the slot (see [chat-list.md](client/chat-list.md)) | [L474](../Shared/Model/ChatModel.swift#L474) | | `im` | `ItemsModel` | Reference to `ItemsModel.shared` | [L432](../Shared/Model/ChatModel.swift#L432) | diff --git a/docs/contributing/TESTS.md b/docs/contributing/TESTS.md index b2ec7d318d..79af86803e 100644 --- a/docs/contributing/TESTS.md +++ b/docs/contributing/TESTS.md @@ -153,10 +153,10 @@ Helpers of [ChatTests/Utils.hs](../../tests/ChatTests/Utils.hs), called in a cha |---|---| | `apiFixture fixture cc placeholders FixtureRequests {frCommands, frMarkdown, frUris}` | an object with `commands`, `markdown` and `uris`, keyed by the request: the response to each command, encoded by `chatSendCmd` of the core library's API; `chatParseMarkdown` of each text; `chatParseUri` of each link | | `nameFixture fixture cc name` | `apiFixture` of `/_connect plan 1 ` and of the markdown of the name, in `names/` | -| `eventsFixture fixture events steps` | an array of the events appended by `recordItemEvent events`, in `eventHook` of `chatHooks`, during `steps`: `newChatItems` and `chatItemUpdated`, encoded as `chatRecvMsg` encodes them | +| `eventsFixture fixture events steps` | an array of the events appended by `recordItemEvent events`, in `eventHook` of `chatHooks`, during `steps`: `newChatItems` and `chatItemUpdated`, encoded as `chatRecvMsg` encodes them; with `recordSndFileEvent events`, `sndFileCompleteXFTP` and `sndFileError` | | `nameMovedFixture` | a `nameMoved` event, built from the IDs of the named contacts and groups | -Examples: `testPlanKnownNameAvailable` in ChatTests/Names.hs, `testDirectMessageUpdatePrevItem` and `testMissedCall` in ChatTests/Direct.hs. +Examples: `testPlanKnownNameAvailable` in ChatTests/Names.hs, `testDirectMessageUpdatePrevItem` and `testMissedCall` in ChatTests/Direct.hs, `testXFTPRecordUploadComplete` in ChatTests/Files.hs. Stable recordings: @@ -165,7 +165,7 @@ Stable recordings: | Fields | Replaced by | |---|---| | `createdAt`
`updatedAt`
`chatTs`
`userMemberProfileSentAt`
`itemTs` | `1970-01-01T00:00:00Z` | - | `agentConnId`
`xContactId`
`connFullLink`
`connShortLink`
`contactLink`
`groupLink`
`viaGroupLinkUri`
`simplexUri`
`memberId`
`memberPubKey`
`publicGroupId`
`businessId`
`customerId`
`itemSharedMsgId` | the field name | + | `agentConnId`
`xContactId`
`connFullLink`
`connShortLink`
`contactLink`
`groupLink`
`viaGroupLinkUri`
`simplexUri`
`memberId`
`memberPubKey`
`publicGroupId`
`businessId`
`customerId`
`itemSharedMsgId`
`agentSndFileId`
`privateSndFileDescr`
`errorMessage` | the field name | | `groupRelays` | `"groupRelay"` per element | A field with a new value in each run is added to this list. @@ -184,7 +184,7 @@ Stable recordings: | Events | `ChatController.processReceivedMsg`, model/SimpleXAPI.kt | `processReceivedMsg`, Shared/Model/SimpleXAPI.swift | | Notifications | `ntfManager`, platform/NtfManager.kt | `NtfManager.shared`, Shared/Model/NtfManager.swift | | Recording read by | `fixtureText` | `fixtureJSON`, then `singleFieldJSON` to the Swift JSON form | -| Tests | [NameAlertsTest.kt](../../apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/NameAlertsTest.kt), [ChatItemUpdateTest.kt](../../apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ChatItemUpdateTest.kt) | [NameAlertsTests.swift](../../apps/ios/SimpleX%20Unit%20Tests/NameAlertsTests.swift), [ChatItemUpdateTests.swift](../../apps/ios/SimpleX%20Unit%20Tests/ChatItemUpdateTests.swift) | +| Tests | [NameAlertsTest.kt](../../apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/NameAlertsTest.kt), [ChatItemUpdateTest.kt](../../apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ChatItemUpdateTest.kt) | [NameAlertsTests.swift](../../apps/ios/SimpleX%20Unit%20Tests/NameAlertsTests.swift), [ChatItemUpdateTests.swift](../../apps/ios/SimpleX%20Unit%20Tests/ChatItemUpdateTests.swift), [FileUploadTests.swift](../../apps/ios/SimpleX%20Unit%20Tests/FileUploadTests.swift) | - Pattern: `recorded(fixture)` in the NameAlerts tests sets the first three seams to lookups in the recording; the test fails at tear-down on a request without a recorded response, unless the request is checked with `assertRequested`. The ChatItemUpdate tests decode the recorded events, pass each to `processReceivedMsg` and compare `ChatModel`. Tear-down restores the seams and clears the model. - Run and CI: [Kotlin apps](#kotlin-apps), [SimpleX Unit Tests](#simplex-unit-tests). CI runs the kotlin and ios scopes for a change in tests/fixtures/api (`BUILD_CHANGES` in scripts/ci/packages_release.py). The recording tests are core tests, selected in the `ci-tests` block by the patterns of the [CI guide, core](../../scripts/ci/README.md#core). diff --git a/plans/2026-10-23-xftp-upload-file-deletion.md b/plans/2026-10-23-xftp-upload-file-deletion.md new file mode 100644 index 0000000000..0d91005514 --- /dev/null +++ b/plans/2026-10-23-xftp-upload-file-deletion.md @@ -0,0 +1,185 @@ +# Agent file deletion after XFTP uploads + +On iOS, with simplexmq PR #2010, the agent completes suspension only after the agent file of each upload started in foreground is deleted by the chat or TTL cleanup, or when the chat is stopped, or at the suspend timeout. Files with rows absent or flagged deleted or failed at the start of the suspension are not awaited. On master, the chat skipped this deletion on several paths of `SFDONE` and `SFERR`, handling errors among them. +The deletions in the branches of `processAgentMsgSndFile` are replaced by one deletion after the handling of each `SFDONE` or `SFERR` with a file ID, also when an error is thrown. On `SFDONE` of an undeleted sent item with a shared message ID, the file descriptions are queued before it in the direct and group branches. +The iOS app holds a background task for each XFTP file it sends, from the send until the upload ends, so that iOS suspends the app later while the upload runs. + +Agent side: https://github.com/simplex-chat/simplexmq/pull/2010 + +## Decisions + +- Terminal events: + - `SFDONE`; + - `SFERR`. +- Deletion: `xftpDeleteSndFileInternal`, once per terminal event with a file ID, after its handling, also when an error is thrown. + + ```mermaid + sequenceDiagram + participant Agent + participant Chat + Agent->>Chat: SFDONE or SFERR with a file ID + Note over Chat: contact or group lock, file lock + Chat->>Agent: file descriptions queued, on SFDONE of an undeleted sent item + Note over Chat: locks released, also after an error + Chat->>Agent: xftpDeleteSndFileInternal + ``` + +- The deletion is executed after the contact or group lock and the file lock are released. +- On `SFDONE` of an undeleted sent item with a shared message ID, file descriptions are queued before the deletion in the direct and group branches. +- `SFPROG` and `SFWARN`: the agent file is deleted only when the user is missing, as on master. +- `SFERR` with an empty entity ID: the agent error is sent to the view; the file lookup and the deletion are skipped. +- Last file event of each branch, sent before the deletion: + + | Branch | Event | + |---|---| + | item missing | `CEvtSndFileRedirectStartXFTP`, `CEvtSndStandaloneFileComplete` or `CEvtSndFileError` | + | direct | `CEvtSndFileProgressXFTP` | + | group | `CEvtSndFileCompleteXFTP` | + | `SFERR` | `CEvtSndFileError` | + +- The deletion is added to these paths of master `99b91696f`: + - the agent file is unknown to the chat (:225); + - file cancelled: the deletion by `agentXFTPDeleteSndFilesRemote` at cancellation is repeated; + - `SFDONE` with fewer descriptions than transfers (:270); + - failed steps: + - the user lookup (:227); + - `getSndFileTransfer` (:240): the file row deleted after the user lookup, or a database error; + - `SFDONE`: the private description update or the item lookup (:251-252); + - direct: + - `contactSendConn_` (:275): contact not ready, inactive or disabled; + - the chat binding (:277); + - the extra descriptions and badge proof write (:281-283); + - queueing (:284); + - the delivery ID update (:287); + - group: + - the recipients lookup (:294); + - the extra descriptions and badge proof write (:303-305); + - queueing (:306-307); + - the item update (:308-310); + - `SFERR`: the status update (:360-362); + - other chat type or direction, or a direct sent item without transfers (:322; `sft : _` is required by the direct branch at :274); + - item deleted or without a shared message ID (:323). +- iOS spec, the same text in each of two files: "While the chat is suspending, the agent continues the XFTP uploads started in foreground by this app process. The chat deletes the agent file of each upload after handling its completion or error, queueing the file descriptions of a completed upload first. The core sends `chatSuspended` after these deletions and the delivery of the queued messages, or at the suspend timeout. Uploads started while suspending or resumed from an earlier process are not awaited." +- App, upload background tasks: + - one task per XFTP file of a sent item, in direct and group chats, keyed by file ID; + - begun on the response to a send or a forward; + - ended once and removed on the first of: + + | Ending | Source | + |---|---| + | `sndFileCompleteXFTP` | event; direct: after the file description is sent; group: after the file descriptions are queued | + | `sndFileError` | event | + | `sndFileCancelled` | response to `/fcancel` | + | `chatItemsDeleted` with the item | response to an item deletion, or event | + | expiration | iOS | + + - message delivery tasks: unchanged; groups keep `msgDelay`. + + ```mermaid + sequenceDiagram + participant App + participant Core + participant iOS + App->>Core: send or forward with an XFTP file + Core-->>App: newChatItems + App->>iOS: beginBackgroundTask, stored in fileUploads by file ID + Core-->>App: sndFileCompleteXFTP, sndFileError, sndFileCancelled or chatItemsDeleted + App->>iOS: endBackgroundTask, removed from fileUploads + iOS-->>App: or expiration: the same end + ``` + +- `cabal.project`: simplexmq pinned to commit `bdda2fa4` of the simplexmq fork during review. +- After the simplexmq pull request in simplex-chat/simplexmq is merged and before the final pull request is opened in simplex-chat/simplex-chat: + - the pin is replaced by the merged simplex-chat/simplexmq commit; + - `scripts/nix/sha256map.nix` is updated. + +## Mechanics + +- `src/Simplex/Chat/Library/Subscriber.hs`, `processAgentMsgSndFile`: + - clause for `SFERR` with an empty entity ID (:224-225): `eToView $ chatErrorAgent e`; + - `flip allFinally (when sndFileEnded deleteAgentFile)` around the handling (:226); + - missing user (:232): `unless sndFileEnded deleteAgentFile`; + - `sndFileEnded :: Bool` (:235-239): `SFDONE` or `SFERR`; + - `deleteAgentFile :: CM ()` (:240-241); + - removed, the deletions of master `99b91696f`: + - :255, item missing; + - :291, direct; + - :311, group; + - :363, `sendFileError`. +- `apps/ios/spec/architecture.md` (:137), "Background Task Protection": the text. +- `apps/ios/spec/services/files.md` (:274), "Sending": the text. +- `apps/ios/Shared/Model/ChatModel.swift`, `fileUploads` (:470). +- `apps/ios/Shared/Model/SimpleXAPI.swift`: + - `processSendMessageCmd`: `beginFileUploadTasks(cItems)` in the direct (:584) and group (:598) branches; + - new: `beginFileUploadTasks` (:606-615), `endFileUploadTask` (:617-620), `endFileUploadTasks` (:622-627); + - `apiDeleteChatItems` (:689), `apiDeleteMemberChatItems` (:698), `apiCancelFile` (:1768); + - `processReceivedMsg`: `chatItemsDeleted` (:2809), `sndFileCompleteXFTP` (:3042), `sndFileError` (:3048). +- `cabal.project` (:23-24): + - `location: https://github.com/evgeny-simplex/simplexmq.git`; + - `tag: bdda2fa40960f7c433138adda00ecfedad0c93f5`. + +## Tests + +`tests/ChatTests/Files.hs`, "file transfer over XFTP": +- `checkNoAgentSndFiles` (:1171-1173): the count of agent `snd_files` rows with `deleted = 0` eventually equals 0. +- "send and receive file" (:703): `checkNoAgentSndFiles alice` after the direct transfer (:732). +- "send and receive file in group" (:789): `checkNoAgentSndFiles alice` after the group transfer (:826). +- "delete agent file after upload error" (:1078): + - XFTP server with `newFileBasicAuth = Just "abcd"`; the client's server password `server_password` differs; + - alice: "error uploading file 1 (test.pdf) for bob"; + - `checkNoAgentSndFiles alice`. +- "delete agent file when contact is deleted during upload" (:1093): + - XFTP server down at the send; + - bob deletes the contact with notification (`/_delete @2 full notify=on`); + - server started: alice "bob: not ready"; + - `checkNoAgentSndFiles alice` (:1106). + - On master, a test failure is expected: the deletion at master :291 is skipped after the error at :275, and the agent row is kept. +- "delete agent file when item is marked deleted during upload" (:1108): + - XFTP server down; + - alice marks the item deleted for everyone; + - the agent row is marked `deleted = 1` by the cancellation (`src/Simplex/Chat/Library/Internal.hs:649, 511, 3213`); + - the agent's prepare worker finds the row marked deleted and sends `SFERR` (simplexmq `src/Simplex/FileTransfer/Agent.hs:510-511, 516-521`); the agent file is deleted after its handling; + - the count of all agent `snd_files` rows eventually equals 0 (:1121). + - On master, a test failure is expected when the check starts within 10 s of the agent start: the deletions are skipped for cancelled files, the marked row is deleted only by the agent cleanup 30 s after the agent starts, and the check polls for 20 s. +- "delete agent file when file user is missing during upload" (:1123): + - XFTP server down at the send of a 17 MB file; + - the user's contact profile is unset, so the file user is not found; + - server started: the agent row is eventually marked `deleted = 1`, by the deletion on the first `SFPROG`. +- "complete upload before chat is suspended" (:1137): + - XFTP server down at the send; + - alice: `/_app suspend 60000000`; + - server started: alice "completed uploading file 1 (test.pdf) for bob", then "chat suspended"; + - `checkNoAgentSndFiles alice`; + - bob receives the file. +- "show agent file error without file ID" (:1161): + - agent cleanup 2 s after the agent starts; + - the agent column `snd_files.prefix_path` renamed, so the three cleanup steps of sent files fail; + - alice: three lines "internal error: …", from `SFERR` without a file ID. + +`tests/ChatTests/Files.hs`, "file transfer over XFTP without chat items": +- "send and receive small standalone file" (:1404): `checkNoAgentSndFiles src` after the upload (:1418). +- "send and receive large standalone file" (:1460): `checkNoAgentSndFiles src` after the upload and its redirect upload (:1477). + +`tests/ChatTests/Files.hs`, "record upload: …", one recording in `tests/fixtures/api/files` each: +- "send text", "send file", "send group file": the responses to a direct text send (`send-text`), a direct file send (`send-file`) and a group file send (`send-group-file`). +- With file 1 sent while the XFTP server is down, and its item received by bob (`withSndFileEvents`): + - "complete": `sndFileCompleteXFTP` after the XFTP server starts (`upload-complete`); + - "error": `sndFileError` from an XFTP server with another password (`upload-error`); + - "cancel": the response to `/fcancel 1` (`cancel`); + - "delete": the response to the internal deletion of the item (`delete`). + +`apps/ios/SimpleX Unit Tests/FileUploadTests.swift`, `sendSimpleXCmdStr` replaced by the recorded response: + +| Test | Path | Asserted `fileUploads` keys | +|---|---|---| +| `testSentFileBeginsTask` | `apiSendMessages`, direct, `send-file` | `[1]` | +| `testSentGroupFileBeginsTask` | `apiSendMessages`, group, `send-group-file` | `[1]` | +| `testSentTextBeginsNoTask` | `apiSendMessages`, direct, `send-text` | `[]` | +| `testCompletedUploadEndsTask` | task of file 1, `processReceivedMsg`, `upload-complete` | `[]` | +| `testUploadErrorEndsTask` | task of file 1, `processReceivedMsg`, `upload-error` | `[]` | +| `testCancelledUploadEndsTask` | task of file 1, `apiCancelFile`, `cancel` | `[]` | +| `testDeletedItemEndsTask` | task of file 1, `apiDeleteChatItems`, `delete` | `[]` | +| `testDeletedItemEventEndsTask` | task of file 1, `processReceivedMsg`, `delete` decoded as the event | `[]` | + +Device tests, run by the user: +- A 20 MB file is sent, and the app leaves the foreground at once: the upload completes and the recipient receives the file, when the upload takes less than the background time iOS grants. diff --git a/scripts/ci/README.md b/scripts/ci/README.md index b5895d9800..904ad69b0f 100644 --- a/scripts/ci/README.md +++ b/scripts/ci/README.md @@ -48,7 +48,7 @@ The reduced build runs the Linux job build-linux (ubuntu-22.04 x86_64) for every - the badge service web app, `npm ci` and `npm run build` in apps/simplex-badge-service/web with Node.js 22, for the test "serves the built web app" (step "Build badge web app for tests"); - simplex-chat-test with the selected tests (step "Run tests"), each attempt limited to 35 minutes by `timeout`; an attempt that reaches the limit fails, and "Attempt timed out." is printed; - step "Check generated files": it fails if a test changed a tracked file, and uploads the change as artifact `generated-files-`. The tests "verify and overwrite schema dump", "verify and overwrite query plans" and the "generate ..." tests of the API docs overwrite their files, so a stale file fails here even when the test passes on retry. -- App test fixtures: core tests write the core's responses and events that the app tests use to tests/fixtures/api (`/names tests/` to tests/fixtures/api/names; `/contact via address/`, `/should validate link type/` and `/reject contact and notify the sender/` to tests/fixtures/api/connect; `/updated item event has the previous item/`, `/should send updated item with mentions added and removed by edit/` and `/mark call invitation missed when the caller ends the call/` to tests/fixtures/api/updates), and fail when a recording differs from the committed file; the rewritten files are committed, and the kotlin and ios scopes run for them. +- App test fixtures: core tests write the core's responses and events that the app tests use to tests/fixtures/api (`/names tests/` to tests/fixtures/api/names; `/contact via address/`, `/should validate link type/` and `/reject contact and notify the sender/` to tests/fixtures/api/connect; `/updated item event has the previous item/`, `/should send updated item with mentions added and removed by edit/` and `/mark call invitation missed when the caller ends the call/` to tests/fixtures/api/updates; `/record upload/` to tests/fixtures/api/files), and fail when a recording differs from the committed file; the rewritten files are committed, and the kotlin and ios scopes run for them. - CI, in test-postgres, except on stable and v* tags: the steps of build-linux with the matrix parameter `postgres` and these job settings: - the Docker image and dependency cache of build-linux, and its own build directory cache `dist-postgres-`; - simplex-chat-test built with `--constraint 'simplexmq +client_postgres' --constraint 'simplex-chat +client_postgres'` at -O0 (step "Build CLI"); diff --git a/src/Simplex/Chat/Library/Subscriber.hs b/src/Simplex/Chat/Library/Subscriber.hs index 715f309234..bb6f780898 100644 --- a/src/Simplex/Chat/Library/Subscriber.hs +++ b/src/Simplex/Chat/Library/Subscriber.hs @@ -222,15 +222,27 @@ processAgentMessageNoConn = \case errsEvent = toView . CEvtChatErrors . map (\(cId, e) -> ChatErrorAgent e (AgentConnId cId) Nothing) processAgentMsgSndFile :: ACorrId -> SndFileId -> AEvent 'AESndFile -> CM () -processAgentMsgSndFile _corrId aFileId msg = do - (cRef_, fileId) <- withStore (`getXFTPSndFileDBIds` AgentSndFileId aFileId) - withEntityLock_ cRef_ . withFileLock "processAgentMsgSndFile" fileId $ - withStore' (`getUserByASndFileId` AgentSndFileId aFileId) >>= \case - Just user -> process user fileId `catchAllErrors` eToView - _ -> do - lift $ withAgent' (`xftpDeleteSndFileInternal` aFileId) - throwChatError $ CENoSndFileUser $ AgentSndFileId aFileId +processAgentMsgSndFile _ "" (SFERR e) = + eToView $ chatErrorAgent e +processAgentMsgSndFile _corrId aFileId msg = flip allFinally (when sndFileEnded deleteAgentFile) $ + withStore' (\db -> runExceptT $ getXFTPSndFileDBIds db $ AgentSndFileId aFileId) >>= \case + Left SESndFileNotFoundXFTP {} -> unless sndFileEnded deleteAgentFile + Left e -> throwError $ ChatErrorStore e + Right (cRef_, fileId) -> + withEntityLock_ cRef_ . withFileLock "processAgentMsgSndFile" fileId $ + withStore' (`getUserByASndFileId` AgentSndFileId aFileId) >>= \case + Just user -> process user fileId `catchAllErrors` eToView + _ -> do + unless sndFileEnded deleteAgentFile + throwChatError $ CENoSndFileUser $ AgentSndFileId aFileId where + sndFileEnded :: Bool + sndFileEnded = case msg of + SFDONE {} -> True + SFERR _ -> True + _ -> False + deleteAgentFile :: CM () + deleteAgentFile = lift $ withAgent' (`xftpDeleteSndFileInternal` aFileId) withEntityLock_ :: Maybe ChatRef -> CM a -> CM a withEntityLock_ = \case Just (ChatRef CTDirect contactId _) -> withContactLock "processAgentMsgSndFile" contactId @@ -253,7 +265,6 @@ processAgentMsgSndFile _corrId aFileId msg = do ci <- withStore $ \db -> lookupChatItemByFileId db cxt user fileId case ci of Nothing -> do - lift $ withAgent' (`xftpDeleteSndFileInternal` aFileId) withStore' $ \db -> createExtraSndFTDescrs db user fileId (map fileDescrText rfds) case rfds of [] -> sendFileError (FileErrOther "no receiver descriptions") "no receiver descriptions" cxt ft @@ -289,7 +300,6 @@ processAgentMsgSndFile _corrId aFileId msg = do Right (deliveryIds, _) -> eToView $ ChatError $ CEInternalError $ "SFDONE, sendFileDescriptions: expected 1 delivery id, got " <> show (length deliveryIds) Left e -> eToView e Nothing -> eToView $ ChatError $ CEInternalError "SFDONE, sendFileDescriptions: expected at least 1 result" - lift $ withAgent' (`xftpDeleteSndFileInternal` aFileId) (_, _, SMDSnd, GroupChat g@GroupInfo {groupId} _scope) -> do -- TODO [relays] single description for all recipients ms <- getRecipients @@ -309,7 +319,6 @@ processAgentMsgSndFile _corrId aFileId msg = do ci' <- withStore $ \db -> do liftIO $ updateCIFileStatus db user fileId CIFSSndComplete getChatItemByFileId db cxt user fileId - lift $ withAgent' (`xftpDeleteSndFileInternal` aFileId) toView $ CEvtSndFileCompleteXFTP user ci' ft where getRecipients @@ -361,7 +370,6 @@ processAgentMsgSndFile _corrId aFileId msg = do ci <- withStore $ \db -> do liftIO $ updateFileCancelled db user fileId (CIFSSndError ferr) lookupChatItemByFileId db cxt user fileId - lift $ withAgent' (`xftpDeleteSndFileInternal` aFileId) toView $ CEvtSndFileError user ci ft err agentFileError :: AgentErrorType -> FileError diff --git a/src/Simplex/Chat/Store/SQLite/Migrations/agent_query_plans.txt b/src/Simplex/Chat/Store/SQLite/Migrations/agent_query_plans.txt index b5ef374775..ea8bd1807c 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations/agent_query_plans.txt +++ b/src/Simplex/Chat/Store/SQLite/Migrations/agent_query_plans.txt @@ -1173,6 +1173,9 @@ SEARCH q USING INDEX idx_rcv_queues_to_subscribe (to_subscribe=? AND host=? AND SEARCH c USING PRIMARY KEY (conn_id=?) SEARCH s USING PRIMARY KEY (host=? AND port=?) +Query: ALTER TABLE snd_files RENAME COLUMN prefix_path TO prefix_path_renamed +Plan: + Query: DELETE FROM client_services WHERE user_id = ? Plan: SEARCH client_services USING COVERING INDEX idx_server_certs_user_id_host_port (user_id=?) @@ -1415,6 +1418,14 @@ Query: SELECT count(1) FROM connections Plan: SCAN connections USING COVERING INDEX idx_connections_deleted +Query: SELECT count(1) FROM snd_files +Plan: +SCAN snd_files USING COVERING INDEX idx_snd_files_user_id + +Query: SELECT count(1) FROM snd_files WHERE deleted = 0 +Plan: +SCAN snd_files + Query: SELECT count(1) FROM snd_message_bodies Plan: SCAN snd_message_bodies @@ -1427,6 +1438,10 @@ Query: SELECT count(1) FROM users Plan: SCAN users +Query: SELECT deleted FROM snd_files +Plan: +SCAN snd_files + Query: SELECT deleted FROM snd_files WHERE snd_file_id = ? Plan: SEARCH snd_files USING INTEGER PRIMARY KEY (rowid=?) @@ -1479,6 +1494,10 @@ Query: SELECT skipped_message_id, header_key, msg_n, msg_key FROM skipped_messag Plan: SEARCH skipped_messages USING INDEX idx_skipped_messages_conn_id (conn_id=?) +Query: SELECT snd_file_entity_id FROM snd_files WHERE deleted = 0 AND failed = 0 +Plan: +SCAN snd_files + Query: SELECT snd_file_id FROM snd_files WHERE snd_file_entity_id = ? Plan: SEARCH snd_files USING COVERING INDEX idx_snd_files_snd_file_entity_id (snd_file_entity_id=?) @@ -1619,6 +1638,14 @@ Query: UPDATE snd_file_chunk_replicas SET replica_status = ?, updated_at = ? WHE Plan: SEARCH snd_file_chunk_replicas USING INTEGER PRIMARY KEY (rowid=?) +Query: UPDATE snd_files SET deleted = 1, updated_at = ? WHERE snd_file_id = ? +Plan: +SEARCH snd_files USING INTEGER PRIMARY KEY (rowid=?) + +Query: UPDATE snd_files SET prefix_path = NULL, error = ?, status = ?, updated_at = ? WHERE snd_file_id = ? +Plan: +SEARCH snd_files USING INTEGER PRIMARY KEY (rowid=?) + Query: UPDATE snd_files SET prefix_path = NULL, status = ?, updated_at = ? WHERE snd_file_id = ? Plan: SEARCH snd_files USING INTEGER PRIMARY KEY (rowid=?) diff --git a/src/Simplex/Chat/Store/SQLite/Migrations/chat_query_plans.txt b/src/Simplex/Chat/Store/SQLite/Migrations/chat_query_plans.txt index b95a7afd30..823a5ca8dc 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations/chat_query_plans.txt +++ b/src/Simplex/Chat/Store/SQLite/Migrations/chat_query_plans.txt @@ -8081,6 +8081,12 @@ Query: SELECT item_content FROM chat_items WHERE group_id = 1 ORDER BY chat_item Plan: SEARCH chat_items USING INDEX idx_chat_items_group_id (group_id=?) +Query: SELECT item_status FROM chat_items WHERE chat_item_id IN (SELECT chat_item_id FROM files) +Plan: +SEARCH chat_items USING INTEGER PRIMARY KEY (rowid=?) +LIST SUBQUERY 1 +SCAN files USING COVERING INDEX idx_files_chat_item_id + Query: SELECT item_status FROM chat_items WHERE item_text = ? Plan: SCAN chat_items @@ -8548,6 +8554,12 @@ Query: UPDATE contacts SET contact_grp_inv_sent = ?, updated_at = ? WHERE contac Plan: SEARCH contacts USING INTEGER PRIMARY KEY (rowid=?) +Query: UPDATE contacts SET contact_profile_id = NULL WHERE contact_id = (SELECT contact_id FROM users WHERE user_id = 1) +Plan: +SEARCH contacts USING INTEGER PRIMARY KEY (rowid=?) +SCALAR SUBQUERY 1 +SEARCH users USING INTEGER PRIMARY KEY (rowid=?) + Query: UPDATE contacts SET contact_used = ? WHERE user_id = ? AND contact_id = ? Plan: SEARCH contacts USING INTEGER PRIMARY KEY (rowid=?) diff --git a/tests/ChatTests/Files.hs b/tests/ChatTests/Files.hs index 9964cd5cd1..fdc2213748 100644 --- a/tests/ChatTests/Files.hs +++ b/tests/ChatTests/Files.hs @@ -12,7 +12,7 @@ import ChatTests.Profiles (addTestBadge, futureDate, issueTestBadge, issueTestBa import ChatTests.Utils import Control.Concurrent (threadDelay) import Control.Concurrent.Async (concurrently_) -import Control.Concurrent.STM (atomically, check, modifyTVar', newTVarIO, readTVar, readTVarIO, writeTVar) +import Control.Concurrent.STM (TVar, atomically, check, modifyTVar', newTVarIO, readTVar, readTVarIO, writeTVar) import Control.Logger.Simple import Control.Monad.Except (runExceptT) import Control.Monad.Reader (runReaderT) @@ -36,6 +36,8 @@ import Simplex.Chat.Options (ChatOpts (..)) import Simplex.Chat.Protocol (MsgContent (MCImage, MCText)) import Simplex.Chat.Types (ImageData (..)) import Simplex.FileTransfer.Server.Env (XFTPServerConfig (..), XFTPStoreConfig (..)) +import Simplex.Messaging.Agent.Env.SQLite (AgentConfig (..)) +import qualified Simplex.Messaging.Agent.Store.DB as DB import Simplex.Messaging.Crypto.BBS (BBSPublicKey, bbsKeyGen) import Simplex.Messaging.Crypto.File (CryptoFile (..), CryptoFileArgs (..)) import Simplex.Messaging.Encoding.String @@ -69,6 +71,19 @@ chatFileTests = do it "send and receive file in group" testXFTPGroupFileTransfer it "delete uploaded file" testXFTPDeleteUploadedFile it "delete uploaded file in group" testXFTPDeleteUploadedFileGroup + it "delete agent file after upload error" testXFTPUploadErrorDeletesAgentFile + it "delete agent file when contact is deleted during upload" testXFTPContactDeletedDuringUpload + it "delete agent file when item is marked deleted during upload" testXFTPMarkDeletedDuringUpload + it "delete agent file when file user is missing during upload" testXFTPMissingUserDuringUpload + it "complete upload before chat is suspended" testXFTPSuspendDuringUpload + it "record upload: send text" testXFTPRecordSendText + it "record upload: send file" testXFTPRecordSendFile + it "record upload: send group file" testXFTPRecordSendGroupFile + it "record upload: complete" testXFTPRecordUploadComplete + it "record upload: error" testXFTPRecordUploadError + it "record upload: cancel" testXFTPRecordCancel + it "record upload: delete" testXFTPRecordDelete + it "show agent file error without file ID" testXFTPAgentErrorWithoutFileId it "with relative paths: send and receive file" testXFTPWithRelativePaths it "continue receiving file after restart" testXFTPContinueRcv it "receive file marked to receive on chat start" testXFTPMarkToReceive @@ -756,6 +771,7 @@ testXFTPFileTransfer = src <- B.readFile "./tests/fixtures/test.pdf" dest <- B.readFile testPdf dest `shouldBe` src + checkNoAgentSndFiles alice testXFTPFileTransferEncrypted :: HasCallStack => TestParams -> IO () testXFTPFileTransferEncrypted = @@ -849,6 +865,7 @@ testXFTPGroupFileTransfer = dest2 <- B.readFile (tmpFile cath "test_1.pdf") dest1 `shouldBe` src dest2 `shouldBe` src + checkNoAgentSndFiles alice badgeFileCfg :: BBSPublicKey -> ChatConfig badgeFileCfg pk = badgeFileCfgLimits pk FileSizeLimits {noBadge = 100000, supporter = 300000, legend = 400000} @@ -1100,6 +1117,167 @@ testXFTPDeleteUploadedFileGroup = cath ##> ("/fr 1 " <> tmpDir cath) cath <## "file cancelled: test.pdf" +testXFTPUploadErrorDeletesAgentFile :: HasCallStack => TestParams -> IO () +testXFTPUploadErrorDeletesAgentFile ps = + withXFTPServer' (xftpServerConfig ps) {newFileBasicAuth = Just "abcd"} $ + testChat2 aliceProfile bobProfile test ps + where + test alice bob = do + connectUsers alice bob + alice #> "/f @bob ./tests/fixtures/test.pdf" + alice <## "use /fc 1 to cancel sending" + bob <# "alice> sends file test.pdf (266.0 KiB / 272376 bytes)" + bob <## "use /fr 1 [/ | ] to receive it" + alice <## "error uploading file 1 (test.pdf) for bob" + alice <##. "XFTP " + checkNoAgentSndFiles alice + +testXFTPContactDeletedDuringUpload :: HasCallStack => TestParams -> IO () +testXFTPContactDeletedDuringUpload = + testChat2 aliceProfile bobProfile $ \alice bob -> do + connectUsers alice bob + alice #> "/f @bob ./tests/fixtures/test.pdf" + alice <## "use /fc 1 to cancel sending" + bob <# "alice> sends file test.pdf (266.0 KiB / 272376 bytes)" + bob <## "use /fr 1 [/ | ] to receive it" + bob ##> "/_delete @2 full notify=on" + bob <## "alice: contact is deleted" + alice <## "bob (Bob) deleted contact with you" + withXFTPServer alice $ do + alice <## "bob: not ready" + checkNoAgentSndFiles alice + +testXFTPMarkDeletedDuringUpload :: HasCallStack => TestParams -> IO () +testXFTPMarkDeletedDuringUpload = + testChat2 aliceProfile bobProfile $ \alice bob -> do + connectUsers alice bob + alice ##> "/_send @2 json [{\"filePath\": \"./tests/fixtures/test_1MB.pdf\", \"msgContent\": {\"type\": \"text\", \"text\": \"hi, sending a file\"}}]" + alice <# "@bob hi, sending a file" + alice <# "/f @bob ./tests/fixtures/test_1MB.pdf" + alice <## "use /fc 1 to cancel sending" + bob <# "alice> hi, sending a file" + bob <# "alice> sends file test_1MB.pdf (1017.7 KiB / 1042157 bytes)" + bob <## "use /fr 1 [/ | ] to receive it" + alice #$> ("/_delete item @2 " <> itemId 1 <> " broadcast", id, "message marked deleted") + bob <# "alice> [marked deleted] hi, sending a file" + (withCCAgentTransaction alice $ \db -> DB.query_ db "SELECT count(1) FROM snd_files" :: IO [[Int]]) `shouldEventuallyReturn` [[0]] + +testXFTPMissingUserDuringUpload :: HasCallStack => TestParams -> IO () +testXFTPMissingUserDuringUpload = + testChat2 aliceProfile bobProfile $ \alice bob -> do + connectUsers alice bob + let srcFile = tmpFile alice "testfile.in" + xftpCLI ["rand", srcFile, "17mb"] `shouldReturn` ["File created: " <> srcFile] + alice #> ("/f @bob " <> srcFile) + alice <## "use /fc 1 to cancel sending" + bob <# "alice> sends file testfile.in (17.0 MiB / 17825792 bytes)" + bob <## "use /fr 1 [/ | ] to receive it" + withCCTransaction alice $ \db -> DB.execute_ db "UPDATE contacts SET contact_profile_id = NULL WHERE contact_id = (SELECT contact_id FROM users WHERE user_id = 1)" + withXFTPServer alice $ + (withCCAgentTransaction alice $ \db -> DB.query_ db "SELECT deleted FROM snd_files" :: IO [[Int]]) `shouldEventuallyReturn` [[1]] + +testXFTPSuspendDuringUpload :: HasCallStack => TestParams -> IO () +testXFTPSuspendDuringUpload = + testChat2 aliceProfile bobProfile $ \alice bob -> do + connectUsers alice bob + alice #> "/f @bob ./tests/fixtures/test.pdf" + alice <## "use /fc 1 to cancel sending" + bob <# "alice> sends file test.pdf (266.0 KiB / 272376 bytes)" + bob <## "use /fr 1 [/ | ] to receive it" + alice ##> "/_app suspend 60000000" + alice <## "ok" + withXFTPServer alice $ do + alice <## "completed uploading file 1 (test.pdf) for bob" + alice <## "chat suspended" + checkNoAgentSndFiles alice + let testPdf = tmpFile bob "test.pdf" + bob ##> ("/fr 1 " <> tmpDir bob) + bob + <### [ ConsoleString $ "saving file 1 from alice to " <> testPdf, + "started receiving file 1 (test.pdf) from alice" + ] + bob <## "completed receiving file 1 (test.pdf) from alice" + src <- B.readFile "./tests/fixtures/test.pdf" + B.readFile testPdf `shouldReturn` src + +testXFTPRecordSendText :: HasCallStack => TestParams -> IO () +testXFTPRecordSendText = + testChat2 aliceProfile bobProfile $ \alice bob -> do + connectUsers alice bob + apiFixture "files/send-text" alice [] FixtureRequests {frMarkdown = [], frUris = [], frCommands = ["/_send @2 json [{\"msgContent\": {\"type\": \"text\", \"text\": \"hi\"}}]"]} + bob <# "alice> hi" + +testXFTPRecordSendFile :: HasCallStack => TestParams -> IO () +testXFTPRecordSendFile = + testChat2 aliceProfile bobProfile $ \alice bob -> do + connectUsers alice bob + apiFixture "files/send-file" alice [] FixtureRequests {frMarkdown = [], frUris = [], frCommands = ["/_send @2 " <> sendFileJSON]} + bob <# "alice> sends file test.pdf (266.0 KiB / 272376 bytes)" + bob <## "use /fr 1 [/ | ] to receive it" + +testXFTPRecordSendGroupFile :: HasCallStack => TestParams -> IO () +testXFTPRecordSendGroupFile = + testChat2 aliceProfile bobProfile $ \alice bob -> do + createGroup2 "team" alice bob + apiFixture "files/send-group-file" alice [] FixtureRequests {frMarkdown = [], frUris = [], frCommands = ["/_send #1 " <> sendFileJSON]} + bob <# "#team alice> sends file test.pdf (266.0 KiB / 272376 bytes)" + bob <## "use /fr 1 [/ | ] to receive it" + +testXFTPRecordUploadComplete :: HasCallStack => TestParams -> IO () +testXFTPRecordUploadComplete ps = + withSndFileEvents ps $ \events alice _ -> + eventsFixture "files/upload-complete" events $ + withXFTPServer ps $ alice <## "completed uploading file 1 (test.pdf) for bob" + +testXFTPRecordUploadError :: HasCallStack => TestParams -> IO () +testXFTPRecordUploadError ps = + withSndFileEvents ps $ \events alice _ -> + eventsFixture "files/upload-error" events $ + withXFTPServer' (xftpServerConfig ps) {newFileBasicAuth = Just "abcd"} $ do + alice <## "error uploading file 1 (test.pdf) for bob" + alice <##. "XFTP " + +testXFTPRecordCancel :: HasCallStack => TestParams -> IO () +testXFTPRecordCancel ps = + withSndFileEvents ps $ \_ alice bob -> do + apiFixture "files/cancel" alice [] FixtureRequests {frMarkdown = [], frUris = [], frCommands = ["/fcancel 1"]} + bob <## "alice cancelled sending file 1 (test.pdf)" + +testXFTPRecordDelete :: HasCallStack => TestParams -> IO () +testXFTPRecordDelete ps = + withSndFileEvents ps $ \_ alice _ -> + apiFixture "files/delete" alice [] FixtureRequests {frMarkdown = [], frUris = [], frCommands = ["/_delete item @2 " <> itemId 1 <> " internal"]} + +withSndFileEvents :: HasCallStack => TestParams -> (TVar [J.Value] -> TestCC -> TestCC -> IO ()) -> IO () +withSndFileEvents ps recordings = do + events <- newTVarIO [] + withNewTestChatCfg ps testCfg {chatHooks = defaultChatHooks {eventHook = Just $ \_ evt -> evt <$ recordSndFileEvent events evt}} "alice" aliceProfile $ \alice -> + withNewTestChat ps "bob" bobProfile $ \bob -> do + connectUsers alice bob + alice #> "/f @bob ./tests/fixtures/test.pdf" + alice <## "use /fc 1 to cancel sending" + bob <# "alice> sends file test.pdf (266.0 KiB / 272376 bytes)" + bob <## "use /fr 1 [/ | ] to receive it" + (withCCTransaction alice $ \db -> DB.query_ db "SELECT item_status FROM chat_items WHERE chat_item_id IN (SELECT chat_item_id FROM files)" :: IO [[String]]) `shouldEventuallyReturn` [["snd_rcvd ok complete"]] + recordings events alice bob + +sendFileJSON :: String +sendFileJSON = "json [{\"filePath\": \"./tests/fixtures/test.pdf\", \"msgContent\": {\"type\": \"file\", \"text\": \"\"}}]" + +testXFTPAgentErrorWithoutFileId :: HasCallStack => TestParams -> IO () +testXFTPAgentErrorWithoutFileId = + testChatCfgOpts cfg testOpts aliceProfile $ \alice -> do + withCCAgentTransaction alice $ \db -> DB.execute_ db "ALTER TABLE snd_files RENAME COLUMN prefix_path TO prefix_path_renamed" + alice <##. "internal error: " + alice <##. "internal error: " + alice <##. "internal error: " + where + cfg = testCfg {agentConfig = testAgentCfg {initialCleanupDelay = 2000000, cleanupInterval = 3600000000}} + +checkNoAgentSndFiles :: HasCallStack => TestCC -> Expectation +checkNoAgentSndFiles cc = + (withCCAgentTransaction cc $ \db -> DB.query_ db "SELECT count(1) FROM snd_files WHERE deleted = 0" :: IO [[Int]]) `shouldEventuallyReturn` [[0]] + testXFTPWithRelativePaths :: HasCallStack => TestParams -> IO () testXFTPWithRelativePaths = testChat2 aliceProfile bobProfile $ \alice bob -> do @@ -1373,6 +1551,7 @@ testXFTPStandaloneSmall = testChat2 aliceProfile aliceDesktopProfile $ \src dst _uri2 <- getTermLine src uri3 <- getTermLine src _uri4 <- getTermLine src + checkNoAgentSndFiles src logNote "receiving" let dstFile = tmpFile dst "logo.jpg" @@ -1431,6 +1610,7 @@ testXFTPStandaloneLarge = testChat2 aliceProfile aliceDesktopProfile $ \src dst _uri2 <- getTermLine src _uri3 <- getTermLine src _uri4 <- getTermLine src + checkNoAgentSndFiles src logNote "receiving" let dstFile = tmpFile dst "testfile.out" diff --git a/tests/ChatTests/Utils.hs b/tests/ChatTests/Utils.hs index d235c1761a..85222735ad 100644 --- a/tests/ChatTests/Utils.hs +++ b/tests/ChatTests/Utils.hs @@ -30,7 +30,7 @@ import Data.Maybe (fromMaybe) import Data.String import qualified Data.Text as T import Simplex.Chat.Badges (BadgeProof (..), BadgeStatus, LocalBadge (..), ProofPresHeader (..)) -import Simplex.Chat.Controller (ChatConfig (..), ChatController (..), ChatError, ChatEvent (CEvtChatItemUpdated, CEvtNameMoved, CEvtNewChatItems), storeCxt) +import Simplex.Chat.Controller (ChatConfig (..), ChatController (..), ChatError, ChatEvent (CEvtChatItemUpdated, CEvtNameMoved, CEvtNewChatItems, CEvtSndFileCompleteXFTP, CEvtSndFileError), storeCxt) import Simplex.Chat.Library.Commands (maxProfileImageSize) import Simplex.Chat.Markdown (viewName) import Simplex.Chat.Mobile (chatParseMarkdown, chatParseUri, chatSendCmd, eitherToResult) @@ -1013,11 +1013,18 @@ nameMovedFixture fixture cc contacts groups = withCCUser cc $ \user -> do recordItemEvent :: TVar [J.Value] -> Either ChatError ChatEvent -> IO () recordItemEvent events evt = case evt of - Right CEvtNewChatItems {} -> record - Right CEvtChatItemUpdated {} -> record + Right CEvtNewChatItems {} -> recordEvent events evt + Right CEvtChatItemUpdated {} -> recordEvent events evt _ -> pure () - where - record = atomically $ modifyTVar' events (<> [J.toJSON $ eitherToResult Nothing evt]) + +recordSndFileEvent :: TVar [J.Value] -> Either ChatError ChatEvent -> IO () +recordSndFileEvent events evt = case evt of + Right CEvtSndFileCompleteXFTP {} -> recordEvent events evt + Right CEvtSndFileError {} -> recordEvent events evt + _ -> pure () + +recordEvent :: TVar [J.Value] -> Either ChatError ChatEvent -> IO () +recordEvent events evt = atomically $ modifyTVar' events (<> [J.toJSON $ eitherToResult Nothing evt]) eventsFixture :: String -> TVar [J.Value] -> IO () -> IO () eventsFixture fixture events steps = do @@ -1048,6 +1055,6 @@ stableJSON = \case where stableField k v | k `elem` ["createdAt", "updatedAt", "chatTs", "userMemberProfileSentAt", "itemTs", "deletedTs", "fileExpires"] = J.String "1970-01-01T00:00:00Z" - | k `elem` ["agentConnId", "xContactId", "connFullLink", "connShortLink", "contactLink", "groupLink", "viaGroupLinkUri", "simplexUri", "memberId", "memberPubKey", "publicGroupId", "businessId", "customerId", "itemSharedMsgId", "fileDescrText"] = J.String $ JK.toText k + | k `elem` ["agentConnId", "xContactId", "connFullLink", "connShortLink", "contactLink", "groupLink", "viaGroupLinkUri", "simplexUri", "memberId", "memberPubKey", "publicGroupId", "businessId", "customerId", "itemSharedMsgId", "fileDescrText", "agentSndFileId", "privateSndFileDescr", "errorMessage"] = J.String $ JK.toText k | k == "groupRelays", J.Array a <- v = J.Array $ J.String "groupRelay" <$ a | otherwise = stableJSON v diff --git a/tests/fixtures/api/files/cancel.json b/tests/fixtures/api/files/cancel.json new file mode 100644 index 0000000000..e76fcc851d --- /dev/null +++ b/tests/fixtures/api/files/cancel.json @@ -0,0 +1,340 @@ +{ + "commands": { + "/fcancel 1": { + "result": { + "chatItem_": { + "chatInfo": { + "contact": { + "activeConn": { + "agentConnId": "agentConnId", + "authErrCounter": 0, + "connChatVersion": 22, + "connId": 1, + "connLevel": 0, + "connStatus": { + "type": "ready" + }, + "connType": "contact", + "contactConnInitiated": false, + "createdAt": "1970-01-01T00:00:00Z", + "entityId": 2, + "localAlias": "", + "peerChatVRange": { + "maxVersion": 22, + "minVersion": 9 + }, + "pqEncryption": true, + "pqRcvEnabled": true, + "pqSndEnabled": true, + "pqSupport": true, + "quotaErrCounter": 0, + "viaGroupLink": false + }, + "chatDeleted": false, + "chatSettings": { + "enableNtfs": "all", + "favorite": false + }, + "chatTags": [], + "chatTs": "1970-01-01T00:00:00Z", + "contactGrpInvSent": false, + "contactId": 2, + "contactStatus": "active", + "contactUsed": true, + "createdAt": "1970-01-01T00:00:00Z", + "localDisplayName": "bob", + "mergedPreferences": { + "calls": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "commands": [], + "files": { + "contactPreference": { + "allow": "always" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "always" + }, + "type": "user" + } + }, + "fullDelete": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "reactions": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "sessions": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "timedMessages": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "voice": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + } + }, + "profile": { + "displayName": "bob", + "fullName": "", + "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAKHGlDQ1BJQ0MgUHJvZmlsZQAASImFVgdUVNcWve9Nb7QZeu9NehtAem/Sq6gMQ28OQxWxgAQjEFFEREARNFQFg1KjiIhiIQgoYA9IEFB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ANbT+yf/iqQIPd21PXgaAcDJcjivtwJAQHLFgcNZ9uBwPlUgYhHf1z37f7V9g9e8ITewiP88wfWIYET6HPg21nzjV2fybQVcxfrg2/onng/F50lD/ccAAAA4ZVhJZk1NACoAAAAIAAGHaQAEAAAAAQAAABoAAAAAAAKgAgAEAAAAAQAAABigAwAEAAAAAQAAABgAAAAAwf1XlwAAAaNJREFUSA3FlT1LA0EQQBN/gYUYRTksJZVgEbCR/D+7QMr8ABtttBBCsLGzsLG2sxaxED/ie4d77u0dyaE5HHjczn7MzO7M7nU6/yXz+bwLhzCCjTQO+rZhDH3opuNLdRYN4RHe4RIKJ7R34Ro+4AEGSw2mE1iUwT18gpI74WvkGlccu4XNdH0jnYU7cAUacidn37qR23cOxc4aGU0nYUAn7iSWEHkz46w0ocdQu1X6B/AMQZ5o7KfBqNOfwRH8JB7FajGhnmcpKvQe3MEbvILiDm5gPXaCHnZr4vvFGMoEKudKn8YvQIOOe+YzCPop7dwJ3zRfJ7GDuso4YJGRa0yZgg4tUaNXdGrbuZWKKxzYYEJc2xp9AUUjGt8KC2jvgYadF8+10vJyDnNLXwbdiWUZi0fUK01Eoc+AZhCLZVzK4Vq6sDUdz+0dEcbbTTIOJmAyTVhx/WmvrExbv2jtPhWLKodjCtefZiEeZeVZWWSndgwj6fVf3XON8Qwq15++uoqrfYVrow6dGBpCq79ME291jaB0/Q2CPncyht/99MNO/vr9AqW/CGi8sJqbAAAAAElFTkSuQmCC", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 2, + "shortDescr": "Bob" + }, + "updatedAt": "1970-01-01T00:00:00Z", + "userPreferences": {} + }, + "type": "direct" + }, + "chatItem": { + "chatDir": { + "type": "directSnd" + }, + "content": { + "msgContent": { + "text": "", + "type": "file" + }, + "type": "sndMsgContent" + }, + "file": { + "fileId": 1, + "fileName": "test.pdf", + "fileProtocol": "xftp", + "fileSize": 272376, + "fileSource": { + "filePath": "./tests/fixtures/test.pdf" + }, + "fileStatus": { + "type": "sndCancelled" + } + }, + "mentions": {}, + "meta": { + "createdAt": "1970-01-01T00:00:00Z", + "deletable": true, + "editable": true, + "hasLink": false, + "itemEdited": false, + "itemId": 8, + "itemSharedMsgId": "itemSharedMsgId", + "itemStatus": { + "msgRcptStatus": "ok", + "sndProgress": "complete", + "type": "sndRcvd" + }, + "itemText": "", + "itemTs": "1970-01-01T00:00:00Z", + "sentViaProxy": false, + "showGroupAsSender": false, + "updatedAt": "1970-01-01T00:00:00Z", + "userMention": false + }, + "reactions": [] + } + }, + "fileTransferMeta": { + "cancelled": false, + "chunkSize": 15780, + "fileId": 1, + "fileName": "test.pdf", + "filePath": "./tests/fixtures/test.pdf", + "fileSize": 272376, + "xftpSndFile": { + "agentSndFileDeleted": false, + "agentSndFileId": "agentSndFileId" + } + }, + "sndFileTransfers": [ + { + "agentConnId": "agentConnId", + "chunkSize": 15780, + "connId": 1, + "fileDescrId": 1, + "fileId": 1, + "fileName": "test.pdf", + "filePath": "./tests/fixtures/test.pdf", + "fileSize": 272376, + "fileStatus": "new", + "recipientDisplayName": "bob" + } + ], + "type": "sndFileCancelled", + "user": { + "activeOrder": 1, + "activeUser": true, + "agentUserId": "1", + "autoAcceptGroupInvitations": false, + "autoAcceptMemberContacts": false, + "clientService": false, + "fullPreferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "localDisplayName": "alice", + "profile": { + "displayName": "alice", + "fullName": "", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 1, + "shortDescr": "Alice" + }, + "sendRcptsContacts": true, + "sendRcptsSmallGroups": true, + "showNtfs": true, + "userChatRelay": false, + "userContactId": 1, + "userId": 1 + } + } + } + }, + "markdown": {}, + "uris": {} +} diff --git a/tests/fixtures/api/files/delete.json b/tests/fixtures/api/files/delete.json new file mode 100644 index 0000000000..26bcd2d7f0 --- /dev/null +++ b/tests/fixtures/api/files/delete.json @@ -0,0 +1,320 @@ +{ + "commands": { + "/_delete item @2 8 internal": { + "result": { + "byUser": true, + "chatItemDeletions": [ + { + "deletedChatItem": { + "chatInfo": { + "contact": { + "activeConn": { + "agentConnId": "agentConnId", + "authErrCounter": 0, + "connChatVersion": 22, + "connId": 1, + "connLevel": 0, + "connStatus": { + "type": "ready" + }, + "connType": "contact", + "contactConnInitiated": false, + "createdAt": "1970-01-01T00:00:00Z", + "entityId": 2, + "localAlias": "", + "peerChatVRange": { + "maxVersion": 22, + "minVersion": 9 + }, + "pqEncryption": true, + "pqRcvEnabled": true, + "pqSndEnabled": true, + "pqSupport": true, + "quotaErrCounter": 0, + "viaGroupLink": false + }, + "chatDeleted": false, + "chatSettings": { + "enableNtfs": "all", + "favorite": false + }, + "chatTags": [], + "chatTs": "1970-01-01T00:00:00Z", + "contactGrpInvSent": false, + "contactId": 2, + "contactStatus": "active", + "contactUsed": true, + "createdAt": "1970-01-01T00:00:00Z", + "localDisplayName": "bob", + "mergedPreferences": { + "calls": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "commands": [], + "files": { + "contactPreference": { + "allow": "always" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "always" + }, + "type": "user" + } + }, + "fullDelete": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "reactions": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "sessions": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "timedMessages": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "voice": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + } + }, + "profile": { + "displayName": "bob", + "fullName": "", + "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAKHGlDQ1BJQ0MgUHJvZmlsZQAASImFVgdUVNcWve9Nb7QZeu9NehtAem/Sq6gMQ28OQxWxgAQjEFFEREARNFQFg1KjiIhiIQgoYA9IEFBisCAq6OQNJNH4//r/zDpz9ttzz7n73ffWmg0A6QCDxYqD+QCIT0hmezlYywQEBsngngEYCAIy0AC6DGYSy8rDwxUg8Xf9d7wbAxC33tHgzvrP3/9nCISFJzEBgIIRTGey2MkILkawT1oyi4tnEUxjI6IQvMLFkauYqxjQQtewwuoaHy8bBNMBwJMZDHYkAERbhJdJZUYic4hhCNZOCItOQDB3vjkzioFwxLsIXhcRl5IOAImrRzs+fivCk7QRrIL0shAcwNUW+tX8yH/tFfrPXgxG5D84Pi6F+dc9ck+HHJ7g641UMSQlQATQBHEgBaQDGcACbLAVYaIRJhx5Dv+9j77aZ4OsZIFtSEc0iARRIBnpt/9qlvfqpGSQBhjImnCEcUU+NtxnujZy4fbqVEiU/wuXdQyA9S0cDqfzC+e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WEHkz46w0ocdQu1X6B/AMQZ5o7KfBqNOfwRH8JB7FajGhnmcpKvQe3MEbvILiDm5gPXaCHnZr4vvFGMoEKudKn8YvQIOOe+YzCPop7dwJ3zRfJ7GDuso4YJGRa0yZgg4tUaNXdGrbuZWKKxzYYEJc2xp9AUUjGt8KC2jvgYadF8+10vJyDnNLXwbdiWUZi0fUK01Eoc+AZhCLZVzK4Vq6sDUdz+0dEcbbTTIOJmAyTVhx/WmvrExbv2jtPhWLKodjCtefZiEeZeVZWWSndgwj6fVf3XON8Qwq15++uoqrfYVrow6dGBpCq79ME291jaB0/Q2CPncyht/99MNO/vr9AqW/CGi8sJqbAAAAAElFTkSuQmCC", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 2, + "shortDescr": "Bob" + }, + "updatedAt": "1970-01-01T00:00:00Z", + "userPreferences": {} + }, + "type": "direct" + }, + "chatItem": { + "chatDir": { + "type": "directSnd" + }, + "content": { + "msgContent": { + "text": "", + "type": "file" + }, + "type": "sndMsgContent" + }, + "file": { + "fileId": 1, + "fileName": "test.pdf", + "fileProtocol": "xftp", + "fileSize": 272376, + "fileSource": { + "filePath": "./tests/fixtures/test.pdf" + }, + "fileStatus": { + "type": "sndStored" + } + }, + "mentions": {}, + "meta": { + "createdAt": "1970-01-01T00:00:00Z", + "deletable": true, + "editable": true, + "hasLink": false, + "itemEdited": false, + "itemId": 8, + "itemSharedMsgId": "itemSharedMsgId", + "itemStatus": { + "msgRcptStatus": "ok", + "sndProgress": "complete", + "type": "sndRcvd" + }, + "itemText": "", + "itemTs": "1970-01-01T00:00:00Z", + "sentViaProxy": false, + "showGroupAsSender": false, + "updatedAt": "1970-01-01T00:00:00Z", + "userMention": false + }, + "reactions": [] + } + } + } + ], + "timed": false, + "type": "chatItemsDeleted", + "user": { + "activeOrder": 1, + "activeUser": true, + "agentUserId": "1", + "autoAcceptGroupInvitations": false, + "autoAcceptMemberContacts": false, + "clientService": false, + "fullPreferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "localDisplayName": "alice", + "profile": { + "displayName": "alice", + "fullName": "", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 1, + "shortDescr": "Alice" + }, + "sendRcptsContacts": true, + "sendRcptsSmallGroups": true, + "showNtfs": true, + "userChatRelay": false, + "userContactId": 1, + "userId": 1 + } + } + } + }, + "markdown": {}, + "uris": {} +} diff --git a/tests/fixtures/api/files/send-file.json b/tests/fixtures/api/files/send-file.json new file mode 100644 index 0000000000..edf3591a51 --- /dev/null +++ b/tests/fixtures/api/files/send-file.json @@ -0,0 +1,313 @@ +{ + "commands": { + "/_send @2 json [{\"filePath\": \"./tests/fixtures/test.pdf\", \"msgContent\": {\"type\": \"file\", \"text\": \"\"}}]": { + "result": { + "chatItems": [ + { + "chatInfo": { + "contact": { + "activeConn": { + "agentConnId": "agentConnId", + "authErrCounter": 0, + "connChatVersion": 22, + "connId": 1, + "connLevel": 0, + "connStatus": { + "type": "ready" + }, + "connType": "contact", + "contactConnInitiated": false, + "createdAt": "1970-01-01T00:00:00Z", + "entityId": 2, + "localAlias": "", + "peerChatVRange": { + "maxVersion": 22, + "minVersion": 9 + }, + "pqEncryption": true, + "pqRcvEnabled": true, + "pqSndEnabled": true, + "pqSupport": true, + "quotaErrCounter": 0, + "viaGroupLink": false + }, + "chatDeleted": false, + "chatSettings": { + "enableNtfs": "all", + "favorite": false + }, + "chatTags": [], + "chatTs": "1970-01-01T00:00:00Z", + "contactGrpInvSent": false, + "contactId": 2, + "contactStatus": "active", + "contactUsed": true, + "createdAt": "1970-01-01T00:00:00Z", + "localDisplayName": "bob", + "mergedPreferences": { + "calls": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "commands": [], + "files": { + "contactPreference": { + "allow": "always" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "always" + }, + "type": "user" + } + }, + "fullDelete": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "reactions": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "sessions": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "timedMessages": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "voice": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + } + }, + "profile": { + "displayName": "bob", + "fullName": "", + "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAKHGlDQ1BJQ0MgUHJvZmlsZQAASImFVgdUVNcWve9Nb7QZeu9NehtAem/Sq6gMQ28OQxWxgAQjEFFEREARNFQFg1KjiIhiIQgoYA9IEFBisCAq6OQNJNH4//r/zDpz9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DJcjivtwJAQHLFgcNZ9uBwPlUgYhHf1z37f7V9g9e8ITewiP88wfWIYET6HPg21nzjV2fybQVcxfrg2/onng/F50lD/ccAAAA4ZVhJZk1NACoAAAAIAAGHaQAEAAAAAQAAABoAAAAAAAKgAgAEAAAAAQAAABigAwAEAAAAAQAAABgAAAAAwf1XlwAAAaNJREFUSA3FlT1LA0EQQBN/gYUYRTksJZVgEbCR/D+7QMr8ABtttBBCsLGzsLG2sxaxED/ie4d77u0dyaE5HHjczn7MzO7M7nU6/yXz+bwLhzCCjTQO+rZhDH3opuNLdRYN4RHe4RIKJ7R34Ro+4AEGSw2mE1iUwT18gpI74WvkGlccu4XNdH0jnYU7cAUacidn37qR23cOxc4aGU0nYUAn7iSWEHkz46w0ocdQu1X6B/AMQZ5o7KfBqNOfwRH8JB7FajGhnmcpKvQe3MEbvILiDm5gPXaCHnZr4vvFGMoEKudKn8YvQIOOe+YzCPop7dwJ3zRfJ7GDuso4YJGRa0yZgg4tUaNXdGrbuZWKKxzYYEJc2xp9AUUjGt8KC2jvgYadF8+10vJyDnNLXwbdiWUZi0fUK01Eoc+AZhCLZVzK4Vq6sDUdz+0dEcbbTTIOJmAyTVhx/WmvrExbv2jtPhWLKodjCtefZiEeZeVZWWSndgwj6fVf3XON8Qwq15++uoqrfYVrow6dGBpCq79ME291jaB0/Q2CPncyht/99MNO/vr9AqW/CGi8sJqbAAAAAElFTkSuQmCC", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 2, + "shortDescr": "Bob" + }, + "updatedAt": "1970-01-01T00:00:00Z", + "userPreferences": {} + }, + "type": "direct" + }, + "chatItem": { + "chatDir": { + "type": "directSnd" + }, + "content": { + "msgContent": { + "text": "", + "type": "file" + }, + "type": "sndMsgContent" + }, + "file": { + "fileId": 1, + "fileName": "test.pdf", + "fileProtocol": "xftp", + "fileSize": 272376, + "fileSource": { + "filePath": "./tests/fixtures/test.pdf" + }, + "fileStatus": { + "type": "sndStored" + } + }, + "mentions": {}, + "meta": { + "createdAt": "1970-01-01T00:00:00Z", + "deletable": true, + "editable": true, + "hasLink": false, + "itemEdited": false, + "itemId": 8, + "itemSharedMsgId": "itemSharedMsgId", + "itemStatus": { + "type": "sndNew" + }, + "itemText": "", + "itemTs": "1970-01-01T00:00:00Z", + "showGroupAsSender": false, + "updatedAt": "1970-01-01T00:00:00Z", + "userMention": false + }, + "reactions": [] + } + } + ], + "type": "newChatItems", + "user": { + "activeOrder": 1, + "activeUser": true, + "agentUserId": "1", + "autoAcceptGroupInvitations": false, + "autoAcceptMemberContacts": false, + "clientService": false, + "fullPreferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "localDisplayName": "alice", + "profile": { + "displayName": "alice", + "fullName": "", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 1, + "shortDescr": "Alice" + }, + "sendRcptsContacts": true, + "sendRcptsSmallGroups": true, + "showNtfs": true, + "userChatRelay": false, + "userContactId": 1, + "userId": 1 + } + } + } + }, + "markdown": {}, + "uris": {} +} diff --git a/tests/fixtures/api/files/send-group-file.json b/tests/fixtures/api/files/send-group-file.json new file mode 100644 index 0000000000..e03001da6f --- /dev/null +++ b/tests/fixtures/api/files/send-group-file.json @@ -0,0 +1,262 @@ +{ + "commands": { + "/_send #1 json [{\"filePath\": \"./tests/fixtures/test.pdf\", \"msgContent\": {\"type\": \"file\", \"text\": \"\"}}]": { + "result": { + "chatItems": [ + { + "chatInfo": { + "groupInfo": { + "chatSettings": { + "enableNtfs": "all", + "favorite": false + }, + "chatTags": [], + "chatTs": "1970-01-01T00:00:00Z", + "createdAt": "1970-01-01T00:00:00Z", + "fullGroupPreferences": { + "commands": [], + "comments": { + "enable": "off" + }, + "directMessages": { + "enable": "on" + }, + "files": { + "enable": "on" + }, + "fullDelete": { + "enable": "off" + }, + "history": { + "enable": "on" + }, + "reactions": { + "enable": "on" + }, + "reports": { + "enable": "on" + }, + "sessions": { + "enable": "off" + }, + "signMessages": { + "enable": "off" + }, + "simplexLinks": { + "enable": "on" + }, + "support": { + "enable": "on" + }, + "timedMessages": { + "enable": "off", + "ttl": 86400 + }, + "voice": { + "enable": "on" + } + }, + "groupId": 1, + "groupProfile": { + "displayName": "team", + "fullName": "", + "groupPreferences": { + "directMessages": { + "enable": "on" + }, + "history": { + "enable": "on" + } + } + }, + "groupSummary": { + "currentMembers": 2 + }, + "localAlias": "", + "localDisplayName": "team", + "membersRequireAttention": 0, + "membership": { + "blockedByAdmin": false, + "createdAt": "1970-01-01T00:00:00Z", + "groupId": 1, + "groupMemberId": 1, + "indexInGroup": 0, + "invitedBy": { + "type": "user" + }, + "localDisplayName": "alice", + "memberCategory": "user", + "memberChatVRange": { + "maxVersion": 22, + "minVersion": 9 + }, + "memberContactId": 1, + "memberContactProfileId": 1, + "memberId": "memberId", + "memberProfile": { + "displayName": "alice", + "fullName": "", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 1, + "shortDescr": "Alice" + }, + "memberPubKey": "memberPubKey", + "memberRole": "owner", + "memberSettings": { + "showMessages": true + }, + "memberStatus": "creator", + "updatedAt": "1970-01-01T00:00:00Z" + }, + "updatedAt": "1970-01-01T00:00:00Z", + "useRelays": false, + "userMemberProfileSentAt": "1970-01-01T00:00:00Z" + }, + "type": "group" + }, + "chatItem": { + "chatDir": { + "type": "groupSnd" + }, + "content": { + "msgContent": { + "text": "", + "type": "file" + }, + "type": "sndMsgContent" + }, + "file": { + "fileId": 1, + "fileName": "test.pdf", + "fileProtocol": "xftp", + "fileSize": 272376, + "fileSource": { + "filePath": "./tests/fixtures/test.pdf" + }, + "fileStatus": { + "type": "sndStored" + } + }, + "mentions": {}, + "meta": { + "createdAt": "1970-01-01T00:00:00Z", + "deletable": true, + "editable": true, + "hasLink": false, + "itemEdited": false, + "itemId": 22, + "itemSharedMsgId": "itemSharedMsgId", + "itemStatus": { + "type": "sndNew" + }, + "itemText": "", + "itemTs": "1970-01-01T00:00:00Z", + "showGroupAsSender": false, + "updatedAt": "1970-01-01T00:00:00Z", + "userMention": false + }, + "reactions": [] + } + } + ], + "type": "newChatItems", + "user": { + "activeOrder": 1, + "activeUser": true, + "agentUserId": "1", + "autoAcceptGroupInvitations": false, + "autoAcceptMemberContacts": false, + "clientService": false, + "fullPreferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "localDisplayName": "alice", + "profile": { + "displayName": "alice", + "fullName": "", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 1, + "shortDescr": "Alice" + }, + "sendRcptsContacts": true, + "sendRcptsSmallGroups": true, + "showNtfs": true, + "userChatRelay": false, + "userContactId": 1, + "userId": 1 + } + } + } + }, + "markdown": {}, + "uris": {} +} diff --git a/tests/fixtures/api/files/send-text.json b/tests/fixtures/api/files/send-text.json new file mode 100644 index 0000000000..d1674056d6 --- /dev/null +++ b/tests/fixtures/api/files/send-text.json @@ -0,0 +1,301 @@ +{ + "commands": { + "/_send @2 json [{\"msgContent\": {\"type\": \"text\", \"text\": \"hi\"}}]": { + "result": { + "chatItems": [ + { + "chatInfo": { + "contact": { + "activeConn": { + "agentConnId": "agentConnId", + "authErrCounter": 0, + "connChatVersion": 22, + "connId": 1, + "connLevel": 0, + "connStatus": { + "type": "ready" + }, + "connType": "contact", + "contactConnInitiated": false, + "createdAt": "1970-01-01T00:00:00Z", + "entityId": 2, + "localAlias": "", + "peerChatVRange": { + "maxVersion": 22, + "minVersion": 9 + }, + "pqEncryption": true, + "pqRcvEnabled": true, + "pqSndEnabled": true, + "pqSupport": true, + "quotaErrCounter": 0, + "viaGroupLink": false + }, + "chatDeleted": false, + "chatSettings": { + "enableNtfs": "all", + "favorite": false + }, + "chatTags": [], + "chatTs": "1970-01-01T00:00:00Z", + "contactGrpInvSent": false, + "contactId": 2, + "contactStatus": "active", + "contactUsed": true, + "createdAt": "1970-01-01T00:00:00Z", + "localDisplayName": "bob", + "mergedPreferences": { + "calls": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "commands": [], + "files": { + "contactPreference": { + "allow": "always" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "always" + }, + "type": "user" + } + }, + "fullDelete": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "reactions": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "sessions": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "timedMessages": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "voice": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + } + }, + "profile": { + "displayName": "bob", + "fullName": "", + "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAKHGlDQ1BJQ0MgUHJvZmlsZQAASImFVgdUVNcWve9Nb7QZeu9NehtAem/Sq6gMQ28OQxWxgAQjEFFEREARNFQFg1KjiIhiIQgoYA9IEFBisCAq6OQNJNH4//r/zDpz9ttzz7n73ffWmg0A6QCDxYqD+QCIT0hmezlYywQEBsngngEYCAIy0AC6DGYSy8rDwxUg8Xf9d7wbAxC33tHgzvrP3/9nCISFJzEBgIIRTGey2MkILkawT1oyi4tnEUxjI6IQvMLFkauYqxjQQtewwuoaHy8bBNMBwJMZDHYkAERbhJdJZUYic4hhCNZOCItOQDB3vjkzioFwxLsIXhcRl5IOAImrRzs+fivCk7QRrIL0shAcwNUW+tX8yH/tFfrPXgxG5D84Pi6F+dc9ck+HHJ7g641UMSQlQATQBHEgBaQDGcACbLAVYaIRJhx5Dv+9j77aZ4OsZIFtSEc0iARRIBnpt/9qlvfqpGSQBhjImnCEcUU+NtxnujZy4fbqVEiU/wuXdQyA9S0cDqfzC+e2F4DzyLkSB79wyi0A8KoBcL2GmcJOXePQ3C8MIAJeQAOiQArIAxXuWwMMgSmwBHbAGbgDHxAINgMmojceUZUGMkEWyAX54AA4DMpAJTgJ6sAZ0ALawQVwGVwDt8AQGAUPwQSYBi/AAngHliEIwkEUiAqJQtKQIqQO6U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8KC2jvgYadF8+10vJyDnNLXwbdiWUZi0fUK01Eoc+AZhCLZVzK4Vq6sDUdz+0dEcbbTTIOJmAyTVhx/WmvrExbv2jtPhWLKodjCtefZiEeZeVZWWSndgwj6fVf3XON8Qwq15++uoqrfYVrow6dGBpCq79ME291jaB0/Q2CPncyht/99MNO/vr9AqW/CGi8sJqbAAAAAElFTkSuQmCC", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 2, + "shortDescr": "Bob" + }, + "updatedAt": "1970-01-01T00:00:00Z", + "userPreferences": {} + }, + "type": "direct" + }, + "chatItem": { + "chatDir": { + "type": "directSnd" + }, + "content": { + "msgContent": { + "text": "hi", + "type": "text" + }, + "type": "sndMsgContent" + }, + "mentions": {}, + "meta": { + "createdAt": "1970-01-01T00:00:00Z", + "deletable": true, + "editable": true, + "hasLink": false, + "itemEdited": false, + "itemId": 8, + "itemSharedMsgId": "itemSharedMsgId", + "itemStatus": { + "type": "sndNew" + }, + "itemText": "hi", + "itemTs": "1970-01-01T00:00:00Z", + "showGroupAsSender": false, + "updatedAt": "1970-01-01T00:00:00Z", + "userMention": false + }, + "reactions": [] + } + } + ], + "type": "newChatItems", + "user": { + "activeOrder": 1, + "activeUser": true, + "agentUserId": "1", + "autoAcceptGroupInvitations": false, + "autoAcceptMemberContacts": false, + "clientService": false, + "fullPreferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "localDisplayName": "alice", + "profile": { + "displayName": "alice", + "fullName": "", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 1, + "shortDescr": "Alice" + }, + "sendRcptsContacts": true, + "sendRcptsSmallGroups": true, + "showNtfs": true, + "userChatRelay": false, + "userContactId": 1, + "userId": 1 + } + } + } + }, + "markdown": {}, + "uris": {} +} diff --git a/tests/fixtures/api/files/upload-complete.json b/tests/fixtures/api/files/upload-complete.json new file mode 100644 index 0000000000..97f2b1f7b1 --- /dev/null +++ b/tests/fixtures/api/files/upload-complete.json @@ -0,0 +1,324 @@ +[ + { + "result": { + "chatItem": { + "chatInfo": { + "contact": { + "activeConn": { + "agentConnId": "agentConnId", + "authErrCounter": 0, + "connChatVersion": 22, + "connId": 1, + "connLevel": 0, + "connStatus": { + "type": "ready" + }, + "connType": "contact", + "contactConnInitiated": false, + "createdAt": "1970-01-01T00:00:00Z", + "entityId": 2, + "localAlias": "", + "peerChatVRange": { + "maxVersion": 22, + "minVersion": 9 + }, + "pqEncryption": true, + "pqRcvEnabled": true, + "pqSndEnabled": true, + "pqSupport": true, + "quotaErrCounter": 0, + "viaGroupLink": false + }, + "chatDeleted": false, + "chatSettings": { + "enableNtfs": "all", + "favorite": false + }, + "chatTags": [], + "chatTs": "1970-01-01T00:00:00Z", + "contactGrpInvSent": false, + "contactId": 2, + "contactStatus": "active", + "contactUsed": true, + "createdAt": "1970-01-01T00:00:00Z", + "localDisplayName": "bob", + "mergedPreferences": { + "calls": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "commands": [], + "files": { + "contactPreference": { + "allow": "always" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "always" + }, + "type": "user" + } + }, + "fullDelete": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "reactions": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "sessions": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "timedMessages": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "voice": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + } + }, + "profile": { + "displayName": "bob", + "fullName": "", + "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAKHGlDQ1BJQ0MgUHJvZmlsZQAASImFVgdUVNcWve9Nb7QZeu9NehtAem/Sq6gMQ28OQxWxgAQjEFFEREARNFQFg1KjiIhiIQgoYA9IEFBisCAq6OQNJNH4//r/zDpz9ttzz7n73ffWmg0A6QCDxYqD+QCIT0hmezlYywQEBsngngEYCAIy0AC6DGYSy8rDwxUg8Xf9d7wbAxC33tHgzvrP3/9nCISFJzEBgIIRTGey2MkILkawT1oyi4tnEUxjI6IQvMLFkauYqxjQQtewwuoaHy8bBNMBwJMZDHYkAERbhJdJZUYic4hhCNZOCItOQDB3vjkzioFwxLsIXhcRl5IOAImrRzs+fivCk7QRrIL0shAcwNUW+tX8yH/tFfrPXgxG5D84Pi6F+dc9ck+HHJ7g641UMSQlQATQBHEgBaQDGcACbLAVYaIRJhx5Dv+9j77aZ4OsZIFtSEc0iARRIBnpt/9qlvfqpGSQBhjImnCEcUU+NtxnujZy4fbqVEiU/wuXdQyA9S0cDqfzC+e2F4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kz46w0ocdQu1X6B/AMQZ5o7KfBqNOfwRH8JB7FajGhnmcpKvQe3MEbvILiDm5gPXaCHnZr4vvFGMoEKudKn8YvQIOOe+YzCPop7dwJ3zRfJ7GDuso4YJGRa0yZgg4tUaNXdGrbuZWKKxzYYEJc2xp9AUUjGt8KC2jvgYadF8+10vJyDnNLXwbdiWUZi0fUK01Eoc+AZhCLZVzK4Vq6sDUdz+0dEcbbTTIOJmAyTVhx/WmvrExbv2jtPhWLKodjCtefZiEeZeVZWWSndgwj6fVf3XON8Qwq15++uoqrfYVrow6dGBpCq79ME291jaB0/Q2CPncyht/99MNO/vr9AqW/CGi8sJqbAAAAAElFTkSuQmCC", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 2, + "shortDescr": "Bob" + }, + "updatedAt": "1970-01-01T00:00:00Z", + "userPreferences": {} + }, + "type": "direct" + }, + "chatItem": { + "chatDir": { + "type": "directSnd" + }, + "content": { + "msgContent": { + "text": "", + "type": "file" + }, + "type": "sndMsgContent" + }, + "file": { + "fileExpires": "1970-01-01T00:00:00Z", + "fileId": 1, + "fileName": "test.pdf", + "fileProtocol": "xftp", + "fileSize": 272376, + "fileSource": { + "filePath": "./tests/fixtures/test.pdf" + }, + "fileStatus": { + "type": "sndComplete" + } + }, + "mentions": {}, + "meta": { + "createdAt": "1970-01-01T00:00:00Z", + "deletable": true, + "editable": true, + "hasLink": false, + "itemEdited": false, + "itemId": 8, + "itemSharedMsgId": "itemSharedMsgId", + "itemStatus": { + "msgRcptStatus": "ok", + "sndProgress": "complete", + "type": "sndRcvd" + }, + "itemText": "", + "itemTs": "1970-01-01T00:00:00Z", + "sentViaProxy": false, + "showGroupAsSender": false, + "updatedAt": "1970-01-01T00:00:00Z", + "userMention": false + }, + "reactions": [] + } + }, + "fileTransferMeta": { + "cancelled": false, + "chunkSize": 15780, + "fileId": 1, + "fileName": "test.pdf", + "filePath": "./tests/fixtures/test.pdf", + "fileSize": 272376, + "xftpSndFile": { + "agentSndFileDeleted": false, + "agentSndFileId": "agentSndFileId", + "privateSndFileDescr": "privateSndFileDescr" + } + }, + "type": "sndFileCompleteXFTP", + "user": { + "activeOrder": 1, + "activeUser": true, + "agentUserId": "1", + "autoAcceptGroupInvitations": false, + "autoAcceptMemberContacts": false, + "clientService": false, + "fullPreferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "localDisplayName": "alice", + "profile": { + "displayName": "alice", + "fullName": "", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 1, + "shortDescr": "Alice" + }, + "sendRcptsContacts": true, + "sendRcptsSmallGroups": true, + "showNtfs": true, + "userChatRelay": false, + "userContactId": 1, + "userId": 1 + } + } + } +] diff --git a/tests/fixtures/api/files/upload-error.json b/tests/fixtures/api/files/upload-error.json new file mode 100644 index 0000000000..d57baa782b --- /dev/null +++ b/tests/fixtures/api/files/upload-error.json @@ -0,0 +1,326 @@ +[ + { + "result": { + "chatItem_": { + "chatInfo": { + "contact": { + "activeConn": { + "agentConnId": "agentConnId", + "authErrCounter": 0, + "connChatVersion": 22, + "connId": 1, + "connLevel": 0, + "connStatus": { + "type": "ready" + }, + "connType": "contact", + "contactConnInitiated": false, + "createdAt": "1970-01-01T00:00:00Z", + "entityId": 2, + "localAlias": "", + "peerChatVRange": { + "maxVersion": 22, + "minVersion": 9 + }, + "pqEncryption": true, + "pqRcvEnabled": true, + "pqSndEnabled": true, + "pqSupport": true, + "quotaErrCounter": 0, + "viaGroupLink": false + }, + "chatDeleted": false, + "chatSettings": { + "enableNtfs": "all", + "favorite": false + }, + "chatTags": [], + "chatTs": "1970-01-01T00:00:00Z", + "contactGrpInvSent": false, + "contactId": 2, + "contactStatus": "active", + "contactUsed": true, + "createdAt": "1970-01-01T00:00:00Z", + "localDisplayName": "bob", + "mergedPreferences": { + "calls": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "commands": [], + "files": { + "contactPreference": { + "allow": "always" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "always" + }, + "type": "user" + } + }, + "fullDelete": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "reactions": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "sessions": { + "contactPreference": { + "allow": "no" + }, + "enabled": { + "forContact": false, + "forUser": false + }, + "userPreference": { + "preference": { + "allow": "no" + }, + "type": "user" + } + }, + "timedMessages": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + }, + "voice": { + "contactPreference": { + "allow": "yes" + }, + "enabled": { + "forContact": true, + "forUser": true + }, + "userPreference": { + "preference": { + "allow": "yes" + }, + "type": "user" + } + } + }, + "profile": { + "displayName": "bob", + "fullName": "", + "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAKHGlDQ1BJQ0MgUHJvZmlsZQAASImFVgdUVNcWve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ASCAB1CPEPG9f8119+BvrK2fyNwVndL5jhvubRVsMQgCakeCFp04OsQ1LJEgAe5NodqT6WANbT+yf/iqQIPd21PXgaAcDJcjivtwJAQHLFgcNZ9uBwPlUgYhHf1z37f7V9g9e8ITewiP88wfWIYET6HPg21nzjV2fybQVcxfrg2/onng/F50lD/ccAAAA4ZVhJZk1NACoAAAAIAAGHaQAEAAAAAQAAABoAAAAAAAKgAgAEAAAAAQAAABigAwAEAAAAAQAAABgAAAAAwf1XlwAAAaNJREFUSA3FlT1LA0EQQBN/gYUYRTksJZVgEbCR/D+7QMr8ABtttBBCsLGzsLG2sxaxED/ie4d77u0dyaE5HHjczn7MzO7M7nU6/yXz+bwLhzCCjTQO+rZhDH3opuNLdRYN4RHe4RIKJ7R34Ro+4AEGSw2mE1iUwT18gpI74WvkGlccu4XNdH0jnYU7cAUacidn37qR23cOxc4aGU0nYUAn7iSWEHkz46w0ocdQu1X6B/AMQZ5o7KfBqNOfwRH8JB7FajGhnmcpKvQe3MEbvILiDm5gPXaCHnZr4vvFGMoEKudKn8YvQIOOe+YzCPop7dwJ3zRfJ7GDuso4YJGRa0yZgg4tUaNXdGrbuZWKKxzYYEJc2xp9AUUjGt8KC2jvgYadF8+10vJyDnNLXwbdiWUZi0fUK01Eoc+AZhCLZVzK4Vq6sDUdz+0dEcbbTTIOJmAyTVhx/WmvrExbv2jtPhWLKodjCtefZiEeZeVZWWSndgwj6fVf3XON8Qwq15++uoqrfYVrow6dGBpCq79ME291jaB0/Q2CPncyht/99MNO/vr9AqW/CGi8sJqbAAAAAElFTkSuQmCC", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 2, + "shortDescr": "Bob" + }, + "updatedAt": "1970-01-01T00:00:00Z", + "userPreferences": {} + }, + "type": "direct" + }, + "chatItem": { + "chatDir": { + "type": "directSnd" + }, + "content": { + "msgContent": { + "text": "", + "type": "file" + }, + "type": "sndMsgContent" + }, + "file": { + "fileId": 1, + "fileName": "test.pdf", + "fileProtocol": "xftp", + "fileSize": 272376, + "fileSource": { + "filePath": "./tests/fixtures/test.pdf" + }, + "fileStatus": { + "sndFileError": { + "type": "auth" + }, + "type": "sndError" + } + }, + "mentions": {}, + "meta": { + "createdAt": "1970-01-01T00:00:00Z", + "deletable": true, + "editable": true, + "hasLink": false, + "itemEdited": false, + "itemId": 8, + "itemSharedMsgId": "itemSharedMsgId", + "itemStatus": { + "msgRcptStatus": "ok", + "sndProgress": "complete", + "type": "sndRcvd" + }, + "itemText": "", + "itemTs": "1970-01-01T00:00:00Z", + "sentViaProxy": false, + "showGroupAsSender": false, + "updatedAt": "1970-01-01T00:00:00Z", + "userMention": false + }, + "reactions": [] + } + }, + "errorMessage": "errorMessage", + "fileTransferMeta": { + "cancelled": false, + "chunkSize": 15780, + "fileId": 1, + "fileName": "test.pdf", + "filePath": "./tests/fixtures/test.pdf", + "fileSize": 272376, + "xftpSndFile": { + "agentSndFileDeleted": false, + "agentSndFileId": "agentSndFileId" + } + }, + "type": "sndFileError", + "user": { + "activeOrder": 1, + "activeUser": true, + "agentUserId": "1", + "autoAcceptGroupInvitations": false, + "autoAcceptMemberContacts": false, + "clientService": false, + "fullPreferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "localDisplayName": "alice", + "profile": { + "displayName": "alice", + "fullName": "", + "localAlias": "", + "preferences": { + "calls": { + "allow": "yes" + }, + "commands": [], + "files": { + "allow": "always" + }, + "fullDelete": { + "allow": "no" + }, + "reactions": { + "allow": "yes" + }, + "sessions": { + "allow": "no" + }, + "timedMessages": { + "allow": "yes" + }, + "voice": { + "allow": "yes" + } + }, + "profileId": 1, + "shortDescr": "Alice" + }, + "sendRcptsContacts": true, + "sendRcptsSmallGroups": true, + "showNtfs": true, + "userChatRelay": false, + "userContactId": 1, + "userId": 1 + } + } + } +]