Search in sources :

Example 1 with GroupChanges

use of org.signal.storageservice.protos.groups.GroupChanges in project Signal-Android by WhisperSystems.

the class PushServiceSocket method getGroupsV2GroupHistory.

public GroupHistory getGroupsV2GroupHistory(int fromVersion, GroupsV2AuthorizationString authorization, int highestKnownEpoch, boolean includeFirstState) throws IOException {
    Response response = makeStorageRequestResponse(authorization.toString(), String.format(Locale.US, GROUPSV2_GROUP_CHANGES, fromVersion, highestKnownEpoch, includeFirstState), "GET", null, GROUPS_V2_GET_LOGS_HANDLER);
    if (response.body() == null) {
        throw new PushNetworkException("No body!");
    }
    GroupChanges groupChanges;
    try (InputStream input = response.body().byteStream()) {
        groupChanges = GroupChanges.parseFrom(input);
    } catch (IOException e) {
        throw new PushNetworkException(e);
    }
    if (response.code() == 206) {
        String contentRangeHeader = response.header("Content-Range");
        Optional<ContentRange> contentRange = ContentRange.parse(contentRangeHeader);
        if (contentRange.isPresent()) {
            Log.i(TAG, "Additional logs for group: " + contentRangeHeader);
            return new GroupHistory(groupChanges, contentRange);
        } else {
            Log.w(TAG, "Unable to parse Content-Range header: " + contentRangeHeader);
            throw new MalformedResponseException("Unable to parse content range header on 206");
        }
    }
    return new GroupHistory(groupChanges, Optional.absent());
}
Also used : CallingResponse(org.whispersystems.signalservice.api.messages.calls.CallingResponse) Response(okhttp3.Response) KeyBackupResponse(org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResponse) ReceiptCredentialResponse(org.signal.zkgroup.receipts.ReceiptCredentialResponse) CredentialResponse(org.whispersystems.signalservice.api.groupsv2.CredentialResponse) StorageAuthResponse(org.whispersystems.signalservice.api.storage.StorageAuthResponse) VerifyDeviceResponse(org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse) DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) ProfileKeyCredentialResponse(org.signal.zkgroup.profiles.ProfileKeyCredentialResponse) TokenResponse(org.whispersystems.signalservice.internal.contacts.entities.TokenResponse) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) GroupChanges(org.signal.storageservice.protos.groups.GroupChanges) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Example 2 with GroupChanges

use of org.signal.storageservice.protos.groups.GroupChanges in project Signal-Android by signalapp.

the class PushServiceSocket method getGroupsV2GroupHistory.

public GroupHistory getGroupsV2GroupHistory(int fromVersion, GroupsV2AuthorizationString authorization, int highestKnownEpoch, boolean includeFirstState) throws IOException {
    Response response = makeStorageRequestResponse(authorization.toString(), String.format(Locale.US, GROUPSV2_GROUP_CHANGES, fromVersion, highestKnownEpoch, includeFirstState), "GET", null, GROUPS_V2_GET_LOGS_HANDLER);
    if (response.body() == null) {
        throw new PushNetworkException("No body!");
    }
    GroupChanges groupChanges;
    try (InputStream input = response.body().byteStream()) {
        groupChanges = GroupChanges.parseFrom(input);
    } catch (IOException e) {
        throw new PushNetworkException(e);
    }
    if (response.code() == 206) {
        String contentRangeHeader = response.header("Content-Range");
        Optional<ContentRange> contentRange = ContentRange.parse(contentRangeHeader);
        if (contentRange.isPresent()) {
            Log.i(TAG, "Additional logs for group: " + contentRangeHeader);
            return new GroupHistory(groupChanges, contentRange);
        } else {
            Log.w(TAG, "Unable to parse Content-Range header: " + contentRangeHeader);
            throw new MalformedResponseException("Unable to parse content range header on 206");
        }
    }
    return new GroupHistory(groupChanges, Optional.absent());
}
Also used : CallingResponse(org.whispersystems.signalservice.api.messages.calls.CallingResponse) Response(okhttp3.Response) KeyBackupResponse(org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResponse) ReceiptCredentialResponse(org.signal.zkgroup.receipts.ReceiptCredentialResponse) CredentialResponse(org.whispersystems.signalservice.api.groupsv2.CredentialResponse) StorageAuthResponse(org.whispersystems.signalservice.api.storage.StorageAuthResponse) VerifyDeviceResponse(org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse) DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) ProfileKeyCredentialResponse(org.signal.zkgroup.profiles.ProfileKeyCredentialResponse) TokenResponse(org.whispersystems.signalservice.internal.contacts.entities.TokenResponse) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) GroupChanges(org.signal.storageservice.protos.groups.GroupChanges) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Response (okhttp3.Response)2 GroupChanges (org.signal.storageservice.protos.groups.GroupChanges)2 ProfileKeyCredentialResponse (org.signal.zkgroup.profiles.ProfileKeyCredentialResponse)2 ReceiptCredentialResponse (org.signal.zkgroup.receipts.ReceiptCredentialResponse)2 CredentialResponse (org.whispersystems.signalservice.api.groupsv2.CredentialResponse)2 GroupsV2AuthorizationString (org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString)2 CallingResponse (org.whispersystems.signalservice.api.messages.calls.CallingResponse)2 VerifyDeviceResponse (org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse)2 MalformedResponseException (org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)2 PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)2 StorageAuthResponse (org.whispersystems.signalservice.api.storage.StorageAuthResponse)2 DiscoveryResponse (org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse)2 KeyBackupResponse (org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResponse)2 TokenResponse (org.whispersystems.signalservice.internal.contacts.entities.TokenResponse)2