Search in sources :

Example 21 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class ReactionsConversationView method buildSortedReactionsList.

@NonNull
private static List<Reaction> buildSortedReactionsList(@NonNull List<ReactionRecord> records) {
    Map<String, Reaction> counters = new LinkedHashMap<>();
    RecipientId selfId = Recipient.self().getId();
    for (ReactionRecord record : records) {
        String baseEmoji = EmojiUtil.getCanonicalRepresentation(record.getEmoji());
        Reaction info = counters.get(baseEmoji);
        if (info == null) {
            info = new Reaction(baseEmoji, record.getEmoji(), 1, record.getDateReceived(), selfId.equals(record.getAuthor()));
        } else {
            info.update(record.getEmoji(), record.getDateReceived(), selfId.equals(record.getAuthor()));
        }
        counters.put(baseEmoji, info);
    }
    List<Reaction> reactions = new ArrayList<>(counters.values());
    Collections.sort(reactions, Collections.reverseOrder());
    if (reactions.size() > 3) {
        List<Reaction> shortened = new ArrayList<>(3);
        shortened.add(reactions.get(0));
        shortened.add(reactions.get(1));
        shortened.add(Stream.of(reactions).skip(2).reduce(new Reaction(null, null, 0, 0, false), Reaction::merge));
        return shortened;
    } else {
        return reactions;
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ArrayList(java.util.ArrayList) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) LinkedHashMap(java.util.LinkedHashMap) NonNull(androidx.annotation.NonNull)

Example 22 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class RegistrationRepository method registerAccountInternal.

@WorkerThread
private void registerAccountInternal(@NonNull RegistrationData registrationData, @NonNull VerifyAccountResponse response, @Nullable String pin, @Nullable KbsPinData kbsData) throws IOException {
    ACI aci = ACI.parseOrThrow(response.getUuid());
    PNI pni = PNI.parseOrThrow(response.getPni());
    boolean hasPin = response.isStorageCapable();
    SignalStore.account().setAci(aci);
    SignalStore.account().setPni(pni);
    ApplicationDependencies.getProtocolStore().aci().sessions().archiveAllSessions();
    ApplicationDependencies.getProtocolStore().pni().sessions().archiveAllSessions();
    SenderKeyUtil.clearAllState(context);
    SignalServiceAccountManager accountManager = AccountManagerFactory.createAuthenticated(context, aci, pni, registrationData.getE164(), SignalServiceAddress.DEFAULT_DEVICE_ID, registrationData.getPassword());
    SignalServiceAccountDataStoreImpl aciProtocolStore = ApplicationDependencies.getProtocolStore().aci();
    SignalServiceAccountDataStoreImpl pniProtocolStore = ApplicationDependencies.getProtocolStore().pni();
    generateAndRegisterPreKeys(ServiceIdType.ACI, accountManager, aciProtocolStore, SignalStore.account().aciPreKeys());
    generateAndRegisterPreKeys(ServiceIdType.PNI, accountManager, pniProtocolStore, SignalStore.account().pniPreKeys());
    if (registrationData.isFcm()) {
        accountManager.setGcmId(Optional.fromNullable(registrationData.getFcmToken()));
    }
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    RecipientId selfId = Recipient.externalPush(aci, registrationData.getE164(), true).getId();
    recipientDatabase.setProfileSharing(selfId, true);
    recipientDatabase.markRegisteredOrThrow(selfId, aci);
    recipientDatabase.setPni(selfId, pni);
    recipientDatabase.setProfileKey(selfId, registrationData.getProfileKey());
    ApplicationDependencies.getRecipientCache().clearSelf();
    SignalStore.account().setE164(registrationData.getE164());
    SignalStore.account().setFcmToken(registrationData.getFcmToken());
    SignalStore.account().setFcmEnabled(registrationData.isFcm());
    long now = System.currentTimeMillis();
    saveOwnIdentityKey(selfId, aciProtocolStore, now);
    saveOwnIdentityKey(selfId, pniProtocolStore, now);
    SignalStore.account().setServicePassword(registrationData.getPassword());
    SignalStore.account().setRegistered(true);
    TextSecurePreferences.setPromptedPushRegistration(context, true);
    TextSecurePreferences.setUnauthorizedReceived(context, false);
    PinState.onRegistration(context, kbsData, pin, hasPin);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ACI(org.whispersystems.signalservice.api.push.ACI) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) PNI(org.whispersystems.signalservice.api.push.PNI) SignalServiceAccountDataStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalServiceAccountDataStoreImpl) WorkerThread(androidx.annotation.WorkerThread)

