Example #1
0
 private Recipients getSyncMessageDestination(TextSecureMessage message) {
   if (message.getGroupInfo().isPresent()) {
     return RecipientFactory.getRecipientsFromString(
         context, GroupUtil.getEncodedId(message.getGroupInfo().get().getGroupId()), false);
   } else {
     return RecipientFactory.getRecipientsFromString(
         context, message.getSyncContext().get().getDestination(), false);
   }
 }
  @Override
  public void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped"));

    if (data == null || resultCode != Activity.RESULT_OK) return;

    switch (reqCode) {
      case PICK_CONTACT:
        List<String> selected = data.getStringArrayListExtra("contacts");
        for (String contact : selected) {
          Recipient recipient =
              RecipientFactory.getRecipientsFromString(this, contact, false).getPrimaryRecipient();

          if (!selectedContacts.contains(recipient)
              && (existingContacts == null || !existingContacts.contains(recipient))
              && recipient != null) {
            addSelectedContact(recipient);
          }
        }
        syncAdapterWithSelectedContacts();
        break;

      case Crop.REQUEST_PICK:
        new Crop(data.getData()).output(outputFile).asSquare().start(this);
        break;
      case Crop.REQUEST_CROP:
        new DecodeCropAndSetAsyncTask(Crop.getOutput(data)).execute();
    }
  }
