Exemplo n.º 1
0
    public SmsMessageRecord getCurrent() {
      long messageId = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.ID));
      String address = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.ADDRESS));
      int addressDeviceId =
          cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.ADDRESS_DEVICE_ID));
      long type = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.TYPE));
      long dateReceived =
          cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.NORMALIZED_DATE_RECEIVED));
      long dateSent =
          cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.NORMALIZED_DATE_SENT));
      long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.THREAD_ID));
      int status = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.STATUS));
      int receiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.RECEIPT_COUNT));
      String mismatchDocument =
          cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.MISMATCHED_IDENTITIES));

      List<IdentityKeyMismatch> mismatches = getMismatches(mismatchDocument);
      Recipients recipients = getRecipientsFor(address);
      DisplayRecord.Body body = getBody(cursor);

      return new SmsMessageRecord(
          context,
          messageId,
          body,
          recipients,
          recipients.getPrimaryRecipient(),
          addressDeviceId,
          dateSent,
          dateReceived,
          receiptCount,
          type,
          threadId,
          status,
          mismatches);
    }
Exemplo n.º 2
0
  private boolean isBlocked(IncomingTextMessage message) {
    if (message.getSender() != null) {
      Recipients recipients =
          RecipientFactory.getRecipientsFromString(context, message.getSender(), false);
      return recipients.isBlocked();
    }

    return false;
  }
Exemplo n.º 3
0
 private long getThreadIdFor(@NonNull NotificationInd notification) {
   String fromString =
       notification.getFrom() != null && notification.getFrom().getTextString() != null
           ? Util.toIsoString(notification.getFrom().getTextString())
           : "";
   Recipients recipients = RecipientFactory.getRecipientsFromString(context, fromString, false);
   if (recipients.isEmpty())
     recipients =
         RecipientFactory.getRecipientsFor(context, Recipient.getUnknownRecipient(), false);
   return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
 }
  public void setTitle(@Nullable Recipients recipients) {
    if (recipients == null) setComposeTitle();
    else if (recipients.isSingleRecipient()) setRecipientTitle(recipients.getPrimaryRecipient());
    else setRecipientsTitle(recipients);

    if (recipients != null && recipients.isBlocked()) {
      title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_white_18dp, 0, 0, 0);
    } else if (recipients != null && recipients.isMuted()) {
      title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_white_18dp, 0, 0, 0);
    } else {
      title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    }
  }
Exemplo n.º 5
0
    private Recipients getRecipientsFor(String address) {
      if (TextUtils.isEmpty(address) || address.equals("insert-address-token")) {
        return RecipientFactory.getRecipientsFor(context, Recipient.getUnknownRecipient(), true);
      }

      Recipients recipients = RecipientFactory.getRecipientsFromString(context, address, true);

      if (recipients == null || recipients.isEmpty()) {
        return RecipientFactory.getRecipientsFor(context, Recipient.getUnknownRecipient(), true);
      }

      return recipients;
    }
Exemplo n.º 6
0
    private Recipients getRecipientsFor(String address) {
      if (address != null) {
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, address, true);

        if (recipients == null || recipients.isEmpty()) {
          return RecipientFactory.getRecipientsFor(context, Recipient.getUnknownRecipient(), true);
        }

        return recipients;
      } else {
        Log.w(TAG, "getRecipientsFor() address is null");
        return RecipientFactory.getRecipientsFor(context, Recipient.getUnknownRecipient(), true);
      }
    }
Exemplo n.º 7
0
    private NotificationMmsMessageRecord getNotificationMmsMessageRecord(Cursor cursor) {
      long id = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.ID));
      long dateSent =
          cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.NORMALIZED_DATE_SENT));
      long dateReceived =
          cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.NORMALIZED_DATE_RECEIVED));
      long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.THREAD_ID));
      long mailbox = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.MESSAGE_BOX));
      String address = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS));
      int addressDeviceId =
          cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS_DEVICE_ID));
      Recipients recipients = getRecipientsFor(address);

      String contentLocation =
          cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.CONTENT_LOCATION));
      String transactionId =
          cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.TRANSACTION_ID));
      long messageSize = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.MESSAGE_SIZE));
      long expiry = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.EXPIRY));
      int status = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.STATUS));
      int receiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.RECEIPT_COUNT));

      byte[] contentLocationBytes = null;
      byte[] transactionIdBytes = null;

      if (!TextUtils.isEmpty(contentLocation))
        contentLocationBytes = org.thoughtcrime.securesms.util.Util.toIsoBytes(contentLocation);

      if (!TextUtils.isEmpty(transactionId))
        transactionIdBytes = org.thoughtcrime.securesms.util.Util.toIsoBytes(transactionId);

      return new NotificationMmsMessageRecord(
          context,
          id,
          recipients,
          recipients.getPrimaryRecipient(),
          addressDeviceId,
          dateSent,
          dateReceived,
          receiptCount,
          threadId,
          contentLocationBytes,
          messageSize,
          expiry,
          status,
          transactionIdBytes,
          mailbox);
    }
 public GroupMembers(Recipients recipients) {
   for (Recipient recipient : recipients.getRecipientsList()) {
     if (isLocalNumber(recipient)) {
       members.push(recipient);
     } else {
       members.add(recipient);
     }
   }
 }
