mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Fixed a couple of bugs where the HomeDiffUtil could incorrectly detect differences
This commit is contained in:
parent
d68d26cd5d
commit
c0bef51fe0
@ -50,7 +50,6 @@ public class ThreadRecord extends DisplayRecord {
|
|||||||
private final long expiresIn;
|
private final long expiresIn;
|
||||||
private final long lastSeen;
|
private final long lastSeen;
|
||||||
private final boolean pinned;
|
private final boolean pinned;
|
||||||
private final int recipientHash;
|
|
||||||
|
|
||||||
public ThreadRecord(@NonNull String body, @Nullable Uri snippetUri,
|
public ThreadRecord(@NonNull String body, @Nullable Uri snippetUri,
|
||||||
@NonNull Recipient recipient, long date, long count, int unreadCount,
|
@NonNull Recipient recipient, long date, long count, int unreadCount,
|
||||||
@ -67,17 +66,12 @@ public class ThreadRecord extends DisplayRecord {
|
|||||||
this.expiresIn = expiresIn;
|
this.expiresIn = expiresIn;
|
||||||
this.lastSeen = lastSeen;
|
this.lastSeen = lastSeen;
|
||||||
this.pinned = pinned;
|
this.pinned = pinned;
|
||||||
this.recipientHash = recipient.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Uri getSnippetUri() {
|
public @Nullable Uri getSnippetUri() {
|
||||||
return snippetUri;
|
return snippetUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRecipientHash() {
|
|
||||||
return recipientHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpannableString getDisplayBody(@NonNull Context context) {
|
public SpannableString getDisplayBody(@NonNull Context context) {
|
||||||
if (isGroupUpdateMessage()) {
|
if (isGroupUpdateMessage()) {
|
||||||
|
@ -22,22 +22,28 @@ class HomeDiffUtil(
|
|||||||
val newItem = new[newItemPosition]
|
val newItem = new[newItemPosition]
|
||||||
|
|
||||||
// return early to save getDisplayBody or expensive calls
|
// return early to save getDisplayBody or expensive calls
|
||||||
val sameCount = oldItem.count == newItem.count
|
var isSameItem = true
|
||||||
if (!sameCount) return false
|
|
||||||
val sameUnreads = oldItem.unreadCount == newItem.unreadCount
|
|
||||||
if (!sameUnreads) return false
|
|
||||||
val samePinned = oldItem.isPinned == newItem.isPinned
|
|
||||||
if (!samePinned) return false
|
|
||||||
val sameRecipientHash = oldItem.recipientHash == newItem.recipientHash
|
|
||||||
if (!sameRecipientHash) return false
|
|
||||||
val sameSnippet = oldItem.getDisplayBody(context) == newItem.getDisplayBody(context)
|
|
||||||
if (!sameSnippet) return false
|
|
||||||
val sameSendStatus = oldItem.isFailed == newItem.isFailed && oldItem.isDelivered == newItem.isDelivered
|
|
||||||
&& oldItem.isSent == newItem.isSent && oldItem.isPending == newItem.isPending
|
|
||||||
if (!sameSendStatus) return false
|
|
||||||
|
|
||||||
// all same
|
if (isSameItem) { isSameItem = (oldItem.count == newItem.count) }
|
||||||
return true
|
if (isSameItem) { isSameItem = (oldItem.unreadCount == newItem.unreadCount) }
|
||||||
|
if (isSameItem) { isSameItem = (oldItem.isPinned == newItem.isPinned) }
|
||||||
|
|
||||||
|
// Note: For some reason the 'hashCode' value can change after initialisation so we can't cache it
|
||||||
|
if (isSameItem) { isSameItem = (oldItem.recipient.hashCode() == newItem.recipient.hashCode()) }
|
||||||
|
|
||||||
|
// Note: Two instances of 'SpannableString' may not equate even though their content matches
|
||||||
|
if (isSameItem) { isSameItem = (oldItem.getDisplayBody(context).toString() == newItem.getDisplayBody(context).toString()) }
|
||||||
|
|
||||||
|
if (isSameItem) {
|
||||||
|
isSameItem = (
|
||||||
|
oldItem.isFailed == newItem.isFailed &&
|
||||||
|
oldItem.isDelivered == newItem.isDelivered &&
|
||||||
|
oldItem.isSent == newItem.isSent &&
|
||||||
|
oldItem.isPending == newItem.isPending
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return isSameItem
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user