Search in sources :

Example 96 with RecipientId

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

the class ContactRecordProcessor method getMatching.

@Override
@NonNull
Optional<SignalContactRecord> getMatching(@NonNull SignalContactRecord remote, @NonNull StorageKeyGenerator keyGenerator) {
    SignalServiceAddress address = remote.getAddress();
    Optional<RecipientId> byUuid = recipientDatabase.getByServiceId(address.getServiceId());
    Optional<RecipientId> byE164 = address.getNumber().isPresent() ? recipientDatabase.getByE164(address.getNumber().get()) : Optional.absent();
    return byUuid.or(byE164).transform(recipientDatabase::getRecordForSync).transform(settings -> {
        if (settings.getStorageId() != null) {
            return StorageSyncModels.localToRemoteRecord(settings);
        } else {
            Log.w(TAG, "Newly discovering a registered user via storage service. Saving a storageId for them.");
            recipientDatabase.updateStorageId(settings.getId(), keyGenerator.generate());
            RecipientRecord updatedSettings = Objects.requireNonNull(recipientDatabase.getRecordForSync(settings.getId()));
            return StorageSyncModels.localToRemoteRecord(updatedSettings);
        }
    }).transform(r -> r.getContact().get());
}
Also used : Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Arrays(java.util.Arrays) ACI(org.whispersystems.signalservice.api.push.ACI) NonNull(androidx.annotation.NonNull) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) IdentityState(org.whispersystems.signalservice.internal.storage.protos.ContactRecord.IdentityState) Optional(org.whispersystems.libsignal.util.guava.Optional) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) Nullable(androidx.annotation.Nullable) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalContactRecord(org.whispersystems.signalservice.api.storage.SignalContactRecord) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) RecipientRecord(org.thoughtcrime.securesms.database.model.RecipientRecord) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) RecipientRecord(org.thoughtcrime.securesms.database.model.RecipientRecord) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) NonNull(androidx.annotation.NonNull)

Example 97 with RecipientId

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

the class ShareActivity method createExtrasFromExtraShortcutId.

/**
 * @param extraShortcutId EXTRA_SHORTCUT_ID string as included in direct share intent
 */
@WorkerThread
@Nullable
private Bundle createExtrasFromExtraShortcutId(@NonNull String extraShortcutId) {
    Bundle extras = new Bundle();
    RecipientId recipientId = ConversationUtil.getRecipientId(extraShortcutId);
    Long threadId = null;
    int distributionType = ThreadDatabase.DistributionTypes.DEFAULT;
    if (recipientId != null) {
        threadId = SignalDatabase.threads().getThreadIdFor(recipientId);
        extras.putString(EXTRA_RECIPIENT_ID, recipientId.serialize());
        extras.putLong(EXTRA_THREAD_ID, threadId != null ? threadId : -1);
        extras.putInt(EXTRA_DISTRIBUTION_TYPE, distributionType);
        return extras;
    }
    return null;
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Bundle(android.os.Bundle) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 98 with RecipientId

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

the class ShareActivity method handleDestination.

private void handleDestination() {
    Intent intent = getIntent();
    long threadId = intent.getLongExtra(EXTRA_THREAD_ID, -1);
    int distributionType = intent.getIntExtra(EXTRA_DISTRIBUTION_TYPE, -1);
    RecipientId recipientId = RecipientId.from(intent.getStringExtra(EXTRA_RECIPIENT_ID));
    boolean hasPreexistingDestination = threadId != -1 && distributionType != -1;
    if (hasPreexistingDestination) {
        if (contactsFragment.getView() != null) {
            contactsFragment.getView().setVisibility(View.GONE);
        }
        onSingleDestinationChosen(threadId, recipientId);
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Intent(android.content.Intent)

Example 99 with RecipientId

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

the class BlockedUsersActivity method onBeforeContactSelected.

@Override
public void onBeforeContactSelected(Optional<RecipientId> recipientId, String number, Consumer<Boolean> callback) {
    final String displayName = recipientId.transform(id -> Recipient.resolved(id).getDisplayName(this)).or(number);
    AlertDialog confirmationDialog = new MaterialAlertDialogBuilder(this).setTitle(R.string.BlockedUsersActivity__block_user).setMessage(getString(R.string.BlockedUserActivity__s_will_not_be_able_to, displayName)).setPositiveButton(R.string.BlockedUsersActivity__block, (dialog, which) -> {
        if (recipientId.isPresent()) {
            viewModel.block(recipientId.get());
        } else {
            viewModel.createAndBlock(number);
        }
        dialog.dismiss();
        onBackPressed();
    }).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).setCancelable(true).create();
    confirmationDialog.setOnShowListener(dialog -> {
        confirmationDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.RED);
    });
    confirmationDialog.show();
    callback.accept(false);
}
Also used : ContactFilterView(org.thoughtcrime.securesms.components.ContactFilterView) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) ContactsCursorLoader(org.thoughtcrime.securesms.contacts.ContactsCursorLoader) NonNull(androidx.annotation.NonNull) ContactSelectionListFragment(org.thoughtcrime.securesms.ContactSelectionListFragment) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Intent(android.content.Intent) R(org.thoughtcrime.securesms.R) Optional(org.whispersystems.libsignal.util.guava.Optional) Color(android.graphics.Color) Consumer(java.util.function.Consumer) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) StringRes(androidx.annotation.StringRes) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) ViewModelProviders(androidx.lifecycle.ViewModelProviders) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Snackbar(com.google.android.material.snackbar.Snackbar) AlertDialog(androidx.appcompat.app.AlertDialog) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 100 with RecipientId

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

