use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer in project libsignal-service-java by signalapp.
the class SignalServiceCipher method createGroupInfo.
private SignalServiceGroup createGroupInfo(SignalServiceEnvelope envelope, DataMessage content) {
if (!content.hasGroup())
return null;
SignalServiceGroup.Type type;
switch(content.getGroup().getType()) {
case DELIVER:
type = SignalServiceGroup.Type.DELIVER;
break;
case UPDATE:
type = SignalServiceGroup.Type.UPDATE;
break;
case QUIT:
type = SignalServiceGroup.Type.QUIT;
break;
case REQUEST_INFO:
type = SignalServiceGroup.Type.REQUEST_INFO;
break;
default:
type = SignalServiceGroup.Type.UNKNOWN;
break;
}
if (content.getGroup().getType() != DELIVER) {
String name = null;
List<String> members = null;
SignalServiceAttachmentPointer avatar = null;
if (content.getGroup().hasName()) {
name = content.getGroup().getName();
}
if (content.getGroup().getMembersCount() > 0) {
members = content.getGroup().getMembersList();
}
if (content.getGroup().hasAvatar()) {
AttachmentPointer pointer = content.getGroup().getAvatar();
avatar = new SignalServiceAttachmentPointer(pointer.getId(), pointer.getContentType(), pointer.getKey().toByteArray(), envelope.getRelay(), Optional.of(pointer.getSize()), Optional.<byte[]>absent(), 0, 0, Optional.fromNullable(pointer.hasDigest() ? pointer.getDigest().toByteArray() : null), Optional.<String>absent(), false);
}
return new SignalServiceGroup(type, content.getGroup().getId().toByteArray(), name, members, avatar);
}
return new SignalServiceGroup(content.getGroup().getId().toByteArray());
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer in project libsignal-service-java by signalapp.
the class SignalServiceCipher method createSignalServiceMessage.
private SignalServiceDataMessage createSignalServiceMessage(SignalServiceEnvelope 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);
SignalServiceDataMessage.Quote quote = createQuote(envelope, content);
for (AttachmentPointer pointer : content.getAttachmentsList()) {
attachments.add(createAttachmentPointer(envelope, pointer));
}
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, quote);
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer in project libsignal-service-java by signalapp.
the class SignalServiceMessageSender method createGroupContent.
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())
builder.addAllMembers(group.getMembers().get());
if (group.getAvatar().isPresent() && group.getAvatar().get().isStream()) {
AttachmentPointer pointer = createAttachmentPointer(group.getAvatar().get().asStream());
builder.setAvatar(pointer);
}
} else {
builder.setType(GroupContext.Type.DELIVER);
}
return builder.build();
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer in project libsignal-service-java by signalapp.
the class SignalServiceMessageSender method createAttachmentPointer.
private AttachmentPointer createAttachmentPointer(SignalServiceAttachmentStream attachment) throws IOException {
byte[] attachmentKey = Util.getSecretBytes(64);
long paddedLength = PaddingInputStream.getPaddedSize(attachment.getLength());
long ciphertextLength = AttachmentCipherOutputStream.getCiphertextLength(paddedLength);
PushAttachmentData attachmentData = new PushAttachmentData(attachment.getContentType(), new PaddingInputStream(attachment.getInputStream(), attachment.getLength()), ciphertextLength, new AttachmentCipherOutputStreamFactory(attachmentKey), attachment.getListener());
Pair<Long, byte[]> attachmentIdAndDigest = socket.sendAttachment(attachmentData);
AttachmentPointer.Builder builder = AttachmentPointer.newBuilder().setContentType(attachment.getContentType()).setId(attachmentIdAndDigest.first()).setKey(ByteString.copyFrom(attachmentKey)).setDigest(ByteString.copyFrom(attachmentIdAndDigest.second())).setSize((int) attachment.getLength());
if (attachment.getFileName().isPresent()) {
builder.setFileName(attachment.getFileName().get());
}
if (attachment.getPreview().isPresent()) {
builder.setThumbnail(ByteString.copyFrom(attachment.getPreview().get()));
}
if (attachment.getWidth() > 0) {
builder.setWidth(attachment.getWidth());
}
if (attachment.getHeight() > 0) {
builder.setHeight(attachment.getHeight());
}
if (attachment.getVoiceNote()) {
builder.setFlags(AttachmentPointer.Flags.VOICE_MESSAGE_VALUE);
}
return builder.build();
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer in project Signal-Android by WhisperSystems.
the class SignalServiceMessageSender method createSharedContactContent.
private List<DataMessage.Contact> createSharedContactContent(List<SharedContact> contacts) throws IOException {
List<DataMessage.Contact> results = new LinkedList<>();
for (SharedContact contact : contacts) {
DataMessage.Contact.Name.Builder nameBuilder = DataMessage.Contact.Name.newBuilder();
if (contact.getName().getFamily().isPresent())
nameBuilder.setFamilyName(contact.getName().getFamily().get());
if (contact.getName().getGiven().isPresent())
nameBuilder.setGivenName(contact.getName().getGiven().get());
if (contact.getName().getMiddle().isPresent())
nameBuilder.setMiddleName(contact.getName().getMiddle().get());
if (contact.getName().getPrefix().isPresent())
nameBuilder.setPrefix(contact.getName().getPrefix().get());
if (contact.getName().getSuffix().isPresent())
nameBuilder.setSuffix(contact.getName().getSuffix().get());
if (contact.getName().getDisplay().isPresent())
nameBuilder.setDisplayName(contact.getName().getDisplay().get());
DataMessage.Contact.Builder contactBuilder = DataMessage.Contact.newBuilder().setName(nameBuilder);
if (contact.getAddress().isPresent()) {
for (SharedContact.PostalAddress address : contact.getAddress().get()) {
DataMessage.Contact.PostalAddress.Builder addressBuilder = DataMessage.Contact.PostalAddress.newBuilder();
switch(address.getType()) {
case HOME:
addressBuilder.setType(DataMessage.Contact.PostalAddress.Type.HOME);
break;
case WORK:
addressBuilder.setType(DataMessage.Contact.PostalAddress.Type.WORK);
break;
case CUSTOM:
addressBuilder.setType(DataMessage.Contact.PostalAddress.Type.CUSTOM);
break;
default:
throw new AssertionError("Unknown type: " + address.getType());
}
if (address.getCity().isPresent())
addressBuilder.setCity(address.getCity().get());
if (address.getCountry().isPresent())
addressBuilder.setCountry(address.getCountry().get());
if (address.getLabel().isPresent())
addressBuilder.setLabel(address.getLabel().get());
if (address.getNeighborhood().isPresent())
addressBuilder.setNeighborhood(address.getNeighborhood().get());
if (address.getPobox().isPresent())
addressBuilder.setPobox(address.getPobox().get());
if (address.getPostcode().isPresent())
addressBuilder.setPostcode(address.getPostcode().get());
if (address.getRegion().isPresent())
addressBuilder.setRegion(address.getRegion().get());
if (address.getStreet().isPresent())
addressBuilder.setStreet(address.getStreet().get());
contactBuilder.addAddress(addressBuilder);
}
}
if (contact.getEmail().isPresent()) {
for (SharedContact.Email email : contact.getEmail().get()) {
DataMessage.Contact.Email.Builder emailBuilder = DataMessage.Contact.Email.newBuilder().setValue(email.getValue());
switch(email.getType()) {
case HOME:
emailBuilder.setType(DataMessage.Contact.Email.Type.HOME);
break;
case WORK:
emailBuilder.setType(DataMessage.Contact.Email.Type.WORK);
break;
case MOBILE:
emailBuilder.setType(DataMessage.Contact.Email.Type.MOBILE);
break;
case CUSTOM:
emailBuilder.setType(DataMessage.Contact.Email.Type.CUSTOM);
break;
default:
throw new AssertionError("Unknown type: " + email.getType());
}
if (email.getLabel().isPresent())
emailBuilder.setLabel(email.getLabel().get());
contactBuilder.addEmail(emailBuilder);
}
}
if (contact.getPhone().isPresent()) {
for (SharedContact.Phone phone : contact.getPhone().get()) {
DataMessage.Contact.Phone.Builder phoneBuilder = DataMessage.Contact.Phone.newBuilder().setValue(phone.getValue());
switch(phone.getType()) {
case HOME:
phoneBuilder.setType(DataMessage.Contact.Phone.Type.HOME);
break;
case WORK:
phoneBuilder.setType(DataMessage.Contact.Phone.Type.WORK);
break;
case MOBILE:
phoneBuilder.setType(DataMessage.Contact.Phone.Type.MOBILE);
break;
case CUSTOM:
phoneBuilder.setType(DataMessage.Contact.Phone.Type.CUSTOM);
break;
default:
throw new AssertionError("Unknown type: " + phone.getType());
}
if (phone.getLabel().isPresent())
phoneBuilder.setLabel(phone.getLabel().get());
contactBuilder.addNumber(phoneBuilder);
}
}
if (contact.getAvatar().isPresent()) {
AttachmentPointer pointer = contact.getAvatar().get().getAttachment().isStream() ? createAttachmentPointer(contact.getAvatar().get().getAttachment().asStream()) : createAttachmentPointer(contact.getAvatar().get().getAttachment().asPointer());
contactBuilder.setAvatar(DataMessage.Contact.Avatar.newBuilder().setAvatar(pointer).setIsProfile(contact.getAvatar().get().isProfile()));
}
if (contact.getOrganization().isPresent()) {
contactBuilder.setOrganization(contact.getOrganization().get());
}
results.add(contactBuilder.build());
}
return results;
}
Aggregations