Fixed an edge case where an OpenGroup might not download it's image

This commit is contained in:
Morgan Pretty
2023-01-20 17:42:46 +11:00
parent 0ed5c5825d
commit 8a4a9623cc
4 changed files with 32 additions and 2 deletions

View File

@@ -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

View File

@@ -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))
}
}