2015-10-13 01:25:05 +00:00
|
|
|
package org.thoughtcrime.securesms.attachments;
|
|
|
|
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
2018-01-25 03:17:44 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Base64;
|
2016-03-23 17:34:41 +00:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
2018-04-02 23:17:32 +00:00
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
2015-10-13 01:25:05 +00:00
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class PointerAttachment extends Attachment {
|
|
|
|
|
2018-01-25 03:17:44 +00:00
|
|
|
private PointerAttachment(@NonNull String contentType, int transferState, long size,
|
2018-02-07 22:01:37 +00:00
|
|
|
@Nullable String fileName, @NonNull String location,
|
2018-04-02 23:17:32 +00:00
|
|
|
@Nullable String key, @Nullable String relay,
|
2018-02-07 22:01:37 +00:00
|
|
|
@Nullable byte[] digest, boolean voiceNote,
|
2018-03-18 23:04:33 +00:00
|
|
|
int width, int height)
|
2015-10-13 01:25:05 +00:00
|
|
|
{
|
2018-02-07 22:01:37 +00:00
|
|
|
super(contentType, transferState, size, fileName, location, key, relay, digest, null, voiceNote, width, height, false);
|
2015-10-13 01:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Uri getDataUri() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Uri getThumbnailUri() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-25 03:17:44 +00:00
|
|
|
public static List<Attachment> forPointers(Optional<List<SignalServiceAttachment>> pointers) {
|
2015-10-13 01:25:05 +00:00
|
|
|
List<Attachment> results = new LinkedList<>();
|
|
|
|
|
|
|
|
if (pointers.isPresent()) {
|
2016-03-23 17:34:41 +00:00
|
|
|
for (SignalServiceAttachment pointer : pointers.get()) {
|
2018-02-07 22:01:37 +00:00
|
|
|
Optional<Attachment> result = forPointer(Optional.of(pointer));
|
|
|
|
|
|
|
|
if (result.isPresent()) {
|
|
|
|
results.add(result.get());
|
2015-10-13 01:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
2018-02-07 22:01:37 +00:00
|
|
|
|
2018-04-02 23:17:32 +00:00
|
|
|
public static List<Attachment> forPointers(List<SignalServiceDataMessage.Quote.QuotedAttachment> pointers) {
|
|
|
|
List<Attachment> results = new LinkedList<>();
|
|
|
|
|
|
|
|
if (pointers != null) {
|
|
|
|
for (SignalServiceDataMessage.Quote.QuotedAttachment pointer : pointers) {
|
|
|
|
Optional<Attachment> result = forPointer(pointer);
|
|
|
|
|
|
|
|
if (result.isPresent()) {
|
|
|
|
results.add(result.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
2018-02-07 22:01:37 +00:00
|
|
|
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer) {
|
|
|
|
if (!pointer.isPresent() || !pointer.get().isPointer()) return Optional.absent();
|
|
|
|
|
|
|
|
String encodedKey = null;
|
|
|
|
|
|
|
|
if (pointer.get().asPointer().getKey() != null) {
|
|
|
|
encodedKey = Base64.encodeBytes(pointer.get().asPointer().getKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Optional.of(new PointerAttachment(pointer.get().getContentType(),
|
|
|
|
AttachmentDatabase.TRANSFER_PROGRESS_PENDING,
|
|
|
|
pointer.get().asPointer().getSize().or(0),
|
|
|
|
pointer.get().asPointer().getFileName().orNull(),
|
|
|
|
String.valueOf(pointer.get().asPointer().getId()),
|
|
|
|
encodedKey, pointer.get().asPointer().getRelay().orNull(),
|
|
|
|
pointer.get().asPointer().getDigest().orNull(),
|
|
|
|
pointer.get().asPointer().getVoiceNote(),
|
|
|
|
pointer.get().asPointer().getWidth(),
|
|
|
|
pointer.get().asPointer().getHeight()));
|
|
|
|
|
|
|
|
}
|
2018-04-02 23:17:32 +00:00
|
|
|
|
|
|
|
public static Optional<Attachment> forPointer(SignalServiceDataMessage.Quote.QuotedAttachment pointer) {
|
|
|
|
SignalServiceAttachment thumbnail = pointer.getThumbnail();
|
|
|
|
|
|
|
|
return Optional.of(new PointerAttachment(pointer.getContentType(),
|
|
|
|
AttachmentDatabase.TRANSFER_PROGRESS_PENDING,
|
|
|
|
thumbnail != null ? thumbnail.asPointer().getSize().or(0) : 0,
|
|
|
|
pointer.getFileName(),
|
|
|
|
String.valueOf(thumbnail != null ? thumbnail.asPointer().getId() : 0),
|
|
|
|
thumbnail != null && thumbnail.asPointer().getKey() != null ? Base64.encodeBytes(thumbnail.asPointer().getKey()) : null,
|
|
|
|
null,
|
|
|
|
thumbnail != null ? thumbnail.asPointer().getDigest().orNull() : null,
|
|
|
|
false,
|
|
|
|
thumbnail != null ? thumbnail.asPointer().getWidth() : 0,
|
|
|
|
thumbnail != null ? thumbnail.asPointer().getHeight() : 0));
|
|
|
|
}
|
2015-10-13 01:25:05 +00:00
|
|
|
}
|