diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/v2/processing/GroupsV2StateProcessor.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/v2/processing/GroupsV2StateProcessor.kt index 00382ee4a4..f4ea6c8b13 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/v2/processing/GroupsV2StateProcessor.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/v2/processing/GroupsV2StateProcessor.kt @@ -279,20 +279,27 @@ class GroupsV2StateProcessor private constructor( ): InternalUpdateResult { var currentLocalState: DecryptedGroup? = groupRecord.map { it.requireV2GroupProperties().decryptedGroup }.orNull() - val latestRevisionOnly = targetRevision == LATEST && (currentLocalState == null || currentLocalState.revision == RESTORE_PLACEHOLDER_REVISION) - - if (latestRevisionOnly) { - Log.i(TAG, "$logPrefix Latest revision or not a member, update to latest directly") + if (targetRevision == LATEST && (currentLocalState == null || currentLocalState.revision == RESTORE_PLACEHOLDER_REVISION)) { + Log.i(TAG, "$logPrefix Latest revision only, update to latest directly") return updateToLatestViaServer(timestamp, currentLocalState, reconstructChange = false) } Log.i(TAG, "$logPrefix Paging from server targetRevision: ${if (targetRevision == LATEST) "latest" else targetRevision}") - val joinedAtRevision = when (val result = groupsApi.getGroupJoinedAt(groupsV2Authorization.getAuthorizationForToday(serviceIds, groupSecretParams))) { - is NetworkResult.Success -> result.result - else -> return InternalUpdateResult.from(result.getCause()!!) + val joinedAtResult = groupsApi.getGroupJoinedAt(groupsV2Authorization.getAuthorizationForToday(serviceIds, groupSecretParams)) + + if (joinedAtResult !is NetworkResult.Success) { + val joinedAtFailure = InternalUpdateResult.from(joinedAtResult.getCause()!!) + if (joinedAtFailure is InternalUpdateResult.NotAMember) { + Log.i(TAG, "$logPrefix Not a member, try to update to latest directly") + return updateToLatestViaServer(timestamp, currentLocalState, reconstructChange = currentLocalState != null) + } else { + return joinedAtFailure + } } + val joinedAtRevision = joinedAtResult.result + val sendEndorsementExpiration = groupRecord.map { it.groupSendEndorsementExpiration }.orElse(0L) var includeFirstState = currentLocalState == null || diff --git a/app/src/test/java/org/thoughtcrime/securesms/groups/v2/processing/GroupsV2StateProcessorTest.kt b/app/src/test/java/org/thoughtcrime/securesms/groups/v2/processing/GroupsV2StateProcessorTest.kt index 3ecf85d19e..74c378837f 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/groups/v2/processing/GroupsV2StateProcessorTest.kt +++ b/app/src/test/java/org/thoughtcrime/securesms/groups/v2/processing/GroupsV2StateProcessorTest.kt @@ -450,6 +450,7 @@ class GroupsV2StateProcessorTest { } every { groupsV2API.getGroupJoinedAt(any()) } returns NetworkResult.StatusCodeError(NotInGroupException()) + every { groupsV2API.getGroupAsResult(any(), any()) } returns NetworkResult.StatusCodeError(NotInGroupException()) val signedChange = DecryptedGroupChange( revision = 2, @@ -477,6 +478,7 @@ class GroupsV2StateProcessorTest { } every { groupsV2API.getGroupJoinedAt(any()) } returns NetworkResult.StatusCodeError(NotInGroupException()) + every { groupsV2API.getGroupAsResult(any(), any()) } returns NetworkResult.StatusCodeError(NotInGroupException()) val signedChange = DecryptedGroupChange( revision = 3, diff --git a/libsignal-service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java b/libsignal-service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java index 241282338c..9eae04814f 100644 --- a/libsignal-service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java +++ b/libsignal-service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java @@ -2798,7 +2798,6 @@ public class PushServiceSocket { private static final ResponseCodeHandler GROUPS_V2_PUT_RESPONSE_HANDLER = (responseCode, body) -> { if (responseCode == 409) throw new GroupExistsException(); };; - private static final ResponseCodeHandler GROUPS_V2_GET_LOGS_HANDLER = NO_HANDLER; private static final ResponseCodeHandler GROUPS_V2_GET_CURRENT_HANDLER = (responseCode, body) -> { switch (responseCode) { case 403: throw new NotInGroupException(); @@ -2893,7 +2892,7 @@ public class PushServiceSocket { "GET", null, headers, - GROUPS_V2_GET_LOGS_HANDLER)) + GROUPS_V2_GET_CURRENT_HANDLER)) { if (response.body() == null) {