Search in sources :

Example 6 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class GroupDescriptionDialog method onCreateDialog.

@Override
@NonNull
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.group_description_dialog, null, false);
    String argumentTitle = requireArguments().getString(ARGUMENT_TITLE, null);
    String argumentDescription = requireArguments().getString(ARGUMENT_DESCRIPTION, null);
    GroupId argumentGroupId = ParcelableGroupId.get(requireArguments().getParcelable(ARGUMENT_GROUP_ID));
    boolean linkify = requireArguments().getBoolean(ARGUMENT_LINKIFY, false);
    LiveGroup liveGroup = argumentGroupId != null ? new LiveGroup(argumentGroupId) : null;
    descriptionText = dialogView.findViewById(R.id.group_description_dialog_text);
    descriptionText.setMovementMethod(LongClickMovementMethod.getInstance(requireContext()));
    MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext(), R.style.Signal_ThemeOverlay_Dialog_Rounded);
    Dialog dialog = builder.setTitle(TextUtils.isEmpty(argumentTitle) ? getString(R.string.GroupDescriptionDialog__group_description) : argumentTitle).setView(dialogView).setPositiveButton(android.R.string.ok, null).create();
    if (argumentDescription != null) {
        GroupDescriptionUtil.setText(requireContext(), descriptionText, argumentDescription, linkify, null);
    } else if (liveGroup != null) {
        liveGroup.getDescription().observe(this, d -> GroupDescriptionUtil.setText(requireContext(), descriptionText, d, linkify, null));
    }
    if (TextUtils.isEmpty(argumentTitle) && liveGroup != null) {
        liveGroup.getTitle().observe(this, dialog::setTitle);
    }
    return dialog;
}
Also used : LiveGroup(org.thoughtcrime.securesms.groups.LiveGroup) FragmentManager(androidx.fragment.app.FragmentManager) Bundle(android.os.Bundle) GroupDescriptionUtil(org.thoughtcrime.securesms.groups.v2.GroupDescriptionUtil) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ParcelableGroupId(org.thoughtcrime.securesms.groups.ParcelableGroupId) LongClickMovementMethod(org.thoughtcrime.securesms.util.LongClickMovementMethod) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) Dialog(android.app.Dialog) TextUtils(android.text.TextUtils) R(org.thoughtcrime.securesms.R) LiveGroup(org.thoughtcrime.securesms.groups.LiveGroup) Nullable(androidx.annotation.Nullable) GroupId(org.thoughtcrime.securesms.groups.GroupId) View(android.view.View) DialogFragment(androidx.fragment.app.DialogFragment) Dialog(android.app.Dialog) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) View(android.view.View) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ParcelableGroupId(org.thoughtcrime.securesms.groups.ParcelableGroupId) GroupId(org.thoughtcrime.securesms.groups.GroupId) NonNull(androidx.annotation.NonNull)

Example 7 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class SendRetryReceiptJob method onRun.

