mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 01:21:09 +00:00
Fix image cache bugs.
1) Index SlideDeckListener cache by MMS (id, timestamp) tuple. 2) Index parts by (id, content_id) tuples. Fixes #840 Closes #3183 // 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());
|
||||
: PartAuthority.getThumbnailUri(getPart().getId(), part.getContentId());
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -32,6 +32,10 @@ public class IncomingMediaMessage {
|
||||
this.body = retreived.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,6 +9,7 @@ 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;
|
||||
@@ -17,8 +18,8 @@ public class PartAuthority {
|
||||
|
||||
private static final String PART_URI_STRING = "content://org.thoughtcrime.securesms/part";
|
||||
private static final String THUMB_URI_STRING = "content://org.thoughtcrime.securesms/thumb";
|
||||
public static final Uri PART_CONTENT_URI = Uri.parse(PART_URI_STRING);
|
||||
public static final Uri THUMB_CONTENT_URI = Uri.parse(THUMB_URI_STRING);
|
||||
private static final Uri PART_CONTENT_URI = Uri.parse(PART_URI_STRING);
|
||||
private static final Uri THUMB_CONTENT_URI = Uri.parse(THUMB_URI_STRING);
|
||||
|
||||
private static final int PART_ROW = 1;
|
||||
private static final int THUMB_ROW = 2;
|
||||
@@ -27,8 +28,8 @@ public class PartAuthority {
|
||||
|
||||
static {
|
||||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
uriMatcher.addURI("org.thoughtcrime.securesms", "part/#", PART_ROW);
|
||||
uriMatcher.addURI("org.thoughtcrime.securesms", "thumb/#", THUMB_ROW);
|
||||
uriMatcher.addURI("org.thoughtcrime.securesms", "part/*/#", PART_ROW);
|
||||
uriMatcher.addURI("org.thoughtcrime.securesms", "thumb/*/#", THUMB_ROW);
|
||||
}
|
||||
|
||||
public static InputStream getPartStream(Context context, MasterSecret masterSecret, Uri uri)
|
||||
@@ -39,9 +40,14 @@ public class PartAuthority {
|
||||
|
||||
try {
|
||||
switch (match) {
|
||||
case PART_ROW: return partDatabase.getPartStream(masterSecret, ContentUris.parseId(uri));
|
||||
case THUMB_ROW: return partDatabase.getThumbnailStream(masterSecret, ContentUris.parseId(uri));
|
||||
default: return context.getContentResolver().openInputStream(uri);
|
||||
case PART_ROW:
|
||||
PartUri partUri = new PartUri(uri);
|
||||
return partDatabase.getPartStream(masterSecret, partUri.getId(), partUri.getContentId());
|
||||
case THUMB_ROW:
|
||||
partUri = new PartUri(uri);
|
||||
return partDatabase.getThumbnailStream(masterSecret, partUri.getId(), partUri.getContentId());
|
||||
default:
|
||||
return context.getContentResolver().openInputStream(uri);
|
||||
}
|
||||
} catch (SecurityException se) {
|
||||
throw new IOException(se);
|
||||
@@ -49,10 +55,17 @@ public class PartAuthority {
|
||||
}
|
||||
|
||||
public static Uri getPublicPartUri(Uri uri) {
|
||||
return ContentUris.withAppendedId(PartProvider.CONTENT_URI, ContentUris.parseId(uri));
|
||||
PartUri partUri = new PartUri(uri);
|
||||
return PartProvider.getContentUri(partUri.getId(), partUri.getContentId());
|
||||
}
|
||||
|
||||
public static Uri getThumbnailUri(long partId) {
|
||||
return ContentUris.withAppendedId(THUMB_CONTENT_URI, partId);
|
||||
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 getThumbnailUri(long partId, byte[] contentId) {
|
||||
Uri uri = Uri.withAppendedPath(THUMB_CONTENT_URI, Hex.toStringCondensed(contentId));
|
||||
return ContentUris.withAppendedId(uri, partId);
|
||||
}
|
||||
}
|
||||
|
||||
30
src/org/thoughtcrime/securesms/mms/PartUri.java
Normal file
30
src/org/thoughtcrime/securesms/mms/PartUri.java
Normal file
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user