Repository navigation
fix(chat): show typing only from participants of the current conversation #6905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ToteMeiSter
wants to merge
1
commit into
nextcloud:master
Choose a base branch
from
ToteMeiSter:fix/typing-indicator-room-sessions-v3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/src/main/java/com/nextcloud/talk/webrtc/RoomSessionRegistry.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * Nextcloud Talk - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
| package com.nextcloud.talk.webrtc | ||
|
|
||
| import com.nextcloud.talk.models.json.participants.ParticipantDto | ||
| import com.nextcloud.talk.models.json.participants.ParticipantDto.ActorType | ||
| import java.util.concurrent.ConcurrentHashMap | ||
|
|
||
| /** | ||
| * The signaling sessions of the room the external signaling connection is currently in. | ||
| * | ||
| * One [WebSocketInstance] lives per account and is shared by all conversations opened with that account, but the | ||
| * signaling server only reports the sessions of the room the connection joined. So the set must hold exactly the | ||
| * sessions of the current room: sessions of a previous room (or of an expired connection) must not stay in it, | ||
| * otherwise typing messages are sent to sessions of other rooms and typing messages of such sessions are accepted | ||
| * (the server delivers messages addressed to a session no matter which room that session is in). | ||
| * | ||
| * Written from the OkHttp thread and from the UI thread ([reset] on leaving a room), read from the UI thread. | ||
| * The changes of the room and of the sessions ([onRoomResponse], [reset], [onJoin]) share one lock, so a join cannot | ||
| * store a session after a [reset] cleared the registry. | ||
| */ | ||
| class RoomSessionRegistry { | ||
| private val sessions = ConcurrentHashMap<String, ParticipantDto>() | ||
|
|
||
| @Volatile | ||
| private var roomToken: String? = null | ||
|
|
||
| /** | ||
| * The server answers every room join/leave with a "room" message. It is sent before the list of the sessions | ||
| * of the new room, so clearing here cannot drop sessions of the new room. The same room (re-sent for an | ||
| * unchanged join) keeps its sessions. After [reset] the room is unknown, so the answer to a leave (empty room) | ||
| * clears as well: it drops what late events of the left room added in between. | ||
| */ | ||
| @Synchronized | ||
| fun onRoomResponse(newRoomToken: String?) { | ||
| val token = newRoomToken ?: "" | ||
| if (token != roomToken) { | ||
| sessions.clear() | ||
| roomToken = token | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The connection leaves the room, got a new signaling session (hello without resume) or lost it | ||
| * (no_such_session, no_such_room). Nothing is known about the room any more. | ||
| */ | ||
| @Synchronized | ||
| fun reset() { | ||
| sessions.clear() | ||
| roomToken = null | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Processes the "join" list of a room event: maps with "sessionid", optional "userid" and optional "user" | ||
| * (with "displayname"). A guest joins without "userid" and stays in the registry. | ||
| * | ||
| * Ignored while no room is known (after [reset] or the answer to a leave): the server sends the answer to a join | ||
| * before the list of the sessions, so a join arriving without a room is a late event of a room which was left. | ||
| */ | ||
| @Synchronized | ||
| fun onJoin(joinEvents: List<Map<String, Any>>?) { | ||
| if (roomToken.isNullOrEmpty()) return | ||
|
ToteMeiSter marked this conversation as resolved.
|
||
|
|
||
| joinEvents?.forEach { event -> | ||
| val sessionId = event["sessionid"] as? String ?: return@forEach | ||
| val participant = ParticipantDto() | ||
| val userId = event["userid"] as? String | ||
| if (userId != null) { | ||
| participant.actorType = ActorType.USERS | ||
| participant.actorId = userId | ||
| } else { | ||
| participant.actorType = ActorType.GUESTS | ||
| } | ||
| // There is no "user" attribute for guest participants. | ||
| val userMap = event["user"] as? Map<*, *> | ||
| participant.displayName = userMap?.get("displayname") as? String | ||
| sessions[sessionId] = participant | ||
| } | ||
| } | ||
|
|
||
| fun onLeave(sessionIds: List<String>?) { | ||
| sessionIds?.forEach { sessions.remove(it) } | ||
| } | ||
|
|
||
| fun contains(sessionId: String?): Boolean = sessionId != null && sessions.containsKey(sessionId) | ||
|
|
||
| /** Display name of the session, or "" if the session is unknown or has no name (e.g. a guest). */ | ||
| fun displayNameFor(sessionId: String?): String = sessionId?.let { sessions[it]?.displayName } ?: "" | ||
|
|
||
| /** Snapshot of the sessions of the current room, without the own session. */ | ||
| fun sessionIdsExcept(ownSessionId: String?): List<String> = sessions.keys.filter { it != ownSessionId } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.