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.crypto.MasterSecretUnion;
|
|
|
|
import org.thoughtcrime.securesms.crypto.MediaKey;
|
|
|
|
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
2016-03-23 17:34:41 +00:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
2015-10-13 01:25:05 +00:00
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class PointerAttachment extends Attachment {
|
|
|
|
|
|
|
|
public PointerAttachment(@NonNull String contentType, int transferState, long size,
|
2017-03-28 19:05:30 +00:00
|
|
|
@Nullable String fileName, @NonNull String location,
|
|
|
|
@NonNull String key, @NonNull String relay,
|
2017-05-12 05:46:35 +00:00
|
|
|
@Nullable byte[] digest, boolean voiceNote)
|
2015-10-13 01:25:05 +00:00
|
|
|
{
|
2017-05-12 05:46:35 +00:00
|
|
|
super(contentType, transferState, size, fileName, location, key, relay, digest, null, voiceNote);
|
2015-10-13 01:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Uri getDataUri() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Uri getThumbnailUri() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-23 17:34:41 +00:00
|
|
|
public static List<Attachment> forPointers(@NonNull MasterSecretUnion masterSecret, 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()) {
|
2015-10-13 01:25:05 +00:00
|
|
|
if (pointer.isPointer()) {
|
|
|
|
String encryptedKey = MediaKey.getEncrypted(masterSecret, pointer.asPointer().getKey());
|
|
|
|
results.add(new PointerAttachment(pointer.getContentType(),
|
2017-07-21 22:59:27 +00:00
|
|
|
AttachmentDatabase.TRANSFER_PROGRESS_PENDING,
|
2015-10-13 01:25:05 +00:00
|
|
|
pointer.asPointer().getSize().or(0),
|
2017-03-28 19:05:30 +00:00
|
|
|
pointer.asPointer().getFileName().orNull(),
|
2015-10-13 01:25:05 +00:00
|
|
|
String.valueOf(pointer.asPointer().getId()),
|
2017-02-26 18:06:27 +00:00
|
|
|
encryptedKey, pointer.asPointer().getRelay().orNull(),
|
2017-05-12 05:46:35 +00:00
|
|
|
pointer.asPointer().getDigest().orNull(),
|
|
|
|
pointer.asPointer().getVoiceNote()));
|
2015-10-13 01:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
}
|