use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer in project libsignal-service-java by signalapp.
the class SignalServiceCipher method createGroupInfo.
private SignalServiceGroup createGroupInfo(DataMessage content) throws ProtocolInvalidMessageException {
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<SignalServiceAddress> members = null;
SignalServiceAttachmentPointer avatar = null;
if (content.getGroup().hasName()) {
name = content.getGroup().getName();
}
if (content.getGroup().getMembersCount() > 0) {
members = new ArrayList<>(content.getGroup().getMembersCount());
for (SignalServiceProtos.GroupContext.Member member : content.getGroup().getMembersList()) {
if (SignalServiceAddress.isValidAddress(member.getUuid(), member.getE164())) {
members.add(new SignalServiceAddress(UuidUtil.parseOrNull(member.getUuid()), member.getE164()));
} else {
throw new ProtocolInvalidMessageException(new InvalidMessageException("GroupContext.Member had no address!"), null, 0);
}
}
} else if (content.getGroup().getMembersE164Count() > 0) {
members = new ArrayList<>(content.getGroup().getMembersE164Count());
for (String member : content.getGroup().getMembersE164List()) {
members.add(new SignalServiceAddress(null, member));
}
}
if (content.getGroup().hasAvatar()) {
AttachmentPointer pointer = content.getGroup().getAvatar();
avatar = new SignalServiceAttachmentPointer(pointer.getId(), pointer.getContentType(), pointer.getKey().toByteArray(), Optional.of(pointer.getSize()), Optional.<byte[]>absent(), 0, 0, Optional.fromNullable(pointer.hasDigest() ? pointer.getDigest().toByteArray() : null), Optional.<String>absent(), false, Optional.<String>absent(), Optional.<String>absent());
}
return new SignalServiceGroup(type, content.getGroup().getId().toByteArray(), name, members, avatar);
}
return new SignalServiceGroup(content.getGroup().getId().toByteArray());
}
use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer in project Signal-Android by signalapp.
the class PushSendJob method getAttachmentPointerFor.
@Nullable
protected SignalServiceAttachment getAttachmentPointerFor(Attachment attachment) {
if (TextUtils.isEmpty(attachment.getLocation())) {
Log.w(TAG, "empty content id");
return null;
}
if (TextUtils.isEmpty(attachment.getKey())) {
Log.w(TAG, "empty encrypted key");
return null;
}
try {
final SignalServiceAttachmentRemoteId remoteId = SignalServiceAttachmentRemoteId.from(attachment.getLocation());
final byte[] key = Base64.decode(attachment.getKey());
int width = attachment.getWidth();
int height = attachment.getHeight();
if ((width == 0 || height == 0) && MediaUtil.hasVideoThumbnail(context, attachment.getUri())) {
Bitmap thumbnail = MediaUtil.getVideoThumbnail(context, attachment.getUri(), 1000);
if (thumbnail != null) {
width = thumbnail.getWidth();
height = thumbnail.getHeight();
}
}
return new SignalServiceAttachmentPointer(attachment.getCdnNumber(), remoteId, attachment.getContentType(), key, Optional.of(Util.toIntExact(attachment.getSize())), Optional.absent(), width, height, Optional.fromNullable(attachment.getDigest()), Optional.fromNullable(attachment.getFileName()), attachment.isVoiceNote(), attachment.isBorderless(), attachment.isVideoGif(), Optional.fromNullable(attachment.getCaption()), Optional.fromNullable(attachment.getBlurHash()).transform(BlurHash::getHash), attachment.getUploadTimestamp());
} catch (IOException | ArithmeticException e) {
Log.w(TAG, e);
return null;
}
}
Aggregations