@Override
protected void onRun() throws Exception {
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
    Optional<UnidentifiedAccessPair> access = UnidentifiedAccessUtil.getAccessFor(context, recipient);
    Optional<byte[]> group = groupId.transform(GroupId::getDecodedId);
    Log.i(TAG, "Sending retry receipt for " + errorMessage.getTimestamp() + " to " + recipientId + ", device: " + errorMessage.getDeviceId());
    ApplicationDependencies.getSignalServiceMessageSender().sendRetryReceipt(address, access, group, errorMessage);
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) UnidentifiedAccessPair(org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 8 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class RemoteDeleteSendJob method deliver.

@NonNull
private List<Recipient> deliver(@NonNull Recipient conversationRecipient, @NonNull List<Recipient> destinations, long targetSentTimestamp) throws IOException, UntrustedIdentityException {
    SignalServiceDataMessage.Builder dataMessageBuilder = SignalServiceDataMessage.newBuilder().withTimestamp(System.currentTimeMillis()).withRemoteDelete(new SignalServiceDataMessage.RemoteDelete(targetSentTimestamp));
    if (conversationRecipient.isGroup()) {
        GroupUtil.setDataMessageGroupContext(context, dataMessageBuilder, conversationRecipient.requireGroupId().requirePush());
    }
    SignalServiceDataMessage dataMessage = dataMessageBuilder.build();
    List<SendMessageResult> results = GroupSendUtil.sendResendableDataMessage(context, conversationRecipient.getGroupId().transform(GroupId::requireV2).orNull(), destinations, false, ContentHint.RESENDABLE, new MessageId(messageId, isMms), dataMessage);
    return GroupSendJobHelper.getCompletedSends(destinations, results);
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) GroupId(org.thoughtcrime.securesms.groups.GroupId) MessageId(org.thoughtcrime.securesms.database.model.MessageId) NonNull(androidx.annotation.NonNull)

Example 9 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class ResendMessageJob method onRun.

@Override
protected void onRun() throws Exception {
    if (SignalStore.internalValues().delayResends()) {
        Log.w(TAG, "Delaying resend by 10 sec because of an internal preference.");
        ThreadUtil.sleep(10000);
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " is unregistered!");
        return;
    }
    SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
    Optional<UnidentifiedAccessPair> access = UnidentifiedAccessUtil.getAccessFor(context, recipient);
    Content contentToSend = content;
    if (distributionId != null) {
        Optional<GroupRecord> groupRecord = SignalDatabase.groups().getGroupByDistributionId(distributionId);
        if (!groupRecord.isPresent()) {
            Log.w(TAG, "Could not find a matching group for the distributionId! Skipping message send.");
            return;
        } else if (!groupRecord.get().getMembers().contains(recipientId)) {
            Log.w(TAG, "The target user is no longer in the group! Skipping message send.");
            return;
        }
        SenderKeyDistributionMessage senderKeyDistributionMessage = messageSender.getOrCreateNewGroupSession(distributionId);
        ByteString distributionBytes = ByteString.copyFrom(senderKeyDistributionMessage.serialize());
        contentToSend = contentToSend.toBuilder().setSenderKeyDistributionMessage(distributionBytes).build();
    }
    SendMessageResult result = messageSender.resendContent(address, access, sentTimestamp, contentToSend, contentHint, Optional.fromNullable(groupId).transform(GroupId::getDecodedId));
    if (result.isSuccess() && distributionId != null) {
        List<SignalProtocolAddress> addresses = result.getSuccess().getDevices().stream().map(device -> recipient.requireServiceId().toProtocolAddress(device)).collect(Collectors.toList());
        ApplicationDependencies.getProtocolStore().aci().markSenderKeySharedWith(distributionId, addresses);
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) UnidentifiedAccessPair(org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) SenderKeyDistributionMessage(org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) UnidentifiedAccessUtil(org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil) ThreadUtil(org.signal.core.util.ThreadUtil) Collectors(java.util.stream.Collectors) Optional(org.whispersystems.libsignal.util.guava.Optional) ByteString(com.google.protobuf.ByteString) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) GroupId(org.thoughtcrime.securesms.groups.GroupId) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) Job(org.thoughtcrime.securesms.jobmanager.Job) ByteString(com.google.protobuf.ByteString) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) UnidentifiedAccessPair(org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) SenderKeyDistributionMessage(org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 10 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId 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)

Aggregations

GroupId (org.thoughtcrime.securesms.groups.GroupId)41 Recipient (org.thoughtcrime.securesms.recipients.Recipient)26 NonNull (androidx.annotation.NonNull)22 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)13 Context (android.content.Context)12 List (java.util.List)11 Log (org.signal.core.util.logging.Log)11 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)11 Collections (java.util.Collections)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)10 Optional (org.whispersystems.libsignal.util.guava.Optional)10 Nullable (androidx.annotation.Nullable)9 IOException (java.io.IOException)9 LinkedList (java.util.LinkedList)8 Collectors (java.util.stream.Collectors)8 SignalStore (org.thoughtcrime.securesms.keyvalue.SignalStore)8 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)8 Intent (android.content.Intent)7 Stream (com.annimon.stream.Stream)7