+ public File getContactAvatarFile(String number) {
+ return new File(avatarsPath, "contact-" + number);
+ }
+
+ private File retrieveContactAvatarAttachment(SignalServiceAttachment attachment, String number) throws IOException, InvalidMessageException {
+ new File(avatarsPath).mkdirs();
+ if (attachment.isPointer()) {
+ SignalServiceAttachmentPointer pointer = attachment.asPointer();
+ return retrieveAttachment(pointer, getContactAvatarFile(number), false);
+ } else {
+ SignalServiceAttachmentStream stream = attachment.asStream();
+ return retrieveAttachment(stream, getContactAvatarFile(number));
+ }
+ }
+
+ public File getGroupAvatarFile(byte[] groupId) {
+ return new File(avatarsPath, "group-" + Base64.encodeBytes(groupId).replace("/", "_"));
+ }
+
+ private File retrieveGroupAvatarAttachment(SignalServiceAttachment attachment, byte[] groupId) throws IOException, InvalidMessageException {
+ new File(avatarsPath).mkdirs();
+ if (attachment.isPointer()) {
+ SignalServiceAttachmentPointer pointer = attachment.asPointer();
+ return retrieveAttachment(pointer, getGroupAvatarFile(groupId), false);
+ } else {
+ SignalServiceAttachmentStream stream = attachment.asStream();
+ return retrieveAttachment(stream, getGroupAvatarFile(groupId));
+ }
+ }
+