コード例 #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);
    }
  }