mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 02:45:53 +03:00
We only need the roomId in many cases, so update the API
This commit is contained in:
parent
4433436416
commit
d9723387eb
5 changed files with 11 additions and 9 deletions
|
@ -129,5 +129,8 @@ interface RoomService {
|
|||
*/
|
||||
fun getChangeMembershipsLive(): LiveData<Map<String, ChangeMembershipState>>
|
||||
|
||||
fun getExistingDirectRoomWithUser(otherUserId: String): Room?
|
||||
/**
|
||||
* Return the roomId of an existing DM with the other user, or null if such room does not exist
|
||||
*/
|
||||
fun getExistingDirectRoomWithUser(otherUserId: String): String?
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ internal class DefaultRoomService @Inject constructor(
|
|||
return roomGetter.getRoom(roomId)
|
||||
}
|
||||
|
||||
override fun getExistingDirectRoomWithUser(otherUserId: String): Room? {
|
||||
override fun getExistingDirectRoomWithUser(otherUserId: String): String? {
|
||||
return roomGetter.getDirectRoomWith(otherUserId)
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import javax.inject.Inject
|
|||
internal interface RoomGetter {
|
||||
fun getRoom(roomId: String): Room?
|
||||
|
||||
fun getDirectRoomWith(otherUserId: String): Room?
|
||||
fun getDirectRoomWith(otherUserId: String): String?
|
||||
}
|
||||
|
||||
@SessionScope
|
||||
|
@ -46,7 +46,7 @@ internal class DefaultRoomGetter @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getDirectRoomWith(otherUserId: String): Room? {
|
||||
override fun getDirectRoomWith(otherUserId: String): String? {
|
||||
return realmSessionProvider.withRealm { realm ->
|
||||
RoomSummaryEntity.where(realm)
|
||||
.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
|
||||
|
@ -55,7 +55,6 @@ internal class DefaultRoomGetter @Inject constructor(
|
|||
.filter { dm -> dm.otherMemberIds.contains(otherUserId) }
|
||||
.map { it.roomId }
|
||||
.firstOrNull { roomId -> otherUserId in RoomMemberHelper(realm, roomId).getActiveRoomMemberIds() }
|
||||
?.let { roomId -> createRoom(realm, roomId) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
|
|||
override fun handle(action: VerificationAction) = withState { state ->
|
||||
val otherUserId = state.otherUserMxItem?.id ?: return@withState
|
||||
val roomId = state.roomId
|
||||
?: session.getExistingDirectRoomWithUser(otherUserId)?.roomId
|
||||
?: session.getExistingDirectRoomWithUser(otherUserId)
|
||||
|
||||
when (action) {
|
||||
is VerificationAction.RequestVerificationByDM -> {
|
||||
|
|
|
@ -279,8 +279,8 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun handleOpenOrCreateDm(action: RoomDetailAction.OpenOrCreateDm) {
|
||||
val existingDm = session.getExistingDirectRoomWithUser(action.userId)
|
||||
if (existingDm == null) {
|
||||
val existingDmRoomId = session.getExistingDirectRoomWithUser(action.userId)
|
||||
if (existingDmRoomId == null) {
|
||||
// First create a direct room
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val roomId = awaitCallback<String> {
|
||||
|
@ -289,7 +289,7 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
_viewEvents.post(RoomDetailViewEvents.OpenRoom(roomId))
|
||||
}
|
||||
} else {
|
||||
_viewEvents.post(RoomDetailViewEvents.OpenRoom(existingDm.roomId))
|
||||
_viewEvents.post(RoomDetailViewEvents.OpenRoom(existingDmRoomId))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue