Search in sources :

Example 1 with DecryptedGroupJoinInfo

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

the class GroupJoinRepository method getGroupDetails.

@WorkerThread
@NonNull
private GroupDetails getGroupDetails() throws VerificationFailedException, IOException, GroupLinkNotActiveException {
    DecryptedGroupJoinInfo joinInfo = GroupManager.getGroupJoinInfoFromServer(context, groupInviteLinkUrl.getGroupMasterKey(), groupInviteLinkUrl.getPassword());
    byte[] avatarBytes = tryGetAvatarBytes(joinInfo);
    return new GroupDetails(joinInfo, avatarBytes);
}
Also used : DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 2 with DecryptedGroupJoinInfo

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

the class LinkPreviewRepository method fetchGroupLinkPreview.

private static RequestController fetchGroupLinkPreview(@NonNull Context context, @NonNull String groupUrl, @NonNull Callback callback) {
    SignalExecutors.UNBOUNDED.execute(() -> {
        try {
            GroupInviteLinkUrl groupInviteLinkUrl = GroupInviteLinkUrl.fromUri(groupUrl);
            if (groupInviteLinkUrl == null) {
                throw new AssertionError();
            }
            GroupMasterKey groupMasterKey = groupInviteLinkUrl.getGroupMasterKey();
            GroupId.V2 groupId = GroupId.v2(groupMasterKey);
            Optional<GroupDatabase.GroupRecord> group = SignalDatabase.groups().getGroup(groupId);
            if (group.isPresent()) {
                Log.i(TAG, "Creating preview for locally available group");
                GroupDatabase.GroupRecord groupRecord = group.get();
                String title = groupRecord.getTitle();
                int memberCount = groupRecord.getMembers().size();
                String description = getMemberCountDescription(context, memberCount);
                Optional<Attachment> thumbnail = Optional.absent();
                if (AvatarHelper.hasAvatar(context, groupRecord.getRecipientId())) {
                    Recipient recipient = Recipient.resolved(groupRecord.getRecipientId());
                    Bitmap bitmap = AvatarUtil.loadIconBitmapSquareNoCache(context, recipient, 512, 512);
                    thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.WEBP, MediaUtil.IMAGE_WEBP);
                }
                callback.onSuccess(new LinkPreview(groupUrl, title, description, 0, thumbnail));
            } else {
                Log.i(TAG, "Group is not locally available for preview generation, fetching from server");
                DecryptedGroupJoinInfo joinInfo = GroupManager.getGroupJoinInfoFromServer(context, groupMasterKey, groupInviteLinkUrl.getPassword());
                String description = getMemberCountDescription(context, joinInfo.getMemberCount());
                Optional<Attachment> thumbnail = Optional.absent();
                byte[] avatarBytes = AvatarGroupsV2DownloadJob.downloadGroupAvatarBytes(context, groupMasterKey, joinInfo.getAvatar());
                if (avatarBytes != null) {
                    Bitmap bitmap = BitmapFactory.decodeByteArray(avatarBytes, 0, avatarBytes.length);
                    thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.WEBP, MediaUtil.IMAGE_WEBP);
                    if (bitmap != null)
                        bitmap.recycle();
                }
                callback.onSuccess(new LinkPreview(groupUrl, joinInfo.getTitle(), description, 0, thumbnail));
            }
        } catch (ExecutionException | InterruptedException | IOException | VerificationFailedException e) {
            Log.w(TAG, "Failed to fetch group link preview.", e);
            callback.onError(Error.PREVIEW_NOT_AVAILABLE);
        } catch (GroupInviteLinkUrl.InvalidGroupLinkException | GroupInviteLinkUrl.UnknownGroupLinkVersionException e) {
            Log.w(TAG, "Bad group link.", e);
            callback.onError(Error.PREVIEW_NOT_AVAILABLE);
        } catch (GroupLinkNotActiveException e) {
            Log.w(TAG, "Group link not active.", e);
            callback.onError(Error.GROUP_LINK_INACTIVE);
        }
    });
    return () -> Log.i(TAG, "Cancelled group link preview fetch -- no effect.");
}
Also used : Attachment(org.thoughtcrime.securesms.attachments.Attachment) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Bitmap(android.graphics.Bitmap) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ExecutionException(java.util.concurrent.ExecutionException) DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) GroupInviteLinkUrl(org.thoughtcrime.securesms.groups.v2.GroupInviteLinkUrl) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) GroupId(org.thoughtcrime.securesms.groups.GroupId) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) GroupLinkNotActiveException(org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException)

