use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupDetails in project Signal-Android by WhisperSystems.
the class DeviceGroupsOutputStream method writeGroupDetails.
private void writeGroupDetails(DeviceGroup group) throws IOException {
GroupDetails.Builder groupDetails = GroupDetails.newBuilder();
groupDetails.setId(ByteString.copyFrom(group.getId()));
if (group.getName().isPresent()) {
groupDetails.setName(group.getName().get());
}
if (group.getAvatar().isPresent()) {
GroupDetails.Avatar.Builder avatarBuilder = GroupDetails.Avatar.newBuilder();
avatarBuilder.setContentType(group.getAvatar().get().getContentType());
avatarBuilder.setLength((int) group.getAvatar().get().getLength());
groupDetails.setAvatar(avatarBuilder);
}
if (group.getExpirationTimer().isPresent()) {
groupDetails.setExpireTimer(group.getExpirationTimer().get());
}
if (group.getColor().isPresent()) {
groupDetails.setColor(group.getColor().get());
}
List<GroupDetails.Member> members = new ArrayList<>(group.getMembers().size());
List<String> membersE164 = new ArrayList<>(group.getMembers().size());
for (SignalServiceAddress address : group.getMembers()) {
if (address.getNumber().isPresent()) {
membersE164.add(address.getNumber().get());
GroupDetails.Member.Builder builder = GroupDetails.Member.newBuilder();
builder.setE164(address.getNumber().get());
members.add(builder.build());
}
}
groupDetails.addAllMembers(members);
groupDetails.addAllMembersE164(membersE164);
groupDetails.setActive(group.isActive());
groupDetails.setBlocked(group.isBlocked());
groupDetails.setArchived(group.isArchived());
if (group.getInboxPosition().isPresent()) {
groupDetails.setInboxPosition(group.getInboxPosition().get());
}
byte[] serializedContactDetails = groupDetails.build().toByteArray();
writeVarint32(serializedContactDetails.length);
out.write(serializedContactDetails);
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupDetails in project libsignal-service-java by signalapp.
the class DeviceGroupsInputStream method read.
public DeviceGroup read() throws IOException {
long detailsLength = readRawVarint32();
byte[] detailsSerialized = new byte[(int) detailsLength];
Util.readFully(in, detailsSerialized);
GroupDetails details = GroupDetails.parseFrom(detailsSerialized);
if (!details.hasId()) {
throw new IOException("ID missing on group record!");
}
byte[] id = details.getId().toByteArray();
Optional<String> name = Optional.fromNullable(details.getName());
List<GroupDetails.Member> members = details.getMembersList();
Optional<SignalServiceAttachmentStream> avatar = Optional.absent();
boolean active = details.getActive();
Optional<Integer> expirationTimer = Optional.absent();
Optional<String> color = Optional.fromNullable(details.getColor());
boolean blocked = details.getBlocked();
if (details.hasAvatar()) {
long avatarLength = details.getAvatar().getLength();
InputStream avatarStream = new ChunkedInputStream.LimitedInputStream(in, avatarLength);
String avatarContentType = details.getAvatar().getContentType();
avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, null));
}
if (details.hasExpireTimer() && details.getExpireTimer() > 0) {
expirationTimer = Optional.of(details.getExpireTimer());
}
List<SignalServiceAddress> addressMembers = new ArrayList<>(members.size());
for (GroupDetails.Member member : members) {
if (SignalServiceAddress.isValidAddress(member.getUuid(), member.getE164())) {
addressMembers.add(new SignalServiceAddress(UuidUtil.parseOrNull(member.getUuid()), member.getE164()));
} else {
throw new IOException("Missing group member address!");
}
}
return new DeviceGroup(id, name, addressMembers, avatar, active, expirationTimer, color, blocked);
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupDetails in project libsignal-service-java by signalapp.
the class DeviceGroupsOutputStream method writeGroupDetails.
private void writeGroupDetails(DeviceGroup group) throws IOException {
GroupDetails.Builder groupDetails = GroupDetails.newBuilder();
groupDetails.setId(ByteString.copyFrom(group.getId()));
if (group.getName().isPresent()) {
groupDetails.setName(group.getName().get());
}
if (group.getAvatar().isPresent()) {
GroupDetails.Avatar.Builder avatarBuilder = GroupDetails.Avatar.newBuilder();
avatarBuilder.setContentType(group.getAvatar().get().getContentType());
avatarBuilder.setLength((int) group.getAvatar().get().getLength());
groupDetails.setAvatar(avatarBuilder);
}
if (group.getExpirationTimer().isPresent()) {
groupDetails.setExpireTimer(group.getExpirationTimer().get());
}
if (group.getColor().isPresent()) {
groupDetails.setColor(group.getColor().get());
}
List<GroupDetails.Member> members = new ArrayList<>(group.getMembers().size());
List<String> membersE164 = new ArrayList<>(group.getMembers().size());
for (SignalServiceAddress address : group.getMembers()) {
GroupDetails.Member.Builder builder = GroupDetails.Member.newBuilder();
if (address.getUuid().isPresent()) {
builder.setUuid(address.getUuid().get().toString());
}
if (address.getNumber().isPresent()) {
builder.setE164(address.getNumber().get());
membersE164.add(address.getNumber().get());
}
members.add(builder.build());
}
groupDetails.addAllMembers(members);
groupDetails.addAllMembersE164(membersE164);
groupDetails.setActive(group.isActive());
groupDetails.setBlocked(group.isBlocked());
byte[] serializedContactDetails = groupDetails.build().toByteArray();
writeVarint32(serializedContactDetails.length);
out.write(serializedContactDetails);
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupDetails in project Signal-Android by signalapp.
the class DeviceGroupsOutputStream method writeGroupDetails.
private void writeGroupDetails(DeviceGroup group) throws IOException {
GroupDetails.Builder groupDetails = GroupDetails.newBuilder();
groupDetails.setId(ByteString.copyFrom(group.getId()));
if (group.getName().isPresent()) {
groupDetails.setName(group.getName().get());
}
if (group.getAvatar().isPresent()) {
GroupDetails.Avatar.Builder avatarBuilder = GroupDetails.Avatar.newBuilder();
avatarBuilder.setContentType(group.getAvatar().get().getContentType());
avatarBuilder.setLength((int) group.getAvatar().get().getLength());
groupDetails.setAvatar(avatarBuilder);
}
if (group.getExpirationTimer().isPresent()) {
groupDetails.setExpireTimer(group.getExpirationTimer().get());
}
if (group.getColor().isPresent()) {
groupDetails.setColor(group.getColor().get());
}
List<GroupDetails.Member> members = new ArrayList<>(group.getMembers().size());
List<String> membersE164 = new ArrayList<>(group.getMembers().size());
for (SignalServiceAddress address : group.getMembers()) {
if (address.getNumber().isPresent()) {
membersE164.add(address.getNumber().get());
GroupDetails.Member.Builder builder = GroupDetails.Member.newBuilder();
builder.setE164(address.getNumber().get());
members.add(builder.build());
}
}
groupDetails.addAllMembers(members);
groupDetails.addAllMembersE164(membersE164);
groupDetails.setActive(group.isActive());
groupDetails.setBlocked(group.isBlocked());
groupDetails.setArchived(group.isArchived());
if (group.getInboxPosition().isPresent()) {
groupDetails.setInboxPosition(group.getInboxPosition().get());
}
byte[] serializedContactDetails = groupDetails.build().toByteArray();
writeVarint32(serializedContactDetails.length);
out.write(serializedContactDetails);
}
Aggregations