Skip to content

Commit

Permalink
fix: isCwAllowBlankをcombine内にまとめた
Browse files Browse the repository at this point in the history
以前までのコードでは、`isCwAllowBlank`は誰からも購読されておらずアクティブになっていなかったため無理やりEagerlyを使うことで値を取得していた。
これはリソース上効率が悪いためcombineを用いて、isPostAvailableが購読された時に一緒に購読が開始されるように修正する。

Fixed #1992
  • Loading branch information
sanao1006 committed Nov 30, 2023
1 parent f6a814b commit 4acbf29
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ class NoteEditorViewModel @Inject constructor(
initialValue = 3000
)

private val isCwAllowBlank = instanceInfoType.map {
it?.isCwAllowBlank ?: true
}.stateIn(viewModelScope, started = SharingStarted.Eagerly, initialValue = true)


val enableFeatures = _currentAccount.filterNotNull().map {
featureEnables.enableFeatures(it.normalizedInstanceUri)
Expand Down Expand Up @@ -245,8 +241,9 @@ class NoteEditorViewModel @Inject constructor(
logger.error("observe meta error", it)
}.stateIn(viewModelScope + Dispatchers.IO, started = SharingStarted.Lazily, initialValue = 1500)

val isPostAvailable = uiState.map {
it.checkValidate(textMaxLength = maxTextLength.value, maxFileCount = maxFileCount.value, isCwAllowBlank = isCwAllowBlank.value)
val isPostAvailable = combine(instanceInfoType, uiState) { instanceInfo, uiState ->
val isCwAllowBlank = instanceInfo?.isCwAllowBlank ?: true
uiState.checkValidate(textMaxLength = maxTextLength.value, maxFileCount = maxFileCount.value, isCwAllowBlank = isCwAllowBlank)
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5_000),
Expand Down

0 comments on commit 4acbf29

Please sign in to comment.