Exemple #1
0
  private static NotificationState constructNotificationState(
      Context context, MasterSecret masterSecret, Cursor cursor) {
    NotificationState notificationState = new NotificationState();
    MessageRecord record;
    MmsSmsDatabase.Reader reader;

    if (masterSecret == null) reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor);
    else reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret);

    while ((record = reader.getNext()) != null) {
      Recipient recipient = record.getIndividualRecipient();
      Recipients recipients = record.getRecipients();
      long threadId = record.getThreadId();
      CharSequence body = record.getDisplayBody();
      Recipients threadRecipients = null;
      ListenableFutureTask<SlideDeck> slideDeck = null;
      long timestamp;

      if (SMSSecurePreferences.showSentTime(context)) timestamp = record.getDateSent();
      else timestamp = record.getDateReceived();

      if (threadId != -1) {
        threadRecipients =
            DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
      }

      if (SmsDatabase.Types.isDecryptInProgressType(record.getType())
          || !record.getBody().isPlaintext()) {
        body = SpanUtil.italic(context.getString(R.string.MessageNotifier_encrypted_message));
      } else if (record.isMms() && TextUtils.isEmpty(body)) {
        body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message));
        slideDeck = ((MediaMmsMessageRecord) record).getSlideDeckFuture();
      } else if (record.isMms() && !record.isMmsNotification()) {
        String message = context.getString(R.string.MessageNotifier_media_message_with_text, body);
        int italicLength = message.length() - body.length();
        body = SpanUtil.italic(message, italicLength);
        slideDeck = ((MediaMmsMessageRecord) record).getSlideDeckFuture();
      }

      if (threadRecipients == null || !threadRecipients.isMuted()) {
        notificationState.addNotification(
            new NotificationItem(
                recipient, recipients, threadRecipients, threadId, body, timestamp, slideDeck));
      }
    }

    reader.close();
    return notificationState;
  }
Exemple #2
0
  public static void updateNotification(Context context, MasterSecret masterSecret, long threadId) {
    Recipients recipients =
        DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);

    if (!SMSSecurePreferences.isNotificationsEnabled(context)
        || (recipients != null && recipients.isMuted())) {
      return;
    }

    if (visibleThread == threadId) {
      ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context);
      threads.setRead(threadId);
      sendInThreadNotification(context, threads.getRecipientsForThreadId(threadId));
    } else {
      updateNotification(context, masterSecret, true, 0);
    }
  }