Java Code Examples for org.whispersystems.signalservice.api.messages.SignalServiceGroup#getType()

The following examples show how to use org.whispersystems.signalservice.api.messages.SignalServiceGroup#getType() . 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: 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 2
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 3
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 4
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 5
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();
}