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