diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java
index 3e23f524f3..584bf3a71a 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java
@@ -318,6 +318,19 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
notifyConversationListListeners();
}
+ public boolean hasDownloadedProfilePicture(String groupId) {
+ try (Cursor cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, new String[]{AVATAR}, GROUP_ID + " = ?",
+ new String[] {groupId},
+ null, null, null))
+ {
+ if (cursor != null && cursor.moveToNext()) {
+ return !cursor.isNull(0);
+ }
+
+ return false;
+ }
+ }
+
public void updateMembers(String groupId, List
members) {
Collections.sort(members);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
index 7daae9ef0c..cc31e71ecf 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
@@ -321,6 +321,10 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
DatabaseComponent.get(context).groupDatabase().updateProfilePicture(groupID, newValue)
}
+ override fun hasDownloadedProfilePicture(groupID: String): Boolean {
+ return DatabaseComponent.get(context).groupDatabase().hasDownloadedProfilePicture(groupID)
+ }
+
override fun getReceivedMessageTimestamps(): Set {
return SessionMetaProtocol.getTimestamps()
}
diff --git a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt
index edca7cd15e..660b919c35 100644
--- a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt
+++ b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt
@@ -81,6 +81,7 @@ interface StorageProtocol {
// Open Group Metadata
fun updateTitle(groupID: String, newValue: String)
fun updateProfilePicture(groupID: String, newValue: ByteArray)
+ fun hasDownloadedProfilePicture(groupID: String): Boolean
fun setUserCount(room: String, server: String, newValue: Int)
// Last Message Server ID
diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt
index 595f7d4dc1..3f4cbc3126 100644
--- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt
+++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt
@@ -117,6 +117,7 @@ class OpenGroupPoller(private val server: String, private val executorService: S
) {
val storage = MessagingModuleConfiguration.shared.storage
val groupId = "$server.$roomToken"
+ val dbGroupId = GroupUtil.getEncodedOpenGroupID(groupId.toByteArray())
val existingOpenGroup = storage.getOpenGroup(roomToken, server)
val publicKey = existingOpenGroup?.publicKey ?: return
@@ -157,8 +158,19 @@ class OpenGroupPoller(private val server: String, private val executorService: S
})
}
- // Start downloading the room image (if we don't have one or it's been updated)
- if (pollInfo.details?.imageId != null && pollInfo.details.imageId != existingOpenGroup.imageId) {
+ if (
+ (
+ pollInfo.details != null &&
+ pollInfo.details.imageId != null && (
+ pollInfo.details.imageId != existingOpenGroup.imageId ||
+ !storage.hasDownloadedProfilePicture(dbGroupId)
+ )
+ ) || (
+ pollInfo.details == null &&
+ existingOpenGroup.imageId != null &&
+ !storage.hasDownloadedProfilePicture(dbGroupId)
+ )
+ ) {
JobQueue.shared.add(GroupAvatarDownloadJob(roomToken, server))
}
}