org.whispersystems.signalservice.api.messages.SignalServiceGroup Java Examples

The following examples show how to use org.whispersystems.signalservice.api.messages.SignalServiceGroup. 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: IncomingTextMessage.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public IncomingTextMessage(Address sender, int senderDeviceId, long sentTimestampMillis,
                           String encodedBody, Optional<SignalServiceGroup> group,
                           long expiresInMillis) {
    this.message = encodedBody;
    this.payloadType = parseBodyPayloadType(encodedBody);
    this.sender = sender;
    this.senderDeviceId = senderDeviceId;
    this.protocol = 31337;
    this.serviceCenterAddress = "GCM";
    this.replyPathPresent = true;
    this.pseudoSubject = "";
    this.sentTimestampMillis = sentTimestampMillis;
    this.push = true;
    this.subscriptionId = -1;
    this.expiresInMillis = expiresInMillis;
    this.groupId = null;
}
 
Example #2
Source File: JsonDataMessage.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
JsonDataMessage(SignalServiceDataMessage dataMessage) {
    this.timestamp = dataMessage.getTimestamp();
    if (dataMessage.getGroupContext().isPresent() && dataMessage.getGroupContext().get().getGroupV1().isPresent()) {
        SignalServiceGroup groupInfo = dataMessage.getGroupContext().get().getGroupV1().get();
        this.groupInfo = new JsonGroupInfo(groupInfo);
    }
    if (dataMessage.getBody().isPresent()) {
        this.message = dataMessage.getBody().get();
    }
    this.expiresInSeconds = dataMessage.getExpiresInSeconds();
    if (dataMessage.getAttachments().isPresent()) {
        this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size());
        for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) {
            this.attachments.add(new JsonAttachment(attachment));
        }
    } else {
        this.attachments = new ArrayList<>();
    }
}
 
Example #3
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
private boolean isMessageBlocked(SignalServiceEnvelope envelope, SignalServiceContent content) {
    SignalServiceAddress source;
    if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
        source = envelope.getSourceAddress();
    } else if (content != null) {
        source = content.getSender();
    } else {
        return false;
    }
    ContactInfo sourceContact = account.getContactStore().getContact(source);
    if (sourceContact != null && sourceContact.blocked) {
        return true;
    }

    if (content != null && content.getDataMessage().isPresent()) {
        SignalServiceDataMessage message = content.getDataMessage().get();
        if (message.getGroupContext().isPresent() && message.getGroupContext().get().getGroupV1().isPresent()) {
            SignalServiceGroup groupInfo = message.getGroupContext().get().getGroupV1().get();
            GroupInfo group = getGroup(groupInfo.getGroupId());
            if (groupInfo.getType() == SignalServiceGroup.Type.DELIVER && group != null && group.blocked) {
                return true;
            }
        }
    }
    return false;
}
 
Example #4
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfo g) throws AttachmentInvalidException {
    SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.UPDATE)
            .withId(g.groupId)
            .withName(g.name)
            .withMembers(new ArrayList<>(g.getMembers()));

    File aFile = getGroupAvatarFile(g.groupId);
    if (aFile.exists()) {
        try {
            group.withAvatar(Utils.createAttachment(aFile));
        } catch (IOException e) {
            throw new AttachmentInvalidException(aFile.toString(), e);
        }
    }

    return SignalServiceDataMessage.newBuilder()
            .asGroupMessage(group.build())
            .withExpiration(g.messageExpirationTime);
}
 
Example #5
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
public long sendGroupMessage(String messageText, List<String> attachments,
                             byte[] groupId)
        throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
    final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
    if (attachments != null) {
        messageBuilder.withAttachments(Utils.getSignalServiceAttachments(attachments));
    }
    if (groupId != null) {
        SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER)
                .withId(groupId)
                .build();
        messageBuilder.asGroupMessage(group);
    }

    final GroupInfo g = getGroupForSending(groupId);

    messageBuilder.withExpiration(g.messageExpirationTime);

    return sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
}
 