Exemplo n.º 9
0
  private List<PushAddress> getPushAddresses(Recipients recipients) throws InvalidNumberException {
    List<PushAddress> addresses = new LinkedList<>();

    for (Recipient recipient : recipients.getRecipientsList()) {
      addresses.add(getPushAddress(recipient));
    }

    return addresses;
  }
 @Override
 protected Recipients doInBackground(Void... params) {
   try {
     String groupId = recipients.getPrimaryRecipient().getNumber();
     return DatabaseFactory.getGroupDatabase(context)
         .getGroupMembers(GroupUtil.getDecodedId(groupId), true);
   } catch (IOException e) {
     Log.w(TAG, e);
     return RecipientFactory.getRecipientsFor(context, new LinkedList<Recipient>(), true);
   }
 }
  private void setRecipientsTitle(Recipients recipients) {
    int size = recipients.getRecipientsList().size();

    title.setText(getContext().getString(R.string.ConversationActivity_group_conversation));
    subtitle.setText(
        (size == 1)
            ? getContext().getString(R.string.ConversationActivity_d_recipients_in_group_singular)
            : String.format(
                getContext().getString(R.string.ConversationActivity_d_recipients_in_group), size));
    subtitle.setVisibility(View.VISIBLE);
  }
Exemplo n.º 12
0
    private MediaMmsMessageRecord getMediaMmsMessageRecord(Cursor cursor) {
      long id = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.ID));
      long dateSent =
          cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.NORMALIZED_DATE_SENT));
      long dateReceived =
          cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.NORMALIZED_DATE_RECEIVED));
      long box = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.MESSAGE_BOX));
      long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.THREAD_ID));
      String address = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS));
      int addressDeviceId =
          cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS_DEVICE_ID));
      int receiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.RECEIPT_COUNT));
      DisplayRecord.Body body = getBody(cursor);
      int partCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.PART_COUNT));
      String mismatchDocument =
          cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.MISMATCHED_IDENTITIES));
      String networkDocument =
          cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.NETWORK_FAILURE));

      Recipients recipients = getRecipientsFor(address);
      List<IdentityKeyMismatch> mismatches = getMismatchedIdentities(mismatchDocument);
      List<NetworkFailure> networkFailures = getFailures(networkDocument);
      SlideDeck slideDeck = getSlideDeck(cursor);

      return new MediaMmsMessageRecord(
          context,
          id,
          recipients,
          recipients.getPrimaryRecipient(),
          addressDeviceId,
          dateSent,
          dateReceived,
          receiptCount,
          threadId,
          body,
          slideDeck,
          partCount,
          box,
          mismatches,
          networkFailures);
    }
  private void handleSelectionFinished() {
    recipients = contactsFragment.getSelectedContacts();
    recipients.append(recentFragment.getSelectedContacts());
    recipients.append(groupsFragment.getSelectedContacts());

    Intent resultIntent = getIntent();
    resultIntent.putExtra("recipients", this.recipients);

    setResult(RESULT_OK, resultIntent);

    finish();
  }
Exemplo n.º 14
0
  private void initializeResources() {
    recipients =
        RecipientFactory.getRecipientsForIds(
            this, getIntent().getStringExtra(RECIPIENTS_EXTRA), true);
    threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
    distributionType =
        getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
    sendButton = (ImageButton) findViewById(R.id.send_button);
    composeText = (EditText) findViewById(R.id.embedded_text_editor);
    masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
    charactersLeft = (TextView) findViewById(R.id.space_left);
    emojiDrawer = (EmojiDrawer) findViewById(R.id.emoji_drawer);
    emojiToggle = (EmojiToggle) findViewById(R.id.emoji_toggle);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      emojiToggle.setVisibility(View.GONE);
    }

    attachmentAdapter = new AttachmentTypeSelectorAdapter(this);
    attachmentManager = new AttachmentManager(this, this);

    SendButtonListener sendButtonListener = new SendButtonListener();
    ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener();

    sendButton.setOnClickListener(sendButtonListener);
    sendButton.setEnabled(true);
    composeText.setOnKeyListener(composeKeyPressedListener);
    composeText.addTextChangedListener(composeKeyPressedListener);
    composeText.setOnEditorActionListener(sendButtonListener);
    composeText.setOnClickListener(composeKeyPressedListener);
    emojiDrawer.setComposeEditText(composeText);
    emojiToggle.setOnClickListener(new EmojiToggleListener());

    recipients.addListener(
        new RecipientModifiedListener() {
          @Override
          public void onModified(Recipient recipient) {
            initializeTitleBar();
          }
        });

    registerForContextMenu(sendButton);
  }
