mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
If not profile picture only check every 15 minutes
This commit is contained in:
@@ -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 ->
|
||||
|
||||
Reference in New Issue
Block a user