16
16
17
17
package im.vector.app.features.spaces.invite
18
18
19
+ import androidx.lifecycle.viewModelScope
19
20
import com.airbnb.mvrx.ActivityViewModelContext
20
21
import com.airbnb.mvrx.Fail
21
22
import com.airbnb.mvrx.FragmentViewModelContext
@@ -32,7 +33,11 @@ import im.vector.app.core.platform.VectorViewModel
32
33
import im.vector.app.features.session.coroutineScope
33
34
import kotlinx.coroutines.Dispatchers
34
35
import kotlinx.coroutines.launch
36
+ import org.matrix.android.sdk.api.extensions.tryOrNull
35
37
import org.matrix.android.sdk.api.session.Session
38
+ import org.matrix.android.sdk.api.session.room.model.Membership
39
+ import org.matrix.android.sdk.api.session.room.model.RoomSummary
40
+ import org.matrix.android.sdk.api.session.room.peeking.PeekResult
36
41
37
42
class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
38
43
@Assisted private val initialState : SpaceInviteBottomSheetState ,
@@ -42,7 +47,6 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
42
47
43
48
init {
44
49
session.getRoomSummary(initialState.spaceId)?.let { roomSummary ->
45
-
46
50
val knownMembers = roomSummary.otherMemberIds.filter {
47
51
session.getExistingDirectRoomWithUser(it) != null
48
52
}.mapNotNull { session.getUser(it) }
@@ -57,6 +61,34 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
57
61
peopleYouKnow = Success (peopleYouKnow)
58
62
)
59
63
}
64
+ if (roomSummary.membership == Membership .INVITE ) {
65
+ getLatestRoomSummary(roomSummary)
66
+ }
67
+ }
68
+ }
69
+
70
+ /* *
71
+ * Try to request the room summary api to get more info
72
+ */
73
+ private fun getLatestRoomSummary (roomSummary : RoomSummary ) {
74
+ viewModelScope.launch(Dispatchers .IO ) {
75
+ val peekResult = tryOrNull { session.peekRoom(roomSummary.roomId) } as ? PeekResult .Success ? : return @launch
76
+ setState {
77
+ copy(
78
+ summary = Success (
79
+ roomSummary.copy(
80
+ joinedMembersCount = peekResult.numJoinedMembers,
81
+ // it's also possible that the name/avatar did change since the invite..
82
+ // if it's null keep the old one as summary API might not be available
83
+ // and peek result could be null for other reasons (not peekable)
84
+ avatarUrl = peekResult.avatarUrl ? : roomSummary.avatarUrl,
85
+ displayName = peekResult.name ? : roomSummary.displayName,
86
+ topic = peekResult.topic ? : roomSummary.topic
87
+ // maybe use someMembers field later?
88
+ )
89
+ )
90
+ )
91
+ }
60
92
}
61
93
}
62
94
0 commit comments