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());
}
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);
}
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);
}
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;
}
}
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);
}
Aggregations