Reformats due to new lint

This commit is contained in:
Vitor Pamplona
2025-07-02 10:51:13 -04:00
parent 774ee20a20
commit 546d238db3
146 changed files with 1151 additions and 1054 deletions
@@ -463,7 +463,18 @@ class Account(
if (!isWriteable()) return
userMetadata.sendNewUserMetadata(
name, picture, banner, website, pronouns, about, nip05, lnAddress, lnURL, twitter, mastodon, github,
name,
picture,
banner,
website,
pronouns,
about,
nip05,
lnAddress,
lnURL,
twitter,
mastodon,
github,
::sendMyPublicAndPrivateOutbox,
)
}
@@ -582,11 +593,13 @@ class Account(
relay = nip47.relayUri,
)
Amethyst.instance.sources.nwc.subscribe(filter)
Amethyst.instance.sources.nwc
.subscribe(filter)
GlobalScope.launch(Dispatchers.IO) {
delay(60000) // waits 1 minute to complete payment.
Amethyst.instance.sources.nwc.unsubscribe(filter)
Amethyst.instance.sources.nwc
.unsubscribe(filter)
}
cache.consume(event, zappedNote, true, nip47.relayUri) {
@@ -723,7 +736,11 @@ class Account(
if (pubkey == userProfile().pubkeyHex) {
notificationRelays.flow.value
} else {
LocalCache.getUserIfExists(pubkey)?.inboxRelays()?.ifEmpty { null }?.toSet()
LocalCache
.getUserIfExists(pubkey)
?.inboxRelays()
?.ifEmpty { null }
?.toSet()
?: cache.relayHints.hintsForKey(pubkey).toSet()
}
}
@@ -749,7 +766,10 @@ class Account(
outboxRelays.flow.value
} else {
replyToAuthor.outboxRelays().ifEmpty { null }?.toSet()
?: cache.relayHints.hintsForKey(replyToAuthor.pubkeyHex).ifEmpty { null }?.toSet()
?: cache.relayHints
.hintsForKey(replyToAuthor.pubkeyHex)
.ifEmpty { null }
?.toSet()
?: emptySet()
}
} else {
@@ -776,11 +796,17 @@ class Account(
outboxRelays.flow.value
} else {
author.outboxRelays().ifEmpty { null }?.toSet()
?: cache.relayHints.hintsForKey(author.pubkeyHex).ifEmpty { null }?.toSet()
?: cache.relayHints
.hintsForKey(author.pubkeyHex)
.ifEmpty { null }
?.toSet()
?: emptySet()
}
} else {
cache.relayHints.hintsForKey(event.pubKey).ifEmpty { null }?.toSet()
cache.relayHints
.hintsForKey(event.pubKey)
.ifEmpty { null }
?.toSet()
emptySet()
}
@@ -789,7 +815,11 @@ class Account(
if (pubkey == userProfile().pubkeyHex) {
notificationRelays.flow.value
} else {
LocalCache.getUserIfExists(pubkey)?.inboxRelays()?.ifEmpty { null }?.toSet()
LocalCache
.getUserIfExists(pubkey)
?.inboxRelays()
?.ifEmpty { null }
?.toSet()
?: cache.relayHints.hintsForKey(pubkey).toSet()
}
}
@@ -832,7 +862,10 @@ class Account(
outboxRelays.flow.value
} else {
replyToAuthor.outboxRelays().ifEmpty { null }?.toSet()
?: cache.relayHints.hintsForKey(replyToAuthor.pubkeyHex).ifEmpty { null }?.toSet()
?: cache.relayHints
.hintsForKey(replyToAuthor.pubkeyHex)
.ifEmpty { null }
?.toSet()
?: emptySet()
}
} else {
@@ -854,7 +887,10 @@ class Account(
outboxRelays.flow.value
} else {
author.outboxRelays().ifEmpty { null }?.toSet()
?: cache.relayHints.hintsForKey(author.pubkeyHex).ifEmpty { null }?.toSet()
?: cache.relayHints
.hintsForKey(author.pubkeyHex)
.ifEmpty { null }
?.toSet()
?: emptySet()
}
} else {
@@ -866,7 +902,11 @@ class Account(
if (pubkey == userProfile().pubkeyHex) {
notificationRelays.flow.value
} else {
LocalCache.getUserIfExists(pubkey)?.inboxRelays()?.ifEmpty { null }?.toSet()
LocalCache
.getUserIfExists(pubkey)
?.inboxRelays()
?.ifEmpty { null }
?.toSet()
?: cache.relayHints.hintsForKey(pubkey).toSet()
}
} ?: emptySet()
@@ -892,7 +932,10 @@ class Account(
outboxRelays.flow.value
} else {
replyToAuthor.outboxRelays().ifEmpty { null }?.toSet()
?: cache.relayHints.hintsForKey(replyToAuthor.pubkeyHex).ifEmpty { null }?.toSet()
?: cache.relayHints
.hintsForKey(replyToAuthor.pubkeyHex)
.ifEmpty { null }
?.toSet()
?: emptySet()
}
} else {
@@ -1675,7 +1718,11 @@ class Account(
if (pubkey == userProfile().pubkeyHex) {
notificationRelays.flow.value
} else {
LocalCache.getUserIfExists(pubkey)?.inboxRelays()?.ifEmpty { null }?.toSet()
LocalCache
.getUserIfExists(pubkey)
?.inboxRelays()
?.ifEmpty { null }
?.toSet()
?: cache.relayHints.hintsForKey(pubkey).toSet()
}
}
@@ -1888,9 +1935,11 @@ class Account(
val relays = nip65RelayList.inboxFlow.value.toSet()
NIP90ContentDiscoveryRequestEvent.create(dvmPublicKey.pubkeyHex, signer.pubKey, relays, signer) {
val relayList =
dvmPublicKey.inboxRelays().ifEmpty {
LocalCache.relayHints.hintsForKey(dvmPublicKey.pubkeyHex)
}.toSet()
dvmPublicKey
.inboxRelays()
.ifEmpty {
LocalCache.relayHints.hintsForKey(dvmPublicKey.pubkeyHex)
}.toSet()
client.send(it, relayList)
cache.justConsumeMyOwnEvent(it)
@@ -250,14 +250,13 @@ class AccountSettings(
// ---
// proxy settings
// ---
fun setTorSettings(newTorSettings: TorSettings): Boolean {
return if (torSettings.update(newTorSettings)) {
fun setTorSettings(newTorSettings: TorSettings): Boolean =
if (torSettings.update(newTorSettings)) {
saveAccountSettings()
true
} else {
false
}
}
// ---
// language services
@@ -114,9 +114,7 @@ class AccountSyncedSettings(
}
}
fun dontTranslateFromFilteredBySpokenLanguages(): Set<String> {
return languages.dontTranslateFrom - getLanguagesSpokenByUser()
}
fun dontTranslateFromFilteredBySpokenLanguages(): Set<String> = languages.dontTranslateFrom - getLanguagesSpokenByUser()
}
@Stable
@@ -59,19 +59,17 @@ class EphemeralChatListState(
fun getEphemeralChatList(): EphemeralChatListEvent? = getEphemeralChatListNote().event as? EphemeralChatListEvent
suspend fun ephemeralChatListWithBackup(note: Note): Set<RoomId> {
return ephemeralChatList(
suspend fun ephemeralChatListWithBackup(note: Note): Set<RoomId> =
ephemeralChatList(
note.event as? EphemeralChatListEvent ?: settings.backupEphemeralChatList,
)
}
suspend fun ephemeralChatList(event: EphemeralChatListEvent?): Set<RoomId> {
return tryAndWait { continuation ->
suspend fun ephemeralChatList(event: EphemeralChatListEvent?): Set<RoomId> =
tryAndWait { continuation ->
event?.publicAndPrivateRoomIds(signer) {
continuation.resume(it)
}
} ?: emptySet()
}
@OptIn(ExperimentalCoroutinesApi::class)
val liveEphemeralChatList: StateFlow<Set<RoomId>> by lazy {
@@ -38,9 +38,7 @@ class LocalRelayListState(
val scope: CoroutineScope,
val settings: AccountSettings,
) {
fun normalizeLocalRelayListWithBackup(relayList: Set<String>): Set<NormalizedRelayUrl> {
return relayList.mapNotNull { RelayUrlNormalizer.normalizeOrNull(it) }.toSet()
}
fun normalizeLocalRelayListWithBackup(relayList: Set<String>): Set<NormalizedRelayUrl> = relayList.mapNotNull { RelayUrlNormalizer.normalizeOrNull(it) }.toSet()
val flow =
settings.localRelayServers
@@ -68,15 +68,18 @@ class FollowListOutboxRelays(
@OptIn(ExperimentalCoroutinesApi::class)
val flow: StateFlow<Set<NormalizedRelayUrl>> =
kind3Follows.flow.transformLatest { followList ->
val flows: List<StateFlow<NoteState>> = allRelayListFlows(followList.authors)
val relayListFlows = combineAllFlows(flows)
emitAll(relayListFlows)
}.onStart {
kind3Follows.flow.value.authors.mapNotNull {
getNIP65RelayList(it)?.writeRelaysNorm()
}.flatten().toSet()
}.flowOn(Dispatchers.Default)
kind3Follows.flow
.transformLatest { followList ->
val flows: List<StateFlow<NoteState>> = allRelayListFlows(followList.authors)
val relayListFlows = combineAllFlows(flows)
emitAll(relayListFlows)
}.onStart {
kind3Follows.flow.value.authors
.mapNotNull {
getNIP65RelayList(it)?.writeRelaysNorm()
}.flatten()
.toSet()
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -85,13 +88,16 @@ class FollowListOutboxRelays(
@OptIn(ExperimentalCoroutinesApi::class)
val flowSet: StateFlow<Set<String>> =
flow.map { relayList ->
relayList.map { it.url }.toSet()
}.onStart {
kind3Follows.flow.value.authors.mapNotNull {
getNIP65RelayList(it)?.writeRelaysNorm()?.map { it.url }?.toSet()
}.flatten().toSet()
}.flowOn(Dispatchers.Default)
flow
.map { relayList ->
relayList.map { it.url }.toSet()
}.onStart {
kind3Follows.flow.value.authors
.mapNotNull {
getNIP65RelayList(it)?.writeRelaysNorm()?.map { it.url }?.toSet()
}.flatten()
.toSet()
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -71,21 +71,22 @@ class FollowsPerOutboxRelay(
@OptIn(ExperimentalCoroutinesApi::class)
val flow: StateFlow<Map<NormalizedRelayUrl, Set<HexKey>>> =
kind3Follows.flow.transformLatest { followList ->
val flows: List<StateFlow<NoteState>> = allRelayListFlows(followList.authors)
val relayListFlows = combineAllFlows(flows)
emitAll(relayListFlows)
}.onStart {
emit(
mapOfSet {
kind3Follows.flow.value.authors.map { authorHex ->
getNIP65RelayList(authorHex)?.writeRelaysNorm()?.forEach { relay ->
add(relay, authorHex)
kind3Follows.flow
.transformLatest { followList ->
val flows: List<StateFlow<NoteState>> = allRelayListFlows(followList.authors)
val relayListFlows = combineAllFlows(flows)
emitAll(relayListFlows)
}.onStart {
emit(
mapOfSet {
kind3Follows.flow.value.authors.map { authorHex ->
getNIP65RelayList(authorHex)?.writeRelaysNorm()?.forEach { relay ->
add(relay, authorHex)
}
}
}
},
)
}.flowOn(Dispatchers.Default)
},
)
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -61,19 +61,17 @@ class PublicChatListState(
fun getChannelList(): ChannelListEvent? = getChannelListNote().event as? ChannelListEvent
suspend fun publicChatListWithBackup(note: Note): Set<EventIdHint> {
return publicChatList(
suspend fun publicChatListWithBackup(note: Note): Set<EventIdHint> =
publicChatList(
note.event as? ChannelListEvent ?: settings.backupChannelList,
)
}
suspend fun publicChatList(event: ChannelListEvent?): Set<EventIdHint> {
return tryAndWait { continuation ->
suspend fun publicChatList(event: ChannelListEvent?): Set<EventIdHint> =
tryAndWait { continuation ->
event?.publicAndPrivateChannels(signer) {
continuation.resume(it)
}
} ?: emptySet()
}
@OptIn(ExperimentalCoroutinesApi::class)
val flow: StateFlow<Set<EventIdHint>> by lazy {
@@ -49,19 +49,17 @@ class BlockPeopleListState(
fun getBlockList(): PeopleListEvent? = getBlockListNote().event as? PeopleListEvent
suspend fun blockListWithBackup(note: Note): PeopleListEvent.UsersAndWords {
return blockList(
suspend fun blockListWithBackup(note: Note): PeopleListEvent.UsersAndWords =
blockList(
note.event as? PeopleListEvent,
)
}
suspend fun blockList(event: PeopleListEvent?): PeopleListEvent.UsersAndWords {
return tryAndWait { continuation ->
suspend fun blockList(event: PeopleListEvent?): PeopleListEvent.UsersAndWords =
tryAndWait { continuation ->
event?.publicAndPrivateUsersAndWords(signer) {
continuation.resume(it)
}
} ?: PeopleListEvent.UsersAndWords()
}
val flow =
getBlockListFlow()
@@ -57,19 +57,17 @@ class GeohashListState(
fun getGeohashList(): GeohashListEvent? = getGeohashListNote().event as? GeohashListEvent
suspend fun geohashListWithBackup(note: Note): Set<String> {
return geohashList(
suspend fun geohashListWithBackup(note: Note): Set<String> =
geohashList(
note.event as? GeohashListEvent ?: settings.backupGeohashList,
)
}
suspend fun geohashList(event: GeohashListEvent?): Set<String> {
return tryAndWait { continuation ->
suspend fun geohashList(event: GeohashListEvent?): Set<String> =
tryAndWait { continuation ->
event?.publicAndPrivateGeohash(signer) {
continuation.resume(it)
}
} ?: emptySet()
}
@OptIn(ExperimentalCoroutinesApi::class)
val flow: StateFlow<Set<String>> by lazy {
@@ -57,19 +57,17 @@ class HashtagListState(
fun getHashtagList(): HashtagListEvent? = getHashtagListNote().event as? HashtagListEvent
suspend fun hashtagListWithBackup(note: Note): Set<String> {
return hashtagList(
suspend fun hashtagListWithBackup(note: Note): Set<String> =
hashtagList(
note.event as? HashtagListEvent ?: settings.backupHashtagList,
)
}
suspend fun hashtagList(event: HashtagListEvent?): Set<String> {
return tryAndWait { continuation ->
suspend fun hashtagList(event: HashtagListEvent?): Set<String> =
tryAndWait { continuation ->
event?.publicAndPrivateHashtag(signer) {
continuation.resume(it)
}
} ?: emptySet()
}
@OptIn(ExperimentalCoroutinesApi::class)
val flow: StateFlow<Set<String>> by lazy {
@@ -65,14 +65,13 @@ class HiddenUsersState(
muteList: PeopleListEvent.UsersAndWords,
transientHiddenUsers: Set<String>,
showSensitiveContent: Boolean?,
): LiveHiddenUsers {
return LiveHiddenUsers(
): LiveHiddenUsers =
LiveHiddenUsers(
hiddenUsers = blockList.users + muteList.users,
hiddenWords = blockList.words + muteList.words,
spammers = transientHiddenUsers,
showSensitiveContent = showSensitiveContent,
)
}
val flow: StateFlow<LiveHiddenUsers> by lazy {
combineTransform(
@@ -56,19 +56,17 @@ class MuteListState(
fun getMuteList(): MuteListEvent? = getMuteListNote().event as? MuteListEvent
suspend fun muteListWithBackup(note: Note): PeopleListEvent.UsersAndWords {
return muteList(
suspend fun muteListWithBackup(note: Note): PeopleListEvent.UsersAndWords =
muteList(
note.event as? MuteListEvent ?: settings.backupMuteList,
)
}
suspend fun muteList(event: MuteListEvent?): PeopleListEvent.UsersAndWords {
return tryAndWait { continuation ->
suspend fun muteList(event: MuteListEvent?): PeopleListEvent.UsersAndWords =
tryAndWait { continuation ->
event?.publicAndPrivateUsersAndWords(signer) {
continuation.resume(it)
}
} ?: PeopleListEvent.UsersAndWords()
}
val flow =
getMuteListFlow()
@@ -67,17 +67,20 @@ class OutboxRelaySetState(
@OptIn(ExperimentalCoroutinesApi::class)
val flow: StateFlow<Set<NormalizedRelayUrl>> =
usersToLoad.transformLatest { followList ->
val flows: List<StateFlow<NoteState>> = allRelayListFlows(followList)
val relayListFlows = combineAllFlows(flows)
emitAll(relayListFlows)
}.onStart {
emit(
usersToLoad.value.mapNotNull {
getNIP65RelayList(it)?.writeRelaysNorm()
}.flatten().toSet(),
)
}.flowOn(Dispatchers.Default)
usersToLoad
.transformLatest { followList ->
val flows: List<StateFlow<NoteState>> = allRelayListFlows(followList)
val relayListFlows = combineAllFlows(flows)
emitAll(relayListFlows)
}.onStart {
emit(
usersToLoad.value
.mapNotNull {
getNIP65RelayList(it)?.writeRelaysNorm()
}.flatten()
.toSet(),
)
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Companion.Eagerly,
@@ -86,15 +89,18 @@ class OutboxRelaySetState(
@OptIn(ExperimentalCoroutinesApi::class)
val flowSet: StateFlow<Set<String>> =
flow.map { relayList ->
relayList.map { it.url }.toSet()
}.onStart {
emit(
usersToLoad.value.mapNotNull {
getNIP65RelayList(it)?.writeRelaysNorm()?.map { it.url }?.toSet()
}.flatten().toSet(),
)
}.flowOn(Dispatchers.Default)
flow
.map { relayList ->
relayList.map { it.url }.toSet()
}.onStart {
emit(
usersToLoad.value
.mapNotNull {
getNIP65RelayList(it)?.writeRelaysNorm()?.map { it.url }?.toSet()
}.flatten()
.toSet(),
)
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Companion.Eagerly,
@@ -60,19 +60,17 @@ class CommunityListState(
fun getCommunityList(): CommunityListEvent? = getCommunityListNote().event as? CommunityListEvent
suspend fun communityListWithBackup(note: Note): Set<AddressHint> {
return communityList(
suspend fun communityListWithBackup(note: Note): Set<AddressHint> =
communityList(
note.event as? CommunityListEvent ?: settings.backupCommunityList,
)
}
suspend fun communityList(event: CommunityListEvent?): Set<AddressHint> {
return tryAndWait { continuation ->
suspend fun communityList(event: CommunityListEvent?): Set<AddressHint> =
tryAndWait { continuation ->
event?.publicAndPrivateCommunities(signer) {
continuation.resume(it)
}
} ?: emptySet()
}
@OptIn(ExperimentalCoroutinesApi::class)
val flow: StateFlow<Set<AddressHint>> by lazy {
@@ -46,15 +46,14 @@ class MergedFollowListsState(
hashtages: Set<String>,
geohashes: Set<String>,
community: Set<AddressHint>,
): FollowListState.Kind3Follows {
return FollowListState.Kind3Follows(
): FollowListState.Kind3Follows =
FollowListState.Kind3Follows(
kind3.authors,
kind3.authorsPlusMe,
kind3.hashtags + hashtages,
kind3.geotags + geohashes,
kind3.communities + community.map { it.addressId },
)
}
val flow: StateFlow<FollowListState.Kind3Follows> =
combine(
@@ -64,18 +63,16 @@ class MergedFollowListsState(
communityList.flow,
) { kind3, hashtag, geohash, community ->
mergeLists(kind3, hashtag, geohash, community)
}
.onStart {
emit(
mergeLists(
kind3List.flow.value,
hashtagList.flow.value,
geohashList.flow.value,
communityList.flow.value,
),
)
}
.flowOn(Dispatchers.Default)
}.onStart {
emit(
mergeLists(
kind3List.flow.value,
hashtagList.flow.value,
geohashList.flow.value,
communityList.flow.value,
),
)
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -47,9 +47,7 @@ class MergedFollowPlusMineRelayListsState(
inbox: Set<NormalizedRelayUrl>,
private: Set<NormalizedRelayUrl>,
local: Set<NormalizedRelayUrl>,
): Set<NormalizedRelayUrl> {
return kind3 + outbox + inbox + private + local
}
): Set<NormalizedRelayUrl> = kind3 + outbox + inbox + private + local
val flow: StateFlow<Set<NormalizedRelayUrl>> =
combine(
@@ -59,19 +57,17 @@ class MergedFollowPlusMineRelayListsState(
privateOutboxRelayList.flow,
localRelayList.flow,
::mergeLists,
)
.onStart {
emit(
mergeLists(
followsOutboxRelayList.flow.value,
nip65RelayList.outboxFlow.value,
nip65RelayList.inboxFlow.value,
privateOutboxRelayList.flow.value,
localRelayList.flow.value,
),
)
}
.flowOn(Dispatchers.Default)
).onStart {
emit(
mergeLists(
followsOutboxRelayList.flow.value,
nip65RelayList.outboxFlow.value,
nip65RelayList.inboxFlow.value,
privateOutboxRelayList.flow.value,
localRelayList.flow.value,
),
)
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -62,8 +62,7 @@ class MergedServerListState(
val liveServerList: StateFlow<List<ServerName>> by lazy {
combine(fileServers, blossomServers) { nip96s, blossoms ->
mergeServerList(nip96s, blossoms)
}
.onStart { emit(mergeServerList(fileServers.value, blossomServers.value)) }
}.onStart { emit(mergeServerList(fileServers.value, blossomServers.value)) }
.flowOn(Dispatchers.Default)
.stateIn(
scope,
@@ -49,9 +49,7 @@ class TrustedRelayListsState(
local: Set<NormalizedRelayUrl>,
dm: Set<NormalizedRelayUrl>,
search: Set<NormalizedRelayUrl>,
): Set<NormalizedRelayUrl> {
return nip65 + private + local + dm + search
}
): Set<NormalizedRelayUrl> = nip65 + private + local + dm + search
val flow: StateFlow<Set<NormalizedRelayUrl>> =
combine(
@@ -61,19 +59,17 @@ class TrustedRelayListsState(
dmRelayList.flow,
searchRelayListState.flow,
::mergeLists,
)
.onStart {
emit(
mergeLists(
nip65RelayList.allFlow.value,
privateOutboxRelayList.flow.value,
localRelayList.flow.value,
dmRelayList.flow.value,
searchRelayListState.flow.value,
),
)
}
.flowOn(Dispatchers.Default)
).onStart {
emit(
mergeLists(
nip65RelayList.allFlow.value,
privateOutboxRelayList.flow.value,
localRelayList.flow.value,
dmRelayList.flow.value,
searchRelayListState.flow.value,
),
)
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -36,11 +36,12 @@ class CommunityRelayLoader {
fun communitiesPerRelay(
communityNotes: Array<NoteState>,
cache: LocalCache,
): Map<NormalizedRelayUrl, Set<HexKey>> {
return mapOfSet {
): Map<NormalizedRelayUrl, Set<HexKey>> =
mapOfSet {
communityNotes.forEach { communityNote ->
val relays =
(communityNote.note.event as? CommunityDefinitionEvent)?.relayUrls()
(communityNote.note.event as? CommunityDefinitionEvent)
?.relayUrls()
?.ifEmpty { null }
?: cache.relayHints.hintsForAddress(communityNote.note.idHex)
@@ -49,7 +50,6 @@ class CommunityRelayLoader {
}
}
}
}
fun <T> communitiesPerRelaySnapshot(
communities: Set<HexKey>,
@@ -57,9 +57,15 @@ class CommunityRelayLoader {
transformation: (Map<NormalizedRelayUrl, Set<HexKey>>) -> T,
): T {
val noteMetadata =
communities.mapNotNull { addressId ->
cache.checkGetOrCreateAddressableNote(addressId)?.flow()?.metadata?.stateFlow?.value
}.toTypedArray()
communities
.mapNotNull { addressId ->
cache
.checkGetOrCreateAddressableNote(addressId)
?.flow()
?.metadata
?.stateFlow
?.value
}.toTypedArray()
return transformation(communitiesPerRelay(noteMetadata, cache))
}
@@ -70,7 +76,11 @@ class CommunityRelayLoader {
): Flow<T> {
val noteMetadataFlows =
communities.mapNotNull { addressId ->
cache.checkGetOrCreateAddressableNote(addressId)?.flow()?.metadata?.stateFlow
cache
.checkGetOrCreateAddressableNote(addressId)
?.flow()
?.metadata
?.stateFlow
}
return combine(noteMetadataFlows) { communityNotes ->
@@ -71,13 +71,12 @@ class FeedTopNavFilterState(
@OptIn(ExperimentalCoroutinesApi::class)
val flow: StateFlow<IFeedTopNavFilter> =
feedFilterListName.transformLatest { listName ->
emitAll(loadFlowsFor(listName).flow())
}
.onStart {
feedFilterListName
.transformLatest { listName ->
emitAll(loadFlowsFor(listName).flow())
}.onStart {
loadFlowsFor(feedFilterListName.value).startValue(this)
}
.flowOn(Dispatchers.Default)
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -47,8 +47,8 @@ class MergedTopFeedAuthorListsState(
val notificationNavFilter: StateFlow<IFeedTopNavPerRelayFilterSet>,
val scope: CoroutineScope,
) {
fun authorList(navFilter: IFeedTopNavPerRelayFilterSet): Map<NormalizedRelayUrl, Set<HexKey>?> {
return when (navFilter) {
fun authorList(navFilter: IFeedTopNavPerRelayFilterSet): Map<NormalizedRelayUrl, Set<HexKey>?> =
when (navFilter) {
is AllCommunitiesTopNavPerRelayFilterSet -> emptyMap()
is AllFollowsByOutboxTopNavPerRelayFilterSet -> navFilter.set.mapValues { it.value.authors }
is AuthorsByOutboxTopNavPerRelayFilterSet -> navFilter.set.mapValues { it.value.authors }
@@ -59,15 +59,14 @@ class MergedTopFeedAuthorListsState(
is SingleCommunityTopNavPerRelayFilterSet -> navFilter.set.mapValues { it.value.authors }
else -> emptyMap()
}
}
fun mergeLists(
homeNavFilter: IFeedTopNavPerRelayFilterSet,
videoNavFilter: IFeedTopNavPerRelayFilterSet,
discoveryNavFilter: IFeedTopNavPerRelayFilterSet,
notificationNavFilter: IFeedTopNavPerRelayFilterSet,
): Map<NormalizedRelayUrl, Set<HexKey>> {
return mapOfSet {
): Map<NormalizedRelayUrl, Set<HexKey>> =
mapOfSet {
authorList(homeNavFilter).forEach { (relay, authors) ->
authors?.let { add(relay, authors) }
}
@@ -84,7 +83,6 @@ class MergedTopFeedAuthorListsState(
authors?.let { add(relay, authors) }
}
}
}
val flow: StateFlow<Map<NormalizedRelayUrl, Set<HexKey>>> =
combine(
@@ -102,8 +100,7 @@ class MergedTopFeedAuthorListsState(
notificationNavFilter.value,
),
)
}
.flowOn(Dispatchers.Default)
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -40,11 +40,12 @@ class OutboxLoaderState(
) {
@OptIn(ExperimentalCoroutinesApi::class)
val flow: StateFlow<IFeedTopNavPerRelayFilterSet> =
topNavFilter.transformLatest { filterSettings ->
emitAll(filterSettings.toPerRelayFlow(cache))
}.onStart {
emit(topNavFilter.value.startValue(cache))
}.flowOn(Dispatchers.Default)
topNavFilter
.transformLatest { filterSettings ->
emitAll(filterSettings.toPerRelayFlow(cache))
}.onStart {
emit(topNavFilter.value.startValue(cache))
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Companion.Eagerly,
@@ -35,19 +35,20 @@ class OutboxRelayLoader {
private fun authorsPerRelay(
outboxRelayNotes: Array<NoteState>,
cache: LocalCache,
): Map<NormalizedRelayUrl, Set<HexKey>> {
return mapOfSet {
): Map<NormalizedRelayUrl, Set<HexKey>> =
mapOfSet {
outboxRelayNotes.forEach { outboxNote ->
val relays =
(outboxNote.note.event as? AdvertisedRelayListEvent)?.writeRelaysNorm()?.ifEmpty { null }
?: outboxNote.note.author?.pubkeyHex ?.let { cache.relayHints.hintsForKey(it) }
?: outboxNote.note.author
?.pubkeyHex
?.let { cache.relayHints.hintsForKey(it) }
relays?.forEach {
add(it, outboxNote.note.idHex)
}
}
}
}
fun <T> authorsPerRelaySnapshot(
authors: Set<HexKey>,
@@ -55,9 +56,13 @@ class OutboxRelayLoader {
transformation: (Map<NormalizedRelayUrl, Set<HexKey>>) -> T,
): T {
val noteMetadata =
authors.map { pubkeyHex ->
cache.getOrCreateAddressableNote(AdvertisedRelayListEvent.createAddress(pubkeyHex)).flow().metadata.stateFlow.value
}.toTypedArray()
authors
.map { pubkeyHex ->
cache
.getOrCreateAddressableNote(AdvertisedRelayListEvent.createAddress(pubkeyHex))
.flow()
.metadata.stateFlow.value
}.toTypedArray()
return transformation(authorsPerRelay(noteMetadata, cache))
}
@@ -54,12 +54,10 @@ class AllFollowsByOutboxTopNavFilter(
val geotagScopes: Set<String>? = geotags?.mapTo(mutableSetOf<String>()) { GeohashId.Companion.toScope(it) }
val hashtagScopes: Set<String>? = hashtags?.mapTo(mutableSetOf<String>()) { HashtagId.Companion.toScope(it) }
override fun matchAuthor(pubkey: HexKey): Boolean {
return authors == null || pubkey in authors
}
override fun matchAuthor(pubkey: HexKey): Boolean = authors == null || pubkey in authors
override fun match(noteEvent: Event): Boolean {
return if (noteEvent is LiveActivitiesEvent) {
override fun match(noteEvent: Event): Boolean =
if (noteEvent is LiveActivitiesEvent) {
(authors != null && noteEvent.participantsIntersect(authors)) ||
(hashtags != null && noteEvent.isTaggedHashes(hashtags)) ||
(geotags != null && noteEvent.isTaggedGeoHashes(geotags)) ||
@@ -78,7 +76,6 @@ class AllFollowsByOutboxTopNavFilter(
(geotags != null && noteEvent.isTaggedGeoHashes(geotags)) ||
(communities != null && noteEvent.isTaggedAddressableNotes(communities))
}
}
override fun toPerRelayFlow(cache: LocalCache): Flow<AllFollowsByOutboxTopNavPerRelayFilterSet> {
val authorsPerRelay =
@@ -32,8 +32,8 @@ class AllFollowsFeedFlow(
val allFollows: StateFlow<FollowListState.Kind3Follows?>,
val followsRelays: StateFlow<Set<NormalizedRelayUrl>>,
) : IFeedFlowsType {
fun convert(kind3: FollowListState.Kind3Follows?): AllFollowsByOutboxTopNavFilter {
return if (kind3 != null) {
fun convert(kind3: FollowListState.Kind3Follows?): AllFollowsByOutboxTopNavFilter =
if (kind3 != null) {
AllFollowsByOutboxTopNavFilter(
authors = kind3.authors,
hashtags = kind3.hashtags,
@@ -47,7 +47,6 @@ class AllFollowsFeedFlow(
defaultRelays = followsRelays,
)
}
}
override fun flow() = allFollows.map(::convert)
@@ -32,8 +32,8 @@ class AroundMeFeedFlow(
val location: StateFlow<LocationState.LocationResult>,
val allFollowRelays: StateFlow<Set<NormalizedRelayUrl>>,
) : IFeedFlowsType {
fun convert(result: LocationState.LocationResult): LocationTopNavFilter {
return if (result is LocationState.LocationResult.Success) {
fun convert(result: LocationState.LocationResult): LocationTopNavFilter =
if (result is LocationState.LocationResult.Success) {
// 2 neighbors deep = 25x25km
LocationTopNavFilter(
geotags = compute50kmRange(result.geoHash).toSet(),
@@ -46,7 +46,6 @@ class AroundMeFeedFlow(
relays = allFollowRelays,
)
}
}
override fun flow() = location.map(::convert)
@@ -53,13 +53,10 @@ class LocationTopNavFilter(
}
}
override fun toPerRelayFlow(cache: LocalCache): Flow<LocationTopNavPerRelayFilterSet> {
return relays.map {
override fun toPerRelayFlow(cache: LocalCache): Flow<LocationTopNavPerRelayFilterSet> =
relays.map {
LocationTopNavPerRelayFilterSet(it.associateWith { LocationTopNavPerRelayFilter(geotags) })
}
}
override fun startValue(cache: LocalCache): LocationTopNavPerRelayFilterSet {
return LocationTopNavPerRelayFilterSet(relays.value.associateWith { LocationTopNavPerRelayFilter(geotags) })
}
override fun startValue(cache: LocalCache): LocationTopNavPerRelayFilterSet = LocationTopNavPerRelayFilterSet(relays.value.associateWith { LocationTopNavPerRelayFilter(geotags) })
}
@@ -38,15 +38,13 @@ class GlobalTopNavFilter(
override fun match(noteEvent: Event) = true
override fun toPerRelayFlow(cache: LocalCache): Flow<GlobalTopNavPerRelayFilterSet> {
return relays.map {
override fun toPerRelayFlow(cache: LocalCache): Flow<GlobalTopNavPerRelayFilterSet> =
relays.map {
GlobalTopNavPerRelayFilterSet(it.associateWith { GlobalTopNavPerRelayFilter })
}
}
override fun startValue(cache: LocalCache): GlobalTopNavPerRelayFilterSet {
return GlobalTopNavPerRelayFilterSet(
override fun startValue(cache: LocalCache): GlobalTopNavPerRelayFilterSet =
GlobalTopNavPerRelayFilterSet(
relays.value.associateWith { GlobalTopNavPerRelayFilter },
)
}
}
@@ -42,27 +42,24 @@ class HashtagTopNavFilter(
override fun matchAuthor(pubkey: HexKey): Boolean = true
override fun match(noteEvent: Event): Boolean {
return if (noteEvent is CommentEvent) {
override fun match(noteEvent: Event): Boolean =
if (noteEvent is CommentEvent) {
noteEvent.isTaggedHashes(hashtags) || noteEvent.isTaggedScopes(hashtagScopes)
} else {
noteEvent.isTaggedHashes(hashtags)
}
}
override fun toPerRelayFlow(cache: LocalCache): Flow<HashtagTopNavPerRelayFilterSet> {
return relays.map {
override fun toPerRelayFlow(cache: LocalCache): Flow<HashtagTopNavPerRelayFilterSet> =
relays.map {
HashtagTopNavPerRelayFilterSet(
it.associateWith { HashtagTopNavPerRelayFilter(hashtags) },
)
}
}
override fun startValue(cache: LocalCache): HashtagTopNavPerRelayFilterSet {
return HashtagTopNavPerRelayFilterSet(
override fun startValue(cache: LocalCache): HashtagTopNavPerRelayFilterSet =
HashtagTopNavPerRelayFilterSet(
relays.value.associateWith {
HashtagTopNavPerRelayFilter(hashtags)
},
)
}
}
@@ -36,24 +36,20 @@ class AllCommunitiesTopNavFilter(
) : IFeedTopNavFilter {
override fun matchAuthor(pubkey: HexKey): Boolean = true
override fun match(noteEvent: Event): Boolean {
return noteEvent.isTaggedAddressableNotes(communities)
}
override fun match(noteEvent: Event): Boolean = noteEvent.isTaggedAddressableNotes(communities)
fun convert(map: Map<NormalizedRelayUrl, Set<HexKey>>) =
AllCommunitiesTopNavPerRelayFilterSet(
map.mapValues { AllCommunitiesTopNavPerRelayFilter(it.value) },
)
override fun toPerRelayFlow(cache: LocalCache): Flow<AllCommunitiesTopNavPerRelayFilterSet> {
return CommunityRelayLoader.toCommunitiesPerRelayFlow(communities, cache) {
override fun toPerRelayFlow(cache: LocalCache): Flow<AllCommunitiesTopNavPerRelayFilterSet> =
CommunityRelayLoader.toCommunitiesPerRelayFlow(communities, cache) {
convert(it)
}
}
override fun startValue(cache: LocalCache): AllCommunitiesTopNavPerRelayFilterSet {
return CommunityRelayLoader.communitiesPerRelaySnapshot(communities, cache) {
override fun startValue(cache: LocalCache): AllCommunitiesTopNavPerRelayFilterSet =
CommunityRelayLoader.communitiesPerRelaySnapshot(communities, cache) {
convert(it)
}
}
}
@@ -36,24 +36,19 @@ class AuthorsByOutboxTopNavFilter(
) : IFeedTopNavFilter {
override fun matchAuthor(pubkey: HexKey) = pubkey in authors
override fun match(noteEvent: Event): Boolean {
return if (noteEvent is LiveActivitiesEvent) {
override fun match(noteEvent: Event): Boolean =
if (noteEvent is LiveActivitiesEvent) {
noteEvent.participantsIntersect(authors)
} else {
noteEvent.pubKey in authors
}
}
fun convert(map: Map<NormalizedRelayUrl, Set<HexKey>>) =
AuthorsByOutboxTopNavPerRelayFilterSet(
map.mapValues { AuthorsByOutboxTopNavPerRelayFilter(it.value) },
)
override fun toPerRelayFlow(cache: LocalCache): Flow<AuthorsByOutboxTopNavPerRelayFilterSet> {
return OutboxRelayLoader.toAuthorsPerRelayFlow(authors, cache, ::convert)
}
override fun toPerRelayFlow(cache: LocalCache): Flow<AuthorsByOutboxTopNavPerRelayFilterSet> = OutboxRelayLoader.toAuthorsPerRelayFlow(authors, cache, ::convert)
override fun startValue(cache: LocalCache): AuthorsByOutboxTopNavPerRelayFilterSet {
return OutboxRelayLoader.authorsPerRelaySnapshot(authors, cache, ::convert)
}
override fun startValue(cache: LocalCache): AuthorsByOutboxTopNavPerRelayFilterSet = OutboxRelayLoader.authorsPerRelaySnapshot(authors, cache, ::convert)
}
@@ -41,15 +41,14 @@ class SingleCommunityTopNavFilter(
) : IFeedTopNavFilter {
override fun matchAuthor(pubkey: HexKey) = authors == null || pubkey in authors
override fun match(noteEvent: Event): Boolean {
return if (noteEvent is LiveActivitiesEvent) {
override fun match(noteEvent: Event): Boolean =
if (noteEvent is LiveActivitiesEvent) {
(authors != null && noteEvent.participantsIntersect(authors)) || noteEvent.isTaggedAddressableNote(community)
} else if (noteEvent is CommentEvent) {
(authors != null && noteEvent.pubKey in authors) || noteEvent.isTaggedAddressableNote(community)
} else {
(authors != null && noteEvent.pubKey in authors) || noteEvent.isTaggedAddressableNote(community)
}
}
override fun toPerRelayFlow(cache: LocalCache): Flow<SingleCommunityTopNavPerRelayFilterSet> {
// relay field takes priority
@@ -36,24 +36,19 @@ class MutedAuthorsByOutboxTopNavFilter(
) : IFeedTopNavFilter {
override fun matchAuthor(pubkey: HexKey) = pubkey in authors
override fun match(noteEvent: Event): Boolean {
return if (noteEvent is LiveActivitiesEvent) {
override fun match(noteEvent: Event): Boolean =
if (noteEvent is LiveActivitiesEvent) {
noteEvent.participantsIntersect(authors)
} else {
noteEvent.pubKey in authors
}
}
fun convert(map: Map<NormalizedRelayUrl, Set<HexKey>>) =
MutedAuthorsByOutboxTopNavPerRelayFilterSet(
map.mapValues { MutedAuthorsByOutboxTopNavPerRelayFilter(it.value) },
)
override fun toPerRelayFlow(cache: LocalCache): Flow<MutedAuthorsByOutboxTopNavPerRelayFilterSet> {
return OutboxRelayLoader.toAuthorsPerRelayFlow(authors, cache, ::convert)
}
override fun toPerRelayFlow(cache: LocalCache): Flow<MutedAuthorsByOutboxTopNavPerRelayFilterSet> = OutboxRelayLoader.toAuthorsPerRelayFlow(authors, cache, ::convert)
override fun startValue(cache: LocalCache): MutedAuthorsByOutboxTopNavPerRelayFilterSet {
return OutboxRelayLoader.authorsPerRelaySnapshot(authors, cache, ::convert)
}
override fun startValue(cache: LocalCache): MutedAuthorsByOutboxTopNavPerRelayFilterSet = OutboxRelayLoader.authorsPerRelaySnapshot(authors, cache, ::convert)
}
@@ -36,9 +36,7 @@ class UnknownTopNavFilter(
override fun match(noteEvent: Event) = false
override fun toPerRelayFlow(cache: LocalCache): Flow<UnknownTopNavPerRelayFilterSet> {
return MutableStateFlow(UnknownTopNavPerRelayFilterSet)
}
override fun toPerRelayFlow(cache: LocalCache): Flow<UnknownTopNavPerRelayFilterSet> = MutableStateFlow(UnknownTopNavPerRelayFilterSet)
override fun startValue(cache: LocalCache) = UnknownTopNavPerRelayFilterSet
}
@@ -30,8 +30,8 @@ class TorRelayEvaluation(
val trustedRelayList: Set<NormalizedRelayUrl>,
val dmRelayList: Set<NormalizedRelayUrl>,
) {
fun useTor(relay: NormalizedRelayUrl): Boolean {
return if (torSettings.torType == TorType.OFF) {
fun useTor(relay: NormalizedRelayUrl): Boolean =
if (torSettings.torType == TorType.OFF) {
false
} else {
if (relay.isLocalHost()) {
@@ -46,5 +46,4 @@ class TorRelayEvaluation(
torSettings.newRelaysViaTor
}
}
}
}
@@ -48,11 +48,11 @@ class TorRelayState(
settings.torSettings.trustedRelaysViaTor,
settings.torSettings.newRelaysViaTor,
) {
torType: TorType,
onionRelaysViaTor: Boolean,
dmRelaysViaTor: Boolean,
trustedRelaysViaTor: Boolean,
newRelaysViaTor: Boolean,
torType: TorType,
onionRelaysViaTor: Boolean,
dmRelaysViaTor: Boolean,
trustedRelaysViaTor: Boolean,
newRelaysViaTor: Boolean,
->
TorRelaySettings(torType, onionRelaysViaTor, dmRelaysViaTor, trustedRelaysViaTor, newRelaysViaTor)
}.onStart {
@@ -65,8 +65,7 @@ class TorRelayState(
settings.torSettings.newRelaysViaTor.value,
),
)
}
.flowOn(Dispatchers.Default)
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -175,15 +175,14 @@ class ZapPaymentHandler(
val user: User? = null,
)
fun receivingRelaySet(userHex: HexKey): Set<NormalizedRelayUrl>? {
return (
fun receivingRelaySet(userHex: HexKey): Set<NormalizedRelayUrl>? =
(
LocalCache
.getAddressableNoteIfExists(
AdvertisedRelayListEvent.createAddressTag(userHex),
)?.event as? AdvertisedRelayListEvent
)
?.readRelaysNorm()?.toSet()
}
)?.readRelaysNorm()
?.toSet()
suspend fun signAllZapRequests(
note: Note,
@@ -26,7 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
class ProxySettingsAnchor() {
class ProxySettingsAnchor {
val flow: MutableStateFlow<StateFlow<TorRelayEvaluation>> =
MutableStateFlow(
MutableStateFlow(
@@ -53,16 +53,17 @@ class RelayProxyClientConnector(
connManager.status,
) { torSettings, torConnection, clearConnection, connectivity ->
torSettings.hashCode() + torConnection.hashCode() + clearConnection.hashCode() + connectivity.hashCode()
}.debounce(100).onEach {
Log.d("ManageRelayServices", "Relay Services have changed")
client.reconnect(true)
}.onStart {
Log.d("ManageRelayServices", "Resuming Relay Services")
client.connect()
}.onCompletion {
Log.d("ManageRelayServices", "Pausing Relay Services")
client.disconnect()
}.flowOn(Dispatchers.IO)
}.debounce(100)
.onEach {
Log.d("ManageRelayServices", "Relay Services have changed")
client.reconnect(true)
}.onStart {
Log.d("ManageRelayServices", "Resuming Relay Services")
client.connect()
}.onCompletion {
Log.d("ManageRelayServices", "Pausing Relay Services")
client.disconnect()
}.flowOn(Dispatchers.IO)
.stateIn(
scope,
SharingStarted.WhileSubscribed(30000),
@@ -43,15 +43,14 @@ class AccountGiftWrapsEoseManager(
override fun updateFilter(
key: AccountQueryState,
since: SincePerRelayMap?,
): List<RelayBasedFilter> {
return key.account.dmRelays.flow.value.flatMap { relay ->
): List<RelayBasedFilter> =
key.account.dmRelays.flow.value.flatMap { relay ->
filterGiftWrapsToPubkey(
relay = relay,
pubkey = user(key).pubkeyHex,
since = since?.get(relay)?.time,
)
}
}
val userJobMap = mutableMapOf<User, List<Job>>()
@@ -38,15 +38,14 @@ class LiveActivityWatcherSubAssembly(
override fun updateFilter(
key: ChannelFinderQueryState,
since: SincePerRelayMap?,
): List<RelayBasedFilter> {
return if (key.channel is LiveActivitiesChannel) {
): List<RelayBasedFilter> =
if (key.channel is LiveActivitiesChannel) {
key.channel.relays().flatMap {
filterLiveStreamUpdatesByAddress(it, listOf(key.channel), since?.get(it)?.time)
}
} else {
emptyList()
}
}
/**
* Only one key per channel.
@@ -80,8 +80,10 @@ class EventWatcherSubAssembler(
notes: Iterable<Note>,
eoseCache: EOSEAccountFast<Note>,
): Collection<List<Note>> =
notes.groupBy { eoseCache.since(it)?.keys?.hashCode() }
.values.map {
notes
.groupBy { eoseCache.since(it)?.keys?.hashCode() }
.values
.map {
// important to keep in order otherwise the Relay thinks the filter has changed and we REQ again
it.sortedBy { it.idHex }
}
@@ -36,11 +36,10 @@ val MetadataAndRelayListKinds =
AdvertisedRelayListEvent.KIND,
)
fun filterFindUserMetadataForKey(author: HexKey): List<RelayBasedFilter> {
return LocalCache.checkGetOrCreateUser(author)?.let {
fun filterFindUserMetadataForKey(author: HexKey): List<RelayBasedFilter> =
LocalCache.checkGetOrCreateUser(author)?.let {
filterFindUserMetadataForKey(setOf(it))
} ?: emptyList()
}
fun filterFindUserMetadataForKey(authors: Set<User>): List<RelayBasedFilter> {
val perRelayKeys =
@@ -45,14 +45,16 @@ fun filterUserMetadataForKey(
since: SincePerRelayMap?,
): List<RelayBasedFilter> {
val relays =
authors.map {
val authorHomeRelayEventAddress = AdvertisedRelayListEvent.createAddressTag(it)
val authorHomeRelayEvent = (LocalCache.getAddressableNoteIfExists(authorHomeRelayEventAddress)?.event as? AdvertisedRelayListEvent)
authors
.map {
val authorHomeRelayEventAddress = AdvertisedRelayListEvent.createAddressTag(it)
val authorHomeRelayEvent = (LocalCache.getAddressableNoteIfExists(authorHomeRelayEventAddress)?.event as? AdvertisedRelayListEvent)
authorHomeRelayEvent?.writeRelaysNorm()?.ifEmpty { null }
?: LocalCache.relayHints.hintsForKey(it).ifEmpty { null }
?: listOfNotNull(LocalCache.getUserIfExists(it)?.latestMetadataRelay)
}.flatten().toSet()
authorHomeRelayEvent?.writeRelaysNorm()?.ifEmpty { null }
?: LocalCache.relayHints.hintsForKey(it).ifEmpty { null }
?: listOfNotNull(LocalCache.getUserIfExists(it)?.latestMetadataRelay)
}.flatten()
.toSet()
return relays.map {
RelayBasedFilter(
@@ -108,7 +108,7 @@ class MediaCompressor {
// videoName = "compressed_video" // => required name
// ),
// OR AND NOT BOTH
appSpecificStorageConfiguration = AppSpecificStorageConfiguration(),
storageConfiguration = AppSpecificStorageConfiguration(),
configureWith =
Configuration(
quality = videoQuality,
@@ -129,7 +129,11 @@ fun EditPostView(
val scrollState = rememberScrollState()
val scope = rememberCoroutineScope()
var showRelaysDialog by remember { mutableStateOf(false) }
var relayList = remember { accountViewModel.account.outboxRelays.flow.value.toImmutableList() }
var relayList =
remember {
accountViewModel.account.outboxRelays.flow.value
.toImmutableList()
}
LaunchedEffect(Unit) {
postViewModel.load(edit, versionLookingAt, accountViewModel)
@@ -101,7 +101,11 @@ fun NewMediaView(
}
var showRelaysDialog by remember { mutableStateOf(false) }
var relayList = remember { accountViewModel.account.outboxRelays.flow.value.toImmutableList() }
var relayList =
remember {
accountViewModel.account.outboxRelays.flow.value
.toImmutableList()
}
Dialog(
onDismissRequest = { onClose() },
@@ -202,7 +206,8 @@ fun ImageVideoPost(
accountViewModel: AccountViewModel,
) {
val nip95description = stringRes(id = R.string.upload_server_relays_nip95)
val fileServers by accountViewModel.account.serverLists.liveServerList.collectAsState()
val fileServers by accountViewModel.account.serverLists.liveServerList
.collectAsState()
val fileServerOptions =
remember(fileServers) {
@@ -30,9 +30,7 @@ import kotlinx.serialization.encoding.Encoder
object NormalizedRelayUrlSerializer : KSerializer<NormalizedRelayUrl> {
override val descriptor = PrimitiveSerialDescriptor("NormalizedRelayUrl", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): NormalizedRelayUrl {
return NormalizedRelayUrl(decoder.decodeString())
}
override fun deserialize(decoder: Decoder): NormalizedRelayUrl = NormalizedRelayUrl(decoder.decodeString())
override fun serialize(
encoder: Encoder,
@@ -139,7 +139,8 @@ class UpdateZapAmountViewModel : ViewModel() {
?.let { TextFieldValue(it) } ?: TextFieldValue("")
this.walletConnectRelay =
myAccount.settings.zapPaymentRequest
?.relayUri?.url
?.relayUri
?.url
?.let { TextFieldValue(it) } ?: TextFieldValue("")
this.walletConnectSecret =
myAccount.settings.zapPaymentRequest
@@ -373,7 +373,8 @@ fun WatchUserFollows(
if (accountViewModel.isLoggedUser(userHex)) {
onFollowChanges(true)
} else {
val state by accountViewModel.account.kind3FollowList.flow.collectAsStateWithLifecycle()
val state by accountViewModel.account.kind3FollowList.flow
.collectAsStateWithLifecycle()
onFollowChanges(state.authors.contains(userHex))
}
@@ -98,7 +98,8 @@ fun ImageVideoDescription(
) {
val nip95description = stringRes(id = R.string.upload_server_relays_nip95)
val fileServers by accountViewModel.account.serverLists.liveServerList.collectAsState()
val fileServers by accountViewModel.account.serverLists.liveServerList
.collectAsState()
val fileServerOptions =
remember(fileServers, includeNIP95) {
@@ -50,7 +50,8 @@ fun DisplayFollowingHashtagsInPost(
accountViewModel: AccountViewModel,
nav: INav,
) {
val userFollowState by accountViewModel.account.allFollows.flow.collectAsStateWithLifecycle()
val userFollowState by accountViewModel.account.allFollows.flow
.collectAsStateWithLifecycle()
var firstTag by remember(baseNote) { mutableStateOf<String?>(null) }
LaunchedEffect(key1 = userFollowState) {
@@ -498,13 +498,14 @@ open class CommentPostViewModel :
multiOrchestrator = null
} else {
val errorMessages =
results.errors.map {
stringRes(
context,
it.errorResource,
*it.params,
)
}.distinct()
results.errors
.map {
stringRes(
context,
it.errorResource,
*it.params,
)
}.distinct()
onError(stringRes(context, R.string.failed_to_upload_media_no_details), errorMessages.joinToString(".\n"))
}
@@ -555,7 +556,9 @@ open class CommentPostViewModel :
fun reloadRelaySet() {
val account = accountViewModel?.account ?: return
relayList = account.outboxRelays.flow.value.toImmutableList()
relayList =
account.outboxRelays.flow.value
.toImmutableList()
}
fun deleteMediaToUpload(selected: SelectedMediaProcessing) {
@@ -626,7 +629,10 @@ open class CommentPostViewModel :
viewModelScope.launch(Dispatchers.IO) {
iMetaAttachments.downloadAndPrepare(
item.link.url,
{ Amethyst.Companion.instance.okHttpClients.getHttpClient(accountViewModel?.account?.shouldUseTorForImageDownload(item.link.url) ?: false) },
{
Amethyst.Companion.instance.okHttpClients
.getHttpClient(accountViewModel?.account?.shouldUseTorForImageDownload(item.link.url) ?: false)
},
)
}
@@ -361,7 +361,8 @@ fun WatchAddressableNoteFollows(
accountViewModel: AccountViewModel,
onFollowChanges: @Composable (Boolean) -> Unit,
) {
val state by accountViewModel.account.kind3FollowList.flow.collectAsStateWithLifecycle()
val state by accountViewModel.account.kind3FollowList.flow
.collectAsStateWithLifecycle()
onFollowChanges(state.communities.contains(note.idHex))
}
@@ -167,7 +167,9 @@ class AccountViewModel(
.flow()
.relays.stateFlow
.map { contactListState ->
contactListState.user.latestContactList?.relays()?.keys ?: emptySet()
contactListState.user.latestContactList
?.relays()
?.keys ?: emptySet()
}.flowOn(Dispatchers.Default)
.stateIn(
viewModelScope,
@@ -1664,27 +1666,29 @@ class AccountViewModel(
fun relayStatusFlow() = app.client.relayStatusFlow()
fun convertAccounts(loggedInAccounts: List<AccountInfo>?): Set<HexKey> {
return loggedInAccounts?.mapNotNull {
try {
it.npub.bechToBytes().toHexKey()
} catch (e: Exception) {
if (e is CancellationException) throw e
null
}
}?.toSet() ?: emptySet()
}
fun convertAccounts(loggedInAccounts: List<AccountInfo>?): Set<HexKey> =
loggedInAccounts
?.mapNotNull {
try {
it.npub.bechToBytes().toHexKey()
} catch (e: Exception) {
if (e is CancellationException) throw e
null
}
}?.toSet() ?: emptySet()
val trustedAccounts: StateFlow<Set<HexKey>> =
LocalPreferences.accountsFlow().map { loggedInAccounts ->
convertAccounts(loggedInAccounts)
}.onStart {
emit(convertAccounts(LocalPreferences.allSavedAccounts()))
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5000),
emptySet<HexKey>(),
)
LocalPreferences
.accountsFlow()
.map { loggedInAccounts ->
convertAccounts(loggedInAccounts)
}.onStart {
emit(convertAccounts(LocalPreferences.allSavedAccounts()))
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5000),
emptySet<HexKey>(),
)
val draftNoteCache = CachedDraftNotes(this)
@@ -130,7 +130,8 @@ fun ObserveAntiSpamFilterSettings(accountViewModel: AccountViewModel) {
@Composable
fun SetProxyDeterminator(accountViewModel: AccountViewModel) {
LaunchedEffect(accountViewModel) {
Amethyst.instance.torProxySettingsAnchor.flow.tryEmit(accountViewModel.account.torRelayState.flow)
Amethyst.instance.torProxySettingsAnchor.flow
.tryEmit(accountViewModel.account.torRelayState.flow)
}
}
@@ -143,7 +144,8 @@ fun ObserveImageLoadingTor(accountViewModel: AccountViewModel) {
@Composable
fun ManageRelayServices(accountViewModel: AccountViewModel) {
val relayServices by Amethyst.instance.relayProxyClientConnector.relayServices.collectAsStateWithLifecycle()
val relayServices by Amethyst.instance.relayProxyClientConnector.relayServices
.collectAsStateWithLifecycle()
Log.d("ManageRelayServices", "Relay Services changed $relayServices")
}
@@ -44,7 +44,8 @@ class NewEphemeralChatMetaViewModel : ViewModel() {
}
fun buildRoom() =
RelayUrlNormalizer.normalizeOrNull(relayUrl.value.text)
RelayUrlNormalizer
.normalizeOrNull(relayUrl.value.text)
?.let { RoomId(channelName.value.text, it) }
/*
@@ -50,30 +50,31 @@ fun filterLastMessageFollowingPublicChats(
}
}
return relayRoomDTags.map {
listOf(
RelayBasedFilter(
// Metadata comes from any relay
relay = it.key,
filter =
Filter(
kinds = listOf(ChannelMetadataEvent.KIND),
tags = mapOf("e" to it.value.sorted()),
since = since?.get(it.key)?.time,
limit = 1,
),
),
RelayBasedFilter(
relay = it.key,
filter =
Filter(
kinds = listOf(ChannelMessageEvent.KIND),
tags = mapOf("e" to it.value.sorted()),
since = since?.get(it.key)?.time,
// Remember to consider spam that is being removed from the UI
limit = 100,
),
),
)
}.flatten()
return relayRoomDTags
.map {
listOf(
RelayBasedFilter(
// Metadata comes from any relay
relay = it.key,
filter =
Filter(
kinds = listOf(ChannelMetadataEvent.KIND),
tags = mapOf("e" to it.value.sorted()),
since = since?.get(it.key)?.time,
limit = 1,
),
),
RelayBasedFilter(
relay = it.key,
filter =
Filter(
kinds = listOf(ChannelMessageEvent.KIND),
tags = mapOf("e" to it.value.sorted()),
since = since?.get(it.key)?.time,
// Remember to consider spam that is being removed from the UI
limit = 100,
),
),
)
}.flatten()
}
@@ -30,8 +30,8 @@ fun filterNip04DMsFromMe(
user: User,
relay: NormalizedRelayUrl,
since: Long?,
): RelayBasedFilter {
return RelayBasedFilter(
): RelayBasedFilter =
RelayBasedFilter(
relay = relay,
filter =
Filter(
@@ -40,4 +40,3 @@ fun filterNip04DMsFromMe(
since = since,
),
)
}
@@ -30,8 +30,8 @@ fun filterNip04DMsToMe(
user: User,
relay: NormalizedRelayUrl,
since: Long?,
): RelayBasedFilter {
return RelayBasedFilter(
): RelayBasedFilter =
RelayBasedFilter(
relay = relay,
filter =
Filter(
@@ -40,4 +40,3 @@ fun filterNip04DMsToMe(
since = since,
),
)
}
@@ -148,7 +148,8 @@ private fun ImageVideoPostChat(
fileUploadState: ChatFileUploadState,
accountViewModel: AccountViewModel,
) {
val fileServers by accountViewModel.account.serverLists.liveServerList.collectAsState()
val fileServers by accountViewModel.account.serverLists.liveServerList
.collectAsState()
val fileServerOptions =
remember(fileServers) {
@@ -30,8 +30,8 @@ fun filterCommunityPosts(
relay: NormalizedRelayUrl,
community: CommunityDefinitionEvent,
since: Long?,
): RelayBasedFilter {
return RelayBasedFilter(
): RelayBasedFilter =
RelayBasedFilter(
relay = relay,
filter =
Filter(
@@ -42,4 +42,3 @@ fun filterCommunityPosts(
since = since,
),
)
}
@@ -42,8 +42,8 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
fun makeLongFormFilter(
feedSettings: IFeedTopNavPerRelayFilterSet,
since: SincePerRelayMap?,
): List<RelayBasedFilter> {
return when (feedSettings) {
): List<RelayBasedFilter> =
when (feedSettings) {
is AllCommunitiesTopNavPerRelayFilterSet -> filterLongFormByAllCommunities(feedSettings, since)
is AllFollowsByOutboxTopNavPerRelayFilterSet -> filterLongFormByFollows(feedSettings, since)
is AuthorsByOutboxTopNavPerRelayFilterSet -> filterLongFormByAuthors(feedSettings, since)
@@ -54,4 +54,3 @@ fun makeLongFormFilter(
is SingleCommunityTopNavPerRelayFilterSet -> filterLongFormByCommunity(feedSettings, since)
else -> emptyList()
}
}
@@ -75,11 +75,12 @@ fun filterLongFormByAllCommunities(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterLongFormAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterLongFormAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -60,17 +60,18 @@ fun filterLongFormByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterLongFormAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterLongFormAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
fun filterLongFormByAuthors(
@@ -81,15 +82,16 @@ fun filterLongFormByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterLongFormAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterLongFormAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -77,12 +77,13 @@ fun filterLongFormByCommunity(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterLongFormByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterLongFormByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -61,15 +61,16 @@ fun filterLongFormByGeohash(
val defaultSince = TimeUtils.oneWeekAgo()
return geoSet.set.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterLiveActivitiesByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return geoSet.set
.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterLiveActivitiesByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -61,15 +61,16 @@ fun filterLongFormByHashtag(
val defaultSince = TimeUtils.oneWeekAgo()
return hashSet.set.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterLongFormByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
return hashSet.set
.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterLongFormByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -42,8 +42,8 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
fun makePublicChatsFilter(
feedSettings: IFeedTopNavPerRelayFilterSet,
since: SincePerRelayMap?,
): List<RelayBasedFilter> {
return when (feedSettings) {
): List<RelayBasedFilter> =
when (feedSettings) {
is AllCommunitiesTopNavPerRelayFilterSet -> filterPublicChatsByAllCommunities(feedSettings, since)
is AllFollowsByOutboxTopNavPerRelayFilterSet -> filterPublicChatsByFollows(feedSettings, since)
is AuthorsByOutboxTopNavPerRelayFilterSet -> filterPublicChatsByAuthors(feedSettings, since)
@@ -54,4 +54,3 @@ fun makePublicChatsFilter(
is SingleCommunityTopNavPerRelayFilterSet -> filterPublicChatsByCommunity(feedSettings, since)
else -> emptyList()
}
}
@@ -82,11 +82,12 @@ fun filterPublicChatsByAllCommunities(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterPublicChatsAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterPublicChatsAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -67,17 +67,18 @@ fun filterPublicChatsByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterPublicChatsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterPublicChatsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
fun filterPublicChatsByAuthors(
@@ -88,15 +89,16 @@ fun filterPublicChatsByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterPublicChatsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterPublicChatsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -84,12 +84,13 @@ fun filterPublicChatsByCommunity(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterPublicChatsByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterPublicChatsByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -67,15 +67,16 @@ fun filterPublicChatsByGeohash(
val defaultSince = TimeUtils.oneWeekAgo()
return geoSet.set.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterPublicChatsByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return geoSet.set
.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterPublicChatsByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -68,15 +68,16 @@ fun filterPublicChatsByHashtag(
val defaultSince = TimeUtils.oneWeekAgo()
return hashSet.set.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterPublicChatsByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
return hashSet.set
.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterPublicChatsByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -42,8 +42,8 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
fun makeFollowSetsFilter(
feedSettings: IFeedTopNavPerRelayFilterSet,
since: SincePerRelayMap?,
): List<RelayBasedFilter> {
return when (feedSettings) {
): List<RelayBasedFilter> =
when (feedSettings) {
is AllCommunitiesTopNavPerRelayFilterSet -> filterFollowSetsByAllCommunities(feedSettings, since)
is AllFollowsByOutboxTopNavPerRelayFilterSet -> filterFollowSetsByFollows(feedSettings, since)
is AuthorsByOutboxTopNavPerRelayFilterSet -> filterFollowSetsByAuthors(feedSettings, since)
@@ -54,4 +54,3 @@ fun makeFollowSetsFilter(
is SingleCommunityTopNavPerRelayFilterSet -> filterFollowSetsByCommunity(feedSettings, since)
else -> emptyList()
}
}
@@ -76,11 +76,12 @@ fun filterFollowSetsByAllCommunities(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterContentDVMsAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterContentDVMsAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -60,17 +60,18 @@ fun filterFollowSetsByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterFollowSetsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterFollowSetsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
fun filterFollowSetsByAuthors(
@@ -81,15 +82,16 @@ fun filterFollowSetsByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterFollowSetsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterFollowSetsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -77,12 +77,13 @@ fun filterFollowSetsByCommunity(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterFollowSetsByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterFollowSetsByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -60,15 +60,16 @@ fun filterFollowSetsByGeohash(
val defaultSince = TimeUtils.oneWeekAgo()
return geoSet.set.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterFollowSetsByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return geoSet.set
.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterFollowSetsByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -61,15 +61,16 @@ fun filterFollowSetsByHashtag(
val defaultSince = TimeUtils.oneWeekAgo()
return hashSet.set.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterFollowSetsByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
return hashSet.set
.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterFollowSetsByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -42,8 +42,8 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
fun makeLiveActivitiesFilter(
feedSettings: IFeedTopNavPerRelayFilterSet,
since: SincePerRelayMap?,
): List<RelayBasedFilter> {
return when (feedSettings) {
): List<RelayBasedFilter> =
when (feedSettings) {
is AllCommunitiesTopNavPerRelayFilterSet -> filterLiveActivitiesByAllCommunities(feedSettings, since)
is AllFollowsByOutboxTopNavPerRelayFilterSet -> filterLiveActivitiesByFollows(feedSettings, since)
is AuthorsByOutboxTopNavPerRelayFilterSet -> filterLiveActivitiesByAuthors(feedSettings, since)
@@ -54,4 +54,3 @@ fun makeLiveActivitiesFilter(
is SingleCommunityTopNavPerRelayFilterSet -> filterLiveActivitiesByCommunity(feedSettings, since)
else -> emptyList()
}
}
@@ -77,11 +77,12 @@ fun filterLiveActivitiesByAllCommunities(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterContentDVMsAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterContentDVMsAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -72,17 +72,18 @@ fun filterLiveActivitiesByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterLiveActivitiesAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterLiveActivitiesAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
fun filterLiveActivitiesByAuthors(
@@ -93,15 +94,16 @@ fun filterLiveActivitiesByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterLiveActivitiesAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterLiveActivitiesAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -78,12 +78,13 @@ fun filterLiveActivitiesByCommunity(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterLiveActivitiesByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterLiveActivitiesByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -61,15 +61,16 @@ fun filterLiveActivitiesByGeohash(
val defaultSince = TimeUtils.oneWeekAgo()
return geoSet.set.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterLiveActivitiesByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return geoSet.set
.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterLiveActivitiesByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -62,15 +62,16 @@ fun filterLiveActivitiesByHashtag(
val defaultSince = TimeUtils.oneWeekAgo()
return hashSet.set.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterLiveActivitiesByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
return hashSet.set
.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterLiveActivitiesByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -42,8 +42,8 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
fun makeCommunitiesFilter(
feedSettings: IFeedTopNavPerRelayFilterSet,
since: SincePerRelayMap?,
): List<RelayBasedFilter> {
return when (feedSettings) {
): List<RelayBasedFilter> =
when (feedSettings) {
is AllCommunitiesTopNavPerRelayFilterSet -> filterCommunitiesByAllCommunities(feedSettings, since)
is AllFollowsByOutboxTopNavPerRelayFilterSet -> filterCommunitiesByFollows(feedSettings, since)
is AuthorsByOutboxTopNavPerRelayFilterSet -> filterCommunitiesByAuthors(feedSettings, since)
@@ -54,4 +54,3 @@ fun makeCommunitiesFilter(
is SingleCommunityTopNavPerRelayFilterSet -> filterCommunitiesByCommunity(feedSettings, since)
else -> emptyList()
}
}
@@ -71,11 +71,12 @@ fun filterCommunitiesByAllCommunities(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterCommunitiesAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterCommunitiesAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -61,17 +61,18 @@ fun filterCommunitiesByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterCommunitiesAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterCommunitiesAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
fun filterCommunitiesByAuthors(
@@ -82,15 +83,16 @@ fun filterCommunitiesByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterCommunitiesAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterCommunitiesAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -60,12 +60,13 @@ fun filterCommunitiesByCommunity(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterClassifiedsByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterClassifiedsByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -61,15 +61,16 @@ fun filterCommunitiesByGeohash(
val defaultSince = TimeUtils.oneWeekAgo()
return geoSet.set.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterCommunitiesByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return geoSet.set
.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterCommunitiesByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -62,15 +62,16 @@ fun filterCommunitiesByHashtag(
val defaultSince = TimeUtils.oneWeekAgo()
return hashSet.set.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterCommunitiesByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
return hashSet.set
.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterCommunitiesByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -42,8 +42,8 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
fun makeContentDVMsFilter(
feedSettings: IFeedTopNavPerRelayFilterSet,
since: SincePerRelayMap?,
): List<RelayBasedFilter> {
return when (feedSettings) {
): List<RelayBasedFilter> =
when (feedSettings) {
is AllCommunitiesTopNavPerRelayFilterSet -> filterContentDVMsByAllCommunities(feedSettings, since)
is AllFollowsByOutboxTopNavPerRelayFilterSet -> filterContentDVMsByFollows(feedSettings, since)
is AuthorsByOutboxTopNavPerRelayFilterSet -> filterContentDVMsByAuthors(feedSettings, since)
@@ -54,4 +54,3 @@ fun makeContentDVMsFilter(
is SingleCommunityTopNavPerRelayFilterSet -> filterContentDVMsByCommunity(feedSettings, since)
else -> emptyList()
}
}
@@ -75,11 +75,12 @@ fun filterContentDVMsByAllCommunities(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterContentDVMsAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterContentDVMsAllCommunities(
relay = it.key,
communities = it.value.communities,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -61,17 +61,18 @@ fun filterContentDVMsByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterContentDVMsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterContentDVMsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
fun filterContentDVMsByAuthors(
@@ -82,15 +83,16 @@ fun filterContentDVMsByAuthors(
val defaultSince = TimeUtils.oneWeekAgo()
return authorSet.set.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterContentDVMsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return authorSet.set
.mapNotNull {
if (it.value.authors.isEmpty()) {
null
} else {
filterContentDVMsAuthors(
relay = it.key,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -77,12 +77,13 @@ fun filterContentDVMsByCommunity(
val defaultSince = TimeUtils.oneWeekAgo()
return communitySet.set.mapNotNull {
filterContentDVMsByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
return communitySet.set
.mapNotNull {
filterContentDVMsByCommunity(
relay = it.key,
community = it.value.community,
authors = it.value.authors,
since = since?.get(it.key)?.time ?: defaultSince,
)
}.flatten()
}
@@ -60,15 +60,16 @@ fun filterContentDVMsByGeohash(
val defaultSince = TimeUtils.oneWeekAgo()
return geoSet.set.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterContentDVMsByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
return geoSet.set
.mapNotNull {
if (it.value.geotags.isEmpty()) {
null
} else {
filterContentDVMsByGeohash(
relay = it.key,
geotags = it.value.geotags,
since = since?.get(it.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -61,15 +61,16 @@ fun filterContentDVMsByHashtag(
val defaultSince = TimeUtils.oneWeekAgo()
return hashSet.set.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterContentDVMsByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
return hashSet.set
.mapNotNull { relayHashSet ->
if (relayHashSet.value.hashtags.isEmpty()) {
null
} else {
filterContentDVMsByHashtag(
relay = relayHashSet.key,
hashtags = relayHashSet.value.hashtags,
since = since?.get(relayHashSet.key)?.time ?: defaultSince,
)
}
}.flatten()
}
@@ -475,7 +475,9 @@ open class NewProductViewModel :
fun reloadRelaySet() {
val account = accountViewModel?.account ?: return
relayList = account.outboxRelays.flow.value.toImmutableList()
relayList =
account.outboxRelays.flow.value
.toImmutableList()
}
fun deleteMediaToUpload(selected: SelectedMediaProcessing) {

Some files were not shown because too many files have changed in this diff Show More