Skip to content

Commit 38ead5d

Browse files
authored
SES-5127 : Promotion acceptance lags behind (session-foundation#1850)
* Added member promotion update * Cleanup * Cleanups * Revert "Cleanups" This reverts commit 7539f5d. * Update promotion message handling * Change requests
1 parent 971334b commit 38ead5d

5 files changed

Lines changed: 34 additions & 26 deletions

File tree

app/src/main/java/org/thoughtcrime/securesms/groups/BaseGroupMembersViewModel.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ abstract class BaseGroupMembersViewModel(
4444
private val storage: StorageProtocol,
4545
private val configFactory: ConfigFactoryProtocol,
4646
private val avatarUtils: AvatarUtils,
47-
private val recipientRepository: RecipientRepository,
47+
private val recipientRepository: RecipientRepository
4848
) : ViewModel() {
4949
private val groupId = groupAddress.accountId
5050

5151
// Output: the source-of-truth group information. Other states are derived from this.
52+
@OptIn(FlowPreview::class)
5253
protected val groupInfo: StateFlow<Pair<GroupDisplayInfo, List<GroupMemberState>>?> =
5354
(configFactory.configUpdateNotifications
5455
.filter {
@@ -65,21 +66,26 @@ abstract class BaseGroupMembersViewModel(
6566
val displayInfo = storage.getClosedGroupDisplayInfo(groupId.hexString)
6667
?: return@withContext null
6768

68-
val rawMembers = configFactory.withGroupConfigs(groupId) { it.groupMembers.allWithStatus() }
69+
val rawMembers =
70+
configFactory.withGroupConfigs(groupId) { it.groupMembers.allWithStatus() }
6971

7072
val memberState = mutableListOf<GroupMemberState>()
7173
for ((member, status) in rawMembers) {
72-
memberState.add(createGroupMember(
73-
member = member, status = status,
74-
shouldShowProBadge = recipientRepository.getRecipient(member.accountId().toAddress()).shouldShowProBadge,
75-
myAccountId = currentUserId,
76-
amIAdmin = displayInfo.isUserAdmin
77-
))
74+
memberState.add(
75+
createGroupMember(
76+
member = member, status = status,
77+
shouldShowProBadge = recipientRepository.getRecipient(
78+
member.accountId().toAddress()
79+
).shouldShowProBadge,
80+
myAccountId = currentUserId,
81+
amIAdmin = displayInfo.isUserAdmin
82+
)
83+
)
7884
}
7985

8086
displayInfo to sortMembers(memberState, currentUserId)
8187
}
82-
}.stateIn(viewModelScope, SharingStarted.Eagerly, null)
88+
}.stateIn(viewModelScope, SharingStarted.Eagerly, null)
8389

8490
// Current group name (for header / text, if needed)
8591
val groupName: StateFlow<String> = groupInfo
@@ -174,7 +180,7 @@ abstract class BaseGroupMembersViewModel(
174180
canResendInvite = amIAdmin && memberAccountId != myAccountId
175181
&& !member.isRemoved(status)
176182
&& (status == GroupMember.Status.INVITE_SENT || status == GroupMember.Status.INVITE_FAILED),
177-
status = status.takeIf { !isMyself }, // Status is only meant for other members
183+
status = status.takeIf { !isMyself }, // status is only for other members
178184
highlightStatus = highlightStatus,
179185
showAsAdmin = member.isAdminOrBeingPromoted(status),
180186
showProBadge = shouldShowProBadge,

app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import com.squareup.phrase.Phrase
66
import dagger.hilt.android.qualifiers.ApplicationContext
77
import kotlinx.coroutines.Dispatchers
88
import kotlinx.coroutines.async
9+
import kotlinx.coroutines.delay
910
import kotlinx.coroutines.flow.filter
1011
import kotlinx.coroutines.flow.first
1112
import kotlinx.coroutines.supervisorScope
1213
import kotlinx.coroutines.withContext
1314
import kotlinx.coroutines.withTimeout
15+
import kotlinx.coroutines.withTimeoutOrNull
1416
import network.loki.messenger.R
1517
import network.loki.messenger.libsession_util.ED25519
1618
import network.loki.messenger.libsession_util.Namespace
@@ -44,6 +46,7 @@ import org.session.libsession.snode.OwnedSwarmAuth
4446
import org.session.libsession.snode.SnodeMessage
4547
import org.session.libsession.snode.model.BatchResponse
4648
import org.session.libsession.utilities.Address
49+
import org.session.libsession.utilities.Address.Companion.toAddress
4750
import org.session.libsession.utilities.StringSubstitutionConstants.GROUP_NAME_KEY
4851
import org.session.libsession.utilities.getGroup
4952
import org.session.libsession.utilities.recipients.Recipient
@@ -75,6 +78,7 @@ import org.thoughtcrime.securesms.util.SessionMetaProtocol
7578
import java.util.concurrent.TimeUnit
7679
import javax.inject.Inject
7780
import javax.inject.Singleton
81+
import kotlin.time.Duration.Companion.seconds
7882

7983
private const val TAG = "GroupManagerV2Impl"
8084

@@ -520,12 +524,17 @@ class GroupManagerV2Impl @Inject constructor(
520524
// Update the group member's promotion status
521525
members.asSequence()
522526
.mapNotNull { configs.groupMembers.get(it.hexString) }
523-
.onEach(GroupMember::setPromoted)
527+
.onEach(GroupMember::setPromotionSent)
524528
.forEach(configs.groupMembers::set)
525529

526530
configs.groupInfo.getName()
527531
}
528532

533+
// Ensure this push is complete before promotion messages go out
534+
withTimeoutOrNull(10.seconds) {
535+
configFactory.waitUntilGroupConfigsPushed(group)
536+
}
537+
529538
// Build a group update message to the group telling members someone has been promoted
530539
val timestamp = clock.currentTimeMillis()
531540
val signature = ED25519.sign(
@@ -589,10 +598,11 @@ class GroupManagerV2Impl @Inject constructor(
589598
promotedByMemberIDs.asSequence()
590599
.mapNotNull { (member, result) ->
591600
configs.groupMembers.get(member.hexString)?.apply {
592-
if (result.isSuccess) {
593-
setPromotionSent()
594-
} else {
595-
setPromotionFailed()
601+
if (result.isFailure) {
602+
configs.groupMembers.get(member.hexString)?.let { member ->
603+
member.setPromotionFailed()
604+
configs.groupMembers.set(member)
605+
}
596606
}
597607
}
598608
}

app/src/main/java/org/thoughtcrime/securesms/groups/GroupMembersViewModel.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import org.session.libsession.utilities.ConfigFactoryProtocol
1818
import org.session.libsignal.utilities.AccountId
1919
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
2020
import org.thoughtcrime.securesms.database.RecipientRepository
21-
import org.thoughtcrime.securesms.pro.ProStatusManager
2221
import org.thoughtcrime.securesms.util.AvatarUtils
2322

2423

@@ -29,7 +28,7 @@ class GroupMembersViewModel @AssistedInject constructor(
2928
storage: StorageProtocol,
3029
configFactory: ConfigFactoryProtocol,
3130
avatarUtils: AvatarUtils,
32-
recipientRepository: RecipientRepository,
31+
recipientRepository: RecipientRepository
3332
) : BaseGroupMembersViewModel(address, context, storage, configFactory, avatarUtils, recipientRepository) {
3433

3534
private val _navigationActions = Channel<Intent>()

app/src/main/java/org/thoughtcrime/securesms/groups/ManageGroupAdminsViewModel.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import dagger.assisted.AssistedInject
1010
import dagger.hilt.android.lifecycle.HiltViewModel
1111
import dagger.hilt.android.qualifiers.ApplicationContext
1212
import kotlinx.coroutines.flow.MutableStateFlow
13-
import kotlinx.coroutines.flow.SharingStarted
1413
import kotlinx.coroutines.flow.StateFlow
15-
import kotlinx.coroutines.flow.map
16-
import kotlinx.coroutines.flow.stateIn
14+
import kotlinx.coroutines.flow.combine
1715
import kotlinx.coroutines.flow.update
1816
import kotlinx.coroutines.launch
1917
import network.loki.messenger.R
@@ -84,7 +82,7 @@ class ManageGroupAdminsViewModel @AssistedInject constructor(
8482
init {
8583
// Build footer from selected admins + collapsed state
8684
viewModelScope.launch {
87-
kotlinx.coroutines.flow.combine(
85+
combine(
8886
selectedAdmins,
8987
footerCollapsed,
9088
::buildFooterState

app/src/main/java/org/thoughtcrime/securesms/groups/PromoteMembersViewModel.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ import dagger.assisted.AssistedInject
99
import dagger.hilt.android.lifecycle.HiltViewModel
1010
import dagger.hilt.android.qualifiers.ApplicationContext
1111
import kotlinx.coroutines.flow.MutableStateFlow
12-
import kotlinx.coroutines.flow.SharingStarted
1312
import kotlinx.coroutines.flow.StateFlow
1413
import kotlinx.coroutines.flow.combine
1514
import kotlinx.coroutines.flow.map
16-
import kotlinx.coroutines.flow.stateIn
1715
import kotlinx.coroutines.flow.update
1816
import kotlinx.coroutines.launch
1917
import network.loki.messenger.R
2018
import org.session.libsession.database.StorageProtocol
21-
import org.session.libsession.messaging.groups.GroupManagerV2
2219
import org.session.libsession.utilities.Address
2320
import org.session.libsession.utilities.ConfigFactoryProtocol
2421
import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
@@ -34,7 +31,6 @@ class PromoteMembersViewModel @AssistedInject constructor(
3431
@ApplicationContext private val context: Context,
3532
storage: StorageProtocol,
3633
private val configFactory: ConfigFactoryProtocol,
37-
private val groupManager: GroupManagerV2,
3834
private val recipientRepository: RecipientRepository,
3935
avatarUtils: AvatarUtils,
4036
) : BaseGroupMembersViewModel(
@@ -45,7 +41,6 @@ class PromoteMembersViewModel @AssistedInject constructor(
4541
avatarUtils = avatarUtils,
4642
recipientRepository = recipientRepository
4743
) {
48-
private val groupId = groupAddress.accountId
4944

5045
private val _mutableSelectedMembers = MutableStateFlow(emptySet<GroupMemberState>())
5146
val selectedMembers: StateFlow<Set<GroupMemberState>> = _mutableSelectedMembers

0 commit comments

Comments
 (0)