Fix to avoid duplicated messages for HTTP_CODE_NOT_MODIFIED

the "historyRead" didn't make any sense to me, and deleting it solved the issue to avoid duplicated messages when the response was HTTP_CODE_NOT_MODIFIED

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-03-07 15:49:23 +01:00
parent 67957996b0
commit 82abb9d9bd
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -257,7 +257,6 @@ class ChatController(args: Bundle) :
private val roomPassword: String private val roomPassword: String
var credentials: String? = null var credentials: String? = null
var currentConversation: Conversation? = null var currentConversation: Conversation? = null
private var historyRead = false
private var globalLastKnownFutureMessageId = -1 private var globalLastKnownFutureMessageId = -1
private var globalLastKnownPastMessageId = -1 private var globalLastKnownPastMessageId = -1
var adapter: TalkMessagesListAdapter<ChatMessage>? = null var adapter: TalkMessagesListAdapter<ChatMessage>? = null
@ -2320,28 +2319,20 @@ class ChatController(args: Bundle) :
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
@Suppress("Detekt.TooGenericExceptionCaught") @Suppress("Detekt.TooGenericExceptionCaught")
override fun onNext(response: Response<*>) { override fun onNext(response: Response<*>) {
// when fetching history in between the regular polling, this is set to false!! -> bug?
pullChatMessagesPending = false pullChatMessagesPending = false
Log.d(TAG, "pullChatMessagesPending was set to false") Log.d(TAG, "pullChatMessagesPending was set to false")
when (response.code()) { when (response.code()) {
HTTP_CODE_NOT_MODIFIED -> { HTTP_CODE_NOT_MODIFIED -> {
Log.d(TAG, "pullChatMessages - HTTP_CODE_NOT_MODIFIED. lookIntoFuture=$lookIntoFuture") Log.d(TAG, "pullChatMessages - HTTP_CODE_NOT_MODIFIED.")
if (lookIntoFuture) { if (lookIntoFuture) {
Log.d(TAG, "recursive call to pullChatMessages. lookIntoFuture=$lookIntoFuture") Log.d(TAG, "recursive call to pullChatMessages.")
pullChatMessages(true, setReadMarker, xChatLastCommonRead) pullChatMessages(true, setReadMarker, xChatLastCommonRead)
} else {
Log.d(TAG, "when is this reached?")
historyRead = true
pullChatMessages(true)
} }
} }
HTTP_CODE_PRECONDITION_FAILED -> { HTTP_CODE_PRECONDITION_FAILED -> {
Log.d( Log.d(TAG, "pullChatMessages - HTTP_CODE_PRECONDITION_FAILED.")
TAG,
"pullChatMessages - HTTP_CODE_PRECONDITION_FAILED. lookIntoFuture=$lookIntoFuture"
)
if (lookIntoFuture) { if (lookIntoFuture) {
futurePreconditionFailed = true futurePreconditionFailed = true
@ -2350,7 +2341,7 @@ class ChatController(args: Bundle) :
} }
} }
HTTP_CODE_OK -> { HTTP_CODE_OK -> {
Log.d(TAG, "pullChatMessages - HTTP_CODE_OK. lookIntoFuture=$lookIntoFuture") Log.d(TAG, "pullChatMessages - HTTP_CODE_OK.")
val chatOverall = response.body() as ChatOverall? val chatOverall = response.body() as ChatOverall?
val chatMessageList = handleSystemMessages(chatOverall?.ocs!!.data!!) val chatMessageList = handleSystemMessages(chatOverall?.ocs!!.data!!)
@ -2378,7 +2369,7 @@ class ChatController(args: Bundle) :
adapter?.notifyDataSetChanged() adapter?.notifyDataSetChanged()
if (isFirstMessagesProcessing || lookIntoFuture) { if (isFirstMessagesProcessing || lookIntoFuture) {
Log.d(TAG, "recursive call to pullChatMessages. lookIntoFuture=$lookIntoFuture") Log.d(TAG, "recursive call to pullChatMessages")
pullChatMessages(true, true, xChatLastCommonRead) pullChatMessages(true, true, xChatLastCommonRead)
} }
} }
@ -2617,11 +2608,9 @@ class ChatController(args: Bundle) :
} }
override fun onLoadMore(page: Int, totalItemsCount: Int) { override fun onLoadMore(page: Int, totalItemsCount: Int) {
if (!historyRead) {
Log.d(TAG, "requested onLoadMore to pullChatMessages with lookIntoFuture=false") Log.d(TAG, "requested onLoadMore to pullChatMessages with lookIntoFuture=false")
pullChatMessages(false) pullChatMessages(false)
} }
}
override fun format(date: Date): String { override fun format(date: Date): String {
return if (DateFormatter.isToday(date)) { return if (DateFormatter.isToday(date)) {