Example 23 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class RegistrationRepository method findExistingProfileKey.

@WorkerThread
@Nullable
private static ProfileKey findExistingProfileKey(@NonNull String e164number) {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    Optional<RecipientId> recipient = recipientDatabase.getByE164(e164number);
    if (recipient.isPresent()) {
        return ProfileKeyUtil.profileKeyOrNull(Recipient.resolved(recipient.get()).getProfileKey());
    }
    return null;
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 24 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class RecipientBottomSheetDialogFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View fragmentView, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(fragmentView, savedInstanceState);
    Bundle arguments = requireArguments();
    RecipientId recipientId = RecipientId.from(Objects.requireNonNull(arguments.getString(ARGS_RECIPIENT_ID)));
    GroupId groupId = GroupId.parseNullableOrThrow(arguments.getString(ARGS_GROUP_ID));
    RecipientDialogViewModel.Factory factory = new RecipientDialogViewModel.Factory(requireContext().getApplicationContext(), recipientId, groupId);
    viewModel = ViewModelProviders.of(this, factory).get(RecipientDialogViewModel.class);
    viewModel.getRecipient().observe(getViewLifecycleOwner(), recipient -> {
        interactionsContainer.setVisibility(recipient.isSelf() ? View.GONE : View.VISIBLE);
        avatar.setFallbackPhotoProvider(new Recipient.FallbackPhotoProvider() {

            @Override
            @NonNull
            public FallbackContactPhoto getPhotoForLocalNumber() {
                return new FallbackPhoto80dp(R.drawable.ic_note_80, recipient.getAvatarColor());
            }
        });
        avatar.setAvatar(recipient);
        if (!recipient.isSelf()) {
            badgeImageView.setBadgeFromRecipient(recipient);
        }
        if (recipient.isSelf()) {
            avatar.setOnClickListener(v -> {
                dismiss();
                viewModel.onMessageClicked(requireActivity());
            });
        }
        String name = recipient.isSelf() ? requireContext().getString(R.string.note_to_self) : recipient.getDisplayName(requireContext());
        fullName.setVisibility(TextUtils.isEmpty(name) ? View.GONE : View.VISIBLE);
        SpannableStringBuilder nameBuilder = new SpannableStringBuilder(name);
        if (recipient.isSystemContact() && !recipient.isSelf()) {
            Drawable systemContact = DrawableUtil.tint(ContextUtil.requireDrawable(requireContext(), R.drawable.ic_profile_circle_outline_16), ContextCompat.getColor(requireContext(), R.color.signal_text_primary));
            SpanUtil.appendCenteredImageSpan(nameBuilder, systemContact, 16, 16);
        } else if (recipient.isReleaseNotes()) {
            SpanUtil.appendCenteredImageSpan(nameBuilder, ContextUtil.requireDrawable(requireContext(), R.drawable.ic_official_28), 28, 28);
        }
        fullName.setText(nameBuilder);
        String aboutText = recipient.getCombinedAboutAndEmoji();
        if (recipient.isReleaseNotes()) {
            aboutText = getString(R.string.ReleaseNotes__signal_release_notes_and_news);
        }
        if (!Util.isEmpty(aboutText)) {
            about.setText(aboutText);
            about.setVisibility(View.VISIBLE);
        } else {
            about.setVisibility(View.GONE);
        }
        String usernameNumberString = recipient.hasAUserSetDisplayName(requireContext()) && !recipient.isSelf() ? recipient.getSmsAddress().transform(PhoneNumberFormatter::prettyPrint).or("").trim() : "";
        usernameNumber.setText(usernameNumberString);
        usernameNumber.setVisibility(TextUtils.isEmpty(usernameNumberString) ? View.GONE : View.VISIBLE);
        usernameNumber.setOnLongClickListener(v -> {
            Util.copyToClipboard(v.getContext(), usernameNumber.getText().toString());
            ServiceUtil.getVibrator(v.getContext()).vibrate(250);
            Toast.makeText(v.getContext(), R.string.RecipientBottomSheet_copied_to_clipboard, Toast.LENGTH_SHORT).show();
            return true;
        });
        noteToSelfDescription.setVisibility(recipient.isSelf() ? View.VISIBLE : View.GONE);
        if (RecipientUtil.isBlockable(recipient)) {
            boolean blocked = recipient.isBlocked();
            blockButton.setVisibility(recipient.isSelf() || blocked ? View.GONE : View.VISIBLE);
            unblockButton.setVisibility(recipient.isSelf() || !blocked ? View.GONE : View.VISIBLE);
        } else {
            blockButton.setVisibility(View.GONE);
            unblockButton.setVisibility(View.GONE);
        }
        ButtonStripPreference.State buttonStripState = new ButtonStripPreference.State(/* isMessageAvailable = */
        !recipient.isBlocked() && !recipient.isSelf() && !recipient.isReleaseNotes(), /* isVideoAvailable   = */
        !recipient.isBlocked() && !recipient.isSelf() && recipient.isRegistered(), /* isAudioAvailable   = */
        !recipient.isBlocked() && !recipient.isSelf() && !recipient.isReleaseNotes(), /* isMuteAvailable    = */
        false, /* isSearchAvailable  = */
        false, /* isAudioSecure      = */
        recipient.isRegistered(), /* isMuted            = */
        false);
        ButtonStripPreference.Model buttonStripModel = new ButtonStripPreference.Model(buttonStripState, DSLSettingsIcon.from(ContextUtil.requireDrawable(requireContext(), R.drawable.selectable_recipient_bottom_sheet_icon_button)), () -> {
            dismiss();
            viewModel.onMessageClicked(requireActivity());
            return Unit.INSTANCE;
        }, () -> {
            viewModel.onSecureVideoCallClicked(requireActivity());
            return Unit.INSTANCE;
        }, () -> {
            if (buttonStripState.isAudioSecure()) {
                viewModel.onSecureCallClicked(requireActivity());
            } else {
                viewModel.onInsecureCallClicked(requireActivity());
            }
            return Unit.INSTANCE;
        }, () -> Unit.INSTANCE, () -> Unit.INSTANCE);
        new ButtonStripPreference.ViewHolder(buttonStrip).bind(buttonStripModel);
        if (recipient.isReleaseNotes()) {
            buttonStrip.setVisibility(View.GONE);
        }
        if (recipient.isSystemContact() || recipient.isGroup() || recipient.isSelf() || recipient.isBlocked() || recipient.isReleaseNotes()) {
            addContactButton.setVisibility(View.GONE);
        } else {
            addContactButton.setVisibility(View.VISIBLE);
            addContactButton.setOnClickListener(v -> {
                openSystemContactSheet(RecipientExporter.export(recipient).asAddContactIntent());
            });
        }
        if (recipient.isSystemContact() && !recipient.isGroup() && !recipient.isSelf()) {
            contactDetailsButton.setVisibility(View.VISIBLE);
            contactDetailsButton.setOnClickListener(v -> {
                openSystemContactSheet(new Intent(Intent.ACTION_VIEW, recipient.getContactUri()));
            });
        } else {
            contactDetailsButton.setVisibility(View.GONE);
        }
    });
    viewModel.getCanAddToAGroup().observe(getViewLifecycleOwner(), canAdd -> {
        addToGroupButton.setText(groupId == null ? R.string.RecipientBottomSheet_add_to_a_group : R.string.RecipientBottomSheet_add_to_another_group);
        addToGroupButton.setVisibility(canAdd ? View.VISIBLE : View.GONE);
    });
    viewModel.getAdminActionStatus().observe(getViewLifecycleOwner(), adminStatus -> {
        makeGroupAdminButton.setVisibility(adminStatus.isCanMakeAdmin() ? View.VISIBLE : View.GONE);
        removeAdminButton.setVisibility(adminStatus.isCanMakeNonAdmin() ? View.VISIBLE : View.GONE);
        removeFromGroupButton.setVisibility(adminStatus.isCanRemove() ? View.VISIBLE : View.GONE);
    });
    viewModel.getIdentity().observe(getViewLifecycleOwner(), identityRecord -> {
        viewSafetyNumberButton.setVisibility(identityRecord != null ? View.VISIBLE : View.GONE);
        if (identityRecord != null) {
            viewSafetyNumberButton.setOnClickListener(view -> {
                dismiss();
                viewModel.onViewSafetyNumberClicked(requireActivity(), identityRecord);
            });
        }
    });
    avatar.setOnClickListener(view -> {
        dismiss();
        viewModel.onAvatarClicked(requireActivity());
    });
    badgeImageView.setOnClickListener(view -> {
        dismiss();
        ViewBadgeBottomSheetDialogFragment.show(getParentFragmentManager(), recipientId, null);
    });
    blockButton.setOnClickListener(view -> viewModel.onBlockClicked(requireActivity()));
    unblockButton.setOnClickListener(view -> viewModel.onUnblockClicked(requireActivity()));
    makeGroupAdminButton.setOnClickListener(view -> viewModel.onMakeGroupAdminClicked(requireActivity()));
    removeAdminButton.setOnClickListener(view -> viewModel.onRemoveGroupAdminClicked(requireActivity()));
    removeFromGroupButton.setOnClickListener(view -> viewModel.onRemoveFromGroupClicked(requireActivity(), this::dismiss));
    addToGroupButton.setOnClickListener(view -> {
        dismiss();
        viewModel.onAddToGroupButton(requireActivity());
    });
    viewModel.getAdminActionBusy().observe(getViewLifecycleOwner(), busy -> {
        adminActionBusy.setVisibility(busy ? View.VISIBLE : View.GONE);
        makeGroupAdminButton.setEnabled(!busy);
        removeAdminButton.setEnabled(!busy);
        removeFromGroupButton.setEnabled(!busy);
    });
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Intent(android.content.Intent) SpannableString(android.text.SpannableString) GroupId(org.thoughtcrime.securesms.groups.GroupId) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) NonNull(androidx.annotation.NonNull) FallbackPhoto80dp(org.thoughtcrime.securesms.contacts.avatars.FallbackPhoto80dp) SpannableStringBuilder(android.text.SpannableStringBuilder) ButtonStripPreference(org.thoughtcrime.securesms.components.settings.conversation.preferences.ButtonStripPreference)

