Creates an additional pointer for Account lists to make sure the GC doesn't clear instances that are only stored in the LocalCache's WeakReference DB.
This commit is contained in:
@@ -399,18 +399,6 @@ class Account(
|
|||||||
|
|
||||||
val liveNotificationFollowListsPerRelay = OutboxLoaderState(liveNotificationFollowLists, cache, scope).flow
|
val liveNotificationFollowListsPerRelay = OutboxLoaderState(liveNotificationFollowLists, cache, scope).flow
|
||||||
|
|
||||||
/*
|
|
||||||
val mergedTopFeedAuthorLists =
|
|
||||||
MergedTopFeedAuthorListsState(
|
|
||||||
liveHomeFollowListsPerRelay,
|
|
||||||
liveStoriesFollowListsPerRelay,
|
|
||||||
liveDiscoveryFollowListsPerRelay,
|
|
||||||
liveNotificationFollowListsPerRelay,
|
|
||||||
scope,
|
|
||||||
).flow
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
fun isWriteable(): Boolean = settings.isWriteable()
|
fun isWriteable(): Boolean = settings.isWriteable()
|
||||||
|
|
||||||
suspend fun updateWarnReports(warnReports: Boolean): Boolean {
|
suspend fun updateWarnReports(warnReports: Boolean): Boolean {
|
||||||
|
|||||||
+6
-6
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.edits
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -48,13 +47,14 @@ class PrivateStorageRelayListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val privateOutboxListNote = cache.getOrCreateAddressableNote(getPrivateOutboxRelayListAddress())
|
||||||
|
|
||||||
fun getPrivateOutboxRelayListAddress() = PrivateOutboxRelayListEvent.createAddress(signer.pubKey)
|
fun getPrivateOutboxRelayListAddress() = PrivateOutboxRelayListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getPrivateOutboxRelayListNote(): AddressableNote = LocalCache.getOrCreateAddressableNote(getPrivateOutboxRelayListAddress())
|
fun getPrivateOutboxRelayListFlow(): StateFlow<NoteState> = privateOutboxListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getPrivateOutboxRelayListFlow(): StateFlow<NoteState> = getPrivateOutboxRelayListNote().flow().metadata.stateFlow
|
fun getPrivateOutboxRelayList(): PrivateOutboxRelayListEvent? = privateOutboxListNote.event as? PrivateOutboxRelayListEvent
|
||||||
|
|
||||||
fun getPrivateOutboxRelayList(): PrivateOutboxRelayListEvent? = getPrivateOutboxRelayListNote().event as? PrivateOutboxRelayListEvent
|
|
||||||
|
|
||||||
suspend fun normalizePrivateOutboxRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
suspend fun normalizePrivateOutboxRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||||
val event = note.event as? PrivateOutboxRelayListEvent ?: settings.backupPrivateHomeRelayList
|
val event = note.event as? PrivateOutboxRelayListEvent ?: settings.backupPrivateHomeRelayList
|
||||||
@@ -65,7 +65,7 @@ class PrivateStorageRelayListState(
|
|||||||
getPrivateOutboxRelayListFlow()
|
getPrivateOutboxRelayListFlow()
|
||||||
.map { normalizePrivateOutboxRelayListWithBackup(it.note) }
|
.map { normalizePrivateOutboxRelayListWithBackup(it.note) }
|
||||||
.onStart {
|
.onStart {
|
||||||
emit(normalizePrivateOutboxRelayListWithBackup(getPrivateOutboxRelayListNote()))
|
emit(normalizePrivateOutboxRelayListWithBackup(privateOutboxListNote))
|
||||||
}.flowOn(Dispatchers.Default)
|
}.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.emphChat
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -49,13 +48,14 @@ class EphemeralChatListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val ephemeralChatListNote = cache.getOrCreateAddressableNote(getEphemeralChatListAddress())
|
||||||
|
|
||||||
fun getEphemeralChatListAddress() = EphemeralChatListEvent.createAddress(signer.pubKey)
|
fun getEphemeralChatListAddress() = EphemeralChatListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getEphemeralChatListNote(): AddressableNote = cache.getOrCreateAddressableNote(getEphemeralChatListAddress())
|
fun getEphemeralChatListFlow(): StateFlow<NoteState> = ephemeralChatListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getEphemeralChatListFlow(): StateFlow<NoteState> = getEphemeralChatListNote().flow().metadata.stateFlow
|
fun getEphemeralChatList(): EphemeralChatListEvent? = ephemeralChatListNote.event as? EphemeralChatListEvent
|
||||||
|
|
||||||
fun getEphemeralChatList(): EphemeralChatListEvent? = getEphemeralChatListNote().event as? EphemeralChatListEvent
|
|
||||||
|
|
||||||
suspend fun ephemeralChatListWithBackup(note: Note): Set<RoomId> {
|
suspend fun ephemeralChatListWithBackup(note: Note): Set<RoomId> {
|
||||||
val event = note.event as? EphemeralChatListEvent ?: settings.backupEphemeralChatList
|
val event = note.event as? EphemeralChatListEvent ?: settings.backupEphemeralChatList
|
||||||
@@ -68,7 +68,7 @@ class EphemeralChatListState(
|
|||||||
.transformLatest { noteState ->
|
.transformLatest { noteState ->
|
||||||
emit(ephemeralChatListWithBackup(noteState.note))
|
emit(ephemeralChatListWithBackup(noteState.note))
|
||||||
}.onStart {
|
}.onStart {
|
||||||
emit(ephemeralChatListWithBackup(getEphemeralChatListNote()))
|
emit(ephemeralChatListWithBackup(ephemeralChatListNote))
|
||||||
}.flowOn(Dispatchers.Default)
|
}.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+4
-5
@@ -51,13 +51,12 @@ class FollowListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
// fun getEphemeralChatListAddress() = cache.getOrCreateUser(signer.pubKey)
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val user = cache.getOrCreateUser(signer.pubKey)
|
||||||
|
|
||||||
fun getFollowListUser(): User = cache.getOrCreateUser(signer.pubKey)
|
fun getFollowListFlow(): StateFlow<UserState> = user.flow().follows.stateFlow
|
||||||
|
|
||||||
fun getFollowListFlow(): StateFlow<UserState> = getFollowListUser().flow().follows.stateFlow
|
fun getFollowListEvent(): ContactListEvent? = user.latestContactList
|
||||||
|
|
||||||
fun getFollowListEvent(): ContactListEvent? = getFollowListUser().latestContactList
|
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
private val innerFlow: Flow<Kind3Follows> =
|
private val innerFlow: Flow<Kind3Follows> =
|
||||||
|
|||||||
+6
-6
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.nip17Dms
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -47,13 +46,14 @@ class DmRelayListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val dmListNote = cache.getOrCreateAddressableNote(getDMRelayListAddress())
|
||||||
|
|
||||||
fun getDMRelayListAddress() = ChatMessageRelayListEvent.createAddress(signer.pubKey)
|
fun getDMRelayListAddress() = ChatMessageRelayListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getDMRelayListNote(): AddressableNote = LocalCache.getOrCreateAddressableNote(getDMRelayListAddress())
|
fun getDMRelayListFlow(): StateFlow<NoteState> = dmListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getDMRelayListFlow(): StateFlow<NoteState> = getDMRelayListNote().flow().metadata.stateFlow
|
fun getDMRelayList(): ChatMessageRelayListEvent? = dmListNote.event as? ChatMessageRelayListEvent
|
||||||
|
|
||||||
fun getDMRelayList(): ChatMessageRelayListEvent? = getDMRelayListNote().event as? ChatMessageRelayListEvent
|
|
||||||
|
|
||||||
fun normalizeDMRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
fun normalizeDMRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||||
val event = note.event as? ChatMessageRelayListEvent ?: settings.backupDMRelayList
|
val event = note.event as? ChatMessageRelayListEvent ?: settings.backupDMRelayList
|
||||||
@@ -63,7 +63,7 @@ class DmRelayListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getDMRelayListFlow()
|
getDMRelayListFlow()
|
||||||
.map { normalizeDMRelayListWithBackup(it.note) }
|
.map { normalizeDMRelayListWithBackup(it.note) }
|
||||||
.onStart { emit(normalizeDMRelayListWithBackup(getDMRelayListNote())) }
|
.onStart { emit(normalizeDMRelayListWithBackup(dmListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.nip28PublicChats
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -51,13 +50,14 @@ class PublicChatListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val publicChatListNote = cache.getOrCreateAddressableNote(getChannelListAddress())
|
||||||
|
|
||||||
fun getChannelListAddress() = ChannelListEvent.createAddress(signer.pubKey)
|
fun getChannelListAddress() = ChannelListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getChannelListNote(): AddressableNote = cache.getOrCreateAddressableNote(getChannelListAddress())
|
fun getChannelListFlow(): StateFlow<NoteState> = publicChatListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getChannelListFlow(): StateFlow<NoteState> = getChannelListNote().flow().metadata.stateFlow
|
fun getChannelList(): ChannelListEvent? = publicChatListNote.event as? ChannelListEvent
|
||||||
|
|
||||||
fun getChannelList(): ChannelListEvent? = getChannelListNote().event as? ChannelListEvent
|
|
||||||
|
|
||||||
suspend fun publicChatListWithBackup(note: Note): Set<ChannelTag> {
|
suspend fun publicChatListWithBackup(note: Note): Set<ChannelTag> {
|
||||||
val event = note.event as? ChannelListEvent ?: settings.backupChannelList
|
val event = note.event as? ChannelListEvent ?: settings.backupChannelList
|
||||||
@@ -70,7 +70,7 @@ class PublicChatListState(
|
|||||||
.transformLatest { noteState ->
|
.transformLatest { noteState ->
|
||||||
emit(publicChatListWithBackup(noteState.note))
|
emit(publicChatListWithBackup(noteState.note))
|
||||||
}.onStart {
|
}.onStart {
|
||||||
emit(publicChatListWithBackup(getChannelListNote()))
|
emit(publicChatListWithBackup(publicChatListNote))
|
||||||
}.flowOn(Dispatchers.Default)
|
}.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+5
-5
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.amethyst.model.nip30CustomEmojis
|
package com.vitorpamplona.amethyst.model.nip30CustomEmojis
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.commons.richtext.MediaUrlImage
|
import com.vitorpamplona.amethyst.commons.richtext.MediaUrlImage
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -52,13 +51,14 @@ class EmojiPackState(
|
|||||||
val link: MediaUrlImage,
|
val link: MediaUrlImage,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val emojiPackListNote = cache.getOrCreateAddressableNote(getEmojiPackSelectionAddress())
|
||||||
|
|
||||||
fun getEmojiPackSelectionAddress() = EmojiPackSelectionEvent.createAddress(signer.pubKey)
|
fun getEmojiPackSelectionAddress() = EmojiPackSelectionEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getEmojiPackSelection(): EmojiPackSelectionEvent? = getEmojiPackSelectionNote().event as? EmojiPackSelectionEvent
|
fun getEmojiPackSelection(): EmojiPackSelectionEvent? = emojiPackListNote.event as? EmojiPackSelectionEvent
|
||||||
|
|
||||||
fun getEmojiPackSelectionFlow(): StateFlow<NoteState> = getEmojiPackSelectionNote().flow().metadata.stateFlow
|
fun getEmojiPackSelectionFlow(): StateFlow<NoteState> = emojiPackListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getEmojiPackSelectionNote(): AddressableNote = cache.getOrCreateAddressableNote(getEmojiPackSelectionAddress())
|
|
||||||
|
|
||||||
fun convertEmojiSelectionPack(selection: EmojiPackSelectionEvent?): List<StateFlow<NoteState>>? =
|
fun convertEmojiSelectionPack(selection: EmojiPackSelectionEvent?): List<StateFlow<NoteState>>? =
|
||||||
selection?.taggedAddresses()?.map {
|
selection?.taggedAddresses()?.map {
|
||||||
|
|||||||
+7
-6
@@ -51,13 +51,14 @@ class BookmarkListState(
|
|||||||
val private: List<Note> = emptyList(),
|
val private: List<Note> = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val bookmarkList = cache.getOrCreateAddressableNote(getBookmarkListAddress())
|
||||||
|
|
||||||
fun getBookmarkListAddress() = BookmarkListEvent.createBookmarkAddress(signer.pubKey)
|
fun getBookmarkListAddress() = BookmarkListEvent.createBookmarkAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getBookmarkListNote() = cache.getOrCreateAddressableNote(getBookmarkListAddress())
|
fun getBookmarkListFlow(): StateFlow<NoteState> = bookmarkList.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getBookmarkListFlow(): StateFlow<NoteState> = getBookmarkListNote().flow().metadata.stateFlow
|
fun getBookmarkList(): BookmarkListEvent? = bookmarkList.event as? BookmarkListEvent
|
||||||
|
|
||||||
fun getBookmarkList(): BookmarkListEvent? = getBookmarkListNote().event as? BookmarkListEvent
|
|
||||||
|
|
||||||
suspend fun publicBookmarks(note: Note): List<BookmarkIdTag> {
|
suspend fun publicBookmarks(note: Note): List<BookmarkIdTag> {
|
||||||
val noteEvent = note.event as? BookmarkListEvent
|
val noteEvent = note.event as? BookmarkListEvent
|
||||||
@@ -75,7 +76,7 @@ class BookmarkListState(
|
|||||||
.map { noteState ->
|
.map { noteState ->
|
||||||
publicBookmarks(noteState.note)
|
publicBookmarks(noteState.note)
|
||||||
}.onStart {
|
}.onStart {
|
||||||
emit(publicBookmarks(getBookmarkListNote()))
|
emit(publicBookmarks(bookmarkList))
|
||||||
}.debounce(100)
|
}.debounce(100)
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
@@ -90,7 +91,7 @@ class BookmarkListState(
|
|||||||
.map { noteState ->
|
.map { noteState ->
|
||||||
privateBookmarks(noteState.note)
|
privateBookmarks(noteState.note)
|
||||||
}.onStart {
|
}.onStart {
|
||||||
emit(privateBookmarks(getBookmarkListNote()))
|
emit(privateBookmarks(bookmarkList))
|
||||||
}.debounce(100)
|
}.debounce(100)
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
|
|||||||
+6
-5
@@ -43,13 +43,14 @@ class BlockPeopleListState(
|
|||||||
val decryptionCache: PeopleListDecryptionCache,
|
val decryptionCache: PeopleListDecryptionCache,
|
||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val blockListNote = cache.getOrCreateAddressableNote(getBlockListAddress())
|
||||||
|
|
||||||
fun getBlockListAddress() = PeopleListEvent.createBlockAddress(signer.pubKey)
|
fun getBlockListAddress() = PeopleListEvent.createBlockAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getBlockListNote() = LocalCache.getOrCreateAddressableNote(getBlockListAddress())
|
fun getBlockListFlow(): StateFlow<NoteState> = blockListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getBlockListFlow(): StateFlow<NoteState> = getBlockListNote().flow().metadata.stateFlow
|
fun getBlockList(): PeopleListEvent? = blockListNote.event as? PeopleListEvent
|
||||||
|
|
||||||
fun getBlockList(): PeopleListEvent? = getBlockListNote().event as? PeopleListEvent
|
|
||||||
|
|
||||||
suspend fun blockListWithBackup(note: Note): List<MuteTag> {
|
suspend fun blockListWithBackup(note: Note): List<MuteTag> {
|
||||||
val event = note.event as? PeopleListEvent
|
val event = note.event as? PeopleListEvent
|
||||||
@@ -59,7 +60,7 @@ class BlockPeopleListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getBlockListFlow()
|
getBlockListFlow()
|
||||||
.map { blockListWithBackup(it.note) }
|
.map { blockListWithBackup(it.note) }
|
||||||
.onStart { emit(blockListWithBackup(getBlockListNote())) }
|
.onStart { emit(blockListWithBackup(blockListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.nip51Lists.blockedRelays
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -49,13 +48,14 @@ class BlockedRelayListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val blockedListNote = cache.getOrCreateAddressableNote(getBlockedRelayListAddress())
|
||||||
|
|
||||||
fun getBlockedRelayListAddress() = BlockedRelayListEvent.createAddress(signer.pubKey)
|
fun getBlockedRelayListAddress() = BlockedRelayListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getBlockedRelayListNote(): AddressableNote = LocalCache.getOrCreateAddressableNote(getBlockedRelayListAddress())
|
fun getBlockedRelayListFlow(): StateFlow<NoteState> = blockedListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getBlockedRelayListFlow(): StateFlow<NoteState> = getBlockedRelayListNote().flow().metadata.stateFlow
|
fun getBlockedRelayList(): BlockedRelayListEvent? = blockedListNote.event as? BlockedRelayListEvent
|
||||||
|
|
||||||
fun getBlockedRelayList(): BlockedRelayListEvent? = getBlockedRelayListNote().event as? BlockedRelayListEvent
|
|
||||||
|
|
||||||
suspend fun normalizeBlockedRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
suspend fun normalizeBlockedRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||||
val event = note.event as? BlockedRelayListEvent ?: settings.backupBlockedRelayList
|
val event = note.event as? BlockedRelayListEvent ?: settings.backupBlockedRelayList
|
||||||
@@ -66,7 +66,7 @@ class BlockedRelayListState(
|
|||||||
getBlockedRelayListFlow()
|
getBlockedRelayListFlow()
|
||||||
.map {
|
.map {
|
||||||
normalizeBlockedRelayListWithBackup(it.note)
|
normalizeBlockedRelayListWithBackup(it.note)
|
||||||
}.onStart { emit(normalizeBlockedRelayListWithBackup(getBlockedRelayListNote())) }
|
}.onStart { emit(normalizeBlockedRelayListWithBackup(blockedListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.amethyst.model.nip51Lists.broadcastRelays
|
package com.vitorpamplona.amethyst.model.nip51Lists.broadcastRelays
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -44,13 +43,14 @@ class BroadcastRelayListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val broadcastListNote = cache.getOrCreateAddressableNote(getBroadcastRelayListAddress())
|
||||||
|
|
||||||
fun getBroadcastRelayListAddress() = BroadcastRelayListEvent.createAddress(signer.pubKey)
|
fun getBroadcastRelayListAddress() = BroadcastRelayListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getBroadcastRelayListNote(): AddressableNote = cache.getOrCreateAddressableNote(getBroadcastRelayListAddress())
|
fun getBroadcastRelayListFlow(): StateFlow<NoteState> = broadcastListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getBroadcastRelayListFlow(): StateFlow<NoteState> = getBroadcastRelayListNote().flow().metadata.stateFlow
|
fun getBroadcastRelayList(): BroadcastRelayListEvent? = broadcastListNote.event as? BroadcastRelayListEvent
|
||||||
|
|
||||||
fun getBroadcastRelayList(): BroadcastRelayListEvent? = getBroadcastRelayListNote().event as? BroadcastRelayListEvent
|
|
||||||
|
|
||||||
suspend fun normalizeBroadcastRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
suspend fun normalizeBroadcastRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||||
val event = note.event as? BroadcastRelayListEvent
|
val event = note.event as? BroadcastRelayListEvent
|
||||||
@@ -60,7 +60,7 @@ class BroadcastRelayListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getBroadcastRelayListFlow()
|
getBroadcastRelayListFlow()
|
||||||
.map { normalizeBroadcastRelayListWithBackup(it.note) }
|
.map { normalizeBroadcastRelayListWithBackup(it.note) }
|
||||||
.onStart { emit(normalizeBroadcastRelayListWithBackup(getBroadcastRelayListNote())) }
|
.onStart { emit(normalizeBroadcastRelayListWithBackup(broadcastListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.nip51Lists.geohashLists
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -48,13 +47,14 @@ class GeohashListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val geohashListNote = cache.getOrCreateAddressableNote(getGeohashListAddress())
|
||||||
|
|
||||||
fun getGeohashListAddress() = GeohashListEvent.createAddress(signer.pubKey)
|
fun getGeohashListAddress() = GeohashListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getGeohashListNote(): AddressableNote = cache.getOrCreateAddressableNote(getGeohashListAddress())
|
fun getGeohashListFlow(): StateFlow<NoteState> = geohashListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getGeohashListFlow(): StateFlow<NoteState> = getGeohashListNote().flow().metadata.stateFlow
|
fun getGeohashList(): GeohashListEvent? = geohashListNote.event as? GeohashListEvent
|
||||||
|
|
||||||
fun getGeohashList(): GeohashListEvent? = getGeohashListNote().event as? GeohashListEvent
|
|
||||||
|
|
||||||
suspend fun geohashListWithBackup(note: Note): Set<String> {
|
suspend fun geohashListWithBackup(note: Note): Set<String> {
|
||||||
val event = note.event as? GeohashListEvent ?: settings.backupGeohashList
|
val event = note.event as? GeohashListEvent ?: settings.backupGeohashList
|
||||||
@@ -67,7 +67,7 @@ class GeohashListState(
|
|||||||
.transformLatest { noteState ->
|
.transformLatest { noteState ->
|
||||||
emit(geohashListWithBackup(noteState.note))
|
emit(geohashListWithBackup(noteState.note))
|
||||||
}.onStart {
|
}.onStart {
|
||||||
emit(geohashListWithBackup(getGeohashListNote()))
|
emit(geohashListWithBackup(geohashListNote))
|
||||||
}.flowOn(Dispatchers.Default)
|
}.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.nip51Lists.hashtagLists
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -48,13 +47,14 @@ class HashtagListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val hashtagListNote = cache.getOrCreateAddressableNote(getHashtagListAddress())
|
||||||
|
|
||||||
fun getHashtagListAddress() = HashtagListEvent.createAddress(signer.pubKey)
|
fun getHashtagListAddress() = HashtagListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getHashtagListNote(): AddressableNote = cache.getOrCreateAddressableNote(getHashtagListAddress())
|
fun getHashtagListFlow(): StateFlow<NoteState> = hashtagListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getHashtagListFlow(): StateFlow<NoteState> = getHashtagListNote().flow().metadata.stateFlow
|
fun getHashtagList(): HashtagListEvent? = hashtagListNote.event as? HashtagListEvent
|
||||||
|
|
||||||
fun getHashtagList(): HashtagListEvent? = getHashtagListNote().event as? HashtagListEvent
|
|
||||||
|
|
||||||
suspend fun hashtagListWithBackup(note: Note): Set<String> {
|
suspend fun hashtagListWithBackup(note: Note): Set<String> {
|
||||||
val event = note.event as? HashtagListEvent ?: settings.backupHashtagList
|
val event = note.event as? HashtagListEvent ?: settings.backupHashtagList
|
||||||
@@ -67,7 +67,7 @@ class HashtagListState(
|
|||||||
.transformLatest { noteState ->
|
.transformLatest { noteState ->
|
||||||
emit(hashtagListWithBackup(noteState.note))
|
emit(hashtagListWithBackup(noteState.note))
|
||||||
}.onStart {
|
}.onStart {
|
||||||
emit(hashtagListWithBackup(getHashtagListNote()))
|
emit(hashtagListWithBackup(hashtagListNote))
|
||||||
}.flowOn(Dispatchers.Default)
|
}.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.amethyst.model.nip51Lists.indexerRelays
|
package com.vitorpamplona.amethyst.model.nip51Lists.indexerRelays
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -45,13 +44,14 @@ class IndexerRelayListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val indexerListNote = cache.getOrCreateAddressableNote(getIndexerRelayListAddress())
|
||||||
|
|
||||||
fun getIndexerRelayListAddress() = IndexerRelayListEvent.createAddress(signer.pubKey)
|
fun getIndexerRelayListAddress() = IndexerRelayListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getIndexerRelayListNote(): AddressableNote = cache.getOrCreateAddressableNote(getIndexerRelayListAddress())
|
fun getIndexerRelayListFlow(): StateFlow<NoteState> = indexerListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getIndexerRelayListFlow(): StateFlow<NoteState> = getIndexerRelayListNote().flow().metadata.stateFlow
|
fun getIndexerRelayList(): IndexerRelayListEvent? = indexerListNote.event as? IndexerRelayListEvent
|
||||||
|
|
||||||
fun getIndexerRelayList(): IndexerRelayListEvent? = getIndexerRelayListNote().event as? IndexerRelayListEvent
|
|
||||||
|
|
||||||
suspend fun normalizeIndexerRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
suspend fun normalizeIndexerRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||||
val event = note.event as? IndexerRelayListEvent
|
val event = note.event as? IndexerRelayListEvent
|
||||||
@@ -61,7 +61,7 @@ class IndexerRelayListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getIndexerRelayListFlow()
|
getIndexerRelayListFlow()
|
||||||
.map { normalizeIndexerRelayListWithBackup(it.note) }
|
.map { normalizeIndexerRelayListWithBackup(it.note) }
|
||||||
.onStart { emit(normalizeIndexerRelayListWithBackup(getIndexerRelayListNote())) }
|
.onStart { emit(normalizeIndexerRelayListWithBackup(indexerListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-5
@@ -49,13 +49,14 @@ class MuteListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val muteListNote = cache.getOrCreateAddressableNote(getMuteListAddress())
|
||||||
|
|
||||||
fun getMuteListAddress() = MuteListEvent.createAddress(signer.pubKey)
|
fun getMuteListAddress() = MuteListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getMuteListNote() = cache.getOrCreateAddressableNote(getMuteListAddress())
|
fun getMuteListFlow(): StateFlow<NoteState> = muteListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getMuteListFlow(): StateFlow<NoteState> = getMuteListNote().flow().metadata.stateFlow
|
fun getMuteList(): MuteListEvent? = muteListNote.event as? MuteListEvent
|
||||||
|
|
||||||
fun getMuteList(): MuteListEvent? = getMuteListNote().event as? MuteListEvent
|
|
||||||
|
|
||||||
suspend fun muteListWithBackup(note: Note): List<MuteTag> {
|
suspend fun muteListWithBackup(note: Note): List<MuteTag> {
|
||||||
val event = note.event as? MuteListEvent ?: settings.backupMuteList
|
val event = note.event as? MuteListEvent ?: settings.backupMuteList
|
||||||
@@ -65,7 +66,7 @@ class MuteListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getMuteListFlow()
|
getMuteListFlow()
|
||||||
.map { muteListWithBackup(it.note) }
|
.map { muteListWithBackup(it.note) }
|
||||||
.onStart { emit(muteListWithBackup(getMuteListNote())) }
|
.onStart { emit(muteListWithBackup(muteListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.amethyst.model.nip51Lists.proxyRelays
|
package com.vitorpamplona.amethyst.model.nip51Lists.proxyRelays
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -44,13 +43,14 @@ class ProxyRelayListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val proxyListNote = cache.getOrCreateAddressableNote(getProxyRelayListAddress())
|
||||||
|
|
||||||
fun getProxyRelayListAddress() = ProxyRelayListEvent.createAddress(signer.pubKey)
|
fun getProxyRelayListAddress() = ProxyRelayListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getProxyRelayListNote(): AddressableNote = cache.getOrCreateAddressableNote(getProxyRelayListAddress())
|
fun getProxyRelayListFlow(): StateFlow<NoteState> = proxyListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getProxyRelayListFlow(): StateFlow<NoteState> = getProxyRelayListNote().flow().metadata.stateFlow
|
fun getProxyRelayList(): ProxyRelayListEvent? = proxyListNote.event as? ProxyRelayListEvent
|
||||||
|
|
||||||
fun getProxyRelayList(): ProxyRelayListEvent? = getProxyRelayListNote().event as? ProxyRelayListEvent
|
|
||||||
|
|
||||||
suspend fun normalizeProxyRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
suspend fun normalizeProxyRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||||
val event = note.event as? ProxyRelayListEvent
|
val event = note.event as? ProxyRelayListEvent
|
||||||
@@ -60,7 +60,7 @@ class ProxyRelayListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getProxyRelayListFlow()
|
getProxyRelayListFlow()
|
||||||
.map { normalizeProxyRelayListWithBackup(it.note) }
|
.map { normalizeProxyRelayListWithBackup(it.note) }
|
||||||
.onStart { emit(normalizeProxyRelayListWithBackup(getProxyRelayListNote())) }
|
.onStart { emit(normalizeProxyRelayListWithBackup(proxyListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+7
-7
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.nip51Lists.searchRelays
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.DefaultSearchRelayList
|
import com.vitorpamplona.amethyst.model.DefaultSearchRelayList
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
@@ -49,13 +48,14 @@ class SearchRelayListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val searchListNote = cache.getOrCreateAddressableNote(getSearchRelayListAddress())
|
||||||
|
|
||||||
fun getSearchRelayListAddress() = SearchRelayListEvent.Companion.createAddress(signer.pubKey)
|
fun getSearchRelayListAddress() = SearchRelayListEvent.Companion.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getSearchRelayListNote(): AddressableNote = LocalCache.getOrCreateAddressableNote(getSearchRelayListAddress())
|
fun getSearchRelayListFlow(): StateFlow<NoteState> = searchListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getSearchRelayListFlow(): StateFlow<NoteState> = getSearchRelayListNote().flow().metadata.stateFlow
|
fun getSearchRelayList(): SearchRelayListEvent? = searchListNote.event as? SearchRelayListEvent
|
||||||
|
|
||||||
fun getSearchRelayList(): SearchRelayListEvent? = getSearchRelayListNote().event as? SearchRelayListEvent
|
|
||||||
|
|
||||||
fun searchListEvent(note: Note) = note.event as? SearchRelayListEvent ?: settings.backupSearchRelayList
|
fun searchListEvent(note: Note) = note.event as? SearchRelayListEvent ?: settings.backupSearchRelayList
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ class SearchRelayListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getSearchRelayListFlow()
|
getSearchRelayListFlow()
|
||||||
.map { normalizeSearchRelayListWithBackup(it.note) }
|
.map { normalizeSearchRelayListWithBackup(it.note) }
|
||||||
.onStart { emit(normalizeSearchRelayListWithBackup(getSearchRelayListNote())) }
|
.onStart { emit(normalizeSearchRelayListWithBackup(searchListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
@@ -77,7 +77,7 @@ class SearchRelayListState(
|
|||||||
val flowNoDefaults =
|
val flowNoDefaults =
|
||||||
getSearchRelayListFlow()
|
getSearchRelayListFlow()
|
||||||
.map { normalizeSearchRelayListWithBackupNoDefaults(it.note) }
|
.map { normalizeSearchRelayListWithBackupNoDefaults(it.note) }
|
||||||
.onStart { emit(normalizeSearchRelayListWithBackupNoDefaults(getSearchRelayListNote())) }
|
.onStart { emit(normalizeSearchRelayListWithBackupNoDefaults(searchListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.nip51Lists.trustedRelays
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -48,13 +47,14 @@ class TrustedRelayListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
fun getTrustedRelayListAddress() = TrustedRelayListEvent.Companion.createAddress(signer.pubKey)
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val trustedListNote = cache.getOrCreateAddressableNote(getTrustedRelayListAddress())
|
||||||
|
|
||||||
fun getTrustedRelayListNote(): AddressableNote = cache.getOrCreateAddressableNote(getTrustedRelayListAddress())
|
fun getTrustedRelayListAddress() = TrustedRelayListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getTrustedRelayListFlow(): StateFlow<NoteState> = getTrustedRelayListNote().flow().metadata.stateFlow
|
fun getTrustedRelayListFlow(): StateFlow<NoteState> = trustedListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getTrustedRelayList(): TrustedRelayListEvent? = getTrustedRelayListNote().event as? TrustedRelayListEvent
|
fun getTrustedRelayList(): TrustedRelayListEvent? = trustedListNote.event as? TrustedRelayListEvent
|
||||||
|
|
||||||
suspend fun normalizeTrustedRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
suspend fun normalizeTrustedRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||||
val event = note.event as? TrustedRelayListEvent ?: settings.backupTrustedRelayList
|
val event = note.event as? TrustedRelayListEvent ?: settings.backupTrustedRelayList
|
||||||
@@ -64,7 +64,7 @@ class TrustedRelayListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getTrustedRelayListFlow()
|
getTrustedRelayListFlow()
|
||||||
.map { normalizeTrustedRelayListWithBackup(it.note) }
|
.map { normalizeTrustedRelayListWithBackup(it.note) }
|
||||||
.onStart { emit(normalizeTrustedRelayListWithBackup(getTrustedRelayListNote())) }
|
.onStart { emit(normalizeTrustedRelayListWithBackup(trustedListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+8
-8
@@ -22,7 +22,6 @@ package com.vitorpamplona.amethyst.model.nip65RelayList
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.Constants
|
import com.vitorpamplona.amethyst.model.Constants
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
@@ -49,13 +48,14 @@ class Nip65RelayListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val nip65ListNote = cache.getOrCreateAddressableNote(getNIP65RelayListAddress())
|
||||||
|
|
||||||
fun getNIP65RelayListAddress() = AdvertisedRelayListEvent.createAddress(signer.pubKey)
|
fun getNIP65RelayListAddress() = AdvertisedRelayListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getNIP65RelayListNote(): AddressableNote = cache.getOrCreateAddressableNote(getNIP65RelayListAddress())
|
fun getNIP65RelayListFlow(): StateFlow<NoteState> = nip65ListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getNIP65RelayListFlow(): StateFlow<NoteState> = getNIP65RelayListNote().flow().metadata.stateFlow
|
fun getNIP65RelayList(): AdvertisedRelayListEvent? = nip65ListNote.event as? AdvertisedRelayListEvent
|
||||||
|
|
||||||
fun getNIP65RelayList(): AdvertisedRelayListEvent? = getNIP65RelayListNote().event as? AdvertisedRelayListEvent
|
|
||||||
|
|
||||||
fun nip65Event(note: Note) = note.event as? AdvertisedRelayListEvent ?: settings.backupNIP65RelayList
|
fun nip65Event(note: Note) = note.event as? AdvertisedRelayListEvent ?: settings.backupNIP65RelayList
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ class Nip65RelayListState(
|
|||||||
val outboxFlow =
|
val outboxFlow =
|
||||||
getNIP65RelayListFlow()
|
getNIP65RelayListFlow()
|
||||||
.map { normalizeNIP65WriteRelayListWithBackup(it.note) }
|
.map { normalizeNIP65WriteRelayListWithBackup(it.note) }
|
||||||
.onStart { emit(normalizeNIP65ReadRelayListWithBackup(getNIP65RelayListNote())) }
|
.onStart { emit(normalizeNIP65ReadRelayListWithBackup(nip65ListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
@@ -81,7 +81,7 @@ class Nip65RelayListState(
|
|||||||
val inboxFlow =
|
val inboxFlow =
|
||||||
getNIP65RelayListFlow()
|
getNIP65RelayListFlow()
|
||||||
.map { normalizeNIP65ReadRelayListWithBackup(it.note) }
|
.map { normalizeNIP65ReadRelayListWithBackup(it.note) }
|
||||||
.onStart { emit(normalizeNIP65ReadRelayListWithBackup(getNIP65RelayListNote())) }
|
.onStart { emit(normalizeNIP65ReadRelayListWithBackup(nip65ListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
@@ -92,7 +92,7 @@ class Nip65RelayListState(
|
|||||||
val allFlowNoDefaults =
|
val allFlowNoDefaults =
|
||||||
getNIP65RelayListFlow()
|
getNIP65RelayListFlow()
|
||||||
.map { normalizeNIP65AllRelayListWithBackupNoDefaults(it.note) }
|
.map { normalizeNIP65AllRelayListWithBackupNoDefaults(it.note) }
|
||||||
.onStart { emit(normalizeNIP65AllRelayListWithBackupNoDefaults(getNIP65RelayListNote())) }
|
.onStart { emit(normalizeNIP65AllRelayListWithBackupNoDefaults(nip65ListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-5
@@ -51,13 +51,14 @@ class CommunityListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val communityListNote = cache.getOrCreateAddressableNote(getCommunityListAddress())
|
||||||
|
|
||||||
fun getCommunityListAddress() = CommunityListEvent.createAddress(signer.pubKey)
|
fun getCommunityListAddress() = CommunityListEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getCommunityListNote(): AddressableNote = cache.getOrCreateAddressableNote(getCommunityListAddress())
|
fun getCommunityListFlow(): StateFlow<NoteState> = communityListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getCommunityListFlow(): StateFlow<NoteState> = getCommunityListNote().flow().metadata.stateFlow
|
fun getCommunityList(): CommunityListEvent? = communityListNote.event as? CommunityListEvent
|
||||||
|
|
||||||
fun getCommunityList(): CommunityListEvent? = getCommunityListNote().event as? CommunityListEvent
|
|
||||||
|
|
||||||
suspend fun communityListWithBackup(note: Note): Set<CommunityTag> {
|
suspend fun communityListWithBackup(note: Note): Set<CommunityTag> {
|
||||||
val event = note.event as? CommunityListEvent ?: settings.backupCommunityList
|
val event = note.event as? CommunityListEvent ?: settings.backupCommunityList
|
||||||
@@ -70,7 +71,7 @@ class CommunityListState(
|
|||||||
.transformLatest { noteState ->
|
.transformLatest { noteState ->
|
||||||
emit(communityListWithBackup(noteState.note))
|
emit(communityListWithBackup(noteState.note))
|
||||||
}.onStart {
|
}.onStart {
|
||||||
emit(communityListWithBackup(getCommunityListNote()))
|
emit(communityListWithBackup(communityListNote))
|
||||||
}.flowOn(Dispatchers.Default)
|
}.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+4
-3
@@ -47,11 +47,12 @@ class AppSpecificState(
|
|||||||
const val APP_SPECIFIC_DATA_D_TAG = "AmethystSettings"
|
const val APP_SPECIFIC_DATA_D_TAG = "AmethystSettings"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val amethystSettingsNote = cache.getOrCreateAddressableNote(getAppSpecificDataAddress())
|
||||||
|
|
||||||
fun getAppSpecificDataAddress() = AppSpecificDataEvent.createAddress(signer.pubKey, APP_SPECIFIC_DATA_D_TAG)
|
fun getAppSpecificDataAddress() = AppSpecificDataEvent.createAddress(signer.pubKey, APP_SPECIFIC_DATA_D_TAG)
|
||||||
|
|
||||||
fun getAppSpecificDataNote() = cache.getOrCreateAddressableNote(getAppSpecificDataAddress())
|
fun getAppSpecificDataFlow(): StateFlow<NoteState> = amethystSettingsNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getAppSpecificDataFlow(): StateFlow<NoteState> = getAppSpecificDataNote().flow().metadata.stateFlow
|
|
||||||
|
|
||||||
suspend fun saveNewAppSpecificData(): AppSpecificDataEvent {
|
suspend fun saveNewAppSpecificData(): AppSpecificDataEvent {
|
||||||
val toInternal = settings.syncedSettings.toInternal()
|
val toInternal = settings.syncedSettings.toInternal()
|
||||||
|
|||||||
+6
-6
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.amethyst.model.nip96FileStorage
|
package com.vitorpamplona.amethyst.model.nip96FileStorage
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -42,13 +41,14 @@ class FileStorageServerListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val fileStorageListNote = cache.getOrCreateAddressableNote(getFileServersAddress())
|
||||||
|
|
||||||
fun getFileServersAddress() = FileServersEvent.createAddress(signer.pubKey)
|
fun getFileServersAddress() = FileServersEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getFileServersNote(): AddressableNote = LocalCache.getOrCreateAddressableNote(getFileServersAddress())
|
fun getFileServersListFlow(): StateFlow<NoteState> = fileStorageListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getFileServersListFlow(): StateFlow<NoteState> = getFileServersNote().flow().metadata.stateFlow
|
fun getFileServersList(): FileServersEvent? = fileStorageListNote.event as? FileServersEvent
|
||||||
|
|
||||||
fun getFileServersList(): FileServersEvent? = getFileServersNote().event as? FileServersEvent
|
|
||||||
|
|
||||||
fun normalizeServers(note: Note): List<String> {
|
fun normalizeServers(note: Note): List<String> {
|
||||||
val event = note.event as? FileServersEvent
|
val event = note.event as? FileServersEvent
|
||||||
@@ -58,7 +58,7 @@ class FileStorageServerListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getFileServersListFlow()
|
getFileServersListFlow()
|
||||||
.map { normalizeServers(it.note) }
|
.map { normalizeServers(it.note) }
|
||||||
.onStart { emit(normalizeServers(getFileServersNote())) }
|
.onStart { emit(normalizeServers(fileStorageListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
+6
-6
@@ -21,7 +21,6 @@
|
|||||||
package com.vitorpamplona.amethyst.model.nipB7Blossom
|
package com.vitorpamplona.amethyst.model.nipB7Blossom
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.NoteState
|
import com.vitorpamplona.amethyst.model.NoteState
|
||||||
@@ -44,13 +43,14 @@ class BlossomServerListState(
|
|||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
val settings: AccountSettings,
|
val settings: AccountSettings,
|
||||||
) {
|
) {
|
||||||
|
// Creates a long-term reference for this note so that the GC doesn't collect the note it self
|
||||||
|
val blossomListNote = cache.getOrCreateAddressableNote(getBlossomServersAddress())
|
||||||
|
|
||||||
fun getBlossomServersAddress() = BlossomServersEvent.createAddress(signer.pubKey)
|
fun getBlossomServersAddress() = BlossomServersEvent.createAddress(signer.pubKey)
|
||||||
|
|
||||||
fun getBlossomServersNote(): AddressableNote = cache.getOrCreateAddressableNote(getBlossomServersAddress())
|
fun getBlossomServersListFlow(): StateFlow<NoteState> = blossomListNote.flow().metadata.stateFlow
|
||||||
|
|
||||||
fun getBlossomServersListFlow(): StateFlow<NoteState> = getBlossomServersNote().flow().metadata.stateFlow
|
fun getBlossomServersList(): BlossomServersEvent? = blossomListNote.event as? BlossomServersEvent
|
||||||
|
|
||||||
fun getBlossomServersList(): BlossomServersEvent? = getBlossomServersNote().event as? BlossomServersEvent
|
|
||||||
|
|
||||||
fun normalizeServers(note: Note): List<String> {
|
fun normalizeServers(note: Note): List<String> {
|
||||||
val event = note.event as? BlossomServersEvent
|
val event = note.event as? BlossomServersEvent
|
||||||
@@ -60,7 +60,7 @@ class BlossomServerListState(
|
|||||||
val flow =
|
val flow =
|
||||||
getBlossomServersListFlow()
|
getBlossomServersListFlow()
|
||||||
.map { normalizeServers(it.note) }
|
.map { normalizeServers(it.note) }
|
||||||
.onStart { emit(normalizeServers(getBlossomServersNote())) }
|
.onStart { emit(normalizeServers(blossomListNote)) }
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
Reference in New Issue
Block a user