mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 20:36:45 +01:00
Migrates to use suspending routines for OTS, statuses and edits
This commit is contained in:
@@ -129,14 +129,13 @@ fun LoadOts(
|
||||
val noteStatus by observeNoteOts(note, accountViewModel)
|
||||
|
||||
LaunchedEffect(key1 = noteStatus) {
|
||||
accountViewModel.findOtsEventsForNote(noteStatus?.note ?: note) { newOts ->
|
||||
earliestDate =
|
||||
if (newOts == null) {
|
||||
GenericLoadable.Empty()
|
||||
} else {
|
||||
GenericLoadable.Loaded(newOts)
|
||||
}
|
||||
}
|
||||
val newOts = accountViewModel.findOtsEventsForNote(noteStatus?.note ?: note)
|
||||
earliestDate =
|
||||
if (newOts == null) {
|
||||
GenericLoadable.Empty()
|
||||
} else {
|
||||
GenericLoadable.Loaded(newOts)
|
||||
}
|
||||
}
|
||||
|
||||
(earliestDate as? GenericLoadable.Loaded)?.let {
|
||||
|
||||
@@ -1230,19 +1230,18 @@ fun observeEdits(
|
||||
|
||||
LaunchedEffect(key1 = updatedNote) {
|
||||
updatedNote?.note?.let {
|
||||
accountViewModel.findModificationEventsForNote(it) { newModifications ->
|
||||
if (newModifications.isEmpty()) {
|
||||
if (editState.value !is GenericLoadable.Empty) {
|
||||
editState.value = GenericLoadable.Empty()
|
||||
}
|
||||
val newModifications = accountViewModel.findModificationEventsForNote(it)
|
||||
if (newModifications.isEmpty()) {
|
||||
if (editState.value !is GenericLoadable.Empty) {
|
||||
editState.value = GenericLoadable.Empty()
|
||||
}
|
||||
} else {
|
||||
if (editState.value is GenericLoadable.Loaded) {
|
||||
(editState.value as? GenericLoadable.Loaded<EditState>)?.loaded?.updateModifications(newModifications)
|
||||
} else {
|
||||
if (editState.value is GenericLoadable.Loaded) {
|
||||
(editState.value as? GenericLoadable.Loaded<EditState>)?.loaded?.updateModifications(newModifications)
|
||||
} else {
|
||||
val state = EditState()
|
||||
state.updateModifications(newModifications)
|
||||
editState.value = GenericLoadable.Loaded(state)
|
||||
}
|
||||
val state = EditState()
|
||||
state.updateModifications(newModifications)
|
||||
editState.value = GenericLoadable.Loaded(state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1026,38 +1026,22 @@ class AccountViewModel(
|
||||
|
||||
fun getAddressableNoteIfExists(key: Address): AddressableNote? = LocalCache.getAddressableNoteIfExists(key)
|
||||
|
||||
suspend fun findStatusesForUser(
|
||||
myUser: User,
|
||||
onResult: (ImmutableList<AddressableNote>) -> Unit,
|
||||
) {
|
||||
suspend fun findStatusesForUser(myUser: User) =
|
||||
withContext(Dispatchers.IO) {
|
||||
onResult(LocalCache.findStatusesForUser(myUser))
|
||||
LocalCache.findStatusesForUser(myUser)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun findOtsEventsForNote(
|
||||
note: Note,
|
||||
onResult: (Long?) -> Unit,
|
||||
) {
|
||||
onResult(
|
||||
withContext(Dispatchers.Default) {
|
||||
LocalCache.findEarliestOtsForNote(note, account.otsResolverBuilder)
|
||||
},
|
||||
)
|
||||
}
|
||||
suspend fun findOtsEventsForNote(note: Note) =
|
||||
withContext(Dispatchers.Default) {
|
||||
LocalCache.findEarliestOtsForNote(note, account.otsResolverBuilder)
|
||||
}
|
||||
|
||||
fun cachedModificationEventsForNote(note: Note) = LocalCache.cachedModificationEventsForNote(note)
|
||||
|
||||
suspend fun findModificationEventsForNote(
|
||||
note: Note,
|
||||
onResult: (List<Note>) -> Unit,
|
||||
) {
|
||||
onResult(
|
||||
withContext(Dispatchers.Default) {
|
||||
LocalCache.findLatestModificationForNote(note)
|
||||
},
|
||||
)
|
||||
}
|
||||
suspend fun findModificationEventsForNote(note: Note): List<Note> =
|
||||
withContext(Dispatchers.Default) {
|
||||
LocalCache.findLatestModificationForNote(note)
|
||||
}
|
||||
|
||||
fun checkGetOrCreatePublicChatChannel(key: HexKey): PublicChatChannel? = LocalCache.getOrCreatePublicChatChannel(key)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user