mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-11 04:07:10 +00:00
mobile: switch to send_v2 in ios, add to android (#605)
This commit is contained in:
committed by
GitHub
parent
e80f617840
commit
c8aa8db973
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user