Example #6
Source File: JsonGroupInfo.java    From signald with GNU General Public License v3.0 6 votes vote down vote up
JsonGroupInfo(SignalServiceGroup groupInfo, String username) throws IOException, NoSuchAccountException {
    Manager manager = Manager.get(username);
    this.groupId = Base64.encodeBytes(groupInfo.getGroupId());
    if (groupInfo.getMembers().isPresent()) {
        this.members = groupInfo.getMembers().get();
    }
    if (groupInfo.getName().isPresent()) {
        this.name = groupInfo.getName().get();
    } else {
        GroupInfo group = manager.getGroup(groupInfo.getGroupId());
        if(group != null) {
            this.name = group.name;
        }
    }

    this.type = groupInfo.getType().toString();
}
 
Example #7
Source File: IncomingMediaMessage.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public IncomingMediaMessage(MasterSecretUnion masterSecret,
                            Address from,
                            long sentTimeMillis,
                            int subscriptionId,
                            long expiresIn,
                            boolean expirationUpdate,
                            Optional<String> relay,
                            Optional<String> body,
                            Optional<SignalServiceGroup> group,
                            Optional<List<SignalServiceAttachment>> attachments)
{
  this.push             = true;
  this.from             = from;
  this.sentTimeMillis   = sentTimeMillis;
  this.body             = body.orNull();
  this.subscriptionId   = subscriptionId;
  this.expiresIn        = expiresIn;
  this.expirationUpdate = expirationUpdate;
  this.groupId = null;

  this.attachments.addAll(PointerAttachment.forPointers(masterSecret, attachments));
}
 
Example #8
Source File: RequestGroupInfoJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  SignalServiceGroup       group   = SignalServiceGroup.newBuilder(Type.REQUEST_INFO)
                                                       .withId(groupId.getDecodedId())
                                                       .build();

  SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder()
                                                             .asGroupMessage(group)
                                                             .withTimestamp(System.currentTimeMillis())
                                                             .build();

  SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
  Recipient                  recipient     = Recipient.resolved(source);

  messageSender.sendMessage(RecipientUtil.toSignalServiceAddress(context, recipient),
                            UnidentifiedAccessUtil.getAccessFor(context, recipient),
                            message);
}
 
Example #9
Source File: GroupUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@WorkerThread
public static void setDataMessageGroupContext(@NonNull Context context,
                                              @NonNull SignalServiceDataMessage.Builder dataMessageBuilder,
                                              @NonNull GroupId.Push groupId)
{
  if (groupId.isV2()) {
      GroupDatabase                   groupDatabase     = DatabaseFactory.getGroupDatabase(context);
      GroupDatabase.GroupRecord       groupRecord       = groupDatabase.requireGroup(groupId);
      GroupDatabase.V2GroupProperties v2GroupProperties = groupRecord.requireV2GroupProperties();
      SignalServiceGroupV2            group             = SignalServiceGroupV2.newBuilder(v2GroupProperties.getGroupMasterKey())
                                                                              .withRevision(v2GroupProperties.getGroupRevision())
                                                                              .build();
      dataMessageBuilder.asGroupMessage(group);
    } else {
      dataMessageBuilder.asGroupMessage(new SignalServiceGroup(groupId.getDecodedId()));
    }
}
 
Example #10
Source File: GroupV1MessageProcessor.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static Long handleGroupLeave(@NonNull Context               context,
                                     @NonNull SignalServiceContent  content,
                                     @NonNull SignalServiceGroup    group,
                                     @NonNull GroupRecord           record,
                                     boolean  outgoing)
{
  GroupDatabase     database = DatabaseFactory.getGroupDatabase(context);
  GroupId           id       = GroupId.v1orThrow(group.getGroupId());
  List<RecipientId> members  = record.getMembers();

  GroupContext.Builder builder = createGroupContext(group);
  builder.setType(GroupContext.Type.QUIT);

  if (members.contains(Recipient.externalPush(context, content.getSender()).getId())) {
    database.remove(id, Recipient.externalPush(context, content.getSender()).getId());
    if (outgoing) database.setActive(id, false);

    return storeMessage(context, content, group, builder.build(), outgoing);
  }

  return null;
}
 
