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 8215cd874..00b4c08ea 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -144,12 +144,14 @@ import com.nextcloud.talk.models.json.conversations.RoomOverall import com.nextcloud.talk.models.json.conversations.RoomsOverall import com.nextcloud.talk.models.json.generic.GenericOverall import com.nextcloud.talk.models.json.mention.Mention +import com.nextcloud.talk.models.json.signaling.NCSignalingMessage import com.nextcloud.talk.polls.ui.PollCreateDialogFragment import com.nextcloud.talk.presenters.MentionAutocompletePresenter import com.nextcloud.talk.remotefilebrowser.activities.RemoteFileBrowserActivity import com.nextcloud.talk.repositories.reactions.ReactionsRepository import com.nextcloud.talk.shareditems.activities.SharedItemsActivity import com.nextcloud.talk.signaling.SignalingMessageReceiver +import com.nextcloud.talk.signaling.SignalingMessageSender import com.nextcloud.talk.translate.TranslateActivity import com.nextcloud.talk.ui.bottom.sheet.ProfileBottomSheet import com.nextcloud.talk.ui.dialog.AttachmentDialog @@ -278,7 +280,8 @@ class ChatActivity : private var conversationVideoMenuItem: MenuItem? = null private var conversationSharedItemsItem: MenuItem? = null - var webSocketInstance: WebSocketInstance? = null + private var webSocketInstance: WebSocketInstance? = null + private var signalingMessageSender: SignalingMessageSender? = null var getRoomInfoTimerHandler: Handler? = null var pastPreconditionFailed = false @@ -515,6 +518,8 @@ class ChatActivity : @Suppress("Detekt.TooGenericExceptionCaught") override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + sendTypingMessage() + if (s.length >= lengthFilter) { binding?.messageInputView?.inputEditText?.error = String.format( Objects.requireNonNull(resources).getString(R.string.nc_limit_hit), @@ -647,6 +652,15 @@ class ChatActivity : } } + fun sendTypingMessage() { + for ((sessionId, participant) in webSocketInstance?.getUserMap()!!) { + val ncSignalingMessage = NCSignalingMessage() + ncSignalingMessage.to = sessionId + ncSignalingMessage.type = "startedTyping" + signalingMessageSender!!.send(ncSignalingMessage) + } + } + private fun initMessageHolders(): MessageHolders { val messageHolders = MessageHolders() val profileBottomSheet = ProfileBottomSheet(ncApi, conversationUser!!) @@ -2323,6 +2337,8 @@ class ChatActivity : if (webSocketInstance == null) { Log.d(TAG, "webSocketInstance not set up. This should only happen when not using the HPB") } + + signalingMessageSender = webSocketInstance?.signalingMessageSender } fun pullChatMessages( diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketInstance.kt b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketInstance.kt index f66e2431a..6b249f18a 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketInstance.kt +++ b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketInstance.kt @@ -206,6 +206,8 @@ class WebSocketInstance internal constructor( processRoomMessageMessage(eventOverallWebSocketMessage) } else if ("join" == eventOverallWebSocketMessage.eventMap!!["type"]) { processRoomJoinMessage(eventOverallWebSocketMessage) + } else if ("leave" == eventOverallWebSocketMessage.eventMap!!["type"]) { + processRoomLeaveMessage(eventOverallWebSocketMessage) } signalingMessageReceiver.process(eventOverallWebSocketMessage.eventMap) } @@ -271,6 +273,17 @@ class WebSocketInstance internal constructor( } } + private fun processRoomLeaveMessage(eventOverallWebSocketMessage: EventOverallWebSocketMessage) { + val leaveEventList = eventOverallWebSocketMessage.eventMap?.get("leave") as List? + for (i in leaveEventList!!.indices) { + usersHashMap.remove(leaveEventList[i]) + } + } + + fun getUserMap(): HashMap { + return usersHashMap + } + @Throws(IOException::class) private fun processJoinedRoomMessage(text: String) { val (_, roomWebSocketMessage) = LoganSquare.parse(text, JoinedRoomOverallWebSocketMessage::class.java)