If not profile picture only check every 15 minutes

This commit is contained in:
greenart7c3
2024-11-18 10:52:17 -03:00
parent edd424def9
commit 9f053e5171
2 changed files with 15 additions and 1 deletions
@@ -57,6 +57,7 @@ private object PrefKeys {
const val SEED_WORDS2 = "seed_words"
const val PROFILE_URL = "profile_url"
const val LAST_METADATA_UPDATE = "last_metadata_update"
const val LAST_CHECK = "last_check"
}
@Immutable
@@ -122,6 +123,16 @@ object LocalPreferences {
}.apply()
}
fun getLastCheck(context: Context, npub: String): Long {
return encryptedPreferences(context, npub).getLong(PrefKeys.LAST_CHECK, 0)
}
fun setLastCheck(context: Context, npub: String, time: Long) {
encryptedPreferences(context, npub).edit().apply {
putLong(PrefKeys.LAST_CHECK, time)
}.apply()
}
fun getLastMetadataUpdate(context: Context, npub: String): Long {
return encryptedPreferences(context, npub).getLong(PrefKeys.LAST_METADATA_UPDATE, 0)
}
@@ -226,9 +226,12 @@ class NostrSigner : Application() {
}
val lastMetaData = LocalPreferences.getLastMetadataUpdate(this, account.signer.keyPair.pubKey.toNpub())
val lastCheck = LocalPreferences.getLastCheck(this, account.signer.keyPair.pubKey.toNpub())
val oneDayAgo = TimeUtils.oneDayAgo()
if (lastMetaData == 0L || oneDayAgo > lastMetaData) {
val fifteenMinutesAgo = TimeUtils.fifteenMinutesAgo()
if ((lastMetaData == 0L || oneDayAgo > lastMetaData) && (lastCheck == 0L || fifteenMinutesAgo > lastCheck)) {
Log.d("NostrSigner", "Fetching profile data for ${account.signer.keyPair.pubKey.toNpub()}")
LocalPreferences.setLastCheck(this, account.signer.keyPair.pubKey.toNpub(), TimeUtils.now())
val listener = RelayListener(
account = account,
onReceiveEvent = { _, _, event ->