We only need the roomId in many cases, so update the API
This commit is contained in:
parent
4433436416
commit
d9723387eb
|
@ -129,5 +129,8 @@ interface RoomService {
|
||||||
*/
|
*/
|
||||||
fun getChangeMembershipsLive(): LiveData<Map<String, ChangeMembershipState>>
|
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)
|
return roomGetter.getRoom(roomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getExistingDirectRoomWithUser(otherUserId: String): Room? {
|
override fun getExistingDirectRoomWithUser(otherUserId: String): String? {
|
||||||
return roomGetter.getDirectRoomWith(otherUserId)
|
return roomGetter.getDirectRoomWith(otherUserId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import javax.inject.Inject
|
||||||
internal interface RoomGetter {
|
internal interface RoomGetter {
|
||||||
fun getRoom(roomId: String): Room?
|
fun getRoom(roomId: String): Room?
|
||||||
|
|
||||||
fun getDirectRoomWith(otherUserId: String): Room?
|
fun getDirectRoomWith(otherUserId: String): String?
|
||||||
}
|
}
|
||||||
|
|
||||||
@SessionScope
|
@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 ->
|
return realmSessionProvider.withRealm { realm ->
|
||||||
RoomSummaryEntity.where(realm)
|
RoomSummaryEntity.where(realm)
|
||||||
.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
|
.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
|
||||||
|
@ -55,7 +55,6 @@ internal class DefaultRoomGetter @Inject constructor(
|
||||||
.filter { dm -> dm.otherMemberIds.contains(otherUserId) }
|
.filter { dm -> dm.otherMemberIds.contains(otherUserId) }
|
||||||
.map { it.roomId }
|
.map { it.roomId }
|
||||||
.firstOrNull { roomId -> otherUserId in RoomMemberHelper(realm, roomId).getActiveRoomMemberIds() }
|
.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 ->
|
override fun handle(action: VerificationAction) = withState { state ->
|
||||||
val otherUserId = state.otherUserMxItem?.id ?: return@withState
|
val otherUserId = state.otherUserMxItem?.id ?: return@withState
|
||||||
val roomId = state.roomId
|
val roomId = state.roomId
|
||||||
?: session.getExistingDirectRoomWithUser(otherUserId)?.roomId
|
?: session.getExistingDirectRoomWithUser(otherUserId)
|
||||||
|
|
||||||
when (action) {
|
when (action) {
|
||||||
is VerificationAction.RequestVerificationByDM -> {
|
is VerificationAction.RequestVerificationByDM -> {
|
||||||
|
|
|
@ -279,8 +279,8 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleOpenOrCreateDm(action: RoomDetailAction.OpenOrCreateDm) {
|
private fun handleOpenOrCreateDm(action: RoomDetailAction.OpenOrCreateDm) {
|
||||||
val existingDm = session.getExistingDirectRoomWithUser(action.userId)
|
val existingDmRoomId = session.getExistingDirectRoomWithUser(action.userId)
|
||||||
if (existingDm == null) {
|
if (existingDmRoomId == null) {
|
||||||
// First create a direct room
|
// First create a direct room
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val roomId = awaitCallback<String> {
|
val roomId = awaitCallback<String> {
|
||||||
|
@ -289,7 +289,7 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
_viewEvents.post(RoomDetailViewEvents.OpenRoom(roomId))
|
_viewEvents.post(RoomDetailViewEvents.OpenRoom(roomId))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_viewEvents.post(RoomDetailViewEvents.OpenRoom(existingDm.roomId))
|
_viewEvents.post(RoomDetailViewEvents.OpenRoom(existingDmRoomId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue