Search in sources :

Example 6 with ThreadDatabase

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();
    });
}
Also used : ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase)

Example 7 with ThreadDatabase

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();
}
Also used : LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 8 with ThreadDatabase

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();
    }
}
Also used : ArrayList(java.util.ArrayList) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase)

Example 9 with ThreadDatabase

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();
    });
}
Also used : GroupPatchNotAcceptedException(org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException) GroupChangeException(org.thoughtcrime.securesms.groups.GroupChangeException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) IOException(java.io.IOException) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase)

Example 10 with ThreadDatabase

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);
}
Also used : ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)29 Recipient (org.thoughtcrime.securesms.recipients.Recipient)14 ThreadRecord (org.thoughtcrime.securesms.database.model.ThreadRecord)7 ArrayList (java.util.ArrayList)6 SuppressLint (android.annotation.SuppressLint)5 Cursor (android.database.Cursor)5 WorkerThread (androidx.annotation.WorkerThread)5 Context (android.content.Context)4 MmsException (org.thoughtcrime.securesms.mms.MmsException)4 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)4 Recipients (org.thoughtcrime.securesms.recipients.Recipients)4 Bundle (android.os.Bundle)3 NonNull (androidx.annotation.NonNull)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 DraftDatabase (org.thoughtcrime.securesms.database.DraftDatabase)3 Drafts (org.thoughtcrime.securesms.database.DraftDatabase.Drafts)3 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)3 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)3 ComponentName (android.content.ComponentName)2