Example 3 with DecryptedGroupJoinInfo

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

the class GroupsV2Api method getGroupJoinInfo.

public DecryptedGroupJoinInfo getGroupJoinInfo(GroupSecretParams groupSecretParams, Optional<byte[]> password, GroupsV2AuthorizationString authorization) throws IOException, GroupLinkNotActiveException {
    try {
        GroupJoinInfo joinInfo = socket.getGroupJoinInfo(password, authorization);
        GroupsV2Operations.GroupOperations groupOperations = groupsOperations.forGroup(groupSecretParams);
        return groupOperations.decryptGroupJoinInfo(joinInfo);
    } catch (ForbiddenException e) {
        throw new GroupLinkNotActiveException();
    }
}
Also used : DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) GroupJoinInfo(org.signal.storageservice.protos.groups.GroupJoinInfo) ForbiddenException(org.whispersystems.signalservice.internal.push.exceptions.ForbiddenException)

Example 4 with DecryptedGroupJoinInfo

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

the class GroupsV2Operations_decrypt_groupJoinInfo_Test method decrypt_title_field_2.

@Test
public void decrypt_title_field_2() {
    GroupJoinInfo groupJoinInfo = GroupJoinInfo.newBuilder().setTitle(groupOperations.encryptTitle("Title!")).build();
    DecryptedGroupJoinInfo decryptedGroupJoinInfo = groupOperations.decryptGroupJoinInfo(groupJoinInfo);
    assertEquals("Title!", decryptedGroupJoinInfo.getTitle());
}
Also used : DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) GroupJoinInfo(org.signal.storageservice.protos.groups.GroupJoinInfo) DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) Test(org.junit.Test)

Example 5 with DecryptedGroupJoinInfo

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

the class GroupsV2Operations_decrypt_groupJoinInfo_Test method member_count_passed_through_4.

@Test
public void member_count_passed_through_4() {
    GroupJoinInfo groupJoinInfo = GroupJoinInfo.newBuilder().setMemberCount(97).build();
    DecryptedGroupJoinInfo decryptedGroupJoinInfo = groupOperations.decryptGroupJoinInfo(groupJoinInfo);
    assertEquals(97, decryptedGroupJoinInfo.getMemberCount());
}
Also used : DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) GroupJoinInfo(org.signal.storageservice.protos.groups.GroupJoinInfo) DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) Test(org.junit.Test)

Aggregations

DecryptedGroupJoinInfo (org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo)12 GroupJoinInfo (org.signal.storageservice.protos.groups.GroupJoinInfo)10 Test (org.junit.Test)9 Bitmap (android.graphics.Bitmap)1 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 VerificationFailedException (org.signal.zkgroup.VerificationFailedException)1 GroupMasterKey (org.signal.zkgroup.groups.GroupMasterKey)1 Attachment (org.thoughtcrime.securesms.attachments.Attachment)1 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)1 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)1 GroupId (org.thoughtcrime.securesms.groups.GroupId)1 GroupInviteLinkUrl (org.thoughtcrime.securesms.groups.v2.GroupInviteLinkUrl)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 GroupLinkNotActiveException (org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException)1 ForbiddenException (org.whispersystems.signalservice.internal.push.exceptions.ForbiddenException)1