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

V0.17.1 fixerino #88

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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