Example #11
Source File: ProfileKeySendJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private List<Recipient> deliver(@NonNull Recipient conversationRecipient, @NonNull List<Recipient> destinations) throws IOException, UntrustedIdentityException {
  SignalServiceMessageSender             messageSender      = ApplicationDependencies.getSignalServiceMessageSender();
  List<SignalServiceAddress>             addresses          = Stream.of(destinations).map(t -> RecipientUtil.toSignalServiceAddress(context, t)).toList();
  List<Optional<UnidentifiedAccessPair>> unidentifiedAccess = Stream.of(destinations).map(recipient -> UnidentifiedAccessUtil.getAccessFor(context, recipient)).toList();
  SignalServiceDataMessage.Builder       dataMessage        = SignalServiceDataMessage.newBuilder()
                                                                                      .asProfileKeyUpdate(true)
                                                                                      .withTimestamp(System.currentTimeMillis())
                                                                                      .withProfileKey(Recipient.self().resolve().getProfileKey());

  if (conversationRecipient.isGroup()) {
    dataMessage.asGroupMessage(new SignalServiceGroup(conversationRecipient.requireGroupId().getDecodedId()));
  }

  List<SendMessageResult> results = messageSender.sendMessage(addresses, unidentifiedAccess, false, dataMessage.build());

  Stream.of(results)
        .filter(r -> r.getIdentityFailure() != null)
        .map(SendMessageResult::getAddress)
        .map(a -> Recipient.externalPush(context, a))
        .forEach(r -> Log.w(TAG, "Identity failure for " + r.getId()));

  Stream.of(results)
        .filter(SendMessageResult::isUnregisteredFailure)
        .map(SendMessageResult::getAddress)
        .map(a -> Recipient.externalPush(context, a))
        .forEach(r -> Log.w(TAG, "Unregistered failure for " + r.getId()));


  return Stream.of(results)
               .filter(r -> r.getSuccess() != null || r.getIdentityFailure() != null || r.isUnregisteredFailure())
               .map(SendMessageResult::getAddress)
               .map(a -> Recipient.externalPush(context, a))
               .toList();
}
 
Example #12
Source File: GroupV1MessageProcessor.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static @Nullable Long process(@NonNull Context context,
                                     @NonNull SignalServiceContent content,
                                     @NonNull SignalServiceDataMessage message,
                                     boolean outgoing)
{
  SignalServiceGroupContext    signalServiceGroupContext = message.getGroupContext().get();
  Optional<SignalServiceGroup> groupV1                   = signalServiceGroupContext.getGroupV1();

  if (signalServiceGroupContext.getGroupV2().isPresent()) {
    throw new AssertionError("Cannot process GV2");
  }

  if (!groupV1.isPresent() || groupV1.get().getGroupId() == null) {
    Log.w(TAG, "Received group message with no id! Ignoring...");
    return null;
  }

  GroupDatabase         database = DatabaseFactory.getGroupDatabase(context);
  SignalServiceGroup    group    = groupV1.get();
  GroupId               id       = GroupId.v1orThrow(group.getGroupId());
  Optional<GroupRecord> record   = database.getGroup(id);

  if (record.isPresent() && group.getType() == Type.UPDATE) {
    return handleGroupUpdate(context, content, group, record.get(), outgoing);
  } else if (!record.isPresent() && group.getType() == Type.UPDATE) {
    return handleGroupCreate(context, content, group, outgoing);
  } else if (record.isPresent() && group.getType() == Type.QUIT) {
    return handleGroupLeave(context, content, group, record.get(), outgoing);
  } else if (record.isPresent() && group.getType() == Type.REQUEST_INFO) {
    return handleGroupInfoRequest(context, content, record.get());
  } else {
    Log.w(TAG, "Received unknown type, ignoring...");
    return null;
  }
}
 
