add sending of "typing" signaling messages

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-05-16 16:32:44 +02:00
parent 8997c3b5c7
commit 6228ec8d75
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
2 changed files with 30 additions and 1 deletions

View file

@ -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>(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(

View file

@ -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<String>?
for (i in leaveEventList!!.indices) {
usersHashMap.remove(leaveEventList[i])
}
}
fun getUserMap(): HashMap<String?, Participant> {
return usersHashMap
}
@Throws(IOException::class)
private fun processJoinedRoomMessage(text: String) {
val (_, roomWebSocketMessage) = LoganSquare.parse(text, JoinedRoomOverallWebSocketMessage::class.java)