mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Reduce profile avatar disk reads.
This commit is contained in:
@@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.crypto.AttachmentSecret;
|
||||
import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider;
|
||||
import org.thoughtcrime.securesms.crypto.ModernDecryptingPartInputStream;
|
||||
import org.thoughtcrime.securesms.crypto.ModernEncryptingPartOutputStream;
|
||||
import org.thoughtcrime.securesms.database.model.ProfileAvatarFileDetails;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
@@ -103,6 +104,14 @@ public class AvatarHelper {
|
||||
return avatarFile.exists() && avatarFile.length() > 0;
|
||||
}
|
||||
|
||||
public static @NonNull ProfileAvatarFileDetails getAvatarFileDetails(@NonNull Context context, @NonNull RecipientId recipientId) {
|
||||
File avatarFile = getAvatarFile(context, recipientId);
|
||||
if (avatarFile.exists() && avatarFile.length() > 0) {
|
||||
return new ProfileAvatarFileDetails(avatarFile.hashCode(), avatarFile.lastModified());
|
||||
}
|
||||
return ProfileAvatarFileDetails.NO_DETAILS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a stream for an avatar. If there is no avatar, the stream will likely throw an
|
||||
* IOException. It is recommended to call {@link #hasAvatar(Context, RecipientId)} first.
|
||||
@@ -174,19 +183,6 @@ public class AvatarHelper {
|
||||
return ModernEncryptingPartOutputStream.createFor(attachmentSecret, targetFile, true).second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp of when the avatar was last modified, or zero if the avatar doesn't exist.
|
||||
*/
|
||||
public static long getLastModified(@NonNull Context context, @NonNull RecipientId recipientId) {
|
||||
File file = getAvatarFile(context, recipientId);
|
||||
|
||||
if (file.exists()) {
|
||||
return file.lastModified();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link StreamDetails} for the local user's own avatar, or null if one does not exist.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user