mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Update the algorithm to find an existing DM: simplify and make sure there is only 2 people in the room
This commit is contained in:
parent
a393c4dfae
commit
1bc726abff
2 changed files with 10 additions and 4 deletions
|
@ -131,6 +131,14 @@ interface RoomService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the roomId of an existing DM with the other user, or null if such room does not exist
|
* Return the roomId of an existing DM with the other user, or null if such room does not exist
|
||||||
|
* A room is a DM if:
|
||||||
|
* - it is listed in the `m.direct` account data
|
||||||
|
* - the current user has joined the room
|
||||||
|
* - the other user is invited or has joined the room
|
||||||
|
* - it has exactly 2 members
|
||||||
|
* Note:
|
||||||
|
* - the returning room can be encrypted or not
|
||||||
|
* - the power level of the users are not taken into account. Normally in a DM, the 2 members are admins of the room
|
||||||
*/
|
*/
|
||||||
fun getExistingDirectRoomWithUser(otherUserId: String): String?
|
fun getExistingDirectRoomWithUser(otherUserId: String): String?
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
|
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.query.where
|
import org.matrix.android.sdk.internal.database.query.where
|
||||||
import org.matrix.android.sdk.internal.session.SessionScope
|
import org.matrix.android.sdk.internal.session.SessionScope
|
||||||
import org.matrix.android.sdk.internal.session.room.membership.RoomMemberHelper
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface RoomGetter {
|
internal interface RoomGetter {
|
||||||
|
@ -52,9 +51,8 @@ internal class DefaultRoomGetter @Inject constructor(
|
||||||
.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
|
.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
|
||||||
.equalTo(RoomSummaryEntityFields.MEMBERSHIP_STR, Membership.JOIN.name)
|
.equalTo(RoomSummaryEntityFields.MEMBERSHIP_STR, Membership.JOIN.name)
|
||||||
.findAll()
|
.findAll()
|
||||||
.filter { dm -> dm.otherMemberIds.contains(otherUserId) }
|
.firstOrNull { dm -> dm.otherMemberIds.size == 1 && dm.otherMemberIds.first() == otherUserId }
|
||||||
.map { it.roomId }
|
?.roomId
|
||||||
.firstOrNull { roomId -> otherUserId in RoomMemberHelper(realm, roomId).getActiveRoomMemberIds() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue