Skip to content

Commit

Permalink
Adjusts Outbox filter as soon as a new NIP-65 relay list shows up
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Aug 15, 2024
1 parent 2f5b99a commit bd18d4b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
47 changes: 21 additions & 26 deletions amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,10 @@ class Account(
val liveKind3Follows = liveKind3FollowsFlow.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(keyPair.pubKeyHex)))

@OptIn(ExperimentalCoroutinesApi::class)
private val liveHomeList: Flow<ListNameNotePair> by lazy {
private val liveHomeList: Flow<ListNameNotePair> =
defaultHomeFollowList.flatMapLatest { listName ->
loadPeopleListFlowFromListName(listName)
}
}

@OptIn(ExperimentalCoroutinesApi::class)
fun loadPeopleListFlowFromListName(listName: String): Flow<ListNameNotePair> =
Expand Down Expand Up @@ -490,7 +489,7 @@ class Account(
}

val liveHomeFollowListFlow: Flow<LiveFollowLists?> by lazy {
combinePeopleListFlows(liveKind3FollowsFlow, liveHomeList)
combinePeopleListFlows(liveKind3Follows, liveHomeList)
}

val liveHomeFollowLists: StateFlow<LiveFollowLists?> by lazy {
Expand Down Expand Up @@ -544,31 +543,27 @@ class Account(
fun authorsPerRelay(
followsNIP65RelayLists: Array<NoteState>,
defaultRelayList: List<String>,
): Map<String, List<HexKey>> {
val test =
assembleAuthorsPerWriteRelay(
followsNIP65RelayLists
.mapNotNull
{
val author = (it.note as? AddressableNote)?.address?.pubKeyHex
val event = (it.note.event as? AdvertisedRelayListEvent)

if (event != null) {
event.pubKey to event.writeRelays()
): Map<String, List<HexKey>> =
assembleAuthorsPerWriteRelay(
followsNIP65RelayLists
.mapNotNull
{
val author = (it.note as? AddressableNote)?.address?.pubKeyHex
val event = (it.note.event as? AdvertisedRelayListEvent)

if (event != null) {
event.pubKey to event.writeRelays()
} else {
if (author != null) {
author to defaultRelayList
} else {
if (author != null) {
author to defaultRelayList
} else {
Log.e("Account", "This author should NEVER be null. Note: ${it.note.idHex}")
null
}
Log.e("Account", "This author should NEVER be null. Note: ${it.note.idHex}")
null
}
}.toMap(),
hasOnionConnection = proxy != null,
)

return test
}
}
}.toMap(),
hasOnionConnection = proxy != null,
)

@OptIn(ExperimentalCoroutinesApi::class)
val liveHomeFollowListAdvertizedRelayListFlow: Flow<Array<NoteState>?> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ object NostrHomeDataSource : AmethystNostrDataSource("HomeFeed") {
val latestEOSEs = EOSEAccount()

var job: Job? = null
var job2: Job? = null

override fun start() {
job?.cancel()
Expand All @@ -68,12 +69,25 @@ object NostrHomeDataSource : AmethystNostrDataSource("HomeFeed") {
}
}
}

job2?.cancel()
job2 =
scope.launch(Dispatchers.IO) {
// creates cache on main
withContext(Dispatchers.Main) { account.userProfile().live() }
account.liveHomeListAuthorsPerRelay.collect {
if (this@NostrHomeDataSource::account.isInitialized) {
invalidateFilters()
}
}
}
super.start()
}

override fun stop() {
super.stop()
job?.cancel()
job2?.cancel()
}

fun createFollowAccountsFilter(): TypedFilter {
Expand Down

0 comments on commit bd18d4b

Please sign in to comment.