diff --git a/domains/store/src/main/sqldelight/app/dapk/db/model/BubbleRoom.sq b/domains/store/src/main/sqldelight/app/dapk/db/model/AppRoom.sq similarity index 56% rename from domains/store/src/main/sqldelight/app/dapk/db/model/BubbleRoom.sq rename to domains/store/src/main/sqldelight/app/dapk/db/model/AppRoom.sq index b936524..0ace052 100644 --- a/domains/store/src/main/sqldelight/app/dapk/db/model/BubbleRoom.sq +++ b/domains/store/src/main/sqldelight/app/dapk/db/model/AppRoom.sq @@ -1,18 +1,18 @@ -CREATE TABLE dbStRoomMeta ( +CREATE TABLE dbAppRoom ( room_id TEXT NOT NULL, is_bubble INTEGER AS Int NOT NULL DEFAULT 0, PRIMARY KEY (room_id) ); markBubble: -INSERT OR REPLACE INTO dbStRoomMeta(room_id, is_bubble) +INSERT OR REPLACE INTO dbAppRoom(room_id, is_bubble) VALUES (?,?); unmarkBubble: -INSERT OR REPLACE INTO dbStRoomMeta(room_id, is_bubble) +INSERT OR REPLACE INTO dbAppRoom(room_id, is_bubble) VALUES (?,?); select: SELECT is_bubble -FROM dbStRoomMeta +FROM dbAppRoom WHERE room_id = ?; diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerScreen.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerScreen.kt index fe54173..375f47c 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerScreen.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerScreen.kt @@ -52,6 +52,8 @@ import app.dapk.st.matrix.common.RichText import app.dapk.st.matrix.common.UserId import app.dapk.st.messenger.gallery.ImageGalleryActivityPayload import app.dapk.st.messenger.state.* +import app.dapk.st.messenger.state.ScreenAction.ChatBubble +import app.dapk.st.messenger.state.ScreenAction.MuteNotifications import app.dapk.st.navigator.Navigator import coil.compose.rememberAsyncImagePainter import coil.request.ImageRequest @@ -115,8 +117,15 @@ internal fun MessengerScreen( OverflowMenu { BooleanOption(value = it.isMuted, trueText = "Unmute notifications", falseText = "Mute notifications") { val action = when (it) { - true -> ScreenAction.Notifications.Unmute - false -> ScreenAction.Notifications.Unmute + true -> MuteNotifications.Unmute + false -> MuteNotifications.Mute + } + viewModel.dispatch(action) + } + BooleanOption(value = it.isMuted, trueText = "Disable bubble", falseText = "Enable bubble") { + val action = when (it) { + true -> ChatBubble.Disable + false -> ChatBubble.Enable } viewModel.dispatch(action) } diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerAction.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerAction.kt index 2cfa295..fdea223 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerAction.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerAction.kt @@ -12,9 +12,14 @@ sealed interface ScreenAction : Action { object OpenGalleryPicker : ScreenAction object LeaveRoom : ScreenAction - sealed interface Notifications : ScreenAction { - object Mute : Notifications - object Unmute : Notifications + sealed interface MuteNotifications : ScreenAction { + object Mute : MuteNotifications + object Unmute : MuteNotifications + } + + sealed interface ChatBubble : ScreenAction { + object Enable: ChatBubble + object Disable: ChatBubble } sealed interface LeaveRoomConfirmation : ScreenAction { @@ -22,7 +27,7 @@ sealed interface ScreenAction : Action { object Deny : LeaveRoomConfirmation } - data class UpdateDialogState(val dialogState: DialogState?): ScreenAction + data class UpdateDialogState(val dialogState: DialogState?) : ScreenAction } sealed interface ComponentLifecycle : Action { @@ -33,6 +38,7 @@ sealed interface ComponentLifecycle : Action { sealed interface MessagesStateChange : Action { data class Content(val content: MessengerPageState) : MessagesStateChange data class MuteContent(val isMuted: Boolean) : MessagesStateChange + data class ChatBubbleContent(val isChatBubble: Boolean) : MessagesStateChange } sealed interface ComposerStateChange : Action { diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerReducer.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerReducer.kt index fc90d92..c48a82d 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerReducer.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerReducer.kt @@ -38,6 +38,7 @@ internal fun messengerReducer( composerState = initialComposerState(initialAttachments), viewerState = null, dialogState = null, + appRoomState = Lce.Loading(), ), async(ComponentLifecycle::class) { action -> @@ -156,22 +157,46 @@ internal fun messengerReducer( } }, - async(ScreenAction.Notifications::class) { action -> + async(ScreenAction.MuteNotifications::class) { action -> when (action) { - ScreenAction.Notifications.Mute -> chatEngine.muteRoom(roomId) - ScreenAction.Notifications.Unmute -> chatEngine.unmuteRoom(roomId) + ScreenAction.MuteNotifications.Mute -> chatEngine.muteRoom(roomId) + ScreenAction.MuteNotifications.Unmute -> chatEngine.unmuteRoom(roomId) } dispatch( MessagesStateChange.MuteContent( isMuted = when (action) { - ScreenAction.Notifications.Mute -> true - ScreenAction.Notifications.Unmute -> false + ScreenAction.MuteNotifications.Mute -> true + ScreenAction.MuteNotifications.Unmute -> false } ) ) }, + async(ScreenAction.ChatBubble::class) { action -> + when (action) { + ScreenAction.ChatBubble.Disable -> {} + ScreenAction.ChatBubble.Enable -> {} + } + + dispatch( + MessagesStateChange.ChatBubbleContent( + isChatBubble = when (action) { + ScreenAction.ChatBubble.Enable -> true + ScreenAction.ChatBubble.Disable -> false + } + ) + ) + }, + + change(MessagesStateChange.ChatBubbleContent::class) { action, state -> + when (val appRoomState = state.appRoomState) { + is Lce.Content -> state.copy(appRoomState = appRoomState.copy(value = appRoomState.value.copy(isChatBubble = action.isChatBubble))) + is Lce.Error -> state + is Lce.Loading -> state + } + }, + change(ScreenAction.UpdateDialogState::class) { action, state -> state.copy(dialogState = action.dialogState) }, diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerState.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerState.kt index 095c509..ca5ba0d 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerState.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerState.kt @@ -17,6 +17,11 @@ data class MessengerScreenState( val composerState: ComposerState, val viewerState: ViewerState?, val dialogState: DialogState?, + val appRoomState: Lce, +) + +data class AppRoomState( + val isChatBubble: Boolean ) data class ViewerState( diff --git a/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerReducerTest.kt b/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerReducerTest.kt index 478ec19..6a358e1 100644 --- a/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerReducerTest.kt +++ b/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerReducerTest.kt @@ -15,7 +15,6 @@ import fake.FakeChatEngine import fake.FakeJobBag import fake.FakeMessageOptionsStore import fixture.* -import io.mockk.coEvery import io.mockk.every import io.mockk.mockk import kotlinx.coroutines.flow.flowOf @@ -77,6 +76,7 @@ class MessengerReducerTest { composerState = ComposerState.Text(value = "", reply = null), viewerState = null, dialogState = null, + appRoomState = Lce.Loading(), ) ) } @@ -90,6 +90,7 @@ class MessengerReducerTest { composerState = ComposerState.Text(value = "", reply = null), viewerState = null, dialogState = null, + appRoomState = Lce.Loading(), ) ) } @@ -103,6 +104,7 @@ class MessengerReducerTest { composerState = ComposerState.Attachments(listOf(A_MESSAGE_ATTACHMENT), reply = null), viewerState = null, dialogState = null, + appRoomState = Lce.Loading(), ) ) }