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-02-26 18:06:27 +00:00
|
|
|
@NonNull String location, @NonNull String key, @NonNull String relay,
|
|
|
|
@Nullable byte[] digest)
|
2015-10-13 01:25:05 +00:00
|
|
|
{
|
2017-02-26 18:06:27 +00:00
|
|
|
super(contentType, transferState, size, location, key, relay, digest);
|
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(),
|
|
|
|
AttachmentDatabase.TRANSFER_PROGRESS_AUTO_PENDING,
|
|
|
|
pointer.asPointer().getSize().or(0),
|
|
|
|
String.valueOf(pointer.asPointer().getId()),
|
2017-02-26 18:06:27 +00:00
|
|
|
encryptedKey, pointer.asPointer().getRelay().orNull(),
|
|
|
|
pointer.asPointer().getDigest().orNull()));
|
2015-10-13 01:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
}
|