From fa71ea1850e0d3444eac4176df2ac82002b53f96 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 9 May 2023 14:14:49 +1000 Subject: [PATCH] make RetrieveProfileAvatarJob work --- .../main/java/org/thoughtcrime/securesms/database/Storage.kt | 5 +++++ .../thoughtcrime/securesms/sskenvironment/ProfileManager.kt | 1 - .../java/org/session/libsession/database/StorageProtocol.kt | 2 +- .../java/org/session/libsession/messaging/jobs/JobQueue.kt | 2 ++ .../libsession/messaging/jobs/RetrieveProfileAvatarJob.kt | 2 -- 5 files changed, 8 insertions(+), 4 deletions(-) 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 3e21f63c09..54d36af896 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -77,6 +77,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, JobQueue.shared.add(RetrieveProfileAvatarJob(newValue, ourRecipient.address)) } + override fun setProfileAvatar(recipient: Recipient, profileAvatar: String) { + val database = DatabaseComponent.get(context).recipientDatabase() + database.setProfileAvatar(recipient, profileAvatar) + } + override fun getOrGenerateRegistrationID(): Int { var registrationID = TextSecurePreferences.getLocalRegistrationId(context) if (registrationID == 0) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt b/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt index 08ca6090bf..f9f5524efa 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ProfileManager.kt @@ -41,7 +41,6 @@ class ProfileManager : SSKEnvironment.ProfileManagerProtocol { override fun setProfilePictureURL(context: Context, recipient: Recipient, profilePictureURL: String) { val job = RetrieveProfileAvatarJob(profilePictureURL, recipient.address) - job.context = context JobQueue.shared.add(job) val sessionID = recipient.address.serialize() val contactDatabase = DatabaseComponent.get(context).sessionContactDatabase() 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 8ae9442748..0727d1ab56 100644 --- a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt @@ -38,7 +38,7 @@ interface StorageProtocol { fun getUserX25519KeyPair(): ECKeyPair fun getUserProfile(): Profile fun setUserProfilePictureURL(newProfilePicture: String) - fun + fun setProfileAvatar(recipient: Recipient, profileAvatar: String) // Signal fun getOrGenerateRegistrationID(): Int diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/JobQueue.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/JobQueue.kt index b78590c729..03b9546c4c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/JobQueue.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/JobQueue.kt @@ -125,6 +125,7 @@ class JobQueue : JobDelegate { is NotifyPNServerJob, is AttachmentUploadJob, is MessageSendJob -> { txQueue.send(job) } + is RetrieveProfileAvatarJob, is AttachmentDownloadJob -> { mediaQueue.send(job) } @@ -224,6 +225,7 @@ class JobQueue : JobDelegate { GroupAvatarDownloadJob.KEY, BackgroundGroupAddJob.KEY, OpenGroupDeleteJob.KEY, + RetrieveProfileAvatarJob.KEY, ) allJobTypes.forEach { type -> resumePendingJobs(type) diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/RetrieveProfileAvatarJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/RetrieveProfileAvatarJob.kt index f00ba49a5f..8ce397a3a9 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/RetrieveProfileAvatarJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/RetrieveProfileAvatarJob.kt @@ -1,6 +1,5 @@ package org.session.libsession.messaging.jobs -import android.content.Context import android.text.TextUtils import org.session.libsession.avatars.AvatarHelper import org.session.libsession.messaging.MessagingModuleConfiguration @@ -13,7 +12,6 @@ import org.session.libsession.utilities.Address import org.session.libsession.utilities.recipients.Recipient import org.session.libsignal.streams.ProfileCipherInputStream import org.session.libsignal.utilities.Log -import org.thoughtcrime.securesms.dependencies.DatabaseComponent.Companion.get import java.io.File import java.io.FileInputStream import java.io.FileOutputStream