Example #13
Source File: JsonGroupInfo.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
JsonGroupInfo(SignalServiceGroup groupInfo) {
    this.groupId = Base64.encodeBytes(groupInfo.getGroupId());
    if (groupInfo.getMembers().isPresent()) {
        this.members = new ArrayList<>(groupInfo.getMembers().get().size());
        for (SignalServiceAddress address : groupInfo.getMembers().get()) {
            this.members.add(address.getNumber().get());
        }
    }
    if (groupInfo.getName().isPresent()) {
        this.name = groupInfo.getName().get();
    }
    this.type = groupInfo.getType().toString();
}
 
Example #14
Source File: GroupV1MessageProcessor.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static @Nullable Long handleGroupCreate(@NonNull Context context,
                                                @NonNull SignalServiceContent content,
                                                @NonNull SignalServiceGroup group,
                                                boolean outgoing)
{
  GroupDatabase        database = DatabaseFactory.getGroupDatabase(context);
  GroupId.V1           id       = GroupId.v1orThrow(group.getGroupId());
  GroupContext.Builder builder  = createGroupContext(group);
  builder.setType(GroupContext.Type.UPDATE);

  SignalServiceAttachment avatar  = group.getAvatar().orNull();
  List<RecipientId>       members = new LinkedList<>();

  if (group.getMembers().isPresent()) {
    for (SignalServiceAddress member : group.getMembers().get()) {
      members.add(Recipient.externalPush(context, member).getId());
    }
  }

  database.create(id, group.getName().orNull(), members,
                  avatar != null && avatar.isPointer() ? avatar.asPointer() : null, null);

  Recipient sender = Recipient.externalPush(context, content.getSender());

  if (FeatureFlags.messageRequests() && (sender.isSystemContact() || sender.isProfileSharing())) {
    Log.i(TAG, "Auto-enabling profile sharing because 'adder' is trusted. contact: " + sender.isSystemContact() + ", profileSharing: " + sender.isProfileSharing());
    DatabaseFactory.getRecipientDatabase(context).setProfileSharing(Recipient.externalGroup(context, id).getId(), true);
  }

  return storeMessage(context, content, group, builder.build(), outgoing);
}
 
Example #15
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
void sendGroupInfoRequest(byte[] groupId, SignalServiceAddress recipient) throws IOException, EncapsulatedExceptions {
    if (groupId == null) {
        return;
    }

    SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.REQUEST_INFO)
            .withId(groupId);

    SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
            .asGroupMessage(group.build());

    // Send group info request message to the recipient who sent us a message with this groupId
    sendMessageLegacy(messageBuilder, Collections.singleton(recipient));
}
 
Example #16
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public void sendQuitGroupMessage(byte[] groupId) throws GroupNotFoundException, IOException, EncapsulatedExceptions, NotAGroupMemberException {
    SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.QUIT)
            .withId(groupId)
            .build();

    SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
            .asGroupMessage(group);

    final GroupInfo g = getGroupForSending(groupId);
    g.removeMember(account.getSelfAddress());
    account.getGroupStore().updateGroup(g);

    sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
}
 
Example #17
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public void sendGroupMessageReaction(String emoji, boolean remove, String targetAuthor,
                                     long targetSentTimestamp, byte[] groupId)
        throws IOException, EncapsulatedExceptions, InvalidNumberException, NotAGroupMemberException, GroupNotFoundException {
    SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, canonicalizeAndResolveSignalServiceAddress(targetAuthor), targetSentTimestamp);
    final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
            .withReaction(reaction);
    if (groupId != null) {
        SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER)
                .withId(groupId)
                .build();
        messageBuilder.asGroupMessage(group);
    }
    final GroupInfo g = getGroupForSending(groupId);
    sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
}
 
Example #18
Source File: UnsupportedDataMessageException.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public UnsupportedDataMessageException(int currentVersion,
                                       int requiredVersion,
                                       String sender,
                                       int senderDevice,
                                       Optional<SignalServiceGroup> group)
{
  super("Required version: " + requiredVersion + ", Our version: " + currentVersion);
  this.requiredVersion = requiredVersion;
  this.sender          = sender;
  this.senderDevice    = senderDevice;
  this.group           = group;
}
 
Example #19
Source File: Signal.java    From signal-bot with GNU Affero General Public License v3.0 5 votes vote down vote up
public void sendMessage(User sender, Group group, SignalServiceDataMessage.Builder messageBuilder) throws IOException {
	messageBuilder.withTimestamp(System.currentTimeMillis());
	if(group != null) {
		messageBuilder.asGroupMessage(SignalServiceGroup.newBuilder(Type.DELIVER).withId(group.getId().getId()).build());
		sendMessage(group.getMembers(), messageBuilder.build());
	} else {
		sendMessage(sender.getNumber(), messageBuilder.build());
	}
}
 
Example #20
Source File: GroupV1MessageProcessor.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static GroupContext.Builder createGroupContext(SignalServiceGroup group) {
  GroupContext.Builder builder = GroupContext.newBuilder();
  builder.setId(ByteString.copyFrom(group.getGroupId()));

  if (group.getAvatar().isPresent() && group.getAvatar().get().isPointer()) {
    builder.setAvatar(AttachmentPointer.newBuilder()
                                       .setCdnId(group.getAvatar().get().asPointer().getRemoteId().getV2().get())
                                       .setKey(ByteString.copyFrom(group.getAvatar().get().asPointer().getKey()))
                                       .setContentType(group.getAvatar().get().getContentType()));
  }

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

  if (group.getMembers().isPresent()) {
    builder.addAllMembersE164(Stream.of(group.getMembers().get())
                                    .filter(a -> a.getNumber().isPresent())
                                    .map(a -> a.getNumber().get())
                                    .toList());
    builder.addAllMembers(Stream.of(group.getMembers().get())
                                .map(GroupV1MessageProcessor::createMember)
                                .toList());
  }

  return builder;
}
 
Example #21
Source File: IdentityUtil.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static void markIdentityVerified(Recipient recipient, boolean verified, boolean remote) {

        PrivateChatRepo repo = Repository.getChatRepo(recipient.getAddress().context());
        ThreadRepo threadRepo = Repository.getThreadRepo(recipient.getAddress().context());
        if (repo == null || threadRepo == null) {
            return;
        }

        long threadId = threadRepo.getThreadIdFor(recipient);
        long time = ChatTimestamp.getTime(recipient.getAddress().context(), threadId);
        if (remote) {
            IncomingTextMessage incoming = new IncomingTextMessage(recipient.getAddress(), 1, time, null, Optional.<SignalServiceGroup>absent(), 0);

            if (verified)
                incoming = new IncomingIdentityVerifiedMessage(incoming);
            else
                incoming = new IncomingIdentityDefaultMessage(incoming);

            repo.insertIncomingTextMessage(incoming);
        } else {
            OutgoingTextMessage outgoing;

            if (verified)
                outgoing = new OutgoingIdentityVerifiedMessage(recipient);
            else
                outgoing = new OutgoingIdentityDefaultMessage(recipient);

            Log.w(TAG, "Inserting verified outbox...");
            repo.insertOutgoingTextMessage(threadId, outgoing, time, null);
        }
    }
 
