This commit is contained in:
ceokot 2022-05-14 19:08:49 +10:00
parent 93f719f3aa
commit 598aeca42a
3 changed files with 8 additions and 6 deletions

View File

@ -363,7 +363,7 @@ object OpenGroupApi {
// endregion // endregion
// region Sending // region Sending
fun send( fun sendMessage(
message: OpenGroupMessage, message: OpenGroupMessage,
room: String, room: String,
server: String, server: String,
@ -684,8 +684,8 @@ object OpenGroupApi {
request: Request, request: Request,
requests: MutableList<BatchRequestInfo<*>> requests: MutableList<BatchRequestInfo<*>>
): Promise<List<BatchResponse<*>>, Exception> { ): Promise<List<BatchResponse<*>>, Exception> {
return getResponseBody(request).map { return getResponseBody(request).map { batch ->
val results = JsonUtil.fromJson(it, List::class.java) ?: throw Error.ParsingFailed val results = JsonUtil.fromJson(batch, List::class.java) ?: throw Error.ParsingFailed
results.mapIndexed { idx, result -> results.mapIndexed { idx, result ->
val response = result as? Map<*, *> ?: throw Error.ParsingFailed val response = result as? Map<*, *> ?: throw Error.ParsingFailed
val code = response["code"] as Int val code = response["code"] as Int
@ -694,7 +694,9 @@ object OpenGroupApi {
code = code, code = code,
headers = response["headers"] as Map<String, String>, headers = response["headers"] as Map<String, String>,
body = if (code in 200..299) { body = if (code in 200..299) {
JsonUtil.fromJson(JsonUtil.toJson(response["body"]), requests[idx].responseType) JsonUtil.toJson(response["body"]).takeIf { it != "[]" }?.let {
JsonUtil.fromJson(it, requests[idx].responseType)
}
} else null } else null
) )
} }

View File

@ -245,7 +245,7 @@ object MessageSender {
sentTimestamp = message.sentTimestamp!!, sentTimestamp = message.sentTimestamp!!,
base64EncodedData = Base64.encodeBytes(plaintext), base64EncodedData = Base64.encodeBytes(plaintext),
) )
OpenGroupApi.send(openGroupMessage, destination.roomToken, destination.server, destination.whisperTo, destination.whisperMods, destination.fileIds).success { OpenGroupApi.sendMessage(openGroupMessage, destination.roomToken, destination.server, destination.whisperTo, destination.whisperMods, destination.fileIds).success {
message.openGroupServerMessageID = it.serverID message.openGroupServerMessageID = it.serverID
handleSuccessfulMessageSend(message, destination, openGroupSentTimestamp = it.sentTimestamp) handleSuccessfulMessageSend(message, destination, openGroupSentTimestamp = it.sentTimestamp)
deferred.resolve(Unit) deferred.resolve(Unit)

View File

@ -54,7 +54,7 @@ class OpenGroupPoller(private val server: String, private val executorService: S
val rooms = storage.getAllOpenGroups().values.filter { it.server == server }.map { it.room } val rooms = storage.getAllOpenGroups().values.filter { it.server == server }.map { it.room }
rooms.forEach { downloadGroupAvatarIfNeeded(it) } rooms.forEach { downloadGroupAvatarIfNeeded(it) }
return OpenGroupApi.poll(rooms, server).successBackground { responses -> return OpenGroupApi.poll(rooms, server).successBackground { responses ->
responses.forEach { response -> responses.filterNot { it.body == null }.forEach { response ->
when (response.endpoint) { when (response.endpoint) {
is Endpoint.Capabilities -> { is Endpoint.Capabilities -> {
handleCapabilities(server, response.body as OpenGroupApi.Capabilities) handleCapabilities(server, response.body as OpenGroupApi.Capabilities)