Ejemplo n.º 1
0
  private void deliver(MasterSecret masterSecret, SendReq message)
      throws RetryLaterException, InsecureFallbackApprovalException, UntrustedIdentityException,
          UndeliverableMessageException {
    TextSecureMessageSender messageSender = messageSenderFactory.create(masterSecret);
    String destination = message.getTo()[0].getString();

    try {
      message = getResolvedMessage(masterSecret, message, MediaConstraints.PUSH_CONSTRAINTS, false);

      TextSecureAddress address = getPushAddress(destination);
      List<TextSecureAttachment> attachments = getAttachments(masterSecret, message);
      String body = PartParser.getMessageText(message.getBody());
      TextSecureMessage mediaMessage =
          TextSecureMessage.newBuilder()
              .withBody(body)
              .withAttachments(attachments)
              .withTimestamp(message.getSentTimestamp())
              .build();

      messageSender.sendMessage(address, mediaMessage);
    } catch (InvalidNumberException | UnregisteredUserException e) {
      Log.w(TAG, e);
      throw new InsecureFallbackApprovalException(e);
    } catch (IOException e) {
      Log.w(TAG, e);
      throw new RetryLaterException(e);
    }
  }
Ejemplo n.º 2
0
  private void deliver(MasterSecret masterSecret, SendReq message)
      throws IOException, RecipientFormattingException, InvalidNumberException,
          EncapsulatedExceptions {
    TextSecureMessageSender messageSender = messageSenderFactory.create(masterSecret);
    byte[] groupId = GroupUtil.getDecodedId(message.getTo()[0].getString());
    Recipients recipients =
        DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false);
    List<PushAddress> addresses = getPushAddresses(recipients);
    List<TextSecureAttachment> attachments = getAttachments(masterSecret, message);

    if (MmsSmsColumns.Types.isGroupUpdate(message.getDatabaseMessageBox())
        || MmsSmsColumns.Types.isGroupQuit(message.getDatabaseMessageBox())) {
      String content = PartParser.getMessageText(message.getBody());

      if (content != null && !content.trim().isEmpty()) {
        PushMessageProtos.PushMessageContent.GroupContext groupContext =
            PushMessageProtos.PushMessageContent.GroupContext.parseFrom(Base64.decode(content));
        TextSecureAttachment avatar = attachments.isEmpty() ? null : attachments.get(0);
        TextSecureGroup.Type type =
            MmsSmsColumns.Types.isGroupQuit(message.getDatabaseMessageBox())
                ? TextSecureGroup.Type.QUIT
                : TextSecureGroup.Type.UPDATE;
        TextSecureGroup group =
            new TextSecureGroup(
                type, groupId, groupContext.getName(), groupContext.getMembersList(), avatar);
        TextSecureMessage groupMessage =
            new TextSecureMessage(message.getSentTimestamp(), group, null, null);

        messageSender.sendMessage(addresses, groupMessage);
      }
    } else {
      String body = PartParser.getMessageText(message.getBody());
      TextSecureGroup group = new TextSecureGroup(groupId);
      TextSecureMessage groupMessage =
          new TextSecureMessage(message.getSentTimestamp(), group, attachments, body);

      messageSender.sendMessage(addresses, groupMessage);
    }
  }