Example #22
Source File: SignalServiceCipher.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private SignalServiceDataMessage createSignalServiceMessage(SignalServiceProtos.Envelope envelope, DataMessage content) throws InvalidMessageException {
  SignalServiceGroup            groupInfo        = createGroupInfo(envelope, content);
  List<SignalServiceAttachment> attachments      = new LinkedList<>();
  boolean                       endSession       = ((content.getFlags() & DataMessage.Flags.END_SESSION_VALUE) != 0);
  boolean                       expirationUpdate = ((content.getFlags() & DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0);
  boolean                       profileKeyUpdate = ((content.getFlags() & DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE) != 0);
    boolean newGroupShare = ((content.getFlags() & 8) != 0);//添加 newGroupShare 类型

  for (AttachmentPointer pointer : content.getAttachmentsList()) {
    attachments.add(new SignalServiceAttachmentPointer(pointer.getId(),
                                                       pointer.getContentType(),
                                                       pointer.getKey().toByteArray(),
                                                       envelope.getRelay(),
                                                       pointer.hasSize() ? Optional.of(pointer.getSize()) : Optional.<Integer>absent(),
                                                       pointer.hasThumbnail() ? Optional.of(pointer.getThumbnail().toByteArray()): Optional.<byte[]>absent(),
                                                       pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.<byte[]>absent(),
                                                       pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.<String>absent(),
                                                       (pointer.getFlags() & AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) != 0,
                                                       pointer.hasUrl() ? Optional.of(pointer.getUrl()) : Optional.<String>absent()));
  }

  if (content.hasTimestamp() && content.getTimestamp() != envelope.getTimestamp()) {
    throw new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + envelope.getTimestamp());
  }

  return new SignalServiceDataMessage(envelope.getTimestamp(), groupInfo, attachments,
                                      content.getBody(), endSession, content.getExpireTimer(),
                                      expirationUpdate, content.hasProfileKey() ? content.getProfileKey().toByteArray() : null,
          profileKeyUpdate, newGroupShare);
}
 
Example #23
Source File: PushProcessMessageJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleUnknownGroupMessage(@NonNull SignalServiceContent content,
                                       @NonNull SignalServiceGroupContext group)
    throws BadGroupIdException
{
  if (group.getGroupV1().isPresent()) {
    SignalServiceGroup groupV1 = group.getGroupV1().get();
    if (groupV1.getType() != SignalServiceGroup.Type.REQUEST_INFO) {
      ApplicationDependencies.getJobManager().add(new RequestGroupInfoJob(Recipient.externalPush(context, content.getSender()).getId(), GroupId.v1(groupV1.getGroupId())));
    } else {
      Log.w(TAG, "Received a REQUEST_INFO message for a group we don't know about. Ignoring.");
    }
  } else {
    Log.w(TAG, "Received a message for a group we don't know about without a GV1 context. Ignoring.");
  }
}
 
Example #24
Source File: LeaveGroupJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static @NonNull List<Recipient> deliver(@NonNull Context context,
                                                @NonNull GroupId.Push groupId,
                                                @NonNull String name,
                                                @NonNull List<RecipientId> members,
                                                @NonNull List<RecipientId> destinations)
    throws IOException, UntrustedIdentityException
{
  SignalServiceMessageSender             messageSender      = ApplicationDependencies.getSignalServiceMessageSender();
  List<SignalServiceAddress>             addresses          = Stream.of(destinations).map(Recipient::resolved).map(t -> RecipientUtil.toSignalServiceAddress(context, t)).toList();
  List<SignalServiceAddress>             memberAddresses    = Stream.of(members).map(Recipient::resolved).map(t -> RecipientUtil.toSignalServiceAddress(context, t)).toList();
  List<Optional<UnidentifiedAccessPair>> unidentifiedAccess = Stream.of(destinations).map(Recipient::resolved).map(recipient -> UnidentifiedAccessUtil.getAccessFor(context, recipient)).toList();
  SignalServiceGroup                     serviceGroup       = new SignalServiceGroup(SignalServiceGroup.Type.QUIT, groupId.getDecodedId(), name, memberAddresses, null);
  SignalServiceDataMessage.Builder       dataMessage        = SignalServiceDataMessage.newBuilder()
                                                                                      .withTimestamp(System.currentTimeMillis())
                                                                                      .asGroupMessage(serviceGroup);


  List<SendMessageResult> results = messageSender.sendMessage(addresses, unidentifiedAccess, false, dataMessage.build());

  Stream.of(results)
        .filter(r -> r.getIdentityFailure() != null)
        .map(SendMessageResult::getAddress)
        .map(a -> Recipient.externalPush(context, a))
        .forEach(r -> Log.w(TAG, "Identity failure for " + r.getId()));

  Stream.of(results)
        .filter(SendMessageResult::isUnregisteredFailure)
        .map(SendMessageResult::getAddress)
        .map(a -> Recipient.externalPush(context, a))
        .forEach(r -> Log.w(TAG, "Unregistered failure for " + r.getId()));


  return Stream.of(results)
               .filter(r -> r.getSuccess() != null || r.getIdentityFailure() != null || r.isUnregisteredFailure())
               .map(SendMessageResult::getAddress)
               .map(a -> Recipient.externalPush(context, a))
               .toList();
}
 
