Fixed a few issues with the GroupAvatarDownloadJob

Added a method to remove the Group avatar
Fixed an issue where the recipient diffing on the HomeActivity wasn't working properly
Fixed an issue where the GroupAvatarDownloadJob could be scheduled even when there was already one scheduled
This commit is contained in:
Morgan Pretty
2023-02-10 10:05:28 +11:00
parent cd3b8f3571
commit 9fd68d27f8
9 changed files with 47 additions and 5 deletions

View File

@@ -80,6 +80,7 @@ interface StorageProtocol {
// Open Group Metadata
fun updateTitle(groupID: String, newValue: String)
fun updateProfilePicture(groupID: String, newValue: ByteArray)
fun removeProfilePicture(groupID: String)
fun hasDownloadedProfilePicture(groupID: String): Boolean
fun setUserCount(room: String, server: String, newValue: Int)

View File

@@ -68,8 +68,8 @@ class GroupAvatarDownloadJob(val server: String, val room: String, val imageId:
override fun create(data: Data): GroupAvatarDownloadJob {
return GroupAvatarDownloadJob(
data.getString(ROOM),
data.getString(SERVER),
data.getString(ROOM),
if (data.hasString(IMAGE_ID)) { data.getString(IMAGE_ID) } else { null }
)
}

View File

@@ -36,7 +36,7 @@ data class OpenGroup(
val server = json.get("server").asText().lowercase(Locale.US)
val displayName = json.get("displayName").asText()
val publicKey = json.get("publicKey").asText()
val imageId = json.get("imageId")?.asText()
val imageId = if (json.hasNonNull("imageId")) { json.get("imageId")?.asText() } else { null }
val canWrite = json.get("canWrite")?.asText()?.toBoolean() ?: true
val infoUpdates = json.get("infoUpdates")?.asText()?.toIntOrNull() ?: 0
OpenGroup(server = server, room = room, name = displayName, publicKey = publicKey, imageId = imageId, canWrite = canWrite, infoUpdates = infoUpdates)

View File

@@ -159,6 +159,7 @@ class OpenGroupPoller(private val server: String, private val executorService: S
})
}
// Update the group avatar
if (
(
pollInfo.details != null &&
@@ -174,7 +175,14 @@ class OpenGroupPoller(private val server: String, private val executorService: S
storage.getGroupAvatarDownloadJob(openGroup.server, openGroup.room, existingOpenGroup.imageId) == null
)
) {
JobQueue.shared.add(GroupAvatarDownloadJob(roomToken, server, existingOpenGroup.imageId))
JobQueue.shared.add(GroupAvatarDownloadJob(server, roomToken, existingOpenGroup.imageId))
}
else if (
pollInfo.details != null &&
pollInfo.details.imageId == null &&
existingOpenGroup.imageId != null
) {
storage.removeProfilePicture(dbGroupId)
}
}