mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-27 12:15:50 +01:00
Remove TextSecurePreferences.getAvatarId()
This commit is contained in:
@@ -6,32 +6,37 @@ import android.net.Uri;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ProfileContactPhoto implements ContactPhoto {
|
||||
|
||||
private final @NonNull RecipientId recipient;
|
||||
private final @NonNull String avatarObject;
|
||||
private final @NonNull Recipient recipient;
|
||||
private final @NonNull String avatarObject;
|
||||
|
||||
public ProfileContactPhoto(@NonNull RecipientId recipient, @NonNull String avatarObject) {
|
||||
public ProfileContactPhoto(@NonNull Recipient recipient, @Nullable String avatarObject) {
|
||||
this.recipient = recipient;
|
||||
this.avatarObject = avatarObject;
|
||||
this.avatarObject = avatarObject == null ? "" : avatarObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull InputStream openInputStream(Context context) throws IOException {
|
||||
return AvatarHelper.getInputStreamFor(context, recipient);
|
||||
return AvatarHelper.getInputStreamFor(context, recipient.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Uri getUri(@NonNull Context context) {
|
||||
File avatarFile = AvatarHelper.getAvatarFile(context, recipient);
|
||||
File avatarFile = AvatarHelper.getAvatarFile(context, recipient.getId());
|
||||
return avatarFile.exists() ? Uri.fromFile(avatarFile) : null;
|
||||
}
|
||||
|
||||
@@ -42,21 +47,37 @@ public class ProfileContactPhoto implements ContactPhoto {
|
||||
|
||||
@Override
|
||||
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
||||
messageDigest.update(recipient.serialize().getBytes());
|
||||
messageDigest.update(recipient.getId().serialize().getBytes());
|
||||
messageDigest.update(avatarObject.getBytes());
|
||||
messageDigest.update(ByteUtil.longToByteArray(getFileLastModified()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof ProfileContactPhoto)) return false;
|
||||
|
||||
ProfileContactPhoto that = (ProfileContactPhoto)other;
|
||||
|
||||
return this.recipient.equals(that.recipient) && this.avatarObject.equals(that.avatarObject);
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ProfileContactPhoto that = (ProfileContactPhoto) o;
|
||||
return recipient.equals(that.recipient) &&
|
||||
avatarObject.equals(that.avatarObject) &&
|
||||
getFileLastModified() == that.getFileLastModified();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return recipient.hashCode() ^ avatarObject.hashCode();
|
||||
return Objects.hash(recipient, avatarObject, getFileLastModified());
|
||||
}
|
||||
|
||||
private long getFileLastModified() {
|
||||
if (!recipient.isLocalNumber()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
File avatarFile = AvatarHelper.getAvatarFile(ApplicationDependencies.getApplication(), recipient.getId());
|
||||
|
||||
if (avatarFile.exists()) {
|
||||
return avatarFile.lastModified();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user