mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-01 20:22:03 +00:00
Extract creation of fieldMap for pullChatMessages
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
2a4ac69d89
commit
6efbbae823
@ -2251,52 +2251,13 @@ class ChatController(args: Bundle) :
|
|||||||
Log.d(TAG, "pullChatMessages - pullChatMessagesPending is true, exiting")
|
Log.d(TAG, "pullChatMessages - pullChatMessagesPending is true, exiting")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pullChatMessagesPending = true
|
pullChatMessagesPending = true
|
||||||
Log.d(TAG, "pullChatMessagesPending was set to true")
|
|
||||||
|
|
||||||
val fieldMap = HashMap<String, Int>()
|
val pullChatMessagesFieldMap = setupFieldsForPullChatMessages(
|
||||||
fieldMap["includeLastKnown"] = 0
|
lookIntoFuture,
|
||||||
|
xChatLastCommonRead,
|
||||||
if (!lookIntoFuture && isFirstMessagesProcessing) {
|
setReadMarker
|
||||||
if (currentConversation != null) {
|
)
|
||||||
globalLastKnownFutureMessageId = currentConversation!!.lastReadMessage
|
|
||||||
globalLastKnownPastMessageId = currentConversation!!.lastReadMessage
|
|
||||||
fieldMap["includeLastKnown"] = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val lastKnown = if (lookIntoFuture) {
|
|
||||||
globalLastKnownFutureMessageId
|
|
||||||
} else {
|
|
||||||
globalLastKnownPastMessageId
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldMap["lastKnownMessageId"] = lastKnown
|
|
||||||
xChatLastCommonRead?.let {
|
|
||||||
fieldMap["lastCommonReadId"] = it
|
|
||||||
}
|
|
||||||
|
|
||||||
val timeout = if (lookIntoFuture) {
|
|
||||||
LOOKING_INTO_FUTURE_TIMEOUT
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldMap["timeout"] = timeout
|
|
||||||
fieldMap["limit"] = MESSAGE_PULL_LIMIT
|
|
||||||
|
|
||||||
if (lookIntoFuture) {
|
|
||||||
fieldMap["lookIntoFuture"] = 1
|
|
||||||
} else {
|
|
||||||
fieldMap["lookIntoFuture"] = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setReadMarker) {
|
|
||||||
fieldMap["setReadMarker"] = 1
|
|
||||||
} else {
|
|
||||||
fieldMap["setReadMarker"] = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
var apiVersion = 1
|
var apiVersion = 1
|
||||||
// FIXME this is a best guess, guests would need to get the capabilities themselves
|
// FIXME this is a best guess, guests would need to get the capabilities themselves
|
||||||
@ -2307,7 +2268,7 @@ class ChatController(args: Bundle) :
|
|||||||
ncApi.pullChatMessages(
|
ncApi.pullChatMessages(
|
||||||
credentials,
|
credentials,
|
||||||
ApiUtils.getUrlForChat(apiVersion, conversationUser?.baseUrl, roomToken),
|
ApiUtils.getUrlForChat(apiVersion, conversationUser?.baseUrl, roomToken),
|
||||||
fieldMap
|
pullChatMessagesFieldMap
|
||||||
)
|
)
|
||||||
?.subscribeOn(Schedulers.io())
|
?.subscribeOn(Schedulers.io())
|
||||||
?.observeOn(AndroidSchedulers.mainThread())
|
?.observeOn(AndroidSchedulers.mainThread())
|
||||||
@ -2320,7 +2281,6 @@ class ChatController(args: Bundle) :
|
|||||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||||
override fun onNext(response: Response<*>) {
|
override fun onNext(response: Response<*>) {
|
||||||
pullChatMessagesPending = false
|
pullChatMessagesPending = false
|
||||||
Log.d(TAG, "pullChatMessagesPending was set to false")
|
|
||||||
|
|
||||||
when (response.code()) {
|
when (response.code()) {
|
||||||
HTTP_CODE_NOT_MODIFIED -> {
|
HTTP_CODE_NOT_MODIFIED -> {
|
||||||
@ -2396,6 +2356,56 @@ class ChatController(args: Bundle) :
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupFieldsForPullChatMessages(
|
||||||
|
lookIntoFuture: Boolean,
|
||||||
|
xChatLastCommonRead: Int?,
|
||||||
|
setReadMarker: Boolean
|
||||||
|
): HashMap<String, Int> {
|
||||||
|
val fieldMap = HashMap<String, Int>()
|
||||||
|
fieldMap["includeLastKnown"] = 0
|
||||||
|
|
||||||
|
if (!lookIntoFuture && isFirstMessagesProcessing) {
|
||||||
|
if (currentConversation != null) {
|
||||||
|
globalLastKnownFutureMessageId = currentConversation!!.lastReadMessage
|
||||||
|
globalLastKnownPastMessageId = currentConversation!!.lastReadMessage
|
||||||
|
fieldMap["includeLastKnown"] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val lastKnown = if (lookIntoFuture) {
|
||||||
|
globalLastKnownFutureMessageId
|
||||||
|
} else {
|
||||||
|
globalLastKnownPastMessageId
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldMap["lastKnownMessageId"] = lastKnown
|
||||||
|
xChatLastCommonRead?.let {
|
||||||
|
fieldMap["lastCommonReadId"] = it
|
||||||
|
}
|
||||||
|
|
||||||
|
val timeout = if (lookIntoFuture) {
|
||||||
|
LOOKING_INTO_FUTURE_TIMEOUT
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldMap["timeout"] = timeout
|
||||||
|
fieldMap["limit"] = MESSAGE_PULL_LIMIT
|
||||||
|
|
||||||
|
if (lookIntoFuture) {
|
||||||
|
fieldMap["lookIntoFuture"] = 1
|
||||||
|
} else {
|
||||||
|
fieldMap["lookIntoFuture"] = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setReadMarker) {
|
||||||
|
fieldMap["setReadMarker"] = 1
|
||||||
|
} else {
|
||||||
|
fieldMap["setReadMarker"] = 0
|
||||||
|
}
|
||||||
|
return fieldMap
|
||||||
|
}
|
||||||
|
|
||||||
private fun processExpiredMessages() {
|
private fun processExpiredMessages() {
|
||||||
fun deleteExpiredMessages() {
|
fun deleteExpiredMessages() {
|
||||||
val messagesToDelete: ArrayList<ChatMessage> = ArrayList()
|
val messagesToDelete: ArrayList<ChatMessage> = ArrayList()
|
||||||
@ -2608,7 +2618,6 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onLoadMore(page: Int, totalItemsCount: Int) {
|
override fun onLoadMore(page: Int, totalItemsCount: Int) {
|
||||||
Log.d(TAG, "requested onLoadMore to pullChatMessages with lookIntoFuture=false")
|
|
||||||
pullChatMessages(false)
|
pullChatMessages(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user