diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 8e29da80a..f53707be4 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -989,7 +989,8 @@ class ChatActivity : super.onScrollStateChanged(recyclerView, newState) if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { - if (layoutManager!!.findFirstCompletelyVisibleItemPosition() > 0) { + if (layoutManager!!.findFirstCompletelyVisibleItemPosition() > 0 && + !binding.unreadMessagesPopup.isShown) { binding.scrollDownButton.visibility = View.VISIBLE } else { binding.scrollDownButton.visibility = View.GONE @@ -999,7 +1000,7 @@ class ChatActivity : if (layoutManager!!.findFirstCompletelyVisibleItemPosition() < newMessagesCount) { newMessagesCount = 0 - if (binding.unreadMessagesPopup.isShown == true) { + if (binding.unreadMessagesPopup.isShown) { binding.unreadMessagesPopup.hide() } } @@ -1280,7 +1281,7 @@ class ChatActivity : .setInterpolator(AccelerateDecelerateInterpolator()) .duration = TYPING_INDICATOR_ANIMATION_DURATION } else { - binding.typingIndicatorWrapper.visibility = View.GONE + binding.typingIndicatorWrapper.visibility = View.INVISIBLE binding.typingIndicatorWrapper.y += DisplayUtils.convertDpToPixel(18f, context) } } diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt index e1f3fe77c..ec2d2710e 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt @@ -89,7 +89,6 @@ class OfflineFirstChatRepository @Inject constructor( this.conversationModel = conversationModel this.credentials = credentials this.urlForChatting = urlForChatting - // internalConversationId = userProvider.currentUser.blockingGet().id!!.toString() + "@" + conversationModel.token internalConversationId = conversationModel.internalId } @@ -134,26 +133,11 @@ class OfflineFirstChatRepository @Inject constructor( lastKnown = beforeMessageId.toInt() ) withNetworkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap) - // withNetworkParams.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken) val loadFromServer = hasToLoadPreviousMessagesFromServer(beforeMessageId) - if (loadFromServer) { - if (monitor.isOnline.first()) { - sync(withNetworkParams) - } else { - // TODO: handle how user is informed about gaps when being offline. Something like: - // val offlineChatMessage = ChatMessage( - // message = "you are offline. Some messages might be missing here." - // ) - // val list = mutableListOf() - // list.add(offlineChatMessage) - // - // if (list.isNotEmpty()) { - // val pair = Pair(false, list) - // _messageFlow.emit(pair) - // } - } + if (loadFromServer && monitor.isOnline.first()) { + sync(withNetworkParams) } showLast100MessagesBefore(internalConversationId, beforeMessageId) @@ -161,8 +145,6 @@ class OfflineFirstChatRepository @Inject constructor( override fun initMessagePolling(): Job = scope.launch { - // monitor.isOnline.onEach { online -> - Log.d(TAG, "---- initMessagePolling ------------") val initialMessageId = chatDao.getNewestMessageId(internalConversationId).toInt() @@ -180,15 +162,10 @@ class OfflineFirstChatRepository @Inject constructor( while (!itIsPaused) { if (!monitor.isOnline.first()) Thread.sleep(500) - // sync database with server ( This is a long blocking call b/c long polling is set ) + // sync database with server (This is a long blocking call because long polling (lookIntoFuture) is set) networkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap) - // withNetworkParams.putString(BundleKeys.KEY_ROOM_TOKEN, roomToken) - - // this@OfflineFirstChatRepository.sync(withNetworkParams) - // sync(withNetworkParams) val resultsFromSync = sync(networkParams) - // TODO: load from DB?! at least make sure no changes are made here that are not saved to DB then! Log.d(TAG, "got result from longpolling") if (!resultsFromSync.isNullOrEmpty()) { @@ -209,18 +186,16 @@ class OfflineFirstChatRepository @Inject constructor( // return@map chatMessage // } - val newestMessage2 = chatDao.getNewestMessageId(internalConversationId).toInt() - Log.d(TAG, "newestMessage in loop: $newestMessage2") + val newestMessage = chatDao.getNewestMessageId(internalConversationId).toInt() // update field map vars for next cycle fieldMap = getFieldMap( lookIntoFuture = true, includeLastKnown = false, setReadMarker = true, - lastKnown = newestMessage2 + lastKnown = newestMessage ) } - // }.flowOn(Dispatchers.IO).collect() } private suspend fun hasToLoadPreviousMessagesFromServer( @@ -282,11 +257,6 @@ class OfflineFirstChatRepository @Inject constructor( return fieldMap } - private suspend fun getMessagesFrom(messageIds: List): List = - chatDao.getMessagesFromIds(messageIds).map { - it.map(ChatMessageEntity::asModel) - }.first() - override suspend fun getMessage(messageId: Long, bundle: Bundle): Flow { @@ -314,8 +284,6 @@ class OfflineFirstChatRepository @Inject constructor( @Suppress("UNCHECKED_CAST") private fun getMessagesFromServer(bundle: Bundle): Pair>? { Log.d(TAG, "An online request is made!!!!!!!!!!!!!!!!!!!!") - // val credentials = bundle.getString(BundleKeys.KEY_CREDENTIALS) - // val url = bundle.getString(BundleKeys.KEY_CHAT_URL) val fieldMap = bundle.getSerializable(BundleKeys.KEY_FIELD_MAP) as HashMap try { @@ -393,7 +361,6 @@ class OfflineFirstChatRepository @Inject constructor( val lookIntoFuture = fieldMap["lookIntoFuture"] == 1 val statusCode = result.first - // val statusCode = result.first val hasHistory = getHasHistory(statusCode, lookIntoFuture) @@ -487,7 +454,6 @@ class OfflineFirstChatRepository @Inject constructor( // We scroll up and load the system message. Deleting everything is not an option as we // would loose the messages that we want to keep. We only want to // delete the messages and chatBlocks older than the system message. - chatDao.deleteMessagesOlderThan(internalConversationId, messageJson.id) chatBlocksDao.deleteChatBlocksOlderThan(internalConversationId, messageJson.id) } diff --git a/app/src/main/res/layout/activity_chat.xml b/app/src/main/res/layout/activity_chat.xml index fc4a0efc8..b73e404d9 100644 --- a/app/src/main/res/layout/activity_chat.xml +++ b/app/src/main/res/layout/activity_chat.xml @@ -166,7 +166,7 @@ android:layout_marginStart="64dp" android:layout_marginTop="16dp" android:layout_marginEnd="64dp" - android:layout_marginBottom="26dp" + android:layout_marginBottom="45dp" android:layout_toStartOf="@+id/scrollDownButton" android:ellipsize="middle" android:minHeight="@dimen/min_size_clickable_area"