Exemplo n.º 15
0
  private long[] getRecipientIds(Recipients recipients) {
    Set<Long> recipientSet = new HashSet<>();
    List<Recipient> recipientList = recipients.getRecipientsList();

    for (Recipient recipient : recipientList) {
      recipientSet.add(recipient.getRecipientId());
    }

    long[] recipientArray = new long[recipientSet.size()];
    int i = 0;

    for (Long recipientId : recipientSet) {
      recipientArray[i++] = recipientId;
    }

    Arrays.sort(recipientArray);

    return recipientArray;
  }
  private CharSequence formatFrom(Recipients from, long count, boolean read) {
    String fromString = from.toShortString();
    SpannableStringBuilder builder = new SpannableStringBuilder(fromString);

    if (count > 0) {
      builder.append(" " + count);
      builder.setSpan(
          new ForegroundColorSpan(Color.parseColor("#66333333")),
          fromString.length(),
          builder.length(),
          Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }

    if (!read) {
      builder.setSpan(
          new StyleSpan(Typeface.BOLD), 0, builder.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }

    return builder;
  }
Exemplo n.º 17
0
  private void initializeSecurity() {
    TypedArray drawables = obtainStyledAttributes(SEND_ATTRIBUTES);
    Recipient primaryRecipient =
        getRecipients() == null ? null : getRecipients().getPrimaryRecipient();
    boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients());
    boolean isSecureDestination =
        isSingleConversation() && Session.hasSession(this, masterSecret, primaryRecipient);

    if (isPushDestination || isSecureDestination) {
      this.isEncryptedConversation = true;
      this.characterCalculator = new EncryptedCharacterCalculator();
    } else {
      this.isEncryptedConversation = false;
      this.characterCalculator = new CharacterCalculator();
    }

    if (isPushDestination) {
      sendButton.setImageDrawable(drawables.getDrawable(0));
      setComposeTextHint(getString(R.string.conversation_activity__type_message_push));
    } else if (isSecureDestination) {
      sendButton.setImageDrawable(drawables.getDrawable(1));
      setComposeTextHint(
          attachmentManager.isAttachmentPresent()
              ? getString(R.string.conversation_activity__type_message_mms_secure)
              : getString(R.string.conversation_activity__type_message_sms_secure));
    } else {
      sendButton.setImageDrawable(drawables.getDrawable(2));
      setComposeTextHint(
          (attachmentManager.isAttachmentPresent() || !recipients.isSingleRecipient())
              ? getString(R.string.conversation_activity__type_message_mms_insecure)
              : getString(R.string.conversation_activity__type_message_sms_insecure));
    }

    drawables.recycle();

    calculateCharactersRemaining();
  }
Exemplo n.º 18
0
    public String toString() {
      if (groupContext == null) {
        return context.getString(R.string.GroupUtil_group_updated);
      }

      StringBuilder description = new StringBuilder();
      String title = groupContext.getName();

      if (members != null) {
        description.append(
            context.getString(R.string.GroupUtil_joined_the_group, members.toShortString()));
      }

      if (title != null && !title.trim().isEmpty()) {
        if (description.length() > 0) description.append(" ");
        description.append(context.getString(R.string.GroupUtil_title_is_now, title));
      }

      if (description.length() > 0) {
        return description.toString();
      } else {
        return context.getString(R.string.GroupUtil_group_updated);
      }
    }
Exemplo n.º 19
0
  private void sendMessage(boolean forcePlaintext, boolean forceSms) {
    try {
      Recipients recipients = getRecipients();

      if (recipients == null) throw new RecipientFormattingException("Badly formatted");

      long allocatedThreadId;

      if ((!recipients.isSingleRecipient() || recipients.isEmailRecipient()) && !isMmsEnabled) {
        handleManualMmsRequired();
        return;
      } else if (attachmentManager.isAttachmentPresent()
          || !recipients.isSingleRecipient()
          || recipients.isGroupRecipient()
          || recipients.isEmailRecipient()) {
        allocatedThreadId = sendMediaMessage(forcePlaintext, forceSms);
      } else {
        allocatedThreadId = sendTextMessage(forcePlaintext, forceSms);
      }

      sendComplete(recipients, allocatedThreadId, allocatedThreadId != this.threadId);
    } catch (RecipientFormattingException ex) {
      Toast.makeText(
              ConversationActivity.this,
              R.string
                  .ConversationActivity_recipient_is_not_a_valid_sms_or_email_address_exclamation,
              Toast.LENGTH_LONG)
          .show();
      Log.w(TAG, ex);
    } catch (InvalidMessageException ex) {
      Toast.makeText(
              ConversationActivity.this,
              R.string.ConversationActivity_message_is_empty_exclamation,
              Toast.LENGTH_SHORT)
          .show();
      Log.w(TAG, ex);
    } catch (MmsException e) {
      Log.w(TAG, e);
    }
  }
 public void display() {
   if (recipients.isGroupRecipient()) execute();
   else onPostExecute(recipients);
 }
Exemplo n.º 21
0
 private String formatFrom(Recipients from, long count) {
   return from.toShortString() + (count > 0 ? " (" + count + ")" : "");
 }