Example #25
Source File: GroupV1MessageProcessor.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static @Nullable Long storeMessage(@NonNull Context context,
                                           @NonNull SignalServiceContent content,
                                           @NonNull SignalServiceGroup group,
                                           @NonNull GroupContext storage,
                                           boolean  outgoing)
{
  if (group.getAvatar().isPresent()) {
    ApplicationDependencies.getJobManager()
                           .add(new AvatarGroupsV1DownloadJob(GroupId.v1orThrow(group.getGroupId())));
  }

  try {
    if (outgoing) {
      MmsDatabase                mmsDatabase     = DatabaseFactory.getMmsDatabase(context);
      RecipientId                recipientId     = DatabaseFactory.getRecipientDatabase(context).getOrInsertFromGroupId(GroupId.v1orThrow(group.getGroupId()));
      Recipient                  recipient       = Recipient.resolved(recipientId);
      OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(recipient, storage, null, content.getTimestamp(), 0, false, null, Collections.emptyList(), Collections.emptyList());
      long                       threadId        = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
      long                       messageId       = mmsDatabase.insertMessageOutbox(outgoingMessage, threadId, false, null);

      mmsDatabase.markAsSent(messageId, true);

      return threadId;
    } else {
      SmsDatabase          smsDatabase  = DatabaseFactory.getSmsDatabase(context);
      String               body         = Base64.encodeBytes(storage.toByteArray());
      IncomingTextMessage  incoming     = new IncomingTextMessage(Recipient.externalPush(context, content.getSender()).getId(), content.getSenderDevice(), content.getTimestamp(), content.getServerTimestamp(), body, Optional.of(GroupId.v1orThrow(group.getGroupId())), 0, content.isNeedsReceipt());
      IncomingGroupUpdateMessage groupMessage = new IncomingGroupUpdateMessage(incoming, storage, body);

      Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(groupMessage);

      if (insertResult.isPresent()) {
        ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
        return insertResult.get().getThreadId();
      } else {
        return null;
      }
    }
  } catch (MmsException e) {
    Log.w(TAG, e);
  }

  return null;
}
 
Example #26
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
private GroupContext createGroupContent(SignalServiceGroup group) throws IOException {
  GroupContext.Builder builder = GroupContext.newBuilder();
  builder.setId(ByteString.copyFrom(group.getGroupId()));

  if (group.getType() != SignalServiceGroup.Type.DELIVER) {
    if      (group.getType() == SignalServiceGroup.Type.UPDATE)       builder.setType(GroupContext.Type.UPDATE);
    else if (group.getType() == SignalServiceGroup.Type.QUIT)         builder.setType(GroupContext.Type.QUIT);
    else if (group.getType() == SignalServiceGroup.Type.REQUEST_INFO) builder.setType(GroupContext.Type.REQUEST_INFO);
    else                                                              throw new AssertionError("Unknown type: " + group.getType());

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

    if (group.getMembers().isPresent()) {
      for (SignalServiceAddress address : group.getMembers().get()) {
        if (address.getNumber().isPresent()) {
          builder.addMembersE164(address.getNumber().get());
        }

        GroupContext.Member.Builder memberBuilder = GroupContext.Member.newBuilder();

        if (address.getUuid().isPresent()) {
          memberBuilder.setUuid(address.getUuid().get().toString());
        }

        if (address.getNumber().isPresent()) {
          memberBuilder.setE164(address.getNumber().get());
        }

        builder.addMembers(memberBuilder.build());
      }
    }

    if (group.getAvatar().isPresent()) {
      if (group.getAvatar().get().isStream()) {
        builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asStream()));
      } else {
        builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asPointer()));
      }
    }
  } else {
    builder.setType(GroupContext.Type.DELIVER);
  }

  return builder.build();
}
 
