Esempio n. 1
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);
    }
  }
Esempio n. 2
0
  @Override
  public void onCanceled() {
    Log.w(TAG, "onCanceled()");
    long threadId = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageId);
    Recipients recipients =
        DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);

    DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId);
    if (threadId != -1 && recipients != null) {
      MessageNotifier.notifyMessageDeliveryFailed(context, recipients, threadId);
    }
  }
Esempio n. 3
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;
  }
 public ConversationListAdapter(
     @NonNull Context context,
     @NonNull MasterSecret masterSecret,
     @NonNull Locale locale,
     @Nullable Cursor cursor,
     @Nullable ItemClickListener clickListener) {
   super(context, cursor);
   try {
     this.masterSecret = masterSecret;
     this.masterCipher = new MasterCipher(masterSecret);
     this.threadDatabase = DatabaseFactory.getThreadDatabase(context);
     this.locale = locale;
     this.inflater = LayoutInflater.from(context);
     this.clickListener = clickListener;
     this.digest = MessageDigest.getInstance("SHA1");
     setHasStableIds(true);
   } catch (NoSuchAlgorithmException nsae) {
     throw new AssertionError("SHA-1 missing");
   }
 }