mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 01:21:09 +00:00
Introduce unique part ID column for better cache accuracy.
Closes #3226 // FREEBIE
This commit is contained in:
@@ -46,7 +46,7 @@ public class ImageSlide extends Slide {
|
||||
if (!getPart().isPendingPush() && getPart().getDataUri() != null) {
|
||||
return isDraft()
|
||||
? getPart().getDataUri()
|
||||
: PartAuthority.getThumbnailUri(getPart().getId(), part.getContentId());
|
||||
: PartAuthority.getThumbnailUri(getPart().getPartId());
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -27,15 +27,11 @@ public class IncomingMediaMessage {
|
||||
private final String groupId;
|
||||
private final boolean push;
|
||||
|
||||
public IncomingMediaMessage(RetrieveConf retreived) {
|
||||
this.headers = retreived.getPduHeaders();
|
||||
this.body = retreived.getBody();
|
||||
public IncomingMediaMessage(RetrieveConf retrieved) {
|
||||
this.headers = retrieved.getPduHeaders();
|
||||
this.body = retrieved.getBody();
|
||||
this.groupId = null;
|
||||
this.push = false;
|
||||
|
||||
for (int i=0;i<body.getPartsNum();i++) {
|
||||
body.getPart(i).setContentId(String.valueOf(System.currentTimeMillis()).getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
public IncomingMediaMessage(MasterSecret masterSecret,
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||
import org.thoughtcrime.securesms.providers.PartProvider;
|
||||
import org.thoughtcrime.securesms.util.Hex;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -41,11 +40,11 @@ public class PartAuthority {
|
||||
try {
|
||||
switch (match) {
|
||||
case PART_ROW:
|
||||
PartUri partUri = new PartUri(uri);
|
||||
return partDatabase.getPartStream(masterSecret, partUri.getId(), partUri.getContentId());
|
||||
PartUriParser partUri = new PartUriParser(uri);
|
||||
return partDatabase.getPartStream(masterSecret, partUri.getPartId());
|
||||
case THUMB_ROW:
|
||||
partUri = new PartUri(uri);
|
||||
return partDatabase.getThumbnailStream(masterSecret, partUri.getId(), partUri.getContentId());
|
||||
partUri = new PartUriParser(uri);
|
||||
return partDatabase.getThumbnailStream(masterSecret, partUri.getPartId());
|
||||
default:
|
||||
return context.getContentResolver().openInputStream(uri);
|
||||
}
|
||||
@@ -55,17 +54,17 @@ public class PartAuthority {
|
||||
}
|
||||
|
||||
public static Uri getPublicPartUri(Uri uri) {
|
||||
PartUri partUri = new PartUri(uri);
|
||||
return PartProvider.getContentUri(partUri.getId(), partUri.getContentId());
|
||||
PartUriParser partUri = new PartUriParser(uri);
|
||||
return PartProvider.getContentUri(partUri.getPartId());
|
||||
}
|
||||
|
||||
public static Uri getPartUri(long partId, byte[] contentId) {
|
||||
Uri uri = Uri.withAppendedPath(PART_CONTENT_URI, Hex.toStringCondensed(contentId));
|
||||
return ContentUris.withAppendedId(uri, partId);
|
||||
public static Uri getPartUri(PartDatabase.PartId partId) {
|
||||
Uri uri = Uri.withAppendedPath(PART_CONTENT_URI, String.valueOf(partId.getUniqueId()));
|
||||
return ContentUris.withAppendedId(uri, partId.getRowId());
|
||||
}
|
||||
|
||||
public static Uri getThumbnailUri(long partId, byte[] contentId) {
|
||||
Uri uri = Uri.withAppendedPath(THUMB_CONTENT_URI, Hex.toStringCondensed(contentId));
|
||||
return ContentUris.withAppendedId(uri, partId);
|
||||
public static Uri getThumbnailUri(PartDatabase.PartId partId) {
|
||||
Uri uri = Uri.withAppendedPath(THUMB_CONTENT_URI, String.valueOf(partId.getUniqueId()));
|
||||
return ContentUris.withAppendedId(uri, partId.getRowId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Hex;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PartUri {
|
||||
|
||||
private final Uri uri;
|
||||
|
||||
public PartUri(Uri uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return ContentUris.parseId(uri);
|
||||
}
|
||||
|
||||
public byte[] getContentId() {
|
||||
try {
|
||||
return Hex.fromStringCondensed(uri.getPathSegments().get(1));
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
31
src/org/thoughtcrime/securesms/mms/PartUriParser.java
Normal file
31
src/org/thoughtcrime/securesms/mms/PartUriParser.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||
import org.thoughtcrime.securesms.util.Hex;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PartUriParser {
|
||||
|
||||
private final Uri uri;
|
||||
|
||||
public PartUriParser(Uri uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public PartDatabase.PartId getPartId() {
|
||||
return new PartDatabase.PartId(getId(), getUniqueId());
|
||||
}
|
||||
|
||||
private long getId() {
|
||||
return ContentUris.parseId(uri);
|
||||
}
|
||||
|
||||
private long getUniqueId() {
|
||||
return Long.parseLong(uri.getPathSegments().get(1));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public abstract class Slide {
|
||||
}
|
||||
|
||||
public boolean isDraft() {
|
||||
return getPart().getId() < 0;
|
||||
return !getPart().getPartId().isValid();
|
||||
}
|
||||
|
||||
protected static void assertMediaSize(Context context, Uri uri)
|
||||
|
||||
Reference in New Issue
Block a user