Skip to content

Commit

Permalink
feat: DBからロードが終わるまではメモリ上で検索した結果を返すようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Oct 16, 2023
1 parent d16e91e commit 33b2e98
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext
import net.pantasystem.milktea.common.runCancellableCatching
import net.pantasystem.milktea.common_android.hilt.DefaultDispatcher
Expand Down Expand Up @@ -172,7 +173,13 @@ internal class CustomEmojiRepositoryImpl @Inject constructor(
override fun observeWithSearch(host: String, keyword: String): Flow<List<CustomEmoji>> {
return customEmojiDAO.observeAndSearch(host, keyword).map { list ->
convertToModel(list)
}.flowOn(defaultDispatcher)
}.flowOn(defaultDispatcher).onStart {
customEmojiCache.get(host)?.filter {
it.name.contains(keyword)
}?.let {
emit(it)
}
}
}

override suspend fun search(host: String, keyword: String): Result<List<CustomEmoji>> = runCancellableCatching {
Expand Down

0 comments on commit 33b2e98

Please sign in to comment.