org.whispersystems.signalservice.internal.push.SignalServiceProtos Java Examples

The following examples show how to use org.whispersystems.signalservice.internal.push.SignalServiceProtos. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static SignalServiceGroupV2 createGroupV2Info(SignalServiceProtos.DataMessage content) throws ProtocolInvalidMessageException {
  if (!content.hasGroupV2()) return null;

  SignalServiceProtos.GroupContextV2 groupV2 = content.getGroupV2();
  if (!groupV2.hasMasterKey()) {
    throw new ProtocolInvalidMessageException(new InvalidMessageException("No GV2 master key on message"), null, 0);
  }
  if (!groupV2.hasRevision()) {
    throw new ProtocolInvalidMessageException(new InvalidMessageException("No GV2 revision on message"), null, 0);
  }

  SignalServiceGroupV2.Builder builder;
  try {
    builder = SignalServiceGroupV2.newBuilder(new GroupMasterKey(groupV2.getMasterKey().toByteArray()))
                                  .withRevision(groupV2.getRevision());
  } catch (InvalidInputException e) {
    throw new ProtocolInvalidMessageException(new InvalidMessageException(e), null, 0);
  }

  if (groupV2.hasGroupChange()) {
    builder.withSignedGroupChange(groupV2.getGroupChange().toByteArray());
  }

  return builder.build();
}
 
Example #2
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleEndSessionMessage(@NonNull SignalServiceProtos.Envelope envelope,
                                     @NonNull SignalServiceDataMessage message) {
    ALog.i(TAG, "handleEndSessionMessage");
    PrivateChatRepo chatRepo = repository.getChatRepo();
    IncomingTextMessage incomingTextMessage = new IncomingTextMessage(Address.from(accountContext, envelope.getSource()),
            envelope.getSourceDevice(),
            message.getTimestamp(),
            "", Optional.absent(), 0);

    long threadId;

    IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage);
    kotlin.Pair<Long, Long> insertResult = chatRepo.insertIncomingTextMessage(incomingEndSessionMessage);

    if (insertResult.getSecond() > 0)
        threadId = insertResult.getFirst();
    else
        threadId = 0L;

    if (threadId > 0L) {
        SessionStore sessionStore = new TextSecureSessionStore(context, accountContext);
        sessionStore.deleteAllSessions(envelope.getSource());

        SecurityEvent.broadcastSecurityUpdateEvent(context);
    }
}
 
Example #3
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleCallIceUpdateMessage(@NonNull SignalServiceProtos.Envelope envelope,
                                        @NonNull List<IceUpdateMessage> messages) {
    ALog.i(TAG, "handleCallIceUpdateMessage... " + messages.size());
    for (IceUpdateMessage message : messages) {
        try {
            Intent intent = new Intent(context, WebRtcCallService.class);
            intent.setAction(WebRtcCallService.ACTION_ICE_MESSAGE);
            intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
            intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.from(accountContext, envelope.getSource()));
            intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP, message.getSdp());
            intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_MID, message.getSdpMid());
            intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_LINE_INDEX, message.getSdpMLineIndex());
            intent.putExtra(ARouterConstants.PARAM.PARAM_ACCOUNT_CONTEXT, accountContext);
            AppUtilKotlinKt.startForegroundServiceCompat(context, intent);
        } catch (Exception ex) {
            ALog.e(TAG, "handleCallIceUpdateMessage error", ex);
        }
    }
}
 
Example #4
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleExpirationUpdate(@NonNull MasterSecretUnion masterSecret,
                                    @NonNull SignalServiceProtos.Envelope envelope,
                                    @NonNull SignalServiceDataMessage message) {
    ALog.i(TAG, "handleExpirationUpdate");

    PrivateChatRepo chatRepo = repository.getChatRepo();
    Recipient recipient = getMessageDestination(envelope, message);
    IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret,
            Address.from(accountContext, envelope.getSource()),
            message.getTimestamp(), -1,
            message.getExpiresInSeconds() * 1000, true,
            Optional.fromNullable(envelope.getRelay()),
            Optional.absent(), message.getGroupInfo(),
            Optional.absent());


    chatRepo.insertIncomingMediaMessage(masterSecret.getMasterSecret().get(), mediaMessage);

    repository.getRecipientRepo().setExpireTime(recipient, message.getExpiresInSeconds());
}
 