Example #3
0
  private void handleUntrustedIdentityMessage(
      MasterSecret masterSecret, TextSecureEnvelope envelope, Optional<Long> smsMessageId) {
    try {
      EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
      Recipients recipients =
          RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
      long recipientId = recipients.getPrimaryRecipient().getRecipientId();
      PreKeyWhisperMessage whisperMessage = new PreKeyWhisperMessage(envelope.getMessage());
      IdentityKey identityKey = whisperMessage.getIdentityKey();
      String encoded = Base64.encodeBytes(envelope.getMessage());
      IncomingTextMessage textMessage =
          new IncomingTextMessage(
              envelope.getSource(),
              envelope.getSourceDevice(),
              envelope.getTimestamp(),
              encoded,
              Optional.<TextSecureGroup>absent());

      if (!smsMessageId.isPresent()) {
        IncomingPreKeyBundleMessage bundleMessage =
            new IncomingPreKeyBundleMessage(textMessage, encoded);
        Pair<Long, Long> messageAndThreadId =
            database.insertMessageInbox(masterSecret, bundleMessage);

        database.setMismatchedIdentity(messageAndThreadId.first, recipientId, identityKey);
        MessageNotifier.updateNotification(context, masterSecret, messageAndThreadId.second);
      } else {
        database.updateMessageBody(masterSecret, smsMessageId.get(), encoded);
        database.markAsPreKeyBundle(smsMessageId.get());
        database.setMismatchedIdentity(smsMessageId.get(), recipientId, identityKey);
      }
    } catch (InvalidMessageException | InvalidVersionException e) {
      throw new AssertionError(e);
    }
  }
  private Pair<Long, Recipients> handlePushOperation(
      byte[] groupId, String groupName, byte[] avatar, Set<String> e164numbers)
      throws InvalidNumberException {
    String groupRecipientId = GroupUtil.getEncodedId(groupId);
    Recipients groupRecipient =
        RecipientFactory.getRecipientsFromString(this, groupRecipientId, false);

    GroupContext context =
        GroupContext.newBuilder()
            .setId(ByteString.copyFrom(groupId))
            .setType(GroupContext.Type.UPDATE)
            .setName(groupName)
            .addAllMembers(e164numbers)
            .build();

    OutgoingGroupMediaMessage outgoingMessage =
        new OutgoingGroupMediaMessage(this, groupRecipient, context, avatar);
    long threadId = MessageSender.send(this, masterSecret, outgoingMessage, -1, false);

    return new Pair<>(threadId, groupRecipient);
  }
    @Override
    protected void onPostExecute(Long resultThread) {
      if (resultThread > -1) {
        Intent intent = new Intent(GroupCreateActivity.this, ConversationActivity.class);
        intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, resultThread.longValue());
        intent.putExtra(
            ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);

        ArrayList<Recipient> selectedContactsList = setToArrayList(selectedContacts);
        intent.putExtra(
            ConversationActivity.RECIPIENTS_EXTRA,
            RecipientFactory.getRecipientsFor(GroupCreateActivity.this, selectedContactsList, true)
                .getIds());
        startActivity(intent);
        finish();
      } else {
        Toast.makeText(
                getApplicationContext(),
                R.string.GroupCreateActivity_contacts_mms_exception,
                Toast.LENGTH_LONG)
            .show();
        finish();
      }
    }
 private long handleCreateMmsGroup(Set<Recipient> members) {
   Recipients recipients =
       RecipientFactory.getRecipientsFor(this, new LinkedList<>(members), false);
   return DatabaseFactory.getThreadDatabase(this)
       .getThreadIdFor(recipients, ThreadDatabase.DistributionTypes.CONVERSATION);
 }
  private void initializeResources() {
    groupRecipient =
        RecipientFactory.getRecipientForId(
            this, getIntent().getLongExtra(GROUP_RECIPIENT_EXTRA, -1), true);
    groupThread = getIntent().getLongExtra(GROUP_THREAD_EXTRA, -1);
    if (groupRecipient != null) {
      final String encodedGroupId = groupRecipient.getNumber();
      if (encodedGroupId != null) {
        try {
          groupId = GroupUtil.getDecodedId(encodedGroupId);
        } catch (IOException ioe) {
          Log.w(TAG, "Couldn't decode the encoded groupId passed in via intent", ioe);
          groupId = null;
        }
        if (groupId != null) {
          new FillExistingGroupInfoAsyncTask().execute();
        }
      }
    }

    lv = (ListView) findViewById(R.id.selected_contacts_list);
    avatar = (ImageView) findViewById(R.id.avatar);
    groupName = (EditText) findViewById(R.id.group_name);
    creatingText = (TextView) findViewById(R.id.creating_group_text);
    recipientsPanel = (PushRecipientsPanel) findViewById(R.id.recipients);

    groupName.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

          @Override
          public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

          @Override
          public void afterTextChanged(Editable editable) {
            final int prefixResId =
                (groupId != null)
                    ? R.string.GroupCreateActivity_actionbar_update_title
                    : R.string.GroupCreateActivity_actionbar_title;
            if (editable.length() > 0) {
              getSupportActionBar().setTitle(getString(prefixResId) + ": " + editable.toString());
            } else {
              getSupportActionBar().setTitle(prefixResId);
            }
          }
        });

    SelectedRecipientsAdapter adapter =
        new SelectedRecipientsAdapter(
            this, android.R.id.text1, new ArrayList<SelectedRecipientsAdapter.RecipientWrapper>());
    adapter.setOnRecipientDeletedListener(
        new SelectedRecipientsAdapter.OnRecipientDeletedListener() {
          @Override
          public void onRecipientDeleted(Recipient recipient) {
            removeSelectedContact(recipient);
          }
        });
    lv.setAdapter(adapter);

    recipientsPanel.setPanelChangeListener(
        new PushRecipientsPanel.RecipientsPanelChangedListener() {
          @Override
          public void onRecipientsPanelUpdate(Recipients recipients) {
            Log.i(TAG, "onRecipientsPanelUpdate received.");
            if (recipients != null) {
              addAllSelectedContacts(recipients.getRecipientsList());
              syncAdapterWithSelectedContacts();
            }
          }
        });
    (findViewById(R.id.contacts_button)).setOnClickListener(new AddRecipientButtonListener());

    avatar.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Crop.pickImage(GroupCreateActivity.this);
          }
        });

    ((RecipientsEditor) findViewById(R.id.recipients_text))
        .setHint(R.string.recipients_panel__add_member);
  }