-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ommonMain/kotlin/dev/dimension/flare/data/datasource/microblog/DirectMessageDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.dimension.flare.data.datasource.microblog | ||
|
||
import androidx.paging.PagingData | ||
import dev.dimension.flare.ui.model.UiDMItem | ||
import dev.dimension.flare.ui.model.UiDMList | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
internal interface DirectMessageDataSource { | ||
fun directMessageList(): Flow<PagingData<UiDMList>> | ||
|
||
fun directMessageConversation(id: String): Flow<PagingData<UiDMItem>> | ||
|
||
fun sendDirectMessage( | ||
id: String, | ||
message: String, | ||
) | ||
|
||
fun getDirectMessageConversationInfo(id: String): Flow<UiDMList> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 28 additions & 2 deletions
30
shared/src/commonMain/kotlin/dev/dimension/flare/ui/presenter/dm/DMListPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,49 @@ | ||
package dev.dimension.flare.ui.presenter.dm | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.paging.compose.collectAsLazyPagingItems | ||
import dev.dimension.flare.common.PagingState | ||
import dev.dimension.flare.common.onSuccess | ||
import dev.dimension.flare.common.toPagingState | ||
import dev.dimension.flare.data.datasource.microblog.DirectMessageDataSource | ||
import dev.dimension.flare.data.repository.accountServiceProvider | ||
import dev.dimension.flare.model.AccountType | ||
import dev.dimension.flare.ui.model.UiDMList | ||
import dev.dimension.flare.ui.model.map | ||
import dev.dimension.flare.ui.presenter.PresenterBase | ||
|
||
class DMListPresenter( | ||
private val accountType: AccountType, | ||
) : PresenterBase<DMListState>() { | ||
@Composable | ||
override fun body(): DMListState { | ||
TODO() | ||
val serviceState = accountServiceProvider(accountType = accountType) | ||
val items = | ||
serviceState | ||
.map { service -> | ||
require(service is DirectMessageDataSource) | ||
remember(service) { | ||
service.directMessageList() | ||
}.collectAsLazyPagingItems() | ||
}.toPagingState() | ||
return object : DMListState { | ||
override val items = items | ||
|
||
override val isRefreshing = false | ||
|
||
override suspend fun refreshSuspend() { | ||
items.onSuccess { | ||
refreshSuspend() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
interface DMListState { | ||
val items: PagingState<UiDMList> | ||
val isRefreshing: Boolean | ||
|
||
fun refresh() | ||
suspend fun refreshSuspend() | ||
} |