mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-14 11:38:05 +00:00
Merge pull request #1107 from mpretty-cyro/fix/group-avatar-download-job-duplication
Fixed a few issues related to the GroupAvatarDownloadJob
This commit is contained in:
@@ -318,6 +318,25 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
||||
notifyConversationListListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeProfilePicture(String groupID) {
|
||||
databaseHelper.getWritableDatabase()
|
||||
.execSQL("UPDATE " + TABLE_NAME +
|
||||
" SET " + AVATAR + " = NULL, " +
|
||||
AVATAR_ID + " = NULL, " +
|
||||
AVATAR_KEY + " = NULL, " +
|
||||
AVATAR_CONTENT_TYPE + " = NULL, " +
|
||||
AVATAR_RELAY + " = NULL, " +
|
||||
AVATAR_DIGEST + " = NULL, " +
|
||||
AVATAR_URL + " = NULL" +
|
||||
" WHERE " +
|
||||
GROUP_ID + " = ?",
|
||||
new String[] {groupID});
|
||||
|
||||
Recipient.applyCached(Address.fromSerialized(groupID), recipient -> recipient.setGroupAvatarId(null));
|
||||
notifyConversationListListeners();
|
||||
}
|
||||
|
||||
public boolean hasDownloadedProfilePicture(String groupId) {
|
||||
try (Cursor cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, new String[]{AVATAR}, GROUP_ID + " = ?",
|
||||
new String[] {groupId},
|
||||
|
@@ -83,11 +83,11 @@ class SessionJobDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
||||
}
|
||||
}
|
||||
|
||||
fun getGroupAvatarDownloadJob(server: String, room: String): GroupAvatarDownloadJob? {
|
||||
fun getGroupAvatarDownloadJob(server: String, room: String, imageId: String?): GroupAvatarDownloadJob? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.getAll(sessionJobTable, "$jobType = ?", arrayOf(GroupAvatarDownloadJob.KEY)) {
|
||||
jobFromCursor(it) as GroupAvatarDownloadJob?
|
||||
}.filterNotNull().find { it.server == server && it.room == room }
|
||||
}.filterNotNull().find { it.server == server && it.room == room && (imageId == null || it.imageId == imageId) }
|
||||
}
|
||||
|
||||
fun cancelPendingMessageSendJobs(threadID: Long) {
|
||||
|
@@ -226,8 +226,8 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
return DatabaseComponent.get(context).sessionJobDatabase().getMessageReceiveJob(messageReceiveJobID)
|
||||
}
|
||||
|
||||
override fun getGroupAvatarDownloadJob(server: String, room: String): GroupAvatarDownloadJob? {
|
||||
return DatabaseComponent.get(context).sessionJobDatabase().getGroupAvatarDownloadJob(server, room)
|
||||
override fun getGroupAvatarDownloadJob(server: String, room: String, imageId: String?): GroupAvatarDownloadJob? {
|
||||
return DatabaseComponent.get(context).sessionJobDatabase().getGroupAvatarDownloadJob(server, room, imageId)
|
||||
}
|
||||
|
||||
override fun resumeMessageSendJobIfNeeded(messageSendJobID: String) {
|
||||
@@ -324,6 +324,10 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
DatabaseComponent.get(context).groupDatabase().updateProfilePicture(groupID, newValue)
|
||||
}
|
||||
|
||||
override fun removeProfilePicture(groupID: String) {
|
||||
DatabaseComponent.get(context).groupDatabase().removeProfilePicture(groupID)
|
||||
}
|
||||
|
||||
override fun hasDownloadedProfilePicture(groupID: String): Boolean {
|
||||
return DatabaseComponent.get(context).groupDatabase().hasDownloadedProfilePicture(groupID)
|
||||
}
|
||||
|
@@ -51,6 +51,7 @@ public class ThreadRecord extends DisplayRecord {
|
||||
private final long expiresIn;
|
||||
private final long lastSeen;
|
||||
private final boolean pinned;
|
||||
private final int initialRecipientHash;
|
||||
|
||||
public ThreadRecord(@NonNull String body, @Nullable Uri snippetUri,
|
||||
@NonNull Recipient recipient, long date, long count, int unreadCount,
|
||||
@@ -68,6 +69,7 @@ public class ThreadRecord extends DisplayRecord {
|
||||
this.expiresIn = expiresIn;
|
||||
this.lastSeen = lastSeen;
|
||||
this.pinned = pinned;
|
||||
this.initialRecipientHash = recipient.hashCode();
|
||||
}
|
||||
|
||||
public @Nullable Uri getSnippetUri() {
|
||||
@@ -176,4 +178,8 @@ public class ThreadRecord extends DisplayRecord {
|
||||
public boolean isPinned() {
|
||||
return pinned;
|
||||
}
|
||||
|
||||
public int getInitialRecipientHash() {
|
||||
return initialRecipientHash;
|
||||
}
|
||||
}
|
||||
|
@@ -28,8 +28,11 @@ class HomeDiffUtil(
|
||||
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()) }
|
||||
// The recipient is passed as a reference and changes to recipients update the reference so we
|
||||
// need to cache the hashCode for the recipient and use that for diffing - unfortunately
|
||||
// recipient data is also loaded asyncronously which means every thread will refresh at least
|
||||
// once when the initial recipient data is loaded
|
||||
if (isSameItem) { isSameItem = (oldItem.initialRecipientHash == newItem.initialRecipientHash) }
|
||||
|
||||
// Note: Two instances of 'SpannableString' may not equate even though their content matches
|
||||
if (isSameItem) { isSameItem = (oldItem.getDisplayBody(context).toString() == newItem.getDisplayBody(context).toString()) }
|
||||
|
Reference in New Issue
Block a user