Search in sources :

Example 71 with RecipientId

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

the class SearchRepository method queryMentions.

@NonNull
private List<MessageResult> queryMentions(@NonNull List<String> cleanQueries, long threadId) {
    Set<RecipientId> recipientIds = new HashSet<>();
    for (String cleanQuery : cleanQueries) {
        for (Recipient recipient : recipientDatabase.queryRecipientsForMentions(cleanQuery)) {
            recipientIds.add(recipient.getId());
        }
    }
    Map<Long, List<Mention>> mentionQueryResults = mentionDatabase.getMentionsContainingRecipients(recipientIds, threadId, 500);
    if (mentionQueryResults.isEmpty()) {
        return Collections.emptyList();
    }
    List<MessageResult> results = new ArrayList<>();
    try (MessageDatabase.Reader reader = mmsDatabase.getMessages(mentionQueryResults.keySet())) {
        MessageRecord record;
        while ((record = reader.getNext()) != null) {
            // noinspection ConstantConditions
            results.add(new MessageResult(threadDatabase.getRecipientForThreadId(record.getThreadId()), record.getRecipient(), record.getBody(), record.getBody(), record.getThreadId(), record.getId(), record.getDateReceived(), true));
        }
    }
    return results;
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) NonNull(androidx.annotation.NonNull)

Example 72 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 73 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 74 with RecipientId

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

the class IdentityUtil method markIdentityVerified.

public static void markIdentityVerified(Context context, Recipient recipient, boolean verified, boolean remote) {
    long time = System.currentTimeMillis();
    MessageDatabase smsDatabase = SignalDatabase.sms();
    GroupDatabase groupDatabase = SignalDatabase.groups();
    try (GroupDatabase.Reader reader = groupDatabase.getGroups()) {
        GroupDatabase.GroupRecord groupRecord;
        while ((groupRecord = reader.getNext()) != null) {
            if (groupRecord.getMembers().contains(recipient.getId()) && groupRecord.isActive() && !groupRecord.isMms()) {
                if (remote) {
                    IncomingTextMessage incoming = new IncomingTextMessage(recipient.getId(), 1, time, -1, time, null, Optional.of(groupRecord.getId()), 0, false, null);
                    if (verified)
                        incoming = new IncomingIdentityVerifiedMessage(incoming);
                    else
                        incoming = new IncomingIdentityDefaultMessage(incoming);
                    smsDatabase.insertMessageInbox(incoming);
                } else {
                    RecipientId recipientId = SignalDatabase.recipients().getOrInsertFromGroupId(groupRecord.getId());
                    Recipient groupRecipient = Recipient.resolved(recipientId);
                    long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient);
                    OutgoingTextMessage outgoing;
                    if (verified)
                        outgoing = new OutgoingIdentityVerifiedMessage(recipient);
                    else
                        outgoing = new OutgoingIdentityDefaultMessage(recipient);
                    SignalDatabase.sms().insertMessageOutbox(threadId, outgoing, false, time, null);
                    SignalDatabase.threads().update(threadId, true);
                }
            }
        }
    }
    if (remote) {
        IncomingTextMessage incoming = new IncomingTextMessage(recipient.getId(), 1, time, -1, time, null, Optional.absent(), 0, false, null);
        if (verified)
            incoming = new IncomingIdentityVerifiedMessage(incoming);
        else
            incoming = new IncomingIdentityDefaultMessage(incoming);
        smsDatabase.insertMessageInbox(incoming);
    } else {
        OutgoingTextMessage outgoing;
        if (verified)
            outgoing = new OutgoingIdentityVerifiedMessage(recipient);
        else
            outgoing = new OutgoingIdentityDefaultMessage(recipient);
        long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
        Log.i(TAG, "Inserting verified outbox...");
        SignalDatabase.sms().insertMessageOutbox(threadId, outgoing, false, time, null);
        SignalDatabase.threads().update(threadId, true);
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) OutgoingIdentityVerifiedMessage(org.thoughtcrime.securesms.sms.OutgoingIdentityVerifiedMessage) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) IncomingIdentityVerifiedMessage(org.thoughtcrime.securesms.sms.IncomingIdentityVerifiedMessage) OutgoingIdentityDefaultMessage(org.thoughtcrime.securesms.sms.OutgoingIdentityDefaultMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) IncomingIdentityDefaultMessage(org.thoughtcrime.securesms.sms.IncomingIdentityDefaultMessage)

Example 75 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