use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by WhisperSystems.
the class ConversationListFragment method handleUnpin.
private void handleUnpin(@NonNull Collection<Long> ids) {
SimpleTask.run(SignalExecutors.BOUNDED, () -> {
ThreadDatabase db = SignalDatabase.threads();
db.unpinConversations(ids);
return null;
}, unused -> {
endActionModeIfActive();
});
}
use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by WhisperSystems.
the class InviteReminderModel method createReminderInfo.
@WorkerThread
@NonNull
private ReminderInfo createReminderInfo(Recipient recipient) {
Recipient resolved = recipient.resolve();
if (resolved.isRegistered() || resolved.isGroup() || resolved.hasSeenSecondInviteReminder()) {
return new NoReminderInfo();
}
ThreadDatabase threadDatabase = SignalDatabase.threads();
Long threadId = threadDatabase.getThreadIdFor(recipient.getId());
if (threadId != null) {
int conversationCount = SignalDatabase.mmsSms().getInsecureSentCount(threadId);
if (conversationCount >= SECOND_INVITE_REMINDER_MESSAGE_THRESHOLD && !resolved.hasSeenSecondInviteReminder()) {
return new SecondInviteReminderInfo(context, resolved, repository, repository.getPercentOfInsecureMessages(conversationCount));
} else if (conversationCount >= FIRST_INVITE_REMINDER_MESSAGE_THRESHOLD && !resolved.hasSeenFirstInviteReminder()) {
return new FirstInviteReminderInfo(context, resolved, repository, repository.getPercentOfInsecureMessages(conversationCount));
}
}
return new NoReminderInfo();
}
use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by WhisperSystems.
the class ConversationShortcutUpdateJob method onRun.
@Override
protected void onRun() throws Exception {
if (TextSecurePreferences.isScreenLockEnabled(context)) {
Log.i(TAG, "Screen lock enabled. Clearing shortcuts.");
ConversationUtil.clearAllShortcuts(context);
return;
}
ThreadDatabase threadDatabase = SignalDatabase.threads();
int maxShortcuts = ConversationUtil.getMaxShortcuts(context);
List<Recipient> ranked = new ArrayList<>(maxShortcuts);
try (ThreadDatabase.Reader reader = threadDatabase.readerFor(threadDatabase.getRecentConversationList(maxShortcuts, false, false))) {
ThreadRecord record;
while ((record = reader.getNext()) != null) {
ranked.add(record.getRecipient().resolve());
}
}
boolean success = ConversationUtil.setActiveShortcuts(context, ranked);
if (!success) {
throw new RetryLaterException();
}
}
use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by WhisperSystems.
the class MessageRequestRepository method deleteMessageRequest.
void deleteMessageRequest(@NonNull LiveRecipient recipient, long threadId, @NonNull Runnable onMessageRequestDeleted, @NonNull GroupChangeErrorCallback error) {
executor.execute(() -> {
Recipient resolved = recipient.resolve();
if (resolved.isGroup() && resolved.requireGroupId().isPush()) {
try {
GroupManager.leaveGroupFromBlockOrMessageRequest(context, resolved.requireGroupId().requirePush());
} catch (GroupChangeException | GroupPatchNotAcceptedException e) {
if (SignalDatabase.groups().isCurrentMember(resolved.requireGroupId().requirePush(), Recipient.self().getId())) {
Log.w(TAG, "Failed to leave group, and we're still a member.", e);
error.onError(GroupChangeFailureReason.fromException(e));
return;
} else {
Log.w(TAG, "Failed to leave group, but we're not a member, so ignoring.");
}
} catch (IOException e) {
Log.w(TAG, e);
error.onError(GroupChangeFailureReason.fromException(e));
return;
}
}
if (TextSecurePreferences.isMultiDevice(context)) {
ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forDelete(recipient.getId()));
}
ThreadDatabase threadDatabase = SignalDatabase.threads();
threadDatabase.deleteConversation(threadId);
onMessageRequestDeleted.run();
});
}
use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by WhisperSystems.
the class RecipientUtil method isMessageRequestAccepted.
/**
* If true, the new message request UI does not need to be shown, and it's safe to send read
* receipts.
*
* Note that this does not imply that a user has explicitly accepted a message request -- it could
* also be the case that the thread in question is for a system contact or something of the like.
*/
@WorkerThread
public static boolean isMessageRequestAccepted(@NonNull Context context, long threadId) {
if (threadId < 0) {
return true;
}
ThreadDatabase threadDatabase = SignalDatabase.threads();
Recipient threadRecipient = threadDatabase.getRecipientForThreadId(threadId);
if (threadRecipient == null) {
return true;
}
return isMessageRequestAccepted(context, threadId, threadRecipient);
}
Aggregations