mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
Refactor pullChatMessages request
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
21606bc9c1
commit
7065b18d07
@ -2234,7 +2234,11 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pullChatMessages(lookIntoFuture: Boolean, setReadMarker: Boolean = true, xChatLastCommonRead: Int? = null) {
|
fun pullChatMessages(
|
||||||
|
lookIntoFuture: Boolean,
|
||||||
|
setReadMarker: Boolean = true,
|
||||||
|
xChatLastCommonRead: Int? = null
|
||||||
|
) {
|
||||||
if (!validSessionId()) {
|
if (!validSessionId()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2301,24 +2305,23 @@ class ChatController(args: Bundle) :
|
|||||||
apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
|
apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lookIntoFuture) {
|
ncApi.pullChatMessages(
|
||||||
Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture > 0] - calling")
|
credentials,
|
||||||
ncApi.pullChatMessages(
|
ApiUtils.getUrlForChat(apiVersion, conversationUser?.baseUrl, roomToken),
|
||||||
credentials,
|
fieldMap
|
||||||
ApiUtils.getUrlForChat(apiVersion, conversationUser?.baseUrl, roomToken),
|
)
|
||||||
fieldMap
|
?.subscribeOn(Schedulers.io())
|
||||||
)
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
?.subscribeOn(Schedulers.io())
|
?.subscribe(object : Observer<Response<*>> {
|
||||||
?.observeOn(AndroidSchedulers.mainThread())
|
override fun onSubscribe(d: Disposable) {
|
||||||
?.subscribe(object : Observer<Response<*>> {
|
disposables.add(d)
|
||||||
override fun onSubscribe(d: Disposable) {
|
}
|
||||||
disposables.add(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||||
override fun onNext(response: Response<*>) {
|
override fun onNext(response: Response<*>) {
|
||||||
Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture > 0] - got response")
|
pullChatMessagesPending = false
|
||||||
pullChatMessagesPending = false
|
|
||||||
|
if (lookIntoFuture) {
|
||||||
if (response.code() == HTTP_CODE_NOT_MODIFIED) {
|
if (response.code() == HTTP_CODE_NOT_MODIFIED) {
|
||||||
Log.d(TAG, "pullChatMessages - quasi recursive call to pullChatMessages")
|
Log.d(TAG, "pullChatMessages - quasi recursive call to pullChatMessages")
|
||||||
pullChatMessages(true, setReadMarker, xChatLastCommonRead)
|
pullChatMessages(true, setReadMarker, xChatLastCommonRead)
|
||||||
@ -2327,56 +2330,26 @@ class ChatController(args: Bundle) :
|
|||||||
} else {
|
} else {
|
||||||
processMessagesResponse(response, true)
|
processMessagesResponse(response, true)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
processExpiredMessages()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
|
||||||
Log.e(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture > 0] - ERROR", e)
|
|
||||||
pullChatMessagesPending = false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onComplete() {
|
|
||||||
pullChatMessagesPending = false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture <= 0] - calling")
|
|
||||||
ncApi.pullChatMessages(
|
|
||||||
credentials,
|
|
||||||
ApiUtils.getUrlForChat(apiVersion, conversationUser?.baseUrl, roomToken),
|
|
||||||
fieldMap
|
|
||||||
)
|
|
||||||
?.subscribeOn(Schedulers.io())
|
|
||||||
?.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
?.subscribe(object : Observer<Response<*>> {
|
|
||||||
override fun onSubscribe(d: Disposable) {
|
|
||||||
disposables.add(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
|
||||||
override fun onNext(response: Response<*>) {
|
|
||||||
Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture <= 0] - got response")
|
|
||||||
pullChatMessagesPending = false
|
|
||||||
if (response.code() == HTTP_CODE_PRECONDITION_FAILED) {
|
if (response.code() == HTTP_CODE_PRECONDITION_FAILED) {
|
||||||
pastPreconditionFailed = true
|
pastPreconditionFailed = true
|
||||||
} else {
|
} else {
|
||||||
processMessagesResponse(response, false)
|
processMessagesResponse(response, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
processExpiredMessages()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
processExpiredMessages()
|
||||||
Log.e(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture <= 0] - ERROR", e)
|
}
|
||||||
pullChatMessagesPending = false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onComplete() {
|
override fun onError(e: Throwable) {
|
||||||
pullChatMessagesPending = false
|
Log.e(TAG, "pullChatMessages - pullChatMessages ERROR", e)
|
||||||
}
|
pullChatMessagesPending = false
|
||||||
})
|
}
|
||||||
}
|
|
||||||
|
override fun onComplete() {
|
||||||
|
pullChatMessagesPending = false
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processExpiredMessages() {
|
private fun processExpiredMessages() {
|
||||||
|
Loading…
Reference in New Issue
Block a user