Search in sources :

Example 56 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class GroupManagerV1 method updateGroupTimer.

@WorkerThread
static void updateGroupTimer(@NonNull Context context, @NonNull GroupId.V1 groupId, int expirationTime) {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    Recipient recipient = Recipient.externalGroupExact(context, groupId);
    long threadId = threadDatabase.getOrCreateThreadIdFor(recipient);
    recipientDatabase.setExpireMessages(recipient.getId(), expirationTime);
    OutgoingExpirationUpdateMessage outgoingMessage = new OutgoingExpirationUpdateMessage(recipient, System.currentTimeMillis(), expirationTime * 1000L);
    MessageSender.send(context, outgoingMessage, threadId, false, null, null);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) WorkerThread(androidx.annotation.WorkerThread)

Example 57 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

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 58 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class Recipient method external.

/**
 * Returns a fully-populated {@link Recipient} based off of a string identifier, creating one in
 * the database if necessary. The identifier may be a uuid, phone number, email,
 * or serialized groupId.
 *
 * If the identifier is a UUID of a Signal user, prefer using
 * {@link #externalPush(ServiceId, String, boolean)} or its overload, as this will let us associate
 * the phone number with the recipient.
 */
@WorkerThread
@NonNull
public static Recipient external(@NonNull Context context, @NonNull String identifier) {
    Preconditions.checkNotNull(identifier, "Identifier cannot be null!");
    RecipientDatabase db = SignalDatabase.recipients();
    RecipientId id = null;
    if (UuidUtil.isUuid(identifier)) {
        ACI uuid = ACI.parseOrThrow(identifier);
        id = db.getOrInsertFromServiceId(uuid);
    } else if (GroupId.isEncodedGroup(identifier)) {
        id = db.getOrInsertFromGroupId(GroupId.parseOrThrow(identifier));
    } else if (NumberUtil.isValidEmail(identifier)) {
        id = db.getOrInsertFromEmail(identifier);
    } else {
        String e164 = PhoneNumberFormatter.get(context).format(identifier);
        id = db.getOrInsertFromE164(e164);
    }
    return Recipient.resolved(id);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) ACI(org.whispersystems.signalservice.api.push.ACI) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 59 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class Recipient method externalContact.

/**
 * A safety wrapper around {@link #external(Context, String)} for when you know you're using an
 * identifier for a system contact, and therefore always want to prevent interpreting it as a
 * UUID. This will crash if given a UUID.
 *
 * (This may seem strange, but apparently some devices are returning valid UUIDs for contacts)
 */
@WorkerThread
@NonNull
public static Recipient externalContact(@NonNull Context context, @NonNull String identifier) {
    RecipientDatabase db = SignalDatabase.recipients();
    RecipientId id = null;
    if (UuidUtil.isUuid(identifier)) {
        throw new AssertionError("UUIDs are not valid system contact identifiers!");
    } else if (NumberUtil.isValidEmail(identifier)) {
        id = db.getOrInsertFromEmail(identifier);
    } else {
        id = db.getOrInsertFromE164(identifier);
    }
    return Recipient.resolved(id);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 60 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class Recipient method externalPush.

/**
 * Returns a fully-populated {@link Recipient} based off of an ACI and phone number, creating one
 * in the database if necessary. We want both piece of information so we're able to associate them
 * both together, depending on which are available.
 *
 * In particular, while we'll eventually get the ACI of a user created via a phone number
 * (through a directory sync), the only way we can store the phone number is by retrieving it from
 * sent messages and whatnot. So we should store it when available.
 *
 * @param highTrust This should only be set to true if the source of the E164-ACI pairing is one
 *                  that can be trusted as accurate (like an envelope).
 */
@WorkerThread
@NonNull
public static Recipient externalPush(@Nullable ServiceId serviceId, @Nullable String e164, boolean highTrust) {
    if (ServiceId.UNKNOWN.equals(serviceId)) {
        throw new AssertionError();
    }
    RecipientDatabase db = SignalDatabase.recipients();
    RecipientId recipientId = db.getAndPossiblyMerge(serviceId, e164, highTrust);
    Recipient resolved = resolved(recipientId);
    if (!resolved.getId().equals(recipientId)) {
        Log.w(TAG, "Resolved " + recipientId + ", but got back a recipient with " + resolved.getId());
    }
    if (highTrust && !resolved.isRegistered() && serviceId != null) {
        Log.w(TAG, "External high-trust push was locally marked unregistered. Marking as registered.");
        db.markRegistered(recipientId, serviceId);
    } else if (highTrust && !resolved.isRegistered()) {
        Log.w(TAG, "External high-trust push was locally marked unregistered, but we don't have an ACI, so we can't do anything.", new Throwable());
    }
    return resolved;
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)72 Recipient (org.thoughtcrime.securesms.recipients.Recipient)32 WorkerThread (androidx.annotation.WorkerThread)30 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)20 NonNull (androidx.annotation.NonNull)18 IOException (java.io.IOException)14 Nullable (androidx.annotation.Nullable)10 ArrayList (java.util.ArrayList)10 Log (org.signal.core.util.logging.Log)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ACI (org.whispersystems.signalservice.api.push.ACI)10 Context (android.content.Context)8 Stream (com.annimon.stream.Stream)8 Collections (java.util.Collections)8 List (java.util.List)8 TimeUnit (java.util.concurrent.TimeUnit)8 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)8 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)8 Optional (org.whispersystems.libsignal.util.guava.Optional)8 HashSet (java.util.HashSet)7