the class GroupManagerV2 method migrateGroupOnToServer.

@WorkerThread
void migrateGroupOnToServer(@NonNull GroupId.V1 groupIdV1, @NonNull Collection<Recipient> members) throws IOException, MembershipNotSuitableForV2Exception, GroupAlreadyExistsException, GroupChangeFailedException {
    GroupMasterKey groupMasterKey = groupIdV1.deriveV2MigrationMasterKey();
    GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
    GroupDatabase.GroupRecord groupRecord = groupDatabase.requireGroup(groupIdV1);
    String name = Util.emptyIfNull(groupRecord.getTitle());
    byte[] avatar = groupRecord.hasAvatar() ? AvatarHelper.getAvatarBytes(context, groupRecord.getRecipientId()) : null;
    int messageTimer = Recipient.resolved(groupRecord.getRecipientId()).getExpiresInSeconds();
    Set<RecipientId> memberIds = Stream.of(members).map(Recipient::getId).filterNot(m -> m.equals(Recipient.self().getId())).collect(Collectors.toSet());
    createGroupOnServer(groupSecretParams, name, avatar, memberIds, Member.Role.ADMINISTRATOR, messageTimer);
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Arrays(java.util.Arrays) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) NonNull(androidx.annotation.NonNull) GroupChangeUtil(org.whispersystems.signalservice.api.groupsv2.GroupChangeUtil) RequestGroupV2InfoJob(org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) PushGroupSilentUpdateSendJob(org.thoughtcrime.securesms.jobs.PushGroupSilentUpdateSendJob) Member(org.signal.storageservice.protos.groups.Member) DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) Map(java.util.Map) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) GroupExistsException(org.whispersystems.signalservice.internal.push.exceptions.GroupExistsException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupsV2StateProcessor(org.thoughtcrime.securesms.groups.v2.processing.GroupsV2StateProcessor) OutgoingGroupUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage) InvalidGroupStateException(org.whispersystems.signalservice.api.groupsv2.InvalidGroupStateException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) NotInGroupException(org.whispersystems.signalservice.internal.push.exceptions.NotInGroupException) GroupCandidateHelper(org.thoughtcrime.securesms.groups.v2.GroupCandidateHelper) GroupCandidate(org.whispersystems.signalservice.api.groupsv2.GroupCandidate) GroupExternalCredential(org.signal.storageservice.protos.groups.GroupExternalCredential) ACI(org.whispersystems.signalservice.api.push.ACI) DecryptedGroupUtil(org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) ProfileKeyUtil(org.thoughtcrime.securesms.crypto.ProfileKeyUtil) Set(java.util.Set) DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) GroupLinkPassword(org.thoughtcrime.securesms.groups.v2.GroupLinkPassword) GroupsV2Operations(org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations) UUID(java.util.UUID) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) InvalidInputException(org.signal.zkgroup.InvalidInputException) ByteString(com.google.protobuf.ByteString) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) WorkerThread(androidx.annotation.WorkerThread) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) HashMap(java.util.HashMap) AccessControl(org.signal.storageservice.protos.groups.AccessControl) GroupInviteLinkUrl(org.thoughtcrime.securesms.groups.v2.GroupInviteLinkUrl) GroupPatchNotAcceptedException(org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException) HashSet(java.util.HashSet) AuthorizationFailedException(org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException) ClientZkGroupCipher(org.signal.zkgroup.groups.ClientZkGroupCipher) NotAbleToApplyGroupV2ChangeException(org.whispersystems.signalservice.api.groupsv2.NotAbleToApplyGroupV2ChangeException) DecryptedRequestingMember(org.signal.storageservice.protos.groups.local.DecryptedRequestingMember) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) ConflictException(org.whispersystems.signalservice.api.push.exceptions.ConflictException) GroupChangeReconstruct(org.whispersystems.signalservice.api.groupsv2.GroupChangeReconstruct) Collectors(com.annimon.stream.Collectors) ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) GroupSecretParams(org.signal.zkgroup.groups.GroupSecretParams) AvatarHelper(org.thoughtcrime.securesms.profiles.AvatarHelper) MmsException(org.thoughtcrime.securesms.mms.MmsException) UuidUtil(org.whispersystems.signalservice.api.util.UuidUtil) IOException(java.io.IOException) GroupsV2Api(org.whispersystems.signalservice.api.groupsv2.GroupsV2Api) Optional(org.whispersystems.libsignal.util.guava.Optional) GroupLinkNotActiveException(org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException) UuidCiphertext(org.signal.zkgroup.groups.UuidCiphertext) Closeable(java.io.Closeable) GroupChange(org.signal.storageservice.protos.groups.GroupChange) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) GroupSecretParams(org.signal.zkgroup.groups.GroupSecretParams) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) WorkerThread(androidx.annotation.WorkerThread)

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