Example 25 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class SharedContactView method presentActionButtons.

private void presentActionButtons(@NonNull List<RecipientId> recipients) {
    for (RecipientId recipientId : recipients) {
        activeRecipients.put(recipientId, Recipient.live(recipientId));
    }
    List<Recipient> pushUsers = new ArrayList<>(recipients.size());
    List<Recipient> systemUsers = new ArrayList<>(recipients.size());
    for (LiveRecipient recipient : activeRecipients.values()) {
        if (recipient.get().getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
            pushUsers.add(recipient.get());
        } else if (recipient.get().isSystemContact()) {
            systemUsers.add(recipient.get());
        }
    }
    if (!pushUsers.isEmpty()) {
        actionButtonView.setText(R.string.SharedContactView_message);
        actionButtonView.setOnClickListener(v -> {
            if (eventListener != null) {
                eventListener.onMessageClicked(pushUsers);
            }
        });
    } else if (!systemUsers.isEmpty()) {
        actionButtonView.setText(R.string.SharedContactView_invite_to_signal);
        actionButtonView.setOnClickListener(v -> {
            if (eventListener != null) {
                eventListener.onInviteClicked(systemUsers);
            }
        });
    } else {
        actionButtonView.setText(R.string.SharedContactView_add_to_contacts);
        actionButtonView.setOnClickListener(v -> {
            if (eventListener != null && contact != null) {
                eventListener.onAddToContactsClicked(contact);
            }
        });
    }
}
Also used : RequiresApi(androidx.annotation.RequiresApi) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) ImageView(android.widget.ImageView) HashMap(java.util.HashMap) R(org.thoughtcrime.securesms.R) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) AttributeSet(android.util.AttributeSet) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Locale(java.util.Locale) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Map(java.util.Map) View(android.view.View) Canvas(android.graphics.Canvas) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Build(android.os.Build) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Contact(org.thoughtcrime.securesms.contactshare.Contact) RecipientForeverObserver(org.thoughtcrime.securesms.recipients.RecipientForeverObserver) ContactUtil(org.thoughtcrime.securesms.contactshare.ContactUtil) Color(android.graphics.Color) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) DecryptableUri(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri) GlideRequests(org.thoughtcrime.securesms.mms.GlideRequests) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient)

Aggregations

RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)154 NonNull (androidx.annotation.NonNull)70 Recipient (org.thoughtcrime.securesms.recipients.Recipient)70 List (java.util.List)34 ArrayList (java.util.ArrayList)33 Nullable (androidx.annotation.Nullable)32 Context (android.content.Context)31 Log (org.signal.core.util.logging.Log)31 IOException (java.io.IOException)30 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)29 WorkerThread (androidx.annotation.WorkerThread)28 Stream (com.annimon.stream.Stream)27 LinkedList (java.util.LinkedList)25 ContentValues (android.content.ContentValues)24 Cursor (android.database.Cursor)24 Collections (java.util.Collections)24 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)24 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)23 Optional (org.whispersystems.libsignal.util.guava.Optional)22 HashSet (java.util.HashSet)21