further cleaning up on stickers

This commit is contained in:
Ryan ZHAO
2021-02-23 15:07:31 +11:00
parent fc62fe3b23
commit ff36fbb6a1
43 changed files with 41 additions and 738 deletions

View File

@@ -69,6 +69,6 @@ class Attachment {
fun toDatabaseAttachment(): org.session.libsession.messaging.sending_receiving.attachments.Attachment {
return DatabaseAttachment(null, 0, true, true, contentType, 0,
sizeInBytes?.toLong() ?: 0, fileName, null, key.toString(), null, digest, null, kind == Kind.VOICE_MESSAGE,
size?.width ?: 0, size?.height ?: 0, false, caption, null, url)
size?.width ?: 0, size?.height ?: 0, false, caption, url)
}
}

View File

@@ -39,16 +39,13 @@ public abstract class Attachment {
@Nullable
private final String caption;
@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, String url)
int width, int height, boolean quote, @Nullable String caption, String url)
{
this.contentType = contentType;
this.transferState = transferState;
@@ -63,7 +60,6 @@ public abstract class Attachment {
this.width = width;
this.height = height;
this.quote = quote;
this.stickerLocator = stickerLocator;
this.caption = caption;
this.url = url;
}
@@ -138,14 +134,6 @@ public abstract class Attachment {
return quote;
}
public boolean isSticker() {
return stickerLocator != null;
}
public @Nullable StickerLocator getSticker() {
return stickerLocator;
}
public @Nullable String getCaption() {
return caption;
}

View File

@@ -20,9 +20,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, String url)
String url)
{
super(contentType, transferProgress, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, quote, caption, stickerLocator, url);
super(contentType, transferProgress, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, quote, caption, url);
this.attachmentId = attachmentId;
this.hasData = hasData;
this.hasThumbnail = hasThumbnail;

View File

@@ -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, String url)
int width, int height, @Nullable String caption, String url)
{
super(contentType, transferState, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, false, caption, stickerLocator, url);
super(contentType, transferState, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, false, caption, url);
}
@Nullable
@@ -87,14 +87,10 @@ public class PointerAttachment extends Attachment {
}
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer) {
return forPointer(pointer, null, null);
return forPointer(pointer, null);
}
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer, @Nullable StickerLocator stickerLocator) {
return forPointer(pointer, stickerLocator, null);
}
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer, @Nullable StickerLocator stickerLocator, @Nullable String fastPreflightId) {
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer, @Nullable String fastPreflightId) {
if (!pointer.isPresent() || !pointer.get().isPointer()) return Optional.absent();
String encodedKey = null;
@@ -115,7 +111,6 @@ public class PointerAttachment extends Attachment {
pointer.get().asPointer().getWidth(),
pointer.get().asPointer().getHeight(),
pointer.get().asPointer().getCaption().orNull(),
stickerLocator,
pointer.get().asPointer().getUrl()));
}
@@ -134,7 +129,6 @@ public class PointerAttachment extends Attachment {
pointer.getWidth(),
pointer.getHeight(),
pointer.getCaption(),
null,
pointer.getUrl()));
}
@@ -154,7 +148,6 @@ public class PointerAttachment extends Attachment {
thumbnail != null ? thumbnail.getWidth() : 0,
thumbnail != null ? thumbnail.getHeight() : 0,
thumbnail != null ? thumbnail.getCaption() : null,
null,
thumbnail != null ? thumbnail.getUrl() : ""));
}
@@ -174,7 +167,6 @@ 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,
thumbnail != null ? thumbnail.asPointer().getUrl() : ""));
}
}

View File

@@ -1,61 +0,0 @@
package org.session.libsession.messaging.sending_receiving.attachments;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
public class StickerLocator implements Parcelable {
private final String packId;
private final String packKey;
private final int stickerId;
public StickerLocator(@NonNull String packId, @NonNull String packKey, int stickerId) {
this.packId = packId;
this.packKey = packKey;
this.stickerId = stickerId;
}
private StickerLocator(Parcel in) {
packId = in.readString();
packKey = in.readString();
stickerId = in.readInt();
}
public @NonNull String getPackId() {
return packId;
}
public @NonNull String getPackKey() {
return packKey;
}
public @NonNull int getStickerId() {
return stickerId;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(packId);
dest.writeString(packKey);
dest.writeInt(stickerId);
}
public static final Creator<StickerLocator> CREATOR = new Creator<StickerLocator>() {
@Override
public StickerLocator createFromParcel(Parcel in) {
return new StickerLocator(in);
}
@Override
public StickerLocator[] newArray(int size) {
return new StickerLocator[size];
}
};
}

View File

@@ -11,18 +11,17 @@ public class UriAttachment extends Attachment {
private final @Nullable Uri thumbnailUri;
public UriAttachment(@NonNull Uri uri, @NonNull String contentType, int transferState, long size,
@Nullable String fileName, boolean voiceNote, boolean quote, @Nullable String caption,
@Nullable StickerLocator stickerLocator)
@Nullable String fileName, boolean voiceNote, boolean quote, @Nullable String caption)
{
this(uri, uri, contentType, transferState, size, 0, 0, fileName, null, voiceNote, quote, caption, stickerLocator);
this(uri, uri, contentType, transferState, size, 0, 0, fileName, null, voiceNote, quote, caption);
}
public UriAttachment(@NonNull Uri dataUri, @Nullable Uri thumbnailUri,
@NonNull String contentType, int transferState, long size, int width, int height,
@Nullable String fileName, @Nullable String fastPreflightId,
boolean voiceNote, boolean quote, @Nullable String caption, @Nullable StickerLocator stickerLocator)
boolean voiceNote, boolean quote, @Nullable String caption)
{
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, "");
this.dataUri = dataUri;
this.thumbnailUri = thumbnailUri;
}

View File

@@ -643,7 +643,7 @@ public class Contact implements Parcelable {
private static Attachment attachmentFromUri(@Nullable Uri uri) {
if (uri == null) return null;
return new UriAttachment(uri, MediaTypes.IMAGE_JPEG, AttachmentTransferProgress.TRANSFER_PROGRESS_DONE, 0, null, false, false, null, null);
return new UriAttachment(uri, MediaTypes.IMAGE_JPEG, AttachmentTransferProgress.TRANSFER_PROGRESS_DONE, 0, null, false, false, null);
}
@Override