mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Update attachments to use url.
This commit is contained in:
parent
c8238df8ff
commit
c6f5adb447
@ -108,8 +108,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:visibility="gone">
|
||||
android:clipToPadding="false">
|
||||
|
||||
<org.thoughtcrime.securesms.components.HidingLinearLayout
|
||||
android:id="@+id/quick_attachment_toggle"
|
||||
|
@ -44,10 +44,13 @@ public abstract class Attachment {
|
||||
@Nullable
|
||||
private final StickerLocator stickerLocator;
|
||||
|
||||
// Loki
|
||||
private final String url;
|
||||
|
||||
public Attachment(@NonNull String contentType, int transferState, long size, @Nullable String fileName,
|
||||
@Nullable String location, @Nullable String key, @Nullable String relay,
|
||||
@Nullable byte[] digest, @Nullable String fastPreflightId, boolean voiceNote,
|
||||
int width, int height, boolean quote, @Nullable String caption, @Nullable StickerLocator stickerLocator)
|
||||
int width, int height, boolean quote, @Nullable String caption, @Nullable StickerLocator stickerLocator, String url)
|
||||
{
|
||||
this.contentType = contentType;
|
||||
this.transferState = transferState;
|
||||
@ -64,6 +67,7 @@ public abstract class Attachment {
|
||||
this.quote = quote;
|
||||
this.stickerLocator = stickerLocator;
|
||||
this.caption = caption;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -147,4 +151,6 @@ public abstract class Attachment {
|
||||
public @Nullable String getCaption() {
|
||||
return caption;
|
||||
}
|
||||
|
||||
public String getUrl() { return url; }
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ public class DatabaseAttachment extends Attachment {
|
||||
String fileName, String location, String key, String relay,
|
||||
byte[] digest, String fastPreflightId, boolean voiceNote,
|
||||
int width, int height, boolean quote, @Nullable String caption,
|
||||
@Nullable StickerLocator stickerLocator)
|
||||
@Nullable StickerLocator stickerLocator, String url)
|
||||
{
|
||||
super(contentType, transferProgress, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, quote, caption, stickerLocator);
|
||||
super(contentType, transferProgress, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, quote, caption, stickerLocator, url);
|
||||
this.attachmentId = attachmentId;
|
||||
this.hasData = hasData;
|
||||
this.hasThumbnail = hasThumbnail;
|
||||
|
@ -10,7 +10,7 @@ import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||
public class MmsNotificationAttachment extends Attachment {
|
||||
|
||||
public MmsNotificationAttachment(int status, long size) {
|
||||
super("application/mms", getTransferStateFromStatus(status), size, null, null, null, null, null, null, false, 0, 0, false, null, null);
|
||||
super("application/mms", getTransferStateFromStatus(status), size, null, null, null, null, null, null, false, 0, 0, false, null, null, "");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -20,9 +20,9 @@ public class PointerAttachment extends Attachment {
|
||||
@Nullable String fileName, @NonNull String location,
|
||||
@Nullable String key, @Nullable String relay,
|
||||
@Nullable byte[] digest, @Nullable String fastPreflightId, boolean voiceNote,
|
||||
int width, int height, @Nullable String caption, @Nullable StickerLocator stickerLocator)
|
||||
int width, int height, @Nullable String caption, @Nullable StickerLocator stickerLocator, String url)
|
||||
{
|
||||
super(contentType, transferState, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, false, caption, stickerLocator);
|
||||
super(contentType, transferState, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, false, caption, stickerLocator, url);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -99,7 +99,8 @@ public class PointerAttachment extends Attachment {
|
||||
pointer.get().asPointer().getWidth(),
|
||||
pointer.get().asPointer().getHeight(),
|
||||
pointer.get().asPointer().getCaption().orNull(),
|
||||
stickerLocator));
|
||||
stickerLocator,
|
||||
pointer.get().asPointer().getUrl()));
|
||||
|
||||
}
|
||||
|
||||
@ -119,6 +120,7 @@ public class PointerAttachment extends Attachment {
|
||||
thumbnail != null ? thumbnail.asPointer().getWidth() : 0,
|
||||
thumbnail != null ? thumbnail.asPointer().getHeight() : 0,
|
||||
thumbnail != null ? thumbnail.asPointer().getCaption().orNull() : null,
|
||||
null));
|
||||
null,
|
||||
thumbnail != null ? thumbnail.asPointer().getUrl() : ""));
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class UriAttachment extends Attachment {
|
||||
@Nullable String fileName, @Nullable String fastPreflightId,
|
||||
boolean voiceNote, boolean quote, @Nullable String caption, @Nullable StickerLocator stickerLocator)
|
||||
{
|
||||
super(contentType, transferState, size, fileName, null, null, null, null, fastPreflightId, voiceNote, width, height, quote, caption, stickerLocator);
|
||||
super(contentType, transferState, size, fileName, null, null, null, null, fastPreflightId, voiceNote, width, height, quote, caption, stickerLocator, "");
|
||||
this.dataUri = dataUri;
|
||||
this.thumbnailUri = thumbnailUri;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public class AttachmentDatabase extends Database {
|
||||
static final String WIDTH = "width";
|
||||
static final String HEIGHT = "height";
|
||||
static final String CAPTION = "caption";
|
||||
|
||||
public static final String URL = "url";
|
||||
public static final String DIRECTORY = "parts";
|
||||
|
||||
public static final int TRANSFER_PROGRESS_DONE = 0;
|
||||
@ -119,7 +119,7 @@ public class AttachmentDatabase extends Database {
|
||||
SIZE, FILE_NAME, THUMBNAIL, THUMBNAIL_ASPECT_RATIO,
|
||||
UNIQUE_ID, DIGEST, FAST_PREFLIGHT_ID, VOICE_NOTE,
|
||||
QUOTE, DATA_RANDOM, THUMBNAIL_RANDOM, WIDTH, HEIGHT,
|
||||
CAPTION, STICKER_PACK_ID, STICKER_PACK_KEY, STICKER_ID};
|
||||
CAPTION, STICKER_PACK_ID, STICKER_PACK_KEY, STICKER_ID, URL};
|
||||
|
||||
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ROW_ID + " INTEGER PRIMARY KEY, " +
|
||||
MMS_ID + " INTEGER, " + "seq" + " INTEGER DEFAULT 0, " +
|
||||
@ -132,7 +132,7 @@ public class AttachmentDatabase extends Database {
|
||||
UNIQUE_ID + " INTEGER NOT NULL, " + DIGEST + " BLOB, " + FAST_PREFLIGHT_ID + " TEXT, " +
|
||||
VOICE_NOTE + " INTEGER DEFAULT 0, " + DATA_RANDOM + " BLOB, " + THUMBNAIL_RANDOM + " BLOB, " +
|
||||
QUOTE + " INTEGER DEFAULT 0, " + WIDTH + " INTEGER DEFAULT 0, " + HEIGHT + " INTEGER DEFAULT 0, " +
|
||||
CAPTION + " TEXT DEFAULT NULL, " + STICKER_PACK_ID + " TEXT DEFAULT NULL, " +
|
||||
CAPTION + " TEXT DEFAULT NULL, " + URL + " TEXT, " + STICKER_PACK_ID + " TEXT DEFAULT NULL, " +
|
||||
STICKER_PACK_KEY + " DEFAULT NULL, " + STICKER_ID + " INTEGER DEFAULT -1);";
|
||||
|
||||
public static final String[] CREATE_INDEXS = {
|
||||
@ -361,6 +361,7 @@ public class AttachmentDatabase extends Database {
|
||||
values.put(DIGEST, (byte[])null);
|
||||
values.put(NAME, (String) null);
|
||||
values.put(FAST_PREFLIGHT_ID, (String)null);
|
||||
values.put(URL, "");
|
||||
|
||||
if (database.update(TABLE_NAME, values, PART_ID_WHERE, attachmentId.toStrings()) == 0) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
@ -384,6 +385,7 @@ public class AttachmentDatabase extends Database {
|
||||
values.put(NAME, attachment.getRelay());
|
||||
values.put(SIZE, attachment.getSize());
|
||||
values.put(FAST_PREFLIGHT_ID, attachment.getFastPreflightId());
|
||||
values.put(URL, attachment.getUrl());
|
||||
|
||||
database.update(TABLE_NAME, values, PART_ID_WHERE, id.toStrings());
|
||||
}
|
||||
@ -451,7 +453,8 @@ public class AttachmentDatabase extends Database {
|
||||
mediaStream.getHeight(),
|
||||
databaseAttachment.isQuote(),
|
||||
databaseAttachment.getCaption(),
|
||||
databaseAttachment.getSticker());
|
||||
databaseAttachment.getSticker(),
|
||||
databaseAttachment.getUrl());
|
||||
}
|
||||
|
||||
|
||||
@ -650,7 +653,7 @@ public class AttachmentDatabase extends Database {
|
||||
? new StickerLocator(object.getString(STICKER_PACK_ID),
|
||||
object.getString(STICKER_PACK_KEY),
|
||||
object.getInt(STICKER_ID))
|
||||
: null));
|
||||
: null, "")); // TODO: Not sure if this will break something
|
||||
}
|
||||
}
|
||||
|
||||
@ -679,7 +682,8 @@ public class AttachmentDatabase extends Database {
|
||||
? new StickerLocator(cursor.getString(cursor.getColumnIndexOrThrow(STICKER_PACK_ID)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(STICKER_PACK_KEY)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(STICKER_ID)))
|
||||
: null));
|
||||
: null,
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(URL))));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new AssertionError(e);
|
||||
@ -718,6 +722,7 @@ public class AttachmentDatabase extends Database {
|
||||
contentValues.put(HEIGHT, attachment.getHeight());
|
||||
contentValues.put(QUOTE, quote);
|
||||
contentValues.put(CAPTION, attachment.getCaption());
|
||||
contentValues.put(URL, attachment.getUrl());
|
||||
|
||||
if (attachment.isSticker()) {
|
||||
contentValues.put(STICKER_PACK_ID, attachment.getSticker().getPackId());
|
||||
|
@ -50,6 +50,9 @@ public class GroupDatabase extends Database {
|
||||
private static final String ACTIVE = "active";
|
||||
private static final String MMS = "mms";
|
||||
|
||||
// Loki
|
||||
private static final String AVATAR_URL = "avatar_url";
|
||||
|
||||
public static final String CREATE_TABLE =
|
||||
"CREATE TABLE " + TABLE_NAME +
|
||||
" (" + ID + " INTEGER PRIMARY KEY, " +
|
||||
@ -64,6 +67,7 @@ public class GroupDatabase extends Database {
|
||||
TIMESTAMP + " INTEGER, " +
|
||||
ACTIVE + " INTEGER DEFAULT 1, " +
|
||||
AVATAR_DIGEST + " BLOB, " +
|
||||
AVATAR_URL + " TEXT, " +
|
||||
MMS + " INTEGER DEFAULT 0);";
|
||||
|
||||
public static final String[] CREATE_INDEXS = {
|
||||
@ -72,7 +76,7 @@ public class GroupDatabase extends Database {
|
||||
|
||||
private static final String[] GROUP_PROJECTION = {
|
||||
GROUP_ID, TITLE, MEMBERS, AVATAR, AVATAR_ID, AVATAR_KEY, AVATAR_CONTENT_TYPE, AVATAR_RELAY, AVATAR_DIGEST,
|
||||
TIMESTAMP, ACTIVE, MMS
|
||||
TIMESTAMP, ACTIVE, MMS, AVATAR_URL
|
||||
};
|
||||
|
||||
static final List<String> TYPED_GROUP_PROJECTION = Stream.of(GROUP_PROJECTION).map(columnName -> TABLE_NAME + "." + columnName).toList();
|
||||
@ -167,6 +171,7 @@ public class GroupDatabase extends Database {
|
||||
contentValues.put(AVATAR_KEY, avatar.getKey());
|
||||
contentValues.put(AVATAR_CONTENT_TYPE, avatar.getContentType());
|
||||
contentValues.put(AVATAR_DIGEST, avatar.getDigest().orNull());
|
||||
contentValues.put(AVATAR_URL, avatar.getUrl());
|
||||
}
|
||||
|
||||
contentValues.put(AVATAR_RELAY, relay);
|
||||
@ -194,6 +199,7 @@ public class GroupDatabase extends Database {
|
||||
contentValues.put(AVATAR_CONTENT_TYPE, avatar.getContentType());
|
||||
contentValues.put(AVATAR_KEY, avatar.getKey());
|
||||
contentValues.put(AVATAR_DIGEST, avatar.getDigest().orNull());
|
||||
contentValues.put(AVATAR_URL, avatar.getUrl());
|
||||
}
|
||||
|
||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues,
|
||||
@ -344,7 +350,8 @@ public class GroupDatabase extends Database {
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(AVATAR_RELAY)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(ACTIVE)) == 1,
|
||||
cursor.getBlob(cursor.getColumnIndexOrThrow(AVATAR_DIGEST)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(MMS)) == 1);
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(MMS)) == 1,
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(AVATAR_URL)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -367,10 +374,11 @@ public class GroupDatabase extends Database {
|
||||
private final String relay;
|
||||
private final boolean active;
|
||||
private final boolean mms;
|
||||
private final String url;
|
||||
|
||||
public GroupRecord(String id, String title, String members, byte[] avatar,
|
||||
long avatarId, byte[] avatarKey, String avatarContentType,
|
||||
String relay, boolean active, byte[] avatarDigest, boolean mms)
|
||||
String relay, boolean active, byte[] avatarDigest, boolean mms, String url)
|
||||
{
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
@ -382,6 +390,7 @@ public class GroupDatabase extends Database {
|
||||
this.relay = relay;
|
||||
this.active = active;
|
||||
this.mms = mms;
|
||||
this.url = url;
|
||||
|
||||
if (!TextUtils.isEmpty(members)) this.members = Address.fromSerializedList(members, ',');
|
||||
else this.members = new LinkedList<>();
|
||||
@ -438,5 +447,7 @@ public class GroupDatabase extends Database {
|
||||
public boolean isMms() {
|
||||
return mms;
|
||||
}
|
||||
|
||||
public String getUrl() { return url; }
|
||||
}
|
||||
}
|
||||
|
@ -778,7 +778,8 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
databaseAttachment.getHeight(),
|
||||
databaseAttachment.isQuote(),
|
||||
databaseAttachment.getCaption(),
|
||||
databaseAttachment.getSticker()));
|
||||
databaseAttachment.getSticker(),
|
||||
databaseAttachment.getUrl()));
|
||||
}
|
||||
|
||||
return insertMediaMessage(request.getBody(),
|
||||
|
@ -499,6 +499,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
if (oldVersion < lokiV3) {
|
||||
db.execSQL(LokiAPIDatabase.getCreatePairingAuthorisationTableCommand());
|
||||
db.execSQL(LokiThreadDatabase.getCreatePublicChatTableCommand());
|
||||
|
||||
db.execSQL("ALTER TABLE groups ADD COLUMN avatar_url TEXT");
|
||||
db.execSQL("ALTER TABLE part ADD COLUMN url TEXT");
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
@ -213,7 +213,7 @@ public class AttachmentDownloadJob extends BaseJob implements InjectableType {
|
||||
Optional.fromNullable(attachment.getDigest()),
|
||||
Optional.fromNullable(attachment.getFileName()),
|
||||
attachment.isVoiceNote(),
|
||||
Optional.absent());
|
||||
Optional.absent(), attachment.getUrl());
|
||||
} catch (IOException | ArithmeticException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new InvalidPartException(e);
|
||||
|
@ -80,8 +80,9 @@ public class AvatarDownloadJob extends BaseJob implements InjectableType {
|
||||
String relay = record.get().getRelay();
|
||||
Optional<byte[]> digest = Optional.fromNullable(record.get().getAvatarDigest());
|
||||
Optional<String> fileName = Optional.absent();
|
||||
String url = record.get().getUrl();
|
||||
|
||||
if (avatarId == -1 || key == null) {
|
||||
if (avatarId == -1 || key == null || url.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -92,7 +93,7 @@ public class AvatarDownloadJob extends BaseJob implements InjectableType {
|
||||
attachment = File.createTempFile("avatar", "tmp", context.getCacheDir());
|
||||
attachment.deleteOnExit();
|
||||
|
||||
SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(avatarId, contentType, key, Optional.of(0), Optional.absent(), 0, 0, digest, fileName, false, Optional.absent());
|
||||
SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(avatarId, contentType, key, Optional.of(0), Optional.absent(), 0, 0, digest, fileName, false, Optional.absent(), url);
|
||||
InputStream inputStream = receiver.retrieveAttachment(pointer, attachment, MAX_AVATAR_SIZE);
|
||||
Bitmap avatar = BitmapUtil.createScaledBitmap(context, new AttachmentModel(attachment, key, 0, digest), 500, 500);
|
||||
|
||||
|
@ -105,8 +105,8 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
||||
List<Attachment> attachments = new LinkedList<>();
|
||||
|
||||
// Loki - For now all attachments are re-fetched by the receiver
|
||||
// attachments.addAll(message.getAttachments());
|
||||
// attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList());
|
||||
attachments.addAll(message.getAttachments());
|
||||
attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList());
|
||||
attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList());
|
||||
|
||||
List<AttachmentUploadJob> attachmentJobs = Stream.of(attachments).map(a -> new AttachmentUploadJob(((DatabaseAttachment) a).getAttachmentId())).toList();
|
||||
|
@ -172,7 +172,7 @@ public abstract class PushSendJob extends SendJob {
|
||||
Optional.fromNullable(attachment.getDigest()),
|
||||
Optional.fromNullable(attachment.getFileName()),
|
||||
attachment.isVoiceNote(),
|
||||
Optional.fromNullable(attachment.getCaption()));
|
||||
Optional.fromNullable(attachment.getCaption()), attachment.getUrl());
|
||||
} catch (IOException | ArithmeticException e) {
|
||||
Log.w(TAG, e);
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user