diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/ChatModel.kt b/apps/android/app/src/main/java/chat/simplex/app/model/ChatModel.kt index a726161269..cf2931a0dd 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/ChatModel.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/ChatModel.kt @@ -887,6 +887,8 @@ class CIFile( @Serializable enum class CIFileStatus { @SerialName("snd_stored") SndStored, + @SerialName("snd_transfer") SndTransfer, + @SerialName("snd_complete") SndComplete, @SerialName("snd_cancelled") SndCancelled, @SerialName("rcv_invitation") RcvInvitation, @SerialName("rcv_accepted") RcvAccepted, diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt index 4ec5f17cdf..6f5148106c 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt @@ -567,6 +567,8 @@ sealed class CC { file != null && quotedItemId != null -> "/_send ${chatRef(type, id)} file $file quoted $quotedItemId ${mc.cmdString}" else -> throw Exception() } + // TODO use below + // is ApiSendMessage -> "/_send_v2 ${chatRef(type, id)} ${json.encodeToString(ComposedMessage(file, quotedItemId, mc))}" is ApiUpdateChatItem -> "/_update item ${chatRef(type, id)} $itemId ${mc.cmdString}" is ApiDeleteChatItem -> "/_delete item ${chatRef(type, id)} $itemId ${mode.deleteMode}" is GetUserSMPServers -> "/smp_servers" @@ -621,6 +623,9 @@ sealed class CC { } } +@Serializable +class ComposedMessage(val filePath: String?, val quotedItemId: Long?, val msgContent: MsgContent) + val json = Json { prettyPrint = true ignoreUnknownKeys = true diff --git a/apps/ios/Shared/Model/Shared/APITypes.swift b/apps/ios/Shared/Model/Shared/APITypes.swift index bec9aa4dd5..2c019a834b 100644 --- a/apps/ios/Shared/Model/Shared/APITypes.swift +++ b/apps/ios/Shared/Model/Shared/APITypes.swift @@ -50,16 +50,9 @@ enum ChatCommand { case let .setFilesFolder(filesFolder): return "/_files_folder \(filesFolder)" case .apiGetChats: return "/_get chats pcc=on" case let .apiGetChat(type, id): return "/_get chat \(ref(type, id)) count=100" - // TODO replace with /_send_v2 case let .apiSendMessage(type, id, file, quotedItemId, mc): - switch (file, quotedItemId) { - case (nil, nil): return "/_send \(ref(type, id)) \(mc.cmdString)" - case let (.some(file), nil): return "/_send \(ref(type, id)) file \(file) \(mc.cmdString)" - case let (nil, .some(quotedItemId)): return "/_send \(ref(type, id)) quoted \(quotedItemId) \(mc.cmdString)" - case let (.some(file), .some(quotedItemId)): return "/_send \(ref(type, id)) file \(file) quoted \(quotedItemId) \(mc.cmdString)" - } -// case let .apiSendMessage(type, id, file, quotedItemId, mc): -// return "/_send_v2 \(ref(type, id)) \(try! jsonEncoder.encode(ComposedMessage(filePath: file, quotedItemId: quotedItemId, msgContent: mc)))" + let msg = encodeJSON(ComposedMessage(filePath: file, quotedItemId: quotedItemId, msgContent: mc)) + return "/_send_v2 \(ref(type, id)) \(msg)" case let .apiUpdateChatItem(type, id, itemId, mc): return "/_update item \(ref(type, id)) \(itemId) \(mc.cmdString)" case let .apiDeleteChatItem(type, id, itemId, mode): return "/_delete item \(ref(type, id)) \(itemId) \(mode.rawValue)" case let .apiRegisterToken(token): return "/_ntf register apns \(token)" diff --git a/apps/ios/Shared/Model/Shared/ChatTypes.swift b/apps/ios/Shared/Model/Shared/ChatTypes.swift index adcfe61e45..6e34a62dd9 100644 --- a/apps/ios/Shared/Model/Shared/ChatTypes.swift +++ b/apps/ios/Shared/Model/Shared/ChatTypes.swift @@ -657,6 +657,8 @@ struct CIFile: Decodable { enum CIFileStatus: String, Decodable { case sndStored = "snd_stored" + case sndTransfer = "snd_transfer" + case sndComplete = "snd_complete" case sndCancelled = "snd_cancelled" case rcvInvitation = "rcv_invitation" case rcvAccepted = "rcv_accepted" diff --git a/apps/ios/Shared/Views/Call/CallView.swift b/apps/ios/Shared/Views/Call/CallView.swift index 569f481429..ff67b1e165 100644 --- a/apps/ios/Shared/Views/Call/CallView.swift +++ b/apps/ios/Shared/Views/Call/CallView.swift @@ -50,15 +50,11 @@ class WebRTCCoordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler let corrId_ = corrId corrId = corrId + 1 pendingCommands[corrId_] = cont - do { - let apiData = try jsonEncoder.encode(WVAPICall(corrId: corrId_, command: command)) - DispatchQueue.main.async { - logger.debug("WebRTCCoordinator.processCommand DispatchQueue.main.async") - let js = "processCommand(\(String(decoding: apiData, as: UTF8.self)))" - self.webView.evaluateJavaScript(js) - } - } catch { - logger.error("WebRTCCoordinator.processCommand: error encoding command \(error.localizedDescription)") + let apiCmd = encodeJSON(WVAPICall(corrId: corrId_, command: command)) + DispatchQueue.main.async { + logger.debug("WebRTCCoordinator.processCommand DispatchQueue.main.async") + let js = "processCommand(\(apiCmd))" + self.webView.evaluateJavaScript(js) } } } @@ -143,7 +139,7 @@ struct CallView: View { if let c = coordinator { Task { let resp = await c.processCommand(command: command) - print(String(decoding: try! jsonEncoder.encode(resp), as: UTF8.self)) + print(encodeJSON(resp)) } } } catch { @@ -159,7 +155,7 @@ struct CallView: View { if let c = coordinator { Task { let resp = await c.processCommand(command: .start(media: .video)) - print(String(decoding: try! jsonEncoder.encode(resp), as: UTF8.self)) + print(encodeJSON(resp)) } } }