Rename and reduce complexity of function 'processMessages'

Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
Tim Krüger 2022-09-07 12:31:03 +02:00
parent ae0a9d6aae
commit 0c06c8b2eb
No known key found for this signature in database
GPG Key ID: FECE3A7222C52A4E

View File

@ -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,6 +2305,28 @@ 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!!)
processMessages(chatMessageList, isFromTheFuture, xChatLastCommonRead)
} else if (response.code() == HTTP_CODE_NOT_MODIFIED && !isFromTheFuture) {
if (isFirstMessagesProcessing) {
cancelNotificationsForCurrentConversation()
isFirstMessagesProcessing = false
binding.progressBar.visibility = View.GONE
}
historyRead = true
if (!lookingIntoFuture && inConversation) {
pullChatMessages(1)
}
}
}
private fun processMessages(
chatMessageList: List<ChatMessage>,
isFromTheFuture: Boolean,
xChatLastCommonRead: Int?
) {
if (chatMessageList.isNotEmpty() && if (chatMessageList.isNotEmpty() &&
ChatMessage.SystemMessageType.CLEARED_CHAT == chatMessageList[0].systemMessageType ChatMessage.SystemMessageType.CLEARED_CHAT == chatMessageList[0].systemMessageType
) { ) {
@ -2333,20 +2355,6 @@ class ChatController(args: Bundle) :
if (inConversation) { if (inConversation) {
pullChatMessages(1, 1, xChatLastCommonRead) pullChatMessages(1, 1, xChatLastCommonRead)
} }
} else if (response.code() == HTTP_CODE_NOT_MODIFIED && !isFromTheFuture) {
if (isFirstMessagesProcessing) {
cancelNotificationsForCurrentConversation()
isFirstMessagesProcessing = false
binding.progressBar.visibility = View.GONE
}
historyRead = true
if (!lookingIntoFuture && inConversation) {
pullChatMessages(1)
}
}
} }
private fun updateReadStatusOfAllMessages(xChatLastCommonRead: Int?) { private fun updateReadStatusOfAllMessages(xChatLastCommonRead: Int?) {