Example #27
Source File: SignalServiceCipher.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
private SignalServiceDataMessage createSignalServiceMessage(Metadata metadata, DataMessage content)
    throws ProtocolInvalidMessageException, UnsupportedDataMessageException
{
  SignalServiceGroup             groupInfo        = createGroupInfo(content);
  List<SignalServiceAttachment>  attachments      = new LinkedList<>();
  boolean                        endSession       = ((content.getFlags() & DataMessage.Flags.END_SESSION_VALUE            ) != 0);
  boolean                        expirationUpdate = ((content.getFlags() & DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0);
  boolean                        profileKeyUpdate = ((content.getFlags() & DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE     ) != 0);
  SignalServiceDataMessage.Quote quote            = createQuote(content);
  List<SharedContact>            sharedContacts   = createSharedContacts(content);
  List<Preview>                  previews         = createPreviews(content);
  Sticker                        sticker          = createSticker(content);

  if (content.getRequiredProtocolVersion() > DataMessage.ProtocolVersion.CURRENT.getNumber()) {
    throw new UnsupportedDataMessageException(DataMessage.ProtocolVersion.CURRENT.getNumber(),
                                              content.getRequiredProtocolVersion(),
                                              metadata.getSender().getIdentifier(),
                                              metadata.getSenderDevice(),
                                              Optional.fromNullable(groupInfo));
  }

  for (AttachmentPointer pointer : content.getAttachmentsList()) {
    attachments.add(createAttachmentPointer(pointer));
  }

  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 SignalServiceDataMessage(metadata.getTimestamp(),
                                      groupInfo,
                                      attachments,
                                      content.getBody(),
                                      endSession,
                                      content.getExpireTimer(),
                                      expirationUpdate,
                                      content.hasProfileKey() ? content.getProfileKey().toByteArray() : null,
                                      profileKeyUpdate,
                                      quote,
                                      sharedContacts,
                                      previews,
                                      sticker,
                                      content.getIsViewOnce());
}
 
Example #28
Source File: UnsupportedDataMessageException.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public Optional<SignalServiceGroup> getGroup() {
  return group;
}
 
Example #29
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private GroupContext createGroupContent(SignalServiceGroup group) throws IOException {
  GroupContext.Builder builder = GroupContext.newBuilder();
  builder.setId(ByteString.copyFrom(group.getGroupId()));

  if (group.getType() != SignalServiceGroup.Type.DELIVER) {
    if      (group.getType() == SignalServiceGroup.Type.UPDATE)       builder.setType(GroupContext.Type.UPDATE);
    else if (group.getType() == SignalServiceGroup.Type.QUIT)         builder.setType(GroupContext.Type.QUIT);
    else if (group.getType() == SignalServiceGroup.Type.REQUEST_INFO) builder.setType(GroupContext.Type.REQUEST_INFO);
    else                                                              throw new AssertionError("Unknown type: " + group.getType());

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

    if (group.getMembers().isPresent()) {
      for (SignalServiceAddress address : group.getMembers().get()) {
        if (address.getNumber().isPresent()) {
          builder.addMembersE164(address.getNumber().get());
        }

        GroupContext.Member.Builder memberBuilder = GroupContext.Member.newBuilder();

        if (address.getUuid().isPresent()) {
          memberBuilder.setUuid(address.getUuid().get().toString());
        }

        if (address.getNumber().isPresent()) {
          memberBuilder.setE164(address.getNumber().get());
        }

        builder.addMembers(memberBuilder.build());
      }
    }

    if (group.getAvatar().isPresent()) {
      if (group.getAvatar().get().isStream()) {
        builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asStream()));
      } else {
        builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asPointer()));
      }
    }
  } else {
    builder.setType(GroupContext.Type.DELIVER);
  }

  return builder.build();
}
 
Example #30
Source File: IncomingJoinedMessage.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public IncomingJoinedMessage(Address sender) {
  super(sender, 1, System.currentTimeMillis(), null, Optional.<SignalServiceGroup>absent(), 0);
}