mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01:00
Rename and reduce complexity of function 'processMessages'
Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
parent
ae0a9d6aae
commit
0c06c8b2eb
@ -2206,7 +2206,7 @@ class ChatController(args: Bundle) :
|
|||||||
} else if (response.code() == HTTP_CODE_PRECONDITION_FAILED) {
|
} else if (response.code() == HTTP_CODE_PRECONDITION_FAILED) {
|
||||||
futurePreconditionFailed = true
|
futurePreconditionFailed = true
|
||||||
} else {
|
} else {
|
||||||
processMessages(response, true)
|
processMessagesResponse(response, true)
|
||||||
}
|
}
|
||||||
} catch (npe: NullPointerException) {
|
} catch (npe: NullPointerException) {
|
||||||
// view binding can be null
|
// view binding can be null
|
||||||
@ -2248,7 +2248,7 @@ class ChatController(args: Bundle) :
|
|||||||
if (response.code() == HTTP_CODE_PRECONDITION_FAILED) {
|
if (response.code() == HTTP_CODE_PRECONDITION_FAILED) {
|
||||||
pastPreconditionFailed = true
|
pastPreconditionFailed = true
|
||||||
} else {
|
} else {
|
||||||
processMessages(response, false)
|
processMessagesResponse(response, false)
|
||||||
}
|
}
|
||||||
} catch (e: NullPointerException) {
|
} catch (e: NullPointerException) {
|
||||||
// view binding can be null
|
// view binding can be null
|
||||||
@ -2293,7 +2293,7 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processMessages(response: Response<*>, isFromTheFuture: Boolean) {
|
private fun processMessagesResponse(response: Response<*>, isFromTheFuture: Boolean) {
|
||||||
|
|
||||||
val xChatLastCommonRead = response.headers()["X-Chat-Last-Common-Read"]?.let {
|
val xChatLastCommonRead = response.headers()["X-Chat-Last-Common-Read"]?.let {
|
||||||
Integer.parseInt(it)
|
Integer.parseInt(it)
|
||||||
@ -2305,34 +2305,7 @@ class ChatController(args: Bundle) :
|
|||||||
val chatOverall = response.body() as ChatOverall?
|
val chatOverall = response.body() as ChatOverall?
|
||||||
val chatMessageList = handleSystemMessages(chatOverall?.ocs!!.data!!)
|
val chatMessageList = handleSystemMessages(chatOverall?.ocs!!.data!!)
|
||||||
|
|
||||||
if (chatMessageList.isNotEmpty() &&
|
processMessages(chatMessageList, isFromTheFuture, xChatLastCommonRead)
|
||||||
ChatMessage.SystemMessageType.CLEARED_CHAT == chatMessageList[0].systemMessageType
|
|
||||||
) {
|
|
||||||
adapter?.clear()
|
|
||||||
adapter?.notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isFirstMessagesProcessing) {
|
|
||||||
cancelNotificationsForCurrentConversation()
|
|
||||||
|
|
||||||
isFirstMessagesProcessing = false
|
|
||||||
binding.progressBar.visibility = View.GONE
|
|
||||||
|
|
||||||
binding.messagesListView.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isFromTheFuture) {
|
|
||||||
processMessagesFromTheFuture(chatMessageList)
|
|
||||||
} else {
|
|
||||||
processMessagesNotFromTheFuture(chatMessageList)
|
|
||||||
}
|
|
||||||
|
|
||||||
updateReadStatusOfAllMessages(xChatLastCommonRead)
|
|
||||||
adapter?.notifyDataSetChanged()
|
|
||||||
|
|
||||||
if (inConversation) {
|
|
||||||
pullChatMessages(1, 1, xChatLastCommonRead)
|
|
||||||
}
|
|
||||||
} else if (response.code() == HTTP_CODE_NOT_MODIFIED && !isFromTheFuture) {
|
} else if (response.code() == HTTP_CODE_NOT_MODIFIED && !isFromTheFuture) {
|
||||||
if (isFirstMessagesProcessing) {
|
if (isFirstMessagesProcessing) {
|
||||||
cancelNotificationsForCurrentConversation()
|
cancelNotificationsForCurrentConversation()
|
||||||
@ -2349,6 +2322,41 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun processMessages(
|
||||||
|
chatMessageList: List<ChatMessage>,
|
||||||
|
isFromTheFuture: Boolean,
|
||||||
|
xChatLastCommonRead: Int?
|
||||||
|
) {
|
||||||
|
if (chatMessageList.isNotEmpty() &&
|
||||||
|
ChatMessage.SystemMessageType.CLEARED_CHAT == chatMessageList[0].systemMessageType
|
||||||
|
) {
|
||||||
|
adapter?.clear()
|
||||||
|
adapter?.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFirstMessagesProcessing) {
|
||||||
|
cancelNotificationsForCurrentConversation()
|
||||||
|
|
||||||
|
isFirstMessagesProcessing = false
|
||||||
|
binding.progressBar.visibility = View.GONE
|
||||||
|
|
||||||
|
binding.messagesListView.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFromTheFuture) {
|
||||||
|
processMessagesFromTheFuture(chatMessageList)
|
||||||
|
} else {
|
||||||
|
processMessagesNotFromTheFuture(chatMessageList)
|
||||||
|
}
|
||||||
|
|
||||||
|
updateReadStatusOfAllMessages(xChatLastCommonRead)
|
||||||
|
adapter?.notifyDataSetChanged()
|
||||||
|
|
||||||
|
if (inConversation) {
|
||||||
|
pullChatMessages(1, 1, xChatLastCommonRead)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateReadStatusOfAllMessages(xChatLastCommonRead: Int?) {
|
private fun updateReadStatusOfAllMessages(xChatLastCommonRead: Int?) {
|
||||||
for (message in adapter!!.items) {
|
for (message in adapter!!.items) {
|
||||||
xChatLastCommonRead?.let {
|
xChatLastCommonRead?.let {
|
||||||
|
Loading…
Reference in New Issue
Block a user