From 8f6e759d48c3883edeff8698d2a29cceb187ea15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 17:18:17 +0200 Subject: [PATCH 01/16] Remove unnecessary safe calls and non-null assertions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index f98cd8046..11f68c938 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -583,8 +583,8 @@ class ChatController(args: Bundle) : ) var senderId = "" - if (!conversationUser?.userId.equals("?")) { - senderId = "users/" + conversationUser?.userId + if (!conversationUser.userId.equals("?")) { + senderId = "users/" + conversationUser.userId } else { senderId = currentConversation?.actorType + "/" + currentConversation?.actorId } @@ -618,7 +618,7 @@ class ChatController(args: Bundle) : R.id.playPauseBtn ) { view, message -> val filename = message.selectedIndividualHashMap!!["name"] - val file = File(context!!.cacheDir, filename!!) + val file = File(context.cacheDir, filename!!) if (file.exists()) { if (message.isPlayingVoiceMessage) { pausePlayback(message) @@ -771,7 +771,7 @@ class ChatController(args: Bundle) : requestRecordAudioPermissions() return true } - if (!UploadAndShareFilesWorker.isStoragePermissionGranted(context!!)) { + if (!UploadAndShareFilesWorker.isStoragePermissionGranted(context)) { UploadAndShareFilesWorker.requestStoragePermission(this@ChatController) return true } @@ -806,7 +806,7 @@ class ChatController(args: Bundle) : Log.d(TAG, "voiceRecordDuration: " + voiceRecordDuration) Toast.makeText( context, - context!!.getString(R.string.nc_voice_message_hold_to_record_info), + context.getString(R.string.nc_voice_message_hold_to_record_info), Toast.LENGTH_SHORT ).show() stopAndDiscardAudioRecording() @@ -993,7 +993,7 @@ class ChatController(args: Bundle) : if (mediaPlayer == null) { val fileName = message.selectedIndividualHashMap!!["name"] - val absolutePath = context!!.cacheDir.absolutePath + "/" + fileName + val absolutePath = context.cacheDir.absolutePath + "/" + fileName mediaPlayer = MediaPlayer().apply { setDataSource(absolutePath) prepare() @@ -1050,7 +1050,7 @@ class ChatController(args: Bundle) : // check if download worker is already running val workers = WorkManager.getInstance( - context!! + context ).getWorkInfosByTag(fileId!!) try { for (workInfo in workers.get()) { @@ -1081,7 +1081,7 @@ class ChatController(args: Bundle) : WorkManager.getInstance().enqueue(downloadWorker) - WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(downloadWorker.id) + WorkManager.getInstance(context).getWorkInfoByIdLiveData(downloadWorker.id) .observeForever { workInfo: WorkInfo -> if (workInfo.state == WorkInfo.State.SUCCEEDED) { startPlayback(message) @@ -1096,13 +1096,13 @@ class ChatController(args: Bundle) : val date: String = simpleDateFormat.format(Date()) val fileNameWithoutSuffix = String.format( - context!!.resources.getString(R.string.nc_voice_message_filename), + context.resources.getString(R.string.nc_voice_message_filename), date, currentConversation!!.displayName ) val fileName = fileNameWithoutSuffix + VOICE_MESSAGE_FILE_SUFFIX - currentVoiceRecordFile = "${context!!.cacheDir.absolutePath}/$fileName" + currentVoiceRecordFile = "${context.cacheDir.absolutePath}/$fileName" } private fun showRecordAudioUi(show: Boolean) { @@ -1124,14 +1124,14 @@ class ChatController(args: Bundle) : binding.messageInputView.smileyButton.visibility = View.VISIBLE binding.messageInputView.messageInput.visibility = View.VISIBLE binding.messageInputView.messageInput.hint = - context?.resources?.getString(R.string.nc_hint_enter_a_message) + context.resources?.getString(R.string.nc_hint_enter_a_message) } } private fun isRecordAudioPermissionGranted(): Boolean { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return PermissionChecker.checkSelfPermission( - context!!, + context, Manifest.permission.RECORD_AUDIO ) == PermissionChecker.PERMISSION_GRANTED } else { @@ -1211,7 +1211,7 @@ class ChatController(args: Bundle) : } fun vibrate() { - val vibrator = context?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator + val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator if (Build.VERSION.SDK_INT >= O) { vibrator.vibrate(VibrationEffect.createOneShot(SHORT_VIBRATE, VibrationEffect.DEFAULT_AMPLITUDE)) } else { @@ -1411,10 +1411,10 @@ class ChatController(args: Bundle) : } val confirmationQuestion = when (filesToUpload.size) { - 1 -> context?.resources?.getString(R.string.nc_upload_confirm_send_single)?.let { + 1 -> context.resources?.getString(R.string.nc_upload_confirm_send_single)?.let { String.format(it, title.trim()) } - else -> context?.resources?.getString(R.string.nc_upload_confirm_send_multiple)?.let { + else -> context.resources?.getString(R.string.nc_upload_confirm_send_multiple)?.let { String.format(it, title.trim()) } } @@ -1445,11 +1445,11 @@ class ChatController(args: Bundle) : dialog.getButton(AlertDialog.BUTTON_NEGATIVE) ) } catch (e: IllegalStateException) { - Toast.makeText(context, context?.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG) + Toast.makeText(context, context.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG) .show() Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e) } catch (e: IllegalArgumentException) { - Toast.makeText(context, context?.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG) + Toast.makeText(context, context.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG) .show() Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e) } @@ -1460,8 +1460,8 @@ class ChatController(args: Bundle) : if (cursor != null && cursor.moveToFirst()) { val id = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID)) - val fileName = ContactUtils.getDisplayNameFromDeviceContact(context!!, id) + ".vcf" - val file = File(context?.cacheDir, fileName) + val fileName = ContactUtils.getDisplayNameFromDeviceContact(context, id) + ".vcf" + val file = File(context.cacheDir, fileName) writeContactToVcfFile(cursor, file) val shareUri = FileProvider.getUriForFile( @@ -1486,7 +1486,7 @@ class ChatController(args: Bundle) : } require(filesToUpload.isNotEmpty()) - if (UploadAndShareFilesWorker.isStoragePermissionGranted(context!!)) { + if (UploadAndShareFilesWorker.isStoragePermissionGranted(context)) { uploadFiles(filesToUpload, false) } else { UploadAndShareFilesWorker.requestStoragePermission(this) @@ -1494,7 +1494,7 @@ class ChatController(args: Bundle) : } catch (e: IllegalStateException) { Toast.makeText( context, - context?.resources?.getString(R.string.nc_upload_failed), + context.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG ) .show() @@ -1502,7 +1502,7 @@ class ChatController(args: Bundle) : } catch (e: IllegalArgumentException) { Toast.makeText( context, - context?.resources?.getString(R.string.nc_upload_failed), + context.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG ) .show() @@ -1554,7 +1554,7 @@ class ChatController(args: Bundle) : } } else { Toast - .makeText(context, context?.getString(R.string.read_storage_no_permission), Toast.LENGTH_LONG) + .makeText(context, context.getString(R.string.read_storage_no_permission), Toast.LENGTH_LONG) .show() } } else if (requestCode == REQUEST_RECORD_AUDIO_PERMISSION) { @@ -1563,7 +1563,7 @@ class ChatController(args: Bundle) : } else { Toast.makeText( context, - context!!.getString(R.string.nc_voice_message_missing_audio_permission), + context.getString(R.string.nc_voice_message_missing_audio_permission), Toast.LENGTH_LONG ).show() } @@ -1574,17 +1574,17 @@ class ChatController(args: Bundle) : } else { Toast.makeText( context, - context!!.getString(R.string.nc_share_contact_permission), + context.getString(R.string.nc_share_contact_permission), Toast.LENGTH_LONG ).show() } } else if (requestCode == REQUEST_CAMERA_PERMISSION) { if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d(TAG, "launch cam activity since permission for cam has been granted") - startActivityForResult(TakePhotoActivity.createIntent(context!!), REQUEST_CODE_PICK_CAMERA) + startActivityForResult(TakePhotoActivity.createIntent(context), REQUEST_CODE_PICK_CAMERA) } else { Toast - .makeText(context, context?.getString(R.string.take_photo_permission), Toast.LENGTH_LONG) + .makeText(context, context.getString(R.string.take_photo_permission), Toast.LENGTH_LONG) .show() } } @@ -1621,12 +1621,12 @@ class ChatController(args: Bundle) : if (!isVoiceMessage) { Toast.makeText( context, - context?.getString(R.string.nc_upload_in_progess), + context.getString(R.string.nc_upload_in_progess), Toast.LENGTH_LONG ).show() } } catch (e: IllegalArgumentException) { - Toast.makeText(context, context?.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG).show() + Toast.makeText(context, context.resources?.getString(R.string.nc_upload_failed), Toast.LENGTH_LONG).show() Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e) } } @@ -1640,7 +1640,7 @@ class ChatController(args: Bundle) : startActivityForResult( Intent.createChooser( action, - context?.resources?.getString( + context.resources?.getString( R.string.nc_upload_choose_local_files ) ), @@ -1743,13 +1743,13 @@ class ChatController(args: Bundle) : onEmojiPopupShownListener = { if (resources != null) { smileyButton?.setImageDrawable( - ContextCompat.getDrawable(context!!, R.drawable.ic_baseline_keyboard_24) + ContextCompat.getDrawable(context, R.drawable.ic_baseline_keyboard_24) ) } }, onEmojiPopupDismissListener = { smileyButton?.setImageDrawable( - ContextCompat.getDrawable(context!!, R.drawable.ic_insert_emoticon_black_24dp) + ContextCompat.getDrawable(context, R.drawable.ic_insert_emoticon_black_24dp) ) }, onEmojiClickListener = { @@ -1881,7 +1881,7 @@ class ChatController(args: Bundle) : var apiVersion = 1 // FIXME Fix API checking with guests? if (conversationUser != null) { - apiVersion = ApiUtils.getConversationApiVersion(conversationUser!!, intArrayOf(ApiUtils.APIv4, 1)) + apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1)) } val startNanoTime = System.nanoTime() @@ -2055,7 +2055,7 @@ class ChatController(args: Bundle) : if (conversationUser != null) { val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1)) - ncApi!!.sendChatMessage( + ncApi.sendChatMessage( credentials, ApiUtils.getUrlForChat(apiVersion, conversationUser.baseUrl, roomToken), message, @@ -2388,7 +2388,7 @@ class ChatController(args: Bundle) : unreadChatMessage.jsonMessageId = -1 unreadChatMessage.actorId = "-1" unreadChatMessage.timestamp = chatMessageList[0].timestamp - unreadChatMessage.message = context?.getString(R.string.nc_new_messages) + unreadChatMessage.message = context.getString(R.string.nc_new_messages) adapter?.addToStart(unreadChatMessage, false) } @@ -2760,7 +2760,7 @@ class ChatController(args: Bundle) : currentConversation, isShowMessageDeletionButton(message), hasChatPermission, - ncApi!! + ncApi ).show() } } @@ -2838,7 +2838,7 @@ class ChatController(args: Bundle) : message?.user?.id?.substring(INVITE_LENGTH), null ) - ncApi!!.createRoom( + ncApi.createRoom( credentials, retrofitBucket.url, retrofitBucket.queryMap @@ -2857,7 +2857,7 @@ class ChatController(args: Bundle) : bundle.putString(KEY_ROOM_ID, roomOverall.ocs!!.data!!.roomId) // FIXME once APIv2+ is used only, the createRoom already returns all the data - ncApi!!.getRoom( + ncApi.getRoom( credentials, ApiUtils.getUrlForRoom( apiVersion, @@ -2921,7 +2921,7 @@ class ChatController(args: Bundle) : fun markAsUnread(message: IMessage?) { val chatMessage = message as ChatMessage? if (chatMessage!!.previousMessageId > NO_PREVIOUS_MESSAGE_ID) { - ncApi!!.setChatReadMarker( + ncApi.setChatReadMarker( credentials, ApiUtils.getUrlForSetChatReadMarker( ApiUtils.getChatApiVersion(conversationUser, intArrayOf(ApiUtils.APIv1)), @@ -2966,7 +2966,7 @@ class ChatController(args: Bundle) : return !message.isDeleted || // copy message message.replyable || // reply to message.replyable && // reply privately - conversationUser?.userId?.isNotEmpty() == true && conversationUser?.userId != "?" && + conversationUser?.userId?.isNotEmpty() == true && conversationUser.userId != "?" && message.user.id.startsWith("users/") && message.user.id.substring(ACTOR_LENGTH) != currentConversation?.actorId && currentConversation?.type != Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL || @@ -2993,7 +2993,7 @@ class ChatController(args: Bundle) : quotedMessage?.ellipsize = TextUtils.TruncateAt.END quotedMessage?.text = it.text binding.messageInputView.findViewById(R.id.quotedMessageAuthor)?.text = - it.actorDisplayName ?: context!!.getText(R.string.nc_nick_guest) + it.actorDisplayName ?: context.getText(R.string.nc_nick_guest) conversationUser?.let { currentUser -> val quotedMessageImage = binding @@ -3091,7 +3091,7 @@ class ChatController(args: Bundle) : val isOlderThanSixHours = message .createdAt - ?.before(Date(System.currentTimeMillis() - AGE_THREHOLD_FOR_DELETE_MESSAGE)) == true + .before(Date(System.currentTimeMillis() - AGE_THREHOLD_FOR_DELETE_MESSAGE)) == true return when { !isUserAllowedByPrivileges -> false @@ -3219,7 +3219,7 @@ class ChatController(args: Bundle) : if (!permissionUtil.isCameraPermissionGranted()) { requestCameraPermissions() } else { - startActivityForResult(TakePhotoActivity.createIntent(context!!), REQUEST_CODE_PICK_CAMERA) + startActivityForResult(TakePhotoActivity.createIntent(context), REQUEST_CODE_PICK_CAMERA) } } From f347fe1255099fa1ea7285b54166eb49144aaee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 17:29:24 +0200 Subject: [PATCH 02/16] Remove unnecessary elvis operator (?:) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../java/com/nextcloud/talk/controllers/ChatController.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 11f68c938..ce8ec80a2 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -676,7 +676,7 @@ class ChatController(args: Bundle) : }) val filters = arrayOfNulls(1) - val lengthFilter = CapabilitiesUtilNew.getMessageMaxLength(conversationUser) ?: MESSAGE_MAX_LENGTH + val lengthFilter = CapabilitiesUtilNew.getMessageMaxLength(conversationUser) filters[0] = InputFilter.LengthFilter(lengthFilter) binding.messageInputView.inputEditText?.filters = filters @@ -1724,7 +1724,7 @@ class ChatController(args: Bundle) : eventBus.register(this) if (conversationUser?.userId != "?" && - CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "mention-flag") ?: false && + CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "mention-flag") && activity != null ) { activity?.findViewById(R.id.toolbar)?.setOnClickListener { v -> showConversationInfoScreen() } @@ -3244,7 +3244,6 @@ class ChatController(args: Bundle) : private const val POP_CURRENT_CONTROLLER_DELAY: Long = 100 private const val LOBBY_TIMER_DELAY: Long = 5000 private const val HTTP_CODE_OK: Int = 200 - private const val MESSAGE_MAX_LENGTH: Int = 1000 private const val AGE_THREHOLD_FOR_DELETE_MESSAGE: Int = 21600000 // (6 hours in millis = 6 * 3600 * 1000) private const val REQUEST_CODE_CHOOSE_FILE: Int = 555 private const val REQUEST_CODE_SELECT_CONTACT: Int = 666 From a543bdc7a78cff822b3acbb913d121af3f7d6e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 17:35:13 +0200 Subject: [PATCH 03/16] Remove assingments from 'if' clauses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index ce8ec80a2..b506f4b7e 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -306,10 +306,10 @@ class ChatController(args: Bundle) : this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "") - if (conversationUser?.userId == "?") { - credentials = null + credentials = if (conversationUser?.userId == "?") { + null } else { - credentials = ApiUtils.getCredentials(conversationUser!!.username, conversationUser.token) + ApiUtils.getCredentials(conversationUser!!.username, conversationUser.token) } if (args.containsKey(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) { @@ -582,11 +582,10 @@ class ChatController(args: Bundle) : this ) - var senderId = "" - if (!conversationUser.userId.equals("?")) { - senderId = "users/" + conversationUser.userId + val senderId = if (!conversationUser.userId.equals("?")) { + "users/" + conversationUser.userId } else { - senderId = currentConversation?.actorType + "/" + currentConversation?.actorId + currentConversation?.actorType + "/" + currentConversation?.actorId } Log.d(TAG, "Initialize TalkMessagesListAdapter with senderId: " + senderId) @@ -638,11 +637,10 @@ class ChatController(args: Bundle) : binding.popupBubbleView.setPopupBubbleListener { context -> if (newMessagesCount != 0) { - val scrollPosition: Int - if (newMessagesCount - 1 < 0) { - scrollPosition = 0 + val scrollPosition = if (newMessagesCount - 1 < 0) { + 0 } else { - scrollPosition = newMessagesCount - 1 + newMessagesCount - 1 } Handler().postDelayed( { @@ -2112,13 +2110,13 @@ class ChatController(args: Bundle) : private fun setupWebsocket() { if (conversationUser != null) { - if (WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id!!) != null) { - magicWebSocketInstance = + magicWebSocketInstance = + if (WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id!!) != null) { WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id!!) - } else { - Log.d(TAG, "magicWebSocketInstance became null") - magicWebSocketInstance = null - } + } else { + Log.d(TAG, "magicWebSocketInstance became null") + null + } } } @@ -2166,11 +2164,10 @@ class ChatController(args: Bundle) : fieldMap["limit"] = MESSAGE_PULL_LIMIT fieldMap["setReadMarker"] = setReadMarker - val lastKnown: Int - if (lookIntoFuture > 0) { - lastKnown = globalLastKnownFutureMessageId + val lastKnown = if (lookIntoFuture > 0) { + globalLastKnownFutureMessageId } else { - lastKnown = globalLastKnownPastMessageId + globalLastKnownPastMessageId } fieldMap["lastKnownMessageId"] = lastKnown From 7c8722bfe485713aa347ac219a265cac52cb7528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 17:39:23 +0200 Subject: [PATCH 04/16] Convert string concatination to template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index b506f4b7e..ff226f128 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -329,7 +329,7 @@ class ChatController(args: Bundle) : val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1)) val startNanoTime = System.nanoTime() - Log.d(TAG, "getRoomInfo - getRoom - calling: " + startNanoTime) + Log.d(TAG, "getRoomInfo - getRoom - calling: $startNanoTime") ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, conversationUser.baseUrl, roomToken)) ?.subscribeOn(Schedulers.io()) ?.observeOn(AndroidSchedulers.mainThread()) @@ -340,7 +340,7 @@ class ChatController(args: Bundle) : @Suppress("Detekt.TooGenericExceptionCaught") override fun onNext(roomOverall: RoomOverall) { - Log.d(TAG, "getRoomInfo - getRoom - got response: " + startNanoTime) + Log.d(TAG, "getRoomInfo - getRoom - got response: $startNanoTime") currentConversation = roomOverall.ocs!!.data Log.d( TAG, @@ -377,7 +377,7 @@ class ChatController(args: Bundle) : } override fun onComplete() { - Log.d(TAG, "getRoomInfo - getRoom - onComplete: " + startNanoTime) + Log.d(TAG, "getRoomInfo - getRoom - onComplete: $startNanoTime") if (shouldRepeat) { if (lobbyTimerHandler == null) { lobbyTimerHandler = Handler() @@ -588,7 +588,7 @@ class ChatController(args: Bundle) : currentConversation?.actorType + "/" + currentConversation?.actorId } - Log.d(TAG, "Initialize TalkMessagesListAdapter with senderId: " + senderId) + Log.d(TAG, "Initialize TalkMessagesListAdapter with senderId: $senderId") adapter = TalkMessagesListAdapter( senderId, @@ -801,7 +801,7 @@ class ChatController(args: Bundle) : voiceRecordEndTime = System.currentTimeMillis() val voiceRecordDuration = voiceRecordEndTime - voiceRecordStartTime if (voiceRecordDuration < MINIMUM_VOICE_RECORD_DURATION) { - Log.d(TAG, "voiceRecordDuration: " + voiceRecordDuration) + Log.d(TAG, "voiceRecordDuration: $voiceRecordDuration") Toast.makeText( context, context.getString(R.string.nc_voice_message_hold_to_record_info), @@ -1053,7 +1053,7 @@ class ChatController(args: Bundle) : try { for (workInfo in workers.get()) { if (workInfo.state == WorkInfo.State.RUNNING || workInfo.state == WorkInfo.State.ENQUEUED) { - Log.d(TAG, "Download worker for " + fileId + " is already running or scheduled") + Log.d(TAG, "Download worker for $fileId is already running or scheduled") return } } @@ -1775,7 +1775,7 @@ class ChatController(args: Bundle) : cancelNotificationsForCurrentConversation() - Log.d(TAG, "onAttach inConversation: " + inConversation.toString()) + Log.d(TAG, "onAttach inConversation: $inConversation") if (inConversation) { Log.d(TAG, "execute joinRoomWithPassword in onAttach") joinRoomWithPassword() @@ -1883,7 +1883,7 @@ class ChatController(args: Bundle) : } val startNanoTime = System.nanoTime() - Log.d(TAG, "joinRoomWithPassword - joinRoom - calling: " + startNanoTime) + Log.d(TAG, "joinRoomWithPassword - joinRoom - calling: $startNanoTime") ncApi.joinRoom( credentials, ApiUtils.getUrlForParticipantsActive(apiVersion, conversationUser?.baseUrl, roomToken), @@ -1899,7 +1899,7 @@ class ChatController(args: Bundle) : @Suppress("Detekt.TooGenericExceptionCaught") override fun onNext(roomOverall: RoomOverall) { - Log.d(TAG, "joinRoomWithPassword - joinRoom - got response: " + startNanoTime) + Log.d(TAG, "joinRoomWithPassword - joinRoom - got response: $startNanoTime") inConversation = true currentConversation?.sessionId = roomOverall.ocs!!.data!!.sessionId Log.d(TAG, "joinRoomWithPassword - sessionId: " + currentConversation?.sessionId) @@ -1969,7 +1969,7 @@ class ChatController(args: Bundle) : } val startNanoTime = System.nanoTime() - Log.d(TAG, "leaveRoom - leaveRoom - calling: " + startNanoTime) + Log.d(TAG, "leaveRoom - leaveRoom - calling: $startNanoTime") ncApi.leaveRoom( credentials, ApiUtils.getUrlForParticipantsActive( @@ -1986,7 +1986,7 @@ class ChatController(args: Bundle) : } override fun onNext(genericOverall: GenericOverall) { - Log.d(TAG, "leaveRoom - leaveRoom - got response: " + startNanoTime) + Log.d(TAG, "leaveRoom - leaveRoom - got response: $startNanoTime") checkingLobbyStatus = false if (lobbyTimerHandler != null) { @@ -2010,7 +2010,7 @@ class ChatController(args: Bundle) : } override fun onComplete() { - Log.d(TAG, "leaveRoom - leaveRoom - completed: " + startNanoTime) + Log.d(TAG, "leaveRoom - leaveRoom - completed: $startNanoTime") disposables.dispose() } }) From bb4bccbd08f41dac0aee9689cb228424d53a05e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 17:44:37 +0200 Subject: [PATCH 05/16] Simplify boolean expressions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../java/com/nextcloud/talk/controllers/ChatController.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index ff226f128..40fdaafa5 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2073,7 +2073,7 @@ class ChatController(args: Bundle) : myFirstMessage = message try { - if (binding.popupBubbleView.isShown == true) { + if (binding.popupBubbleView.isShown) { binding.popupBubbleView.hide() } @@ -2091,7 +2091,7 @@ class ChatController(args: Bundle) : if (Integer.toString(code).startsWith("2")) { myFirstMessage = message - if (binding.popupBubbleView.isShown == true) { + if (binding.popupBubbleView.isShown) { binding.popupBubbleView.hide() } @@ -2425,7 +2425,7 @@ class ChatController(args: Bundle) : if (!binding.popupBubbleView.isShown) { newMessagesCount = 1 binding.popupBubbleView.show() - } else if (binding.popupBubbleView.isShown == true) { + } else if (binding.popupBubbleView.isShown) { newMessagesCount++ } } else { @@ -3088,7 +3088,7 @@ class ChatController(args: Bundle) : val isOlderThanSixHours = message .createdAt - .before(Date(System.currentTimeMillis() - AGE_THREHOLD_FOR_DELETE_MESSAGE)) == true + .before(Date(System.currentTimeMillis() - AGE_THREHOLD_FOR_DELETE_MESSAGE)) return when { !isUserAllowedByPrivileges -> false From 7dec6dd4dd7f24d5e2a7b9e29e367d235b81dadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 17:50:18 +0200 Subject: [PATCH 06/16] Fix some spelling issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 40fdaafa5..b5a473f0a 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -367,7 +367,7 @@ class ChatController(args: Bundle) : } } catch (npe: NullPointerException) { // view binding can be null - // since this is called asynchrously and UI might have been destroyed in the meantime + // since this is called asynchronously and UI might have been destroyed in the meantime Log.i(TAG, "UI destroyed - view binding already gone") } } @@ -1401,11 +1401,11 @@ class ChatController(args: Bundle) : } require(filesToUpload.isNotEmpty()) - val filenamesWithLinebreaks = StringBuilder("\n") + val filenamesWithLineBreaks = StringBuilder("\n") for (file in filesToUpload) { val filename = UriUtils.getFileName(Uri.parse(file), context) - filenamesWithLinebreaks.append(filename).append("\n") + filenamesWithLineBreaks.append(filename).append("\n") } val confirmationQuestion = when (filesToUpload.size) { @@ -1419,7 +1419,7 @@ class ChatController(args: Bundle) : val materialAlertDialogBuilder = MaterialAlertDialogBuilder(binding.messageInputView.context) .setTitle(confirmationQuestion) - .setMessage(filenamesWithLinebreaks.toString()) + .setMessage(filenamesWithLineBreaks.toString()) .setPositiveButton(R.string.nc_yes) { _, _ -> if (UploadAndShareFilesWorker.isStoragePermissionGranted(context)) { uploadFiles(filesToUpload, false) @@ -1913,7 +1913,7 @@ class ChatController(args: Bundle) : checkLobbyState() } catch (npe: NullPointerException) { // view binding can be null - // since this is called asynchrously and UI might have been destroyed in the meantime + // since this is called asynchronously and UI might have been destroyed in the meantime Log.i(TAG, "UI destroyed - view binding already gone") } @@ -2080,7 +2080,7 @@ class ChatController(args: Bundle) : binding.messagesListView.smoothScrollToPosition(0) } catch (npe: NullPointerException) { // view binding can be null - // since this is called asynchrously and UI might have been destroyed in the meantime + // since this is called asynchronously and UI might have been destroyed in the meantime Log.i(TAG, "UI destroyed - view binding already gone") } } @@ -2211,7 +2211,7 @@ class ChatController(args: Bundle) : } } catch (npe: NullPointerException) { // view binding can be null - // since this is called asynchrously and UI might have been destroyed in the meantime + // since this is called asynchronously and UI might have been destroyed in the meantime Log.i(TAG, "UI destroyed - view binding already gone") } @@ -2253,7 +2253,7 @@ class ChatController(args: Bundle) : } } catch (e: NullPointerException) { // view binding can be null - // since this is called asynchrously and UI might have been destroyed in the meantime + // since this is called asynchronously and UI might have been destroyed in the meantime Log.i(TAG, "UI destroyed - view binding already gone", e) } @@ -3088,7 +3088,7 @@ class ChatController(args: Bundle) : val isOlderThanSixHours = message .createdAt - .before(Date(System.currentTimeMillis() - AGE_THREHOLD_FOR_DELETE_MESSAGE)) + .before(Date(System.currentTimeMillis() - AGE_THRESHOLD_FOR_DELETE_MESSAGE)) return when { !isUserAllowedByPrivileges -> false @@ -3241,7 +3241,7 @@ class ChatController(args: Bundle) : private const val POP_CURRENT_CONTROLLER_DELAY: Long = 100 private const val LOBBY_TIMER_DELAY: Long = 5000 private const val HTTP_CODE_OK: Int = 200 - private const val AGE_THREHOLD_FOR_DELETE_MESSAGE: Int = 21600000 // (6 hours in millis = 6 * 3600 * 1000) + private const val AGE_THRESHOLD_FOR_DELETE_MESSAGE: Int = 21600000 // (6 hours in millis = 6 * 3600 * 1000) private const val REQUEST_CODE_CHOOSE_FILE: Int = 555 private const val REQUEST_CODE_SELECT_CONTACT: Int = 666 private const val REQUEST_CODE_MESSAGE_SEARCH: Int = 777 From 7b1eda1b85f744340d6be721c90def8bec295976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 17:51:28 +0200 Subject: [PATCH 07/16] Replace 'Integer#toString' with Kotlin functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../java/com/nextcloud/talk/controllers/ChatController.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index b5a473f0a..722b726ec 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -690,7 +690,7 @@ class ChatController(args: Bundle) : if (s.length >= lengthFilter) { binding.messageInputView.inputEditText?.error = String.format( Objects.requireNonNull(resources).getString(R.string.nc_limit_hit), - Integer.toString(lengthFilter) + lengthFilter.toString() ) } else { binding.messageInputView.inputEditText?.error = null @@ -2088,7 +2088,7 @@ class ChatController(args: Bundle) : override fun onError(e: Throwable) { if (e is HttpException) { val code = e.code() - if (Integer.toString(code).startsWith("2")) { + if (code.toString().startsWith("2")) { myFirstMessage = message if (binding.popupBubbleView.isShown) { From 69eea8f56813de0f9eb79a736401fec079b847ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 17:52:51 +0200 Subject: [PATCH 08/16] Use indexing insteat of 'Map#get' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../java/com/nextcloud/talk/controllers/ChatController.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 722b726ec..ae7d1f8bc 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2295,8 +2295,8 @@ class ChatController(args: Bundle) : } private fun processMessages(response: Response<*>, isFromTheFuture: Boolean, timeout: Int) { - val xChatLastGivenHeader: String? = response.headers().get("X-Chat-Last-Given") - val xChatLastCommonRead = response.headers().get("X-Chat-Last-Common-Read")?.let { + val xChatLastGivenHeader: String? = response.headers()["X-Chat-Last-Given"] + val xChatLastCommonRead = response.headers()["X-Chat-Last-Common-Read"]?.let { Integer.parseInt(it) } if (response.headers().size > 0 && !TextUtils.isEmpty(xChatLastGivenHeader)) { From 2d5969964db025e232e25ea3032f4182c602cabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 17:58:11 +0200 Subject: [PATCH 09/16] Make properties private if possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index ae7d1f8bc..9a02d737e 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -238,32 +238,32 @@ class ChatController(args: Bundle) : var roomToken: String? = null val conversationUser: User? - val roomPassword: String + private val roomPassword: String var credentials: String? = null var currentConversation: Conversation? = null var inConversation = false - var historyRead = false - var globalLastKnownFutureMessageId = -1 - var globalLastKnownPastMessageId = -1 + private var historyRead = false + private var globalLastKnownFutureMessageId = -1 + private var globalLastKnownPastMessageId = -1 var adapter: TalkMessagesListAdapter? = null - var mentionAutocomplete: Autocomplete<*>? = null + private var mentionAutocomplete: Autocomplete<*>? = null var layoutManager: LinearLayoutManager? = null var pullChatMessagesPending = false - var lookingIntoFuture = false + private var lookingIntoFuture = false var newMessagesCount = 0 var startCallFromNotification: Boolean? = null val roomId: String val voiceOnly: Boolean var isFirstMessagesProcessing = true - var emojiPopup: EmojiPopup? = null + private var emojiPopup: EmojiPopup? = null var myFirstMessage: CharSequence? = null var checkingLobbyStatus: Boolean = false - var conversationInfoMenuItem: MenuItem? = null - var conversationVoiceCallMenuItem: MenuItem? = null - var conversationVideoMenuItem: MenuItem? = null - var conversationSharedItemsItem: MenuItem? = null + private var conversationInfoMenuItem: MenuItem? = null + private var conversationVoiceCallMenuItem: MenuItem? = null + private var conversationVideoMenuItem: MenuItem? = null + private var conversationSharedItemsItem: MenuItem? = null var magicWebSocketInstance: MagicWebSocketInstance? = null @@ -271,8 +271,8 @@ class ChatController(args: Bundle) : var pastPreconditionFailed = false var futurePreconditionFailed = false - val filesToUpload: MutableList = ArrayList() - var sharedText: String + private val filesToUpload: MutableList = ArrayList() + private var sharedText: String var isVoiceRecordingInProgress: Boolean = false var currentVoiceRecordFile: String = "" @@ -280,7 +280,7 @@ class ChatController(args: Bundle) : var mediaPlayer: MediaPlayer? = null lateinit var mediaPlayerHandler: Handler - var currentlyPlayedVoiceMessage: ChatMessage? = null + private var currentlyPlayedVoiceMessage: ChatMessage? = null var hasChatPermission: Boolean = false From f762d0c9e59218fd1ea8d23513f63742457fde6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 6 Sep 2022 18:04:03 +0200 Subject: [PATCH 10/16] Remove unused parameter 'timeout' from 'ChatController#processMessages' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../java/com/nextcloud/talk/controllers/ChatController.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 9a02d737e..cf5bf25d7 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2182,7 +2182,6 @@ class ChatController(args: Bundle) : } if (lookIntoFuture > 0) { - val finalTimeout = timeout Log.d(TAG, "pullChatMessages - pullChatMessages[lookIntoFuture > 0] - calling") ncApi.pullChatMessages( credentials, @@ -2207,7 +2206,7 @@ class ChatController(args: Bundle) : } else if (response.code() == HTTP_CODE_PRECONDITION_FAILED) { futurePreconditionFailed = true } else { - processMessages(response, true, finalTimeout) + processMessages(response, true) } } catch (npe: NullPointerException) { // view binding can be null @@ -2249,7 +2248,7 @@ class ChatController(args: Bundle) : if (response.code() == HTTP_CODE_PRECONDITION_FAILED) { pastPreconditionFailed = true } else { - processMessages(response, false, 0) + processMessages(response, false) } } catch (e: NullPointerException) { // view binding can be null @@ -2294,7 +2293,7 @@ class ChatController(args: Bundle) : } } - private fun processMessages(response: Response<*>, isFromTheFuture: Boolean, timeout: Int) { + private fun processMessages(response: Response<*>, isFromTheFuture: Boolean) { val xChatLastGivenHeader: String? = response.headers()["X-Chat-Last-Given"] val xChatLastCommonRead = response.headers()["X-Chat-Last-Common-Read"]?.let { Integer.parseInt(it) From 4cab75f6edad9ff3c16adc769ea53609e7576cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 7 Sep 2022 08:56:35 +0200 Subject: [PATCH 11/16] Reduce complexity for function 'ChatController#processMessages' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 309 +++++++++--------- 1 file changed, 163 insertions(+), 146 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index cf5bf25d7..4d5092772 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2294,23 +2294,12 @@ class ChatController(args: Bundle) : } private fun processMessages(response: Response<*>, isFromTheFuture: Boolean) { - val xChatLastGivenHeader: String? = response.headers()["X-Chat-Last-Given"] + val xChatLastCommonRead = response.headers()["X-Chat-Last-Common-Read"]?.let { Integer.parseInt(it) } - if (response.headers().size > 0 && !TextUtils.isEmpty(xChatLastGivenHeader)) { - val header = Integer.parseInt(xChatLastGivenHeader!!) - if (header > 0) { - if (isFromTheFuture) { - globalLastKnownFutureMessageId = header - } else { - if (globalLastKnownFutureMessageId == -1) { - globalLastKnownFutureMessageId = header - } - globalLastKnownPastMessageId = header - } - } - } + + processHeaderChatLastGiven(response, isFromTheFuture) if (response.code() == HTTP_CODE_OK) { val chatOverall = response.body() as ChatOverall? @@ -2332,141 +2321,13 @@ class ChatController(args: Bundle) : binding.messagesListView.visibility = View.VISIBLE } - var countGroupedMessages = 0 - if (!isFromTheFuture) { - var previousMessageId = NO_PREVIOUS_MESSAGE_ID - for (i in chatMessageList.indices.reversed()) { - val chatMessage = chatMessageList[i] - - if (previousMessageId > NO_PREVIOUS_MESSAGE_ID) { - chatMessage.previousMessageId = previousMessageId - } else if (adapter?.isEmpty != true) { - if (adapter!!.items[0].item is ChatMessage) { - chatMessage.previousMessageId = (adapter!!.items[0].item as ChatMessage).jsonMessageId - } else if (adapter!!.items.size > 1 && adapter!!.items[1].item is ChatMessage) { - chatMessage.previousMessageId = (adapter!!.items[1].item as ChatMessage).jsonMessageId - } - } - - previousMessageId = chatMessage.jsonMessageId - } - - for (i in chatMessageList.indices) { - if (chatMessageList.size > i + 1) { - if (isSameDayNonSystemMessages(chatMessageList[i], chatMessageList[i + 1]) && - chatMessageList[i + 1].actorId == chatMessageList[i].actorId && - countGroupedMessages < GROUPED_MESSAGES_THRESHOLD - ) { - chatMessageList[i].isGrouped = true - countGroupedMessages++ - } else { - countGroupedMessages = 0 - } - } - - val chatMessage = chatMessageList[i] - chatMessage.isOneToOneConversation = - currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL - chatMessage.activeUser = conversationUser - } - - if (adapter != null) { - adapter?.addToEnd(chatMessageList, false) - } - scrollToRequestedMessageIfNeeded() + if (isFromTheFuture) { + processMessagesFromTheFuture(chatMessageList) } else { - var chatMessage: ChatMessage - - val shouldAddNewMessagesNotice = (adapter?.itemCount ?: 0) > 0 && chatMessageList.isNotEmpty() - - if (shouldAddNewMessagesNotice) { - val unreadChatMessage = ChatMessage() - unreadChatMessage.jsonMessageId = -1 - unreadChatMessage.actorId = "-1" - unreadChatMessage.timestamp = chatMessageList[0].timestamp - unreadChatMessage.message = context.getString(R.string.nc_new_messages) - adapter?.addToStart(unreadChatMessage, false) - } - - val isThereANewNotice = - shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1 - - var previousMessageId = NO_PREVIOUS_MESSAGE_ID - for (i in chatMessageList.indices.reversed()) { - val chatMessageItem = chatMessageList[i] - - if (previousMessageId > NO_PREVIOUS_MESSAGE_ID) { - chatMessageItem.previousMessageId = previousMessageId - } else if (adapter?.isEmpty != true) { - if (adapter!!.items[0].item is ChatMessage) { - chatMessageItem.previousMessageId = (adapter!!.items[0].item as ChatMessage).jsonMessageId - } else if (adapter!!.items.size > 1 && adapter!!.items[1].item is ChatMessage) { - chatMessageItem.previousMessageId = (adapter!!.items[1].item as ChatMessage).jsonMessageId - } - } - - previousMessageId = chatMessageItem.jsonMessageId - } - - for (i in chatMessageList.indices) { - chatMessage = chatMessageList[i] - - chatMessage.activeUser = conversationUser - - val shouldScroll = - !isThereANewNotice && - !shouldAddNewMessagesNotice && - layoutManager?.findFirstVisibleItemPosition() == 0 || - adapter != null && - adapter?.itemCount == 0 - - if (!shouldAddNewMessagesNotice && !shouldScroll) { - if (!binding.popupBubbleView.isShown) { - newMessagesCount = 1 - binding.popupBubbleView.show() - } else if (binding.popupBubbleView.isShown) { - newMessagesCount++ - } - } else { - newMessagesCount = 0 - } - - if (adapter != null) { - chatMessage.isGrouped = ( - adapter!!.isPreviousSameAuthor( - chatMessage.actorId, - -1 - ) && adapter!!.getSameAuthorLastMessagesCount(chatMessage.actorId) % - GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD > 0 - ) - chatMessage.isOneToOneConversation = - (currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) - adapter?.addToStart(chatMessage, shouldScroll) - } - } - - if (shouldAddNewMessagesNotice && adapter != null) { - layoutManager?.scrollToPositionWithOffset( - adapter!!.getMessagePositionByIdInReverse("-1"), - binding.messagesListView.height / 2 - ) - } + processMessagesNotFromTheFuture(chatMessageList) } - // update read status of all messages - for (message in adapter!!.items) { - xChatLastCommonRead?.let { - if (message.item is ChatMessage) { - val chatMessage = message.item as ChatMessage - - if (chatMessage.jsonMessageId <= it) { - chatMessage.readStatus = ReadStatus.READ - } else { - chatMessage.readStatus = ReadStatus.SENT - } - } - } - } + updateReadStatusOfAllMessages(xChatLastCommonRead) adapter?.notifyDataSetChanged() if (inConversation) { @@ -2488,6 +2349,162 @@ class ChatController(args: Bundle) : } } + private fun updateReadStatusOfAllMessages(xChatLastCommonRead: Int?) { + for (message in adapter!!.items) { + xChatLastCommonRead?.let { + if (message.item is ChatMessage) { + val chatMessage = message.item as ChatMessage + + if (chatMessage.jsonMessageId <= it) { + chatMessage.readStatus = ReadStatus.READ + } else { + chatMessage.readStatus = ReadStatus.SENT + } + } + } + } + } + + private fun processMessagesFromTheFuture(chatMessageList: List) { + var chatMessage: ChatMessage + + val shouldAddNewMessagesNotice = (adapter?.itemCount ?: 0) > 0 && chatMessageList.isNotEmpty() + + if (shouldAddNewMessagesNotice) { + val unreadChatMessage = ChatMessage() + unreadChatMessage.jsonMessageId = -1 + unreadChatMessage.actorId = "-1" + unreadChatMessage.timestamp = chatMessageList[0].timestamp + unreadChatMessage.message = context.getString(R.string.nc_new_messages) + adapter?.addToStart(unreadChatMessage, false) + } + + val isThereANewNotice = + shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1 + + var previousMessageId = NO_PREVIOUS_MESSAGE_ID + for (i in chatMessageList.indices.reversed()) { + val chatMessageItem = chatMessageList[i] + + if (previousMessageId > NO_PREVIOUS_MESSAGE_ID) { + chatMessageItem.previousMessageId = previousMessageId + } else if (adapter?.isEmpty != true) { + if (adapter!!.items[0].item is ChatMessage) { + chatMessageItem.previousMessageId = (adapter!!.items[0].item as ChatMessage).jsonMessageId + } else if (adapter!!.items.size > 1 && adapter!!.items[1].item is ChatMessage) { + chatMessageItem.previousMessageId = (adapter!!.items[1].item as ChatMessage).jsonMessageId + } + } + + previousMessageId = chatMessageItem.jsonMessageId + } + + for (i in chatMessageList.indices) { + chatMessage = chatMessageList[i] + + chatMessage.activeUser = conversationUser + + val shouldScroll = + !isThereANewNotice && + !shouldAddNewMessagesNotice && + layoutManager?.findFirstVisibleItemPosition() == 0 || + adapter != null && + adapter?.itemCount == 0 + + if (!shouldAddNewMessagesNotice && !shouldScroll) { + if (!binding.popupBubbleView.isShown) { + newMessagesCount = 1 + binding.popupBubbleView.show() + } else if (binding.popupBubbleView.isShown) { + newMessagesCount++ + } + } else { + newMessagesCount = 0 + } + + if (adapter != null) { + chatMessage.isGrouped = ( + adapter!!.isPreviousSameAuthor( + chatMessage.actorId, + -1 + ) && adapter!!.getSameAuthorLastMessagesCount(chatMessage.actorId) % + GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD > 0 + ) + chatMessage.isOneToOneConversation = + (currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) + adapter?.addToStart(chatMessage, shouldScroll) + } + } + + if (shouldAddNewMessagesNotice && adapter != null) { + layoutManager?.scrollToPositionWithOffset( + adapter!!.getMessagePositionByIdInReverse("-1"), + binding.messagesListView.height / 2 + ) + } + } + + private fun processMessagesNotFromTheFuture(chatMessageList: List) { + var countGroupedMessages = 0 + var previousMessageId = NO_PREVIOUS_MESSAGE_ID + for (i in chatMessageList.indices.reversed()) { + val chatMessage = chatMessageList[i] + + if (previousMessageId > NO_PREVIOUS_MESSAGE_ID) { + chatMessage.previousMessageId = previousMessageId + } else if (adapter?.isEmpty != true) { + if (adapter!!.items[0].item is ChatMessage) { + chatMessage.previousMessageId = (adapter!!.items[0].item as ChatMessage).jsonMessageId + } else if (adapter!!.items.size > 1 && adapter!!.items[1].item is ChatMessage) { + chatMessage.previousMessageId = (adapter!!.items[1].item as ChatMessage).jsonMessageId + } + } + + previousMessageId = chatMessage.jsonMessageId + } + + for (i in chatMessageList.indices) { + if (chatMessageList.size > i + 1) { + if (isSameDayNonSystemMessages(chatMessageList[i], chatMessageList[i + 1]) && + chatMessageList[i + 1].actorId == chatMessageList[i].actorId && + countGroupedMessages < GROUPED_MESSAGES_THRESHOLD + ) { + chatMessageList[i].isGrouped = true + countGroupedMessages++ + } else { + countGroupedMessages = 0 + } + } + + val chatMessage = chatMessageList[i] + chatMessage.isOneToOneConversation = + currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL + chatMessage.activeUser = conversationUser + } + + if (adapter != null) { + adapter?.addToEnd(chatMessageList, false) + } + scrollToRequestedMessageIfNeeded() + } + + private fun processHeaderChatLastGiven(response: Response<*>, isFromTheFuture: Boolean) { + val xChatLastGivenHeader: String? = response.headers()["X-Chat-Last-Given"] + if (response.headers().size > 0 && !TextUtils.isEmpty(xChatLastGivenHeader)) { + val header = Integer.parseInt(xChatLastGivenHeader!!) + if (header > 0) { + if (isFromTheFuture) { + globalLastKnownFutureMessageId = header + } else { + if (globalLastKnownFutureMessageId == -1) { + globalLastKnownFutureMessageId = header + } + globalLastKnownPastMessageId = header + } + } + } + } + private fun scrollToRequestedMessageIfNeeded() { args.getString(BundleKeys.KEY_MESSAGE_ID)?.let { scrollToMessageWithId(it) From 57ddf9af60b2d90e295b25f2d624dc3ad0729879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 7 Sep 2022 10:34:45 +0200 Subject: [PATCH 12/16] Extract duplicated code to function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The newly created function 'ChatController#determinePreviousMessageIds' contains now the duplicated code from functions 'ChatCtonroller#processMessagesFromTheFuture' and 'ChatController#processMessagesNotFromTheFuture'. Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 53 ++++++++----------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 4d5092772..f03ee2ecb 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2382,22 +2382,7 @@ class ChatController(args: Bundle) : val isThereANewNotice = shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1 - var previousMessageId = NO_PREVIOUS_MESSAGE_ID - for (i in chatMessageList.indices.reversed()) { - val chatMessageItem = chatMessageList[i] - - if (previousMessageId > NO_PREVIOUS_MESSAGE_ID) { - chatMessageItem.previousMessageId = previousMessageId - } else if (adapter?.isEmpty != true) { - if (adapter!!.items[0].item is ChatMessage) { - chatMessageItem.previousMessageId = (adapter!!.items[0].item as ChatMessage).jsonMessageId - } else if (adapter!!.items.size > 1 && adapter!!.items[1].item is ChatMessage) { - chatMessageItem.previousMessageId = (adapter!!.items[1].item as ChatMessage).jsonMessageId - } - } - - previousMessageId = chatMessageItem.jsonMessageId - } + determinePreviousMessageIds(chatMessageList) for (i in chatMessageList.indices) { chatMessage = chatMessageList[i] @@ -2446,22 +2431,7 @@ class ChatController(args: Bundle) : private fun processMessagesNotFromTheFuture(chatMessageList: List) { var countGroupedMessages = 0 - var previousMessageId = NO_PREVIOUS_MESSAGE_ID - for (i in chatMessageList.indices.reversed()) { - val chatMessage = chatMessageList[i] - - if (previousMessageId > NO_PREVIOUS_MESSAGE_ID) { - chatMessage.previousMessageId = previousMessageId - } else if (adapter?.isEmpty != true) { - if (adapter!!.items[0].item is ChatMessage) { - chatMessage.previousMessageId = (adapter!!.items[0].item as ChatMessage).jsonMessageId - } else if (adapter!!.items.size > 1 && adapter!!.items[1].item is ChatMessage) { - chatMessage.previousMessageId = (adapter!!.items[1].item as ChatMessage).jsonMessageId - } - } - - previousMessageId = chatMessage.jsonMessageId - } + determinePreviousMessageIds(chatMessageList) for (i in chatMessageList.indices) { if (chatMessageList.size > i + 1) { @@ -2488,6 +2458,25 @@ class ChatController(args: Bundle) : scrollToRequestedMessageIfNeeded() } + private fun determinePreviousMessageIds(chatMessageList: List) { + var previousMessageId = NO_PREVIOUS_MESSAGE_ID + for (i in chatMessageList.indices.reversed()) { + val chatMessage = chatMessageList[i] + + if (previousMessageId > NO_PREVIOUS_MESSAGE_ID) { + chatMessage.previousMessageId = previousMessageId + } else if (adapter?.isEmpty != true) { + if (adapter!!.items[0].item is ChatMessage) { + chatMessage.previousMessageId = (adapter!!.items[0].item as ChatMessage).jsonMessageId + } else if (adapter!!.items.size > 1 && adapter!!.items[1].item is ChatMessage) { + chatMessage.previousMessageId = (adapter!!.items[1].item as ChatMessage).jsonMessageId + } + } + + previousMessageId = chatMessage.jsonMessageId + } + } + private fun processHeaderChatLastGiven(response: Response<*>, isFromTheFuture: Boolean) { val xChatLastGivenHeader: String? = response.headers()["X-Chat-Last-Given"] if (response.headers().size > 0 && !TextUtils.isEmpty(xChatLastGivenHeader)) { From 5bb63fd58d44b32dc64f5735ba27570c4df435f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 7 Sep 2022 10:51:09 +0200 Subject: [PATCH 13/16] Reduce nested block depth for updateReadStatusOfAllMessages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index f03ee2ecb..82c4adf02 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2352,15 +2352,22 @@ class ChatController(args: Bundle) : private fun updateReadStatusOfAllMessages(xChatLastCommonRead: Int?) { for (message in adapter!!.items) { xChatLastCommonRead?.let { - if (message.item is ChatMessage) { - val chatMessage = message.item as ChatMessage + updateReadStatusOfMessage(message, it) + } + } + } - if (chatMessage.jsonMessageId <= it) { - chatMessage.readStatus = ReadStatus.READ - } else { - chatMessage.readStatus = ReadStatus.SENT - } - } + private fun updateReadStatusOfMessage( + message: MessagesListAdapter.Wrapper, + xChatLastCommonRead: Int + ) { + if (message.item is ChatMessage) { + val chatMessage = message.item as ChatMessage + + if (chatMessage.jsonMessageId <= xChatLastCommonRead) { + chatMessage.readStatus = ReadStatus.READ + } else { + chatMessage.readStatus = ReadStatus.SENT } } } From d0df4039c69eda80a7df7d99abe6cd46f39ffeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 7 Sep 2022 11:34:59 +0200 Subject: [PATCH 14/16] Fix to deeply nested function processHeaderChatLastGiven MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 82c4adf02..5bb943d5c 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2486,17 +2486,23 @@ class ChatController(args: Bundle) : private fun processHeaderChatLastGiven(response: Response<*>, isFromTheFuture: Boolean) { val xChatLastGivenHeader: String? = response.headers()["X-Chat-Last-Given"] - if (response.headers().size > 0 && !TextUtils.isEmpty(xChatLastGivenHeader)) { - val header = Integer.parseInt(xChatLastGivenHeader!!) - if (header > 0) { - if (isFromTheFuture) { + + val header = if (response.headers().size > 0 && + xChatLastGivenHeader?.isNotEmpty() == true + ) { + xChatLastGivenHeader.toInt() + } else { + return + } + + if (header > 0) { + if (isFromTheFuture) { + globalLastKnownFutureMessageId = header + } else { + if (globalLastKnownFutureMessageId == -1) { globalLastKnownFutureMessageId = header - } else { - if (globalLastKnownFutureMessageId == -1) { - globalLastKnownFutureMessageId = header - } - globalLastKnownPastMessageId = header } + globalLastKnownPastMessageId = header } } } From ae0a9d6aae7a194bdcbcbb22bf35a8afce6b13cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 7 Sep 2022 12:06:14 +0200 Subject: [PATCH 15/16] Reduce complexity for 'ChatController#processMessagesFromTheFuture' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 5bb943d5c..5f2046c99 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2373,7 +2373,6 @@ class ChatController(args: Bundle) : } private fun processMessagesFromTheFuture(chatMessageList: List) { - var chatMessage: ChatMessage val shouldAddNewMessagesNotice = (adapter?.itemCount ?: 0) > 0 && chatMessageList.isNotEmpty() @@ -2386,14 +2385,25 @@ class ChatController(args: Bundle) : adapter?.addToStart(unreadChatMessage, false) } - val isThereANewNotice = - shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1 - determinePreviousMessageIds(chatMessageList) - for (i in chatMessageList.indices) { - chatMessage = chatMessageList[i] + addMessagesToAdapter(shouldAddNewMessagesNotice, chatMessageList) + if (shouldAddNewMessagesNotice && adapter != null) { + layoutManager?.scrollToPositionWithOffset( + adapter!!.getMessagePositionByIdInReverse("-1"), + binding.messagesListView.height / 2 + ) + } + } + + private fun addMessagesToAdapter( + shouldAddNewMessagesNotice: Boolean, + chatMessageList: List + ) { + val isThereANewNotice = + shouldAddNewMessagesNotice || adapter?.getMessagePositionByIdInReverse("-1") != -1 + for (chatMessage in chatMessageList) { chatMessage.activeUser = conversationUser val shouldScroll = @@ -2403,36 +2413,33 @@ class ChatController(args: Bundle) : adapter != null && adapter?.itemCount == 0 - if (!shouldAddNewMessagesNotice && !shouldScroll) { - if (!binding.popupBubbleView.isShown) { - newMessagesCount = 1 - binding.popupBubbleView.show() - } else if (binding.popupBubbleView.isShown) { - newMessagesCount++ - } - } else { - newMessagesCount = 0 - } + modifyMessageCount(shouldAddNewMessagesNotice, shouldScroll) - if (adapter != null) { + adapter?.let { chatMessage.isGrouped = ( - adapter!!.isPreviousSameAuthor( + it.isPreviousSameAuthor( chatMessage.actorId, -1 - ) && adapter!!.getSameAuthorLastMessagesCount(chatMessage.actorId) % + ) && it.getSameAuthorLastMessagesCount(chatMessage.actorId) % GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD > 0 ) chatMessage.isOneToOneConversation = (currentConversation?.type == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) - adapter?.addToStart(chatMessage, shouldScroll) + it.addToStart(chatMessage, shouldScroll) } } + } - if (shouldAddNewMessagesNotice && adapter != null) { - layoutManager?.scrollToPositionWithOffset( - adapter!!.getMessagePositionByIdInReverse("-1"), - binding.messagesListView.height / 2 - ) + private fun modifyMessageCount(shouldAddNewMessagesNotice: Boolean, shouldScroll: Boolean) { + if (!shouldAddNewMessagesNotice && !shouldScroll) { + if (!binding.popupBubbleView.isShown) { + newMessagesCount = 1 + binding.popupBubbleView.show() + } else if (binding.popupBubbleView.isShown) { + newMessagesCount++ + } + } else { + newMessagesCount = 0 } } From 0c06c8b2eb953a783841b1c3e31730b3d6b55e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 7 Sep 2022 12:31:03 +0200 Subject: [PATCH 16/16] Rename and reduce complexity of function 'processMessages' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 70 +++++++++++-------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 5f2046c99..ddc8c5460 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -2206,7 +2206,7 @@ class ChatController(args: Bundle) : } else if (response.code() == HTTP_CODE_PRECONDITION_FAILED) { futurePreconditionFailed = true } else { - processMessages(response, true) + processMessagesResponse(response, true) } } catch (npe: NullPointerException) { // view binding can be null @@ -2248,7 +2248,7 @@ class ChatController(args: Bundle) : if (response.code() == HTTP_CODE_PRECONDITION_FAILED) { pastPreconditionFailed = true } else { - processMessages(response, false) + processMessagesResponse(response, false) } } catch (e: NullPointerException) { // 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 { Integer.parseInt(it) @@ -2305,34 +2305,7 @@ class ChatController(args: Bundle) : val chatOverall = response.body() as ChatOverall? val chatMessageList = handleSystemMessages(chatOverall?.ocs!!.data!!) - 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) - } + processMessages(chatMessageList, isFromTheFuture, xChatLastCommonRead) } else if (response.code() == HTTP_CODE_NOT_MODIFIED && !isFromTheFuture) { if (isFirstMessagesProcessing) { cancelNotificationsForCurrentConversation() @@ -2349,6 +2322,41 @@ class ChatController(args: Bundle) : } } + private fun processMessages( + chatMessageList: List, + 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?) { for (message in adapter!!.items) { xChatLastCommonRead?.let {