Skip to content

DROID-2966 Chats | Fix | Misc. fixes #2452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -114,7 +115,7 @@ class HomeScreenFragment : BaseComposeFragment(),
val view = (vm.views.collectAsStateWithLifecycle().value.find {
it is WidgetView.SpaceWidget.View
} as? WidgetView.SpaceWidget.View)
Box(
Column(
modifier = Modifier
.fillMaxSize()
) {
Expand All @@ -131,7 +132,7 @@ class HomeScreenFragment : BaseComposeFragment(),
onSettingsClicked = { vm.onSpaceSettingsClicked(space = SpaceId(space)) }
)
PageWithWidgets(
modifier = Modifier.padding(top = 52.dp),
modifier = Modifier.weight(1f),
showSpaceWidget = false
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ fun HomeScreenToolbar(
) {
Box(
modifier = Modifier
.systemBarsPadding()
.fillMaxWidth()
.height(52.dp)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ fun SpaceChatWidgetCard(
contentAlignment = Alignment.Center
) {
Text(
text = unReadMentionCount.toString(),
modifier = Modifier.padding(horizontal = 6.dp),
text = unReadMessageCount.toString(),
style = Caption1Regular,
color = colorResource(id = R.color.text_white),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ interface ChatEventRemoteChannel {
class Default(
private val channel: ChatEventRemoteChannel
) : ChatEventChannel {

override fun subscribe(subscribe: Id): Flow<List<Event.Command.Chats>> {
return channel.subscribe(subscribe)
}

override fun observe(chat: Id): Flow<List<Event.Command.Chats>> {
return channel.observe(chat)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import kotlinx.coroutines.flow.Flow

interface ChatEventChannel {
fun observe(chat: Id): Flow<List<Event.Command.Chats>>
fun subscribe(subscribe: Id): Flow<List<Event.Command.Chats>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.scan
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -50,7 +51,7 @@ interface ChatPreviewContainer {
.onFailure { logger.logException(it, "DROID-2966 Error while getting initial previews") }
.getOrDefault(emptyList())
events
.observe(SUBSCRIPTION_ID)
.subscribe(SUBSCRIPTION_ID)
.scan(initial = initial) { previews, events ->
events.fold(previews) { state, event ->
when (event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.anytypeio.anytype.domain.chats.ChatPreviewContainer
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.flow
Expand All @@ -14,14 +15,15 @@ class SpaceChatWidgetContainer @Inject constructor(
private val widget: Widget,
private val container: ChatPreviewContainer
) : WidgetContainer {
override val view: Flow<WidgetView> = flow {
override val view: Flow<WidgetView.SpaceChat> = flow {
emitAll(
container
.observePreview(space = SpaceId(widget.config.space))
.map { preview ->
(preview?.state?.unreadMessages?.counter ?: 0) to (preview?.state?.unreadMentions?.counter ?: 0)
}
.distinctUntilChanged()
.debounce(DEBOUNCE_DURATION)
.map { (unreadMessageCount, unreadMentionCount) ->
WidgetView.SpaceChat(
id = widget.id,
Expand All @@ -39,4 +41,8 @@ class SpaceChatWidgetContainer @Inject constructor(
)
)
}

companion object {
const val DEBOUNCE_DURATION = 500L
}
}