Migrates to use suspending routines for OTS, statuses and edits

This commit is contained in:
Vitor Pamplona
2025-09-02 19:20:44 -04:00
parent c46cf79501
commit c64e65ddb4
3 changed files with 28 additions and 46 deletions

View File

@@ -129,7 +129,7 @@ fun LoadOts(
val noteStatus by observeNoteOts(note, accountViewModel)
LaunchedEffect(key1 = noteStatus) {
accountViewModel.findOtsEventsForNote(noteStatus?.note ?: note) { newOts ->
val newOts = accountViewModel.findOtsEventsForNote(noteStatus?.note ?: note)
earliestDate =
if (newOts == null) {
GenericLoadable.Empty()
@@ -137,7 +137,6 @@ fun LoadOts(
GenericLoadable.Loaded(newOts)
}
}
}
(earliestDate as? GenericLoadable.Loaded)?.let {
whenConfirmed(it.loaded)

View File

@@ -1230,7 +1230,7 @@ fun observeEdits(
LaunchedEffect(key1 = updatedNote) {
updatedNote?.note?.let {
accountViewModel.findModificationEventsForNote(it) { newModifications ->
val newModifications = accountViewModel.findModificationEventsForNote(it)
if (newModifications.isEmpty()) {
if (editState.value !is GenericLoadable.Empty) {
editState.value = GenericLoadable.Empty()
@@ -1246,7 +1246,6 @@ fun observeEdits(
}
}
}
}
return editState
}

View File

@@ -1026,37 +1026,21 @@ 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(
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(
suspend fun findModificationEventsForNote(note: Note): List<Note> =
withContext(Dispatchers.Default) {
LocalCache.findLatestModificationForNote(note)
},
)
}
fun checkGetOrCreatePublicChatChannel(key: HexKey): PublicChatChannel? = LocalCache.getOrCreatePublicChatChannel(key)