mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 09:43:39 +00:00
Refactor
This commit is contained in:
parent
93f719f3aa
commit
598aeca42a
@ -363,7 +363,7 @@ object OpenGroupApi {
|
||||
// endregion
|
||||
|
||||
// region Sending
|
||||
fun send(
|
||||
fun sendMessage(
|
||||
message: OpenGroupMessage,
|
||||
room: String,
|
||||
server: String,
|
||||
@ -684,8 +684,8 @@ object OpenGroupApi {
|
||||
request: Request,
|
||||
requests: MutableList<BatchRequestInfo<*>>
|
||||
): Promise<List<BatchResponse<*>>, Exception> {
|
||||
return getResponseBody(request).map {
|
||||
val results = JsonUtil.fromJson(it, List::class.java) ?: throw Error.ParsingFailed
|
||||
return getResponseBody(request).map { batch ->
|
||||
val results = JsonUtil.fromJson(batch, List::class.java) ?: throw Error.ParsingFailed
|
||||
results.mapIndexed { idx, result ->
|
||||
val response = result as? Map<*, *> ?: throw Error.ParsingFailed
|
||||
val code = response["code"] as Int
|
||||
@ -694,7 +694,9 @@ object OpenGroupApi {
|
||||
code = code,
|
||||
headers = response["headers"] as Map<String, String>,
|
||||
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
|
||||
)
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ object MessageSender {
|
||||
sentTimestamp = message.sentTimestamp!!,
|
||||
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
|
||||
handleSuccessfulMessageSend(message, destination, openGroupSentTimestamp = it.sentTimestamp)
|
||||
deferred.resolve(Unit)
|
||||
|
@ -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 }
|
||||
rooms.forEach { downloadGroupAvatarIfNeeded(it) }
|
||||
return OpenGroupApi.poll(rooms, server).successBackground { responses ->
|
||||
responses.forEach { response ->
|
||||
responses.filterNot { it.body == null }.forEach { response ->
|
||||
when (response.endpoint) {
|
||||
is Endpoint.Capabilities -> {
|
||||
handleCapabilities(server, response.body as OpenGroupApi.Capabilities)
|
||||
|
Loading…
x
Reference in New Issue
Block a user