Search in sources :

Example 51 with RecipientDatabase

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

the class InviteReminderRepository method setHasSeenSecondInviteReminder.

@Override
public void setHasSeenSecondInviteReminder(Recipient recipient) {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    recipientDatabase.setSeenSecondInviteReminder(recipient.getId());
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase)

Example 52 with RecipientDatabase

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

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

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

the class DirectoryHelper method refreshDirectoryFor.

@WorkerThread
public static void refreshDirectoryFor(@NonNull Context context, @NonNull List<Recipient> recipients, boolean notifyOfNewUsers) throws IOException {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    for (Recipient recipient : recipients) {
        if (recipient.hasServiceId() && !recipient.hasE164()) {
            if (ApplicationDependencies.getSignalServiceAccountManager().isIdentifierRegistered(recipient.requireServiceId())) {
                recipientDatabase.markRegistered(recipient.getId(), recipient.requireServiceId());
            } else {
                recipientDatabase.markUnregistered(recipient.getId());
            }
        }
    }
    Set<String> numbers = Stream.of(recipients).filter(Recipient::hasE164).map(Recipient::requireE164).collect(Collectors.toSet());
    refreshNumbers(context, numbers, numbers, notifyOfNewUsers, false);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) WorkerThread(androidx.annotation.WorkerThread)

Example 54 with RecipientDatabase

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

the class MessageContentProcessor method handleSynchronizeMessageRequestResponse.

private void handleSynchronizeMessageRequestResponse(@NonNull MessageRequestResponseMessage response, long envelopeTimestamp) throws BadGroupIdException {
    log(envelopeTimestamp, "Synchronize message request response.");
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    Recipient recipient;
    if (response.getPerson().isPresent()) {
        recipient = Recipient.externalPush(response.getPerson().get());
    } else if (response.getGroupId().isPresent()) {
        GroupId groupId = GroupId.v1(response.getGroupId().get());
        recipient = Recipient.externalPossiblyMigratedGroup(context, groupId);
    } else {
        warn("Message request response was missing a thread recipient! Skipping.");
        return;
    }
    long threadId = threadDatabase.getOrCreateThreadIdFor(recipient);
    switch(response.getType()) {
        case ACCEPT:
            recipientDatabase.setProfileSharing(recipient.getId(), true);
            recipientDatabase.setBlocked(recipient.getId(), false);
            break;
        case DELETE:
            recipientDatabase.setProfileSharing(recipient.getId(), false);
            if (threadId > 0)
                threadDatabase.deleteConversation(threadId);
            break;
        case BLOCK:
            recipientDatabase.setBlocked(recipient.getId(), true);
            recipientDatabase.setProfileSharing(recipient.getId(), false);
            break;
        case BLOCK_AND_DELETE:
            recipientDatabase.setBlocked(recipient.getId(), true);
            recipientDatabase.setProfileSharing(recipient.getId(), false);
            if (threadId > 0)
                threadDatabase.deleteConversation(threadId);
            break;
        default:
            warn("Got an unknown response type! Skipping");
            break;
    }
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 55 with RecipientDatabase

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

the class NotificationChannels method restoreContactNotificationChannels.

/**
 * Recreates all notification channels for contacts with custom notifications enabled. Should be
 * safe to call repeatedly. Needs to be executed on a background thread.
 */
@WorkerThread
public static synchronized void restoreContactNotificationChannels(@NonNull Context context) {
    if (!NotificationChannels.supported()) {
        return;
    }
    RecipientDatabase db = SignalDatabase.recipients();
    try (RecipientDatabase.RecipientReader reader = db.getRecipientsWithNotificationChannels()) {
        Recipient recipient;
        while ((recipient = reader.getNext()) != null) {
            NotificationManager notificationManager = ServiceUtil.getNotificationManager(context);
            if (!channelExists(notificationManager.getNotificationChannel(recipient.getNotificationChannel()))) {
                String id = createChannelFor(context, recipient);
                db.setNotificationChannel(recipient.getId(), id);
            }
        }
    }
    ensureCustomChannelConsistency(context);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) NotificationManager(android.app.NotificationManager) Recipient(org.thoughtcrime.securesms.recipients.Recipient) WorkerThread(androidx.annotation.WorkerThread)

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