Search in sources :

Example 1 with ThreadDatabase

use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by WhisperSystems.

the class IdentityUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws Exception {
    Recipient recipient = RecipientFactory.getRecipientForId(context, recipientId, true);
    Recipients recipients = RecipientFactory.getRecipientsFor(context, recipient, true);
    String number = recipient.getNumber();
    long time = System.currentTimeMillis();
    SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    GroupDatabase.Reader reader = groupDatabase.getGroups();
    GroupDatabase.GroupRecord groupRecord;
    while ((groupRecord = reader.getNext()) != null) {
        if (groupRecord.getMembers().contains(number) && groupRecord.isActive()) {
            SignalServiceGroup group = new SignalServiceGroup(groupRecord.getId());
            IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.of(group), 0);
            IncomingIdentityUpdateMessage groupUpdate = new IncomingIdentityUpdateMessage(incoming);
            smsDatabase.insertMessageInbox(groupUpdate);
        }
    }
    if (threadDatabase.getThreadIdIfExistsFor(recipients) != -1) {
        IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.<SignalServiceGroup>absent(), 0);
        IncomingIdentityUpdateMessage individualUpdate = new IncomingIdentityUpdateMessage(incoming);
        smsDatabase.insertMessageInbox(individualUpdate);
    }
}
Also used : IncomingIdentityUpdateMessage(org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

Example 2 with ThreadDatabase

use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by WhisperSystems.

the class MessageNotifier method updateNotification.

public static void updateNotification(@NonNull Context context, @Nullable MasterSecret masterSecret, long threadId, boolean signal) {
    boolean isVisible = visibleThread == threadId;
    ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context);
    Recipients recipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
    if (isVisible) {
        List<MarkedMessageInfo> messageIds = threads.setRead(threadId, false);
        MarkReadReceiver.process(context, messageIds);
    }
    if (!TextSecurePreferences.isNotificationsEnabled(context) || (recipients != null && recipients.isMuted())) {
        return;
    }
    if (isVisible) {
        sendInThreadNotification(context, threads.getRecipientsForThreadId(threadId));
    } else {
        updateNotification(context, masterSecret, signal, 0);
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo)

Example 3 with ThreadDatabase

use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by signalapp.

the class MessageSender method send.

public static long send(final Context context, final OutgoingMediaMessage message, final long threadId, final boolean forceSms, final SmsDatabase.InsertListener insertListener) {
    try {
        ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
        MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
        long allocatedThreadId;
        if (threadId == -1) {
            allocatedThreadId = threadDatabase.getThreadIdFor(message.getRecipient(), message.getDistributionType());
        } else {
            allocatedThreadId = threadId;
        }
        Recipient recipient = message.getRecipient();
        long messageId = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener);
        sendMediaMessage(context, recipient, forceSms, messageId, message.getExpiresIn());
        return allocatedThreadId;
    } catch (MmsException e) {
        Log.w(TAG, e);
        return threadId;
    }
}
Also used : MmsException(org.thoughtcrime.securesms.mms.MmsException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 4 with ThreadDatabase

use of org.thoughtcrime.securesms.database.ThreadDatabase in project Signal-Android by signalapp.

the class MessageNotifier method updateNotification.

public static void updateNotification(@NonNull Context context, long threadId, boolean signal) {
    boolean isVisible = visibleThread == threadId;
    ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context);
    Recipient recipients = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId);
    if (isVisible) {
        List<MarkedMessageInfo> messageIds = threads.setRead(threadId, false);
        MarkReadReceiver.process(context, messageIds);
    }
    if (!TextSecurePreferences.isNotificationsEnabled(context) || (recipients != null && recipients.isMuted())) {
        return;
    }
    if (isVisible) {
        sendInThreadNotification(context, threads.getRecipientForThreadId(threadId));
    } else {
        updateNotification(context, signal, 0);
    }
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo)

Example 5 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)

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