Skip to content

Commit

Permalink
add fetch dm
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Oct 21, 2024
1 parent 08fd68c commit 00c9583
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import app.bsky.graph.MuteActorRequest
import app.bsky.graph.UnmuteActorRequest
import app.bsky.notification.ListNotificationsQueryParams
import app.bsky.unspecced.GetPopularFeedGeneratorsQueryParams
import chat.bsky.convo.MessageInput
import chat.bsky.convo.SendMessageRequest
import com.atproto.moderation.CreateReportRequest
import com.atproto.moderation.CreateReportRequestSubjectUnion
import com.atproto.moderation.Token
Expand Down Expand Up @@ -59,6 +61,7 @@ import dev.dimension.flare.data.datasource.microblog.AuthenticatedMicroblogDataS
import dev.dimension.flare.data.datasource.microblog.ComposeConfig
import dev.dimension.flare.data.datasource.microblog.ComposeData
import dev.dimension.flare.data.datasource.microblog.ComposeProgress
import dev.dimension.flare.data.datasource.microblog.DirectMessageDataSource
import dev.dimension.flare.data.datasource.microblog.ListDataSource
import dev.dimension.flare.data.datasource.microblog.ListMetaData
import dev.dimension.flare.data.datasource.microblog.ListMetaDataType
Expand All @@ -74,6 +77,8 @@ import dev.dimension.flare.data.repository.LocalFilterRepository
import dev.dimension.flare.model.MicroBlogKey
import dev.dimension.flare.model.PlatformType
import dev.dimension.flare.ui.model.UiAccount
import dev.dimension.flare.ui.model.UiDMItem
import dev.dimension.flare.ui.model.UiDMList
import dev.dimension.flare.ui.model.UiHashtag
import dev.dimension.flare.ui.model.UiList
import dev.dimension.flare.ui.model.UiProfile
Expand Down Expand Up @@ -113,7 +118,8 @@ class BlueskyDataSource(
) : AuthenticatedMicroblogDataSource,
KoinComponent,
StatusEvent.Bluesky,
ListDataSource {
ListDataSource,
DirectMessageDataSource {
private val database: CacheDatabase by inject()
private val appDatabase: AppDatabase by inject()
private val localFilterRepository: LocalFilterRepository by inject()
Expand Down Expand Up @@ -1715,6 +1721,37 @@ class BlueskyDataSource(
notifications.count { !it.isRead }
},
)

override fun directMessageList(): Flow<PagingData<UiDMList>> {
TODO("Not yet implemented")
}

override fun directMessageConversation(id: String): Flow<PagingData<UiDMItem>> {
TODO("Not yet implemented")
}

override fun getDirectMessageConversationInfo(id: String): CacheData<UiDMList> {
TODO("Not yet implemented")
}

override fun sendDirectMessage(
id: String,
message: String,
) {
coroutineScope.launch {
service.sendMessage(
request =
SendMessageRequest(
convoId = id,
message = MessageInput(message),
),
)
}
}

override suspend fun fetchNewDirectMessageForConversation(id: String) {
TODO("Not yet implemented")
}
}

internal inline fun <reified T, reified R> T.bskyJson(): R = bskyJson.decodeFromJsonElement(bskyJson.encodeToJsonElement(this))
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.dimension.flare.data.datasource.microblog

import androidx.paging.PagingData
import dev.dimension.flare.common.CacheData
import dev.dimension.flare.ui.model.UiDMItem
import dev.dimension.flare.ui.model.UiDMList
import kotlinx.coroutines.flow.Flow
Expand All @@ -15,5 +16,7 @@ internal interface DirectMessageDataSource {
message: String,
)

fun getDirectMessageConversationInfo(id: String): Flow<UiDMList>
fun getDirectMessageConversationInfo(id: String): CacheData<UiDMList>

suspend fun fetchNewDirectMessageForConversation(id: String)
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package dev.dimension.flare.ui.presenter.dm

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.paging.compose.collectAsLazyPagingItems
import dev.dimension.flare.common.PagingState
import dev.dimension.flare.common.collectAsState
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.UiDMItem
import dev.dimension.flare.ui.model.UiState
import dev.dimension.flare.ui.model.UiUserV2
import dev.dimension.flare.ui.model.collectAsUiState
import dev.dimension.flare.ui.model.flatMap
import dev.dimension.flare.ui.model.map
import dev.dimension.flare.ui.model.onSuccess
import dev.dimension.flare.ui.model.toUi
import dev.dimension.flare.ui.presenter.PresenterBase
import kotlinx.coroutines.delay
import kotlin.time.Duration.Companion.seconds

class DMConversationPresenter(
private val accountType: AccountType,
Expand All @@ -38,10 +42,17 @@ class DMConversationPresenter(
require(service is DirectMessageDataSource)
remember(service, id) {
service.getDirectMessageConversationInfo(id)
}.collectAsUiState().value
}.collectAsState().toUi()
}.map {
it.user
}
LaunchedEffect(Unit) {
serviceState.onSuccess {
require(it is DirectMessageDataSource)
delay(5.seconds)
it.fetchNewDirectMessageForConversation(id)
}
}
return object : DMConversationState {
override val items = items

Expand Down

0 comments on commit 00c9583

Please sign in to comment.