Example #5
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleCallOfferMessage(@NonNull SignalServiceProtos.Envelope envelope,
                                    @NonNull OfferMessage message) {
    ALog.logForSecret(TAG, "handleCallOfferMessage:" + message.getDescription());

    try {
        Intent intent = new Intent(context, WebRtcCallService.class);
        intent.setAction(WebRtcCallService.ACTION_INCOMING_CALL);
        intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
        CameraState.Direction callType = message.callType()== SignalServiceProtos.CallMessage.Offer.CallType.VIDEO? CameraState.Direction.FRONT:CameraState.Direction.NONE;
        intent.putExtra(WebRtcCallService.EXTRA_CALL_TYPE, callType.toString());
        intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.from(accountContext, envelope.getSource()));
        intent.putExtra(WebRtcCallService.EXTRA_REMOTE_DESCRIPTION, message.getDescription());
        intent.putExtra(WebRtcCallService.EXTRA_TIMESTAMP, envelope.getTimestamp());
        intent.putExtra(ARouterConstants.PARAM.PARAM_ACCOUNT_CONTEXT, accountContext);
        AppUtilKotlinKt.startForegroundServiceCompat(context, intent);
    } catch (Exception ex) {
        ALog.e(TAG, "handleCallOfferMessage error", ex);
    }
}
 
Example #6
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleUntrustedIdentityMessage(@NonNull SignalServiceProtos.Envelope envelope) {
    ALog.i(TAG, "handleUntrustedIdentityMessage");
    try {
        PrivateChatRepo chatRepo = repository.getChatRepo();
        Address sourceAddress = Address.from(accountContext, envelope.getSource());
        byte[] serialized = envelope.hasLegacyMessage() ? envelope.getLegacyMessage().toByteArray() : envelope.getContent().toByteArray();
        PreKeySignalMessage whisperMessage = new PreKeySignalMessage(serialized);
        String encoded = Base64.encodeBytes(serialized);

        IncomingTextMessage textMessage = new IncomingTextMessage(sourceAddress,
                envelope.getSourceDevice(),
                envelope.getTimestamp(), encoded,
                Optional.absent(), 0);

        IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded, envelope.hasLegacyMessage());

        chatRepo.insertIncomingTextMessage(bundleMessage);
    } catch (InvalidMessageException | InvalidVersionException e) {
        throw new AssertionError(e);
    }
}
 
Example #7
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleProfileKey(@NonNull SignalServiceProtos.Envelope envelope,
                              @NonNull SignalServiceDataMessage message) {
    ALog.i(TAG, "handleProfileKey");

    RecipientRepo recipientRepo = Repository.getRecipientRepo(accountContext);
    Recipient recipient = Recipient.from(accountContext, envelope.getSource(), false);

    if (recipient.getProfileKey() == null || !MessageDigest.isEqual(recipient.getProfileKey(), message.getProfileKey().get())) {
        if (recipientRepo != null) {
            recipientRepo.setProfileKey(recipient, message.getProfileKey().get());
        }

        JobManager manager = AmeModuleCenter.INSTANCE.accountJobMgr(accountContext);
        if (manager != null) {
            manager.add(new RetrieveProfileJob(context, accountContext, recipient));
        }
    }
}
 
Example #8
Source File: DeviceGroupsOutputStream.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private void writeGroupDetails(DeviceGroup group) throws IOException {
  SignalServiceProtos.GroupDetails.Builder groupDetails = SignalServiceProtos.GroupDetails.newBuilder();
  groupDetails.setId(ByteString.copyFrom(group.getId()));

  if (group.getName().isPresent()) {
    groupDetails.setName(group.getName().get());
  }

  if (group.getAvatar().isPresent()) {
    SignalServiceProtos.GroupDetails.Avatar.Builder avatarBuilder = SignalServiceProtos.GroupDetails.Avatar.newBuilder();
    avatarBuilder.setContentType(group.getAvatar().get().getContentType());
    avatarBuilder.setLength((int)group.getAvatar().get().getLength());
    groupDetails.setAvatar(avatarBuilder);
  }

  groupDetails.addAllMembers(group.getMembers());
  groupDetails.setActive(group.isActive());

  byte[] serializedContactDetails = groupDetails.build().toByteArray();

  writeVarint32(serializedContactDetails.length);
  out.write(serializedContactDetails);
}
 
