@@ -112,14 +112,15 @@ class GroupsV2StateProcessor private constructor(
112
112
@WorkerThread
113
113
@Throws(IOException ::class , GroupNotAMemberException ::class )
114
114
fun forceSanityUpdateFromServer (timestamp : Long ): GroupUpdateResult {
115
- val currentLocalState: DecryptedGroup ? = SignalDatabase .groups.getGroup(groupId).map { it.requireV2GroupProperties().decryptedGroup }.orNull()
115
+ val groupRecord = SignalDatabase .groups.getGroup(groupId).orNull()
116
+ val currentLocalState: DecryptedGroup ? = groupRecord?.requireV2GroupProperties()?.decryptedGroup
116
117
117
118
if (currentLocalState == null ) {
118
119
Log .i(TAG , " $logPrefix No local state to force update" )
119
120
return GroupUpdateResult .CONSISTENT_OR_AHEAD
120
121
}
121
122
122
- return when (val result = updateToLatestViaServer(timestamp, currentLocalState, reconstructChange = true )) {
123
+ return when (val result = updateToLatestViaServer(timestamp, currentLocalState, reconstructChange = true , forceUpdate = ! groupRecord.isActive )) {
123
124
InternalUpdateResult .NoUpdateNeeded -> GroupUpdateResult .CONSISTENT_OR_AHEAD
124
125
is InternalUpdateResult .Updated -> GroupUpdateResult (GroupUpdateResult .UpdateStatus .GROUP_UPDATED , result.updatedLocalState)
125
126
is InternalUpdateResult .NotAMember -> throw result.exception
@@ -267,7 +268,8 @@ class GroupsV2StateProcessor private constructor(
267
268
timestamp = timestamp,
268
269
serverGuid = serverGuid,
269
270
groupStateDiff = groupStateDiff,
270
- groupSendEndorsements = null
271
+ groupSendEndorsements = null ,
272
+ forceSave = forceApply
271
273
)
272
274
}
273
275
@@ -281,7 +283,7 @@ class GroupsV2StateProcessor private constructor(
281
283
282
284
if (targetRevision == LATEST && (currentLocalState == null || currentLocalState.revision == RESTORE_PLACEHOLDER_REVISION )) {
283
285
Log .i(TAG , " $logPrefix Latest revision only, update to latest directly" )
284
- return updateToLatestViaServer(timestamp, currentLocalState, reconstructChange = false )
286
+ return updateToLatestViaServer(timestamp, currentLocalState, reconstructChange = false , forceUpdate = false )
285
287
}
286
288
287
289
Log .i(TAG , " $logPrefix Paging from server targetRevision: ${if (targetRevision == LATEST ) " latest" else targetRevision} " )
@@ -292,7 +294,7 @@ class GroupsV2StateProcessor private constructor(
292
294
val joinedAtFailure = InternalUpdateResult .from(joinedAtResult.getCause()!! )
293
295
if (joinedAtFailure is InternalUpdateResult .NotAMember ) {
294
296
Log .i(TAG , " $logPrefix Not a member, try to update to latest directly" )
295
- return updateToLatestViaServer(timestamp, currentLocalState, reconstructChange = currentLocalState != null )
297
+ return updateToLatestViaServer(timestamp, currentLocalState, reconstructChange = currentLocalState != null , forceUpdate = true )
296
298
} else {
297
299
return joinedAtFailure
298
300
}
@@ -322,7 +324,9 @@ class GroupsV2StateProcessor private constructor(
322
324
val applyGroupStateDiffResult: AdvanceGroupStateResult = GroupStatePatcher .applyGroupStateDiff(remoteGroupStateDiff, targetRevision)
323
325
val updatedGroupState: DecryptedGroup ? = applyGroupStateDiffResult.updatedGroupState
324
326
325
- if (updatedGroupState == null || updatedGroupState == remoteGroupStateDiff.previousGroupState) {
327
+ if (groupRecord.map { it.isActive }.orNull() == false && updatedGroupState != null && updatedGroupState == remoteGroupStateDiff.previousGroupState) {
328
+ Log .w(TAG , " $logPrefix Local state is not active, but server is returning state for us, apply regardless of revision" )
329
+ } else if (updatedGroupState == null || updatedGroupState == remoteGroupStateDiff.previousGroupState) {
326
330
Log .i(TAG , " $logPrefix Local state is at or later than server revision: ${currentLocalState?.revision ? : " null" } " )
327
331
328
332
if (currentLocalState != null && applyGroupStateDiffResult.remainingRemoteGroupChanges.isEmpty()) {
@@ -391,7 +395,7 @@ class GroupsV2StateProcessor private constructor(
391
395
return InternalUpdateResult .Updated (currentLocalState!! )
392
396
}
393
397
394
- private fun updateToLatestViaServer (timestamp : Long , currentLocalState : DecryptedGroup ? , reconstructChange : Boolean ): InternalUpdateResult {
398
+ private fun updateToLatestViaServer (timestamp : Long , currentLocalState : DecryptedGroup ? , reconstructChange : Boolean , forceUpdate : Boolean ): InternalUpdateResult {
395
399
val result = groupsApi.getGroupAsResult(groupSecretParams, groupsV2Authorization.getAuthorizationForToday(serviceIds, groupSecretParams))
396
400
397
401
val groupResponse = if (result is NetworkResult .Success ) {
@@ -407,7 +411,8 @@ class GroupsV2StateProcessor private constructor(
407
411
timestamp = timestamp,
408
412
serverGuid = null ,
409
413
groupStateDiff = remoteGroupStateDiff,
410
- groupSendEndorsements = groupOperations.receiveGroupSendEndorsements(serviceIds.aci, groupResponse.group, groupResponse.groupSendEndorsementsResponse)
414
+ groupSendEndorsements = groupOperations.receiveGroupSendEndorsements(serviceIds.aci, groupResponse.group, groupResponse.groupSendEndorsementsResponse),
415
+ forceSave = forceUpdate && groupResponse.group.members.asSequence().mapNotNull { ACI .parseOrNull(it.aciBytes) }.any { serviceIds.matches(it) }
411
416
)
412
417
}
413
418
@@ -480,13 +485,16 @@ class GroupsV2StateProcessor private constructor(
480
485
timestamp : Long ,
481
486
serverGuid : String? ,
482
487
groupStateDiff : GroupStateDiff ,
483
- groupSendEndorsements : ReceivedGroupSendEndorsements ?
488
+ groupSendEndorsements : ReceivedGroupSendEndorsements ? ,
489
+ forceSave : Boolean
484
490
): InternalUpdateResult {
485
491
val currentLocalState: DecryptedGroup ? = groupStateDiff.previousGroupState
486
492
val applyGroupStateDiffResult = GroupStatePatcher .applyGroupStateDiff(groupStateDiff, GroupStatePatcher .LATEST )
487
493
val updatedGroupState = applyGroupStateDiffResult.updatedGroupState
488
494
489
- if (updatedGroupState == null || updatedGroupState == groupStateDiff.previousGroupState) {
495
+ if (forceSave && updatedGroupState != null ) {
496
+ Log .w(TAG , " $logPrefix Forcing local state update regardless of revision" )
497
+ } else if (updatedGroupState == null || updatedGroupState == groupStateDiff.previousGroupState) {
490
498
Log .i(TAG , " $logPrefix Local state and server state are equal" )
491
499
492
500
if (groupSendEndorsements != null ) {
0 commit comments