use of org.thoughtcrime.securesms.database.ThreadDatabase 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.ThreadDatabase in project Signal-Android by WhisperSystems.
the class UserNotificationMigrationJob method performMigration.
@Override
void performMigration() {
if (!SignalStore.account().isRegistered() || SignalStore.account().getE164() == null || SignalStore.account().getAci() == null) {
Log.w(TAG, "Not registered! Skipping.");
return;
}
if (!SignalStore.settings().isNotifyWhenContactJoinsSignal()) {
Log.w(TAG, "New contact notifications disabled! Skipping.");
return;
}
if (TextSecurePreferences.getFirstInstallVersion(context) < 759) {
Log.w(TAG, "Install is older than v5.0.8. Skipping.");
return;
}
ThreadDatabase threadDatabase = SignalDatabase.threads();
int threadCount = threadDatabase.getUnarchivedConversationListCount() + threadDatabase.getArchivedConversationListCount();
if (threadCount >= 3) {
Log.w(TAG, "Already have 3 or more threads. Skipping.");
return;
}
List<RecipientId> registered = SignalDatabase.recipients().getRegistered();
List<RecipientId> systemContacts = SignalDatabase.recipients().getSystemContacts();
Set<RecipientId> registeredSystemContacts = SetUtil.intersection(registered, systemContacts);
Set<RecipientId> threadRecipients = threadDatabase.getAllThreadRecipients();
if (threadRecipients.containsAll(registeredSystemContacts)) {
Log.w(TAG, "Threads already exist for all relevant contacts. Skipping.");
return;
}
String message = context.getResources().getQuantityString(R.plurals.UserNotificationMigrationJob_d_contacts_are_on_signal, registeredSystemContacts.size(), registeredSystemContacts.size());
Intent mainActivityIntent = new Intent(context, MainActivity.class);
Intent newConversationIntent = new Intent(context, NewConversationActivity.class);
PendingIntent pendingIntent = TaskStackBuilder.create(context).addNextIntent(mainActivityIntent).addNextIntent(newConversationIntent).getPendingIntent(0, 0);
Notification notification = new NotificationCompat.Builder(context, NotificationChannels.getMessagesChannel(context)).setSmallIcon(R.drawable.ic_notification).setContentText(message).setContentIntent(pendingIntent).build();
try {
NotificationManagerCompat.from(context).notify(NotificationIds.USER_NOTIFICATION_MIGRATION, notification);
} catch (Throwable t) {
Log.w(TAG, "Failed to notify!", t);
}
}
use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by WhisperSystems.
the class ReviewCardRepository method delete.
void delete(@NonNull ReviewCard reviewCard, @NonNull Runnable onActionCompleteListener) {
if (recipientId == null) {
throw new UnsupportedOperationException();
}
SignalExecutors.BOUNDED.execute(() -> {
Recipient resolved = Recipient.resolved(recipientId);
if (resolved.isGroup())
throw new AssertionError();
if (TextSecurePreferences.isMultiDevice(context)) {
ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forDelete(recipientId));
}
ThreadDatabase threadDatabase = SignalDatabase.threads();
long threadId = Objects.requireNonNull(threadDatabase.getThreadIdFor(recipientId));
threadDatabase.deleteConversation(threadId);
onActionCompleteListener.run();
});
}
use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by WhisperSystems.
the class LiveRecipientCache method warmUp.
@AnyThread
public void warmUp() {
if (warmedUp.getAndSet(true)) {
return;
}
Stopwatch stopwatch = new Stopwatch("recipient-warm-up");
SignalExecutors.BOUNDED.execute(() -> {
ThreadDatabase threadDatabase = SignalDatabase.threads();
List<Recipient> recipients = new ArrayList<>();
try (ThreadDatabase.Reader reader = threadDatabase.readerFor(threadDatabase.getRecentConversationList(THREAD_CACHE_WARM_MAX, false, false))) {
int i = 0;
ThreadRecord record = null;
while ((record = reader.getNext()) != null && i < THREAD_CACHE_WARM_MAX) {
recipients.add(record.getRecipient());
i++;
}
}
Log.d(TAG, "Warming up " + recipients.size() + " thread recipients.");
addToCache(recipients);
stopwatch.split("thread");
if (SignalStore.registrationValues().isRegistrationComplete() && SignalStore.account().getAci() != null) {
try (Cursor cursor = SignalDatabase.recipients().getNonGroupContacts(false)) {
int count = 0;
while (cursor != null && cursor.moveToNext() && count < CONTACT_CACHE_WARM_MAX) {
RecipientId id = RecipientId.from(CursorUtil.requireLong(cursor, RecipientDatabase.ID));
Recipient.resolved(id);
count++;
}
Log.d(TAG, "Warmed up " + count + " contact recipient.");
stopwatch.split("contact");
}
}
stopwatch.stop(TAG);
});
}
Aggregations