Example #9
Source File: GroupProtoUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public static DecryptedGroupV2Context createDecryptedGroupV2Context(@NonNull GroupMasterKey masterKey,
                                                                    @NonNull DecryptedGroup decryptedGroup,
                                                                    @Nullable DecryptedGroupChange plainGroupChange,
                                                                    @Nullable GroupChange signedServerChange)
{
  int revision = plainGroupChange != null ? plainGroupChange.getRevision() : decryptedGroup.getRevision();
  SignalServiceProtos.GroupContextV2.Builder contextBuilder = SignalServiceProtos.GroupContextV2.newBuilder()
                                                                                                .setMasterKey(ByteString.copyFrom(masterKey.serialize()))
                                                                                                .setRevision(revision);

  if (signedServerChange != null) {
    contextBuilder.setGroupChange(signedServerChange.toByteString());
  }

  DecryptedGroupV2Context.Builder builder = DecryptedGroupV2Context.newBuilder()
                                                                   .setContext(contextBuilder.build())
                                                                   .setGroupState(decryptedGroup);

  if (plainGroupChange != null) {
    builder.setChange(plainGroupChange);
  }

  return builder.build();
}
 
Example #10
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static SignalServiceAttachmentPointer createAttachmentPointer(SignalServiceProtos.AttachmentPointer pointer) throws ProtocolInvalidMessageException {
  return new SignalServiceAttachmentPointer(pointer.getCdnNumber(),
                                            SignalServiceAttachmentRemoteId.from(pointer),
                                            pointer.getContentType(),
                                            pointer.getKey().toByteArray(),
                                            pointer.hasSize() ? Optional.of(pointer.getSize()) : Optional.<Integer>absent(),
                                            pointer.hasThumbnail() ? Optional.of(pointer.getThumbnail().toByteArray()): Optional.<byte[]>absent(),
                                            pointer.getWidth(), pointer.getHeight(),
                                            pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.<byte[]>absent(),
                                            pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.<String>absent(),
                                            (pointer.getFlags() & SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) != 0,
                                            pointer.hasCaption() ? Optional.of(pointer.getCaption()) : Optional.<String>absent(),
                                            pointer.hasBlurHash() ? Optional.of(pointer.getBlurHash()) : Optional.<String>absent(),
                                            pointer.hasUploadTimestamp() ? pointer.getUploadTimestamp() : 0);

}
 
Example #11
Source File: PushDatabase.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private static SignalServiceProtos.Envelope envelopeFromCursor(Cursor cursor) throws IOException {
    if (cursor == null)
        return null;
    int type = cursor.getInt(cursor.getColumnIndexOrThrow(TYPE));
    String source = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE));
    int deviceId = cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID));
    String legacyMessage = cursor.getString(cursor.getColumnIndexOrThrow(LEGACY_MSG));
    String content = cursor.getString(cursor.getColumnIndexOrThrow(CONTENT));
    long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP));
    int sourceRegId = cursor.getInt(cursor.getColumnIndexOrThrow(SOURCE_REG_ID));


    return SignalServiceProtos.Envelope.newBuilder()
            .setType(SignalServiceProtos.Envelope.Type.valueOf(type))
            .setSource(source)
            .setSourceDevice(deviceId)
            .setRelay("")
            .setTimestamp(timestamp)
            .setLegacyMessage(Util.isEmpty(legacyMessage) ? null : ByteString.copyFrom(Base64.decode(legacyMessage)))
            .setContent(Util.isEmpty(content) ? null : ByteString.copyFrom(Base64.decode(content)))
            .setSourceRegistration(sourceRegId)
            .build();

}
 
Example #12
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static SignalServiceDataMessage.Reaction createReaction(SignalServiceProtos.DataMessage content) {
  if (!content.hasReaction()                                                                        ||
      !content.getReaction().hasEmoji()                                                             ||
      !(content.getReaction().hasTargetAuthorE164() || content.getReaction().hasTargetAuthorUuid()) ||
      !content.getReaction().hasTargetSentTimestamp())
  {
    return null;
  }

  SignalServiceProtos.DataMessage.Reaction reaction = content.getReaction();

  return new SignalServiceDataMessage.Reaction(reaction.getEmoji(),
                      reaction.getRemove(),
                      new SignalServiceAddress(UuidUtil.parseOrNull(reaction.getTargetAuthorUuid()), reaction.getTargetAuthorE164()),
                      reaction.getTargetSentTimestamp());
}
 
Example #13
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static List<SignalServiceDataMessage.Preview> createPreviews(SignalServiceProtos.DataMessage content) throws ProtocolInvalidMessageException {
  if (content.getPreviewCount() <= 0) return null;

  List<SignalServiceDataMessage.Preview> results = new LinkedList<>();

  for (SignalServiceProtos.DataMessage.Preview preview : content.getPreviewList()) {
    SignalServiceAttachment attachment = null;

    if (preview.hasImage()) {
      attachment = createAttachmentPointer(preview.getImage());
    }

    results.add(new SignalServiceDataMessage.Preview(preview.getUrl(),
                            preview.getTitle(),
                            Optional.fromNullable(attachment)));
  }

  return results;
}
 
Example #14
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static SignalServiceDataMessage.Quote createQuote(SignalServiceProtos.DataMessage content) throws ProtocolInvalidMessageException {
  if (!content.hasQuote()) return null;

  List<SignalServiceDataMessage.Quote.QuotedAttachment> attachments = new LinkedList<>();

  for (SignalServiceProtos.DataMessage.Quote.QuotedAttachment attachment : content.getQuote().getAttachmentsList()) {
    attachments.add(new SignalServiceDataMessage.Quote.QuotedAttachment(attachment.getContentType(),
                                                                        attachment.getFileName(),
                                                                        attachment.hasThumbnail() ? createAttachmentPointer(attachment.getThumbnail()) : null));
  }

  if (SignalServiceAddress.isValidAddress(content.getQuote().getAuthorUuid(), content.getQuote().getAuthorE164())) {
    SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(content.getQuote().getAuthorUuid()), content.getQuote().getAuthorE164());

    return new SignalServiceDataMessage.Quote(content.getQuote().getId(),
                                              address,
                                              content.getQuote().getText(),
                                              attachments);
  } else {
    Log.w(TAG, "Quote was missing an author! Returning null.");
    return null;
  }
}
 
Example #15
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static SignalServiceTypingMessage createTypingMessage(SignalServiceMetadata metadata, SignalServiceProtos.TypingMessage content) throws ProtocolInvalidMessageException {
  SignalServiceTypingMessage.Action action;

  if      (content.getAction() == SignalServiceProtos.TypingMessage.Action.STARTED) action = SignalServiceTypingMessage.Action.STARTED;
  else if (content.getAction() == SignalServiceProtos.TypingMessage.Action.STOPPED) action = SignalServiceTypingMessage.Action.STOPPED;
  else                                                          action = SignalServiceTypingMessage.Action.UNKNOWN;

  if (content.hasTimestamp() && content.getTimestamp() != metadata.getTimestamp()) {
    throw new ProtocolInvalidMessageException(new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + metadata.getTimestamp()),
                                              metadata.getSender().getIdentifier(),
                                              metadata.getSenderDevice());
  }

  return new SignalServiceTypingMessage(action, content.getTimestamp(),
                                        content.hasGroupId() ? Optional.of(content.getGroupId().toByteArray()) :
                                                               Optional.<byte[]>absent());
}
 
Example #16
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static SignalServiceDataMessage.Sticker createSticker(SignalServiceProtos.DataMessage content) throws ProtocolInvalidMessageException {
  if (!content.hasSticker()                ||
      !content.getSticker().hasPackId()    ||
      !content.getSticker().hasPackKey()   ||
      !content.getSticker().hasStickerId() ||
      !content.getSticker().hasData())
  {
    return null;
  }

  SignalServiceProtos.DataMessage.Sticker sticker = content.getSticker();

  return new SignalServiceDataMessage.Sticker(sticker.getPackId().toByteArray(),
                     sticker.getPackKey().toByteArray(),
                     sticker.getStickerId(),
                     createAttachmentPointer(sticker.getData()));
}
 
Example #17
Source File: GroupDescription.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public GroupDescription(@NonNull Context context, @Nullable SignalServiceProtos.GroupContext groupContext) {
    this.context = context.getApplicationContext();
    this.groupContext = groupContext;

    if (groupContext == null || groupContext.getMembersList().isEmpty()) {
        this.members = null;
        this.groupUpdateModel = null;
    } else {
        this.members = new LinkedList<>();
        try {
            Gson gson = new Gson();
            groupUpdateModel = gson.fromJson(groupContext.getMembers(0), GroupUpdateModel.class);
            for (String member : groupUpdateModel.getNumbers()) {
                Recipient recipient = Recipient.from(AMELogin.INSTANCE.getMajorContext(), member, true);
                this.members.add(recipient);
            }
        } catch (Exception ignore) {
            ALog.e(TAG, "GroupDescription init error", ignore);
        }

    }
}
 
Example #18
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
void requestSyncConfiguration() throws IOException {
    SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.CONFIGURATION).build();
    SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
    try {
        sendSyncMessage(message);
    } catch (UntrustedIdentityException e) {
        e.printStackTrace();
    }
}
 
Example #19
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
void requestSyncBlocked() throws IOException {
    SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.BLOCKED).build();
    SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
    try {
        sendSyncMessage(message);
    } catch (UntrustedIdentityException e) {
        e.printStackTrace();
    }
}
 
Example #20
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
void requestSyncContacts() throws IOException {
    SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.CONTACTS).build();
    SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
    try {
        sendSyncMessage(message);
    } catch (UntrustedIdentityException e) {
        e.printStackTrace();
    }
}
 
Example #21
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
void requestSyncGroups() throws IOException {
    SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.GROUPS).build();
    SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
    try {
        sendSyncMessage(message);
    } catch (UntrustedIdentityException e) {
        e.printStackTrace();
    }
}
 
Example #22
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleSynchronizeSentMessage(@NonNull MasterSecretUnion masterSecret,
                                          @NonNull SignalServiceProtos.Envelope envelope,
                                          @NonNull SentTranscriptMessage message) {
    ALog.i(TAG, "handleSynchronizeSentMessage");
    long threadId;

    if (message.getMessage().isEndSession()) {
        threadId = handleSynchronizeSentEndSessionMessage(message);
    } else if (message.getMessage().isGroupUpdate()) {
        threadId = -1L;
    } else if (message.getMessage().isExpirationUpdate()) {
        threadId = handleSynchronizeSentExpirationUpdate(masterSecret, message);
    } else if (message.getMessage().getAttachments().isPresent()) {
        threadId = handleSynchronizeSentMediaMessage(masterSecret, message);
    } else {
        threadId = handleSynchronizeSentTextMessage(masterSecret, message);
    }

    if (message.getMessage().getProfileKey().isPresent()) {
        Recipient recipient = null;

        if (message.getDestination().isPresent()) {
            recipient = Recipient.from(Address.from(accountContext, message.getDestination().get()), false);
        } else if (message.getMessage().getGroupInfo().isPresent()) {
            recipient = Recipient.from(Address.from(accountContext, GroupUtil.getEncodedId(message.getMessage().getGroupInfo().get().getGroupId(), false)), false);
        }


        if (recipient != null && !recipient.isProfileSharing()) {
            repository.getRecipientRepo().setProfileSharing(recipient, true);
        }
    }

    if (threadId > 0L) {
        repository.getThreadRepo().setRead(threadId, true);
    }
}
 
Example #23
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleTextMessage(@NonNull MasterSecretUnion masterSecret,
                               @NonNull SignalServiceProtos.Envelope envelope,
                               @NonNull SignalServiceDataMessage message) {

    ALog.i(TAG, "handleTextMessage");

    PrivateChatRepo chatRepo = repository.getChatRepo();
    String body = message.getBody().isPresent() ? message.getBody().get() : "";
    Recipient recipient = getMessageDestination(envelope, message);

    if (message.getExpiresInSeconds() != recipient.getExpireMessages()) {
        handleExpirationUpdate(masterSecret, envelope, message);
    }

    if (recipient.getAddress().isIndividual()) {
        AmePushProcess.INSTANCE.processPush(accountContext, new AmePushProcess.BcmData(new AmePushProcess.BcmNotify(AmePushProcess.CHAT_NOTIFY, 0, new AmePushProcess.ChatNotifyData(recipient.getAddress().serialize()), null, null, null, null)));
    }

    long expiresIn = 0;
    if (recipient.getExpireMessages() > 0) {
        expiresIn = recipient.getExpireMessages() * 1000;
    } else if (AmeConfigure.INSTANCE.isOutgoingAutoDelete()) {
        expiresIn = message.getExpiresInSeconds() * 1000;
    }

    IncomingTextMessage textMessage = new IncomingTextMessage(Address.from(accountContext, envelope.getSource()),
            envelope.getSourceDevice(),
            message.getTimestamp(), body,
            message.getGroupInfo(),
            expiresIn);

    textMessage = new IncomingEncryptedMessage(textMessage, body);

    chatRepo.insertIncomingTextMessage(textMessage);
}
 
Example #24
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
public void requestSyncContacts() throws IOException {
    SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.CONTACTS).build();
    SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
    try {
        sendSyncMessage(message);
    } catch (UntrustedIdentityException e) {
        logger.catching(e);
    }
}
 
Example #25
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
private void requestSyncGroups() throws IOException {
    SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.GROUPS).build();
    SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
    try {
        sendSyncMessage(message);
    } catch (UntrustedIdentityException e) {
        logger.catching(e);
    }
}
 
Example #26
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleDeliveryReceipt(@NonNull SignalServiceProtos.Envelope envelope,
                                   @NonNull SignalServiceReceiptMessage message) {
    ALog.i(TAG, "handleDeliveryReceipt");

    for (long timestamp : message.getTimestamps()) {
        Log.w(TAG, String.format("Received encrypted delivery receipt: (XXXXX, %d)", timestamp));
        repository.getChatRepo().incrementDeliveryReceiptCount(envelope.getSource(), timestamp);
    }
}
 
Example #27
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleReadReceipt(@NonNull SignalServiceProtos.Envelope envelope,
                               @NonNull SignalServiceReceiptMessage message) {
    ALog.i(TAG, "handleReadReceipt");

    if (TextSecurePreferences.isReadReceiptsEnabled(accountContext)) {
        for (long timestamp : message.getTimestamps()) {
            Log.w(TAG, String.format("Received encrypted read receipt: (XXXXX, %d)", timestamp));

            repository.getChatRepo().incrementReadReceiptCount(envelope.getSource(), timestamp);
        }
    }
}
 
Example #28
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private kotlin.Pair<Long, Long> insertPlaceholder(@NonNull SignalServiceProtos.Envelope envelope) {
    PrivateChatRepo chatRepo = repository.getChatRepo();
    IncomingTextMessage textMessage = new IncomingTextMessage(Address.from(accountContext, envelope.getSource()),
            envelope.getSourceDevice(),
            envelope.getTimestamp(), "",
            Optional.absent(), 0);

    return chatRepo.insertIncomingTextMessage(textMessage);
}
 
Example #29
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private @NonNull Recipient getMessageDestination(SignalServiceProtos.Envelope envelope, SignalServiceDataMessage message) {
    if (message.getGroupInfo().isPresent()) {
        return Recipient.from(Address.from(accountContext, GroupUtil.getEncodedId(message.getGroupInfo().get().getGroupId(), false)), false);
    } else {
        return Recipient.from(Address.from(accountContext, envelope.getSource()), false);
    }
}
 
Example #30
Source File: PushDatabase.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public Pair<Long, SignalServiceProtos.Envelope> getNextEnvelop() {
    try {
        if (cursor == null || !cursor.moveToNext())
            return null;

        long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));

        return new Pair<>(id, envelopeFromCursor(cursor));
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}