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