Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #88 from dluvian/v0.17.1-fixerino
Browse files Browse the repository at this point in the history
V0.17.1 fixerino
  • Loading branch information
dluvian authored Feb 20, 2024
2 parents 76e796b + 2113ed0 commit 9e9458d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
-keep class com.dluvian.nozzle.model.nostr.Event { <fields>; }
-keep class com.dluvian.nozzle.model.nostr.Metadata { <fields>; }
-keep class com.dluvian.nozzle.model.nostr.nip05.Nip05Response { <fields>; }
-keep class com.dluvian.nozzle.model.nostr.nip11.Nip11Document { <fields>; }

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package com.dluvian.nozzle.data.profileFollower
import android.util.Log
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import com.dluvian.nozzle.data.WAIT_TIME
import com.dluvian.nozzle.data.nostr.INostrService
import com.dluvian.nozzle.data.provider.IPubkeyProvider
import com.dluvian.nozzle.data.provider.IRelayProvider
import com.dluvian.nozzle.data.room.dao.ContactDao
import com.dluvian.nozzle.data.room.entity.ContactEntity
import com.dluvian.nozzle.data.utils.getCurrentTimeInSeconds
import com.dluvian.nozzle.model.Pubkey
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.concurrent.CancellationException

Expand All @@ -28,13 +28,8 @@ class ProfileFollower(
) : IProfileFollower {
private val scope = CoroutineScope(Dispatchers.IO)
private val followProcesses: MutableMap<Pubkey, Job> = mutableMapOf()

private val forcedFollowState = mutableStateOf(emptyMap<Pubkey, Boolean>())

val pubkeyState = pubkeyProvider.getActivePubkeyStateFlow()
.onEach local@{ forcedFollowState.value = emptyMap() }
.stateIn(scope, SharingStarted.Eagerly, "")

override fun follow(pubkeyToFollow: Pubkey) {
putForcedFollowState(pubkey = pubkeyToFollow, isFollowed = true)

Expand Down Expand Up @@ -85,10 +80,27 @@ class ProfileFollower(
.apply { this[pubkey] = isFollowed }
}

private suspend fun updateContactList(personalPubkey: String) {
val contactPubkeys = contactDao.listContactPubkeys(pubkey = personalPubkey)
private var updateJob: Job? = null
private suspend fun updateContactList(personalPubkey: Pubkey) {
contactDao.updateTime(pubkey = personalPubkey, createdAt = getCurrentTimeInSeconds())
updateJob?.cancel(CancellationException("Cancel to prevent spamming relay"))
updateJob = scope.launch {
var jobs: List<Job>
do {
delay(WAIT_TIME)
jobs = followProcesses.values.toList()
} while (jobs.any { it.isActive })
updateContactListOverNostr(pubkey = pubkeyProvider.getActivePubkey())
}
updateJob?.invokeOnCompletion {
Log.i(TAG, "Completed contact list update. Error = ${it?.localizedMessage}")
}
}

private suspend fun updateContactListOverNostr(pubkey: Pubkey) {
val event = nostrService.updateContactList(
contactPubkeys = contactPubkeys, relays = relayProvider.getWriteRelays()
contactPubkeys = contactDao.listContactPubkeys(pubkey = pubkey),
relays = relayProvider.getWriteRelays()
)
contactDao.updateTime(pubkey = event.pubkey, createdAt = event.createdAt)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ interface Nip65Dao {
"WHERE isRead = '1' " +
"AND pubkey = :pubkey"
)
suspend fun getReadRelaysOfPubkey(pubkey: String): List<String>
suspend fun getReadRelaysOfPubkey(pubkey: String): List<Relay>

@Query(
"SELECT url " +
"FROM nip65 " +
"WHERE isWrite = '1' " +
"AND pubkey = :pubkey"
)
suspend fun getWriteRelaysOfPubkey(pubkey: String): List<String>
suspend fun getWriteRelaysOfPubkey(pubkey: String): List<Relay>

@Query(
"SELECT url, isRead, isWrite " +
Expand Down

0 comments on commit 9e9458d

Please sign in to comment.