Add app room state model
This commit is contained in:
parent
8312c20d5d
commit
6a1d360036
|
@ -1,18 +1,18 @@
|
||||||
CREATE TABLE dbStRoomMeta (
|
CREATE TABLE dbAppRoom (
|
||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
is_bubble INTEGER AS Int NOT NULL DEFAULT 0,
|
is_bubble INTEGER AS Int NOT NULL DEFAULT 0,
|
||||||
PRIMARY KEY (room_id)
|
PRIMARY KEY (room_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
markBubble:
|
markBubble:
|
||||||
INSERT OR REPLACE INTO dbStRoomMeta(room_id, is_bubble)
|
INSERT OR REPLACE INTO dbAppRoom(room_id, is_bubble)
|
||||||
VALUES (?,?);
|
VALUES (?,?);
|
||||||
|
|
||||||
unmarkBubble:
|
unmarkBubble:
|
||||||
INSERT OR REPLACE INTO dbStRoomMeta(room_id, is_bubble)
|
INSERT OR REPLACE INTO dbAppRoom(room_id, is_bubble)
|
||||||
VALUES (?,?);
|
VALUES (?,?);
|
||||||
|
|
||||||
select:
|
select:
|
||||||
SELECT is_bubble
|
SELECT is_bubble
|
||||||
FROM dbStRoomMeta
|
FROM dbAppRoom
|
||||||
WHERE room_id = ?;
|
WHERE room_id = ?;
|
|
@ -52,6 +52,8 @@ import app.dapk.st.matrix.common.RichText
|
||||||
import app.dapk.st.matrix.common.UserId
|
import app.dapk.st.matrix.common.UserId
|
||||||
import app.dapk.st.messenger.gallery.ImageGalleryActivityPayload
|
import app.dapk.st.messenger.gallery.ImageGalleryActivityPayload
|
||||||
import app.dapk.st.messenger.state.*
|
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 app.dapk.st.navigator.Navigator
|
||||||
import coil.compose.rememberAsyncImagePainter
|
import coil.compose.rememberAsyncImagePainter
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
|
@ -115,8 +117,15 @@ internal fun MessengerScreen(
|
||||||
OverflowMenu {
|
OverflowMenu {
|
||||||
BooleanOption(value = it.isMuted, trueText = "Unmute notifications", falseText = "Mute notifications") {
|
BooleanOption(value = it.isMuted, trueText = "Unmute notifications", falseText = "Mute notifications") {
|
||||||
val action = when (it) {
|
val action = when (it) {
|
||||||
true -> ScreenAction.Notifications.Unmute
|
true -> MuteNotifications.Unmute
|
||||||
false -> ScreenAction.Notifications.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)
|
viewModel.dispatch(action)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,14 @@ sealed interface ScreenAction : Action {
|
||||||
object OpenGalleryPicker : ScreenAction
|
object OpenGalleryPicker : ScreenAction
|
||||||
object LeaveRoom : ScreenAction
|
object LeaveRoom : ScreenAction
|
||||||
|
|
||||||
sealed interface Notifications : ScreenAction {
|
sealed interface MuteNotifications : ScreenAction {
|
||||||
object Mute : Notifications
|
object Mute : MuteNotifications
|
||||||
object Unmute : Notifications
|
object Unmute : MuteNotifications
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed interface ChatBubble : ScreenAction {
|
||||||
|
object Enable: ChatBubble
|
||||||
|
object Disable: ChatBubble
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface LeaveRoomConfirmation : ScreenAction {
|
sealed interface LeaveRoomConfirmation : ScreenAction {
|
||||||
|
@ -22,7 +27,7 @@ sealed interface ScreenAction : Action {
|
||||||
object Deny : LeaveRoomConfirmation
|
object Deny : LeaveRoomConfirmation
|
||||||
}
|
}
|
||||||
|
|
||||||
data class UpdateDialogState(val dialogState: DialogState?): ScreenAction
|
data class UpdateDialogState(val dialogState: DialogState?) : ScreenAction
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface ComponentLifecycle : Action {
|
sealed interface ComponentLifecycle : Action {
|
||||||
|
@ -33,6 +38,7 @@ sealed interface ComponentLifecycle : Action {
|
||||||
sealed interface MessagesStateChange : Action {
|
sealed interface MessagesStateChange : Action {
|
||||||
data class Content(val content: MessengerPageState) : MessagesStateChange
|
data class Content(val content: MessengerPageState) : MessagesStateChange
|
||||||
data class MuteContent(val isMuted: Boolean) : MessagesStateChange
|
data class MuteContent(val isMuted: Boolean) : MessagesStateChange
|
||||||
|
data class ChatBubbleContent(val isChatBubble: Boolean) : MessagesStateChange
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface ComposerStateChange : Action {
|
sealed interface ComposerStateChange : Action {
|
||||||
|
|
|
@ -38,6 +38,7 @@ internal fun messengerReducer(
|
||||||
composerState = initialComposerState(initialAttachments),
|
composerState = initialComposerState(initialAttachments),
|
||||||
viewerState = null,
|
viewerState = null,
|
||||||
dialogState = null,
|
dialogState = null,
|
||||||
|
appRoomState = Lce.Loading(),
|
||||||
),
|
),
|
||||||
|
|
||||||
async(ComponentLifecycle::class) { action ->
|
async(ComponentLifecycle::class) { action ->
|
||||||
|
@ -156,22 +157,46 @@ internal fun messengerReducer(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async(ScreenAction.Notifications::class) { action ->
|
async(ScreenAction.MuteNotifications::class) { action ->
|
||||||
when (action) {
|
when (action) {
|
||||||
ScreenAction.Notifications.Mute -> chatEngine.muteRoom(roomId)
|
ScreenAction.MuteNotifications.Mute -> chatEngine.muteRoom(roomId)
|
||||||
ScreenAction.Notifications.Unmute -> chatEngine.unmuteRoom(roomId)
|
ScreenAction.MuteNotifications.Unmute -> chatEngine.unmuteRoom(roomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
MessagesStateChange.MuteContent(
|
MessagesStateChange.MuteContent(
|
||||||
isMuted = when (action) {
|
isMuted = when (action) {
|
||||||
ScreenAction.Notifications.Mute -> true
|
ScreenAction.MuteNotifications.Mute -> true
|
||||||
ScreenAction.Notifications.Unmute -> false
|
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 ->
|
change(ScreenAction.UpdateDialogState::class) { action, state ->
|
||||||
state.copy(dialogState = action.dialogState)
|
state.copy(dialogState = action.dialogState)
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,6 +17,11 @@ data class MessengerScreenState(
|
||||||
val composerState: ComposerState,
|
val composerState: ComposerState,
|
||||||
val viewerState: ViewerState?,
|
val viewerState: ViewerState?,
|
||||||
val dialogState: DialogState?,
|
val dialogState: DialogState?,
|
||||||
|
val appRoomState: Lce<AppRoomState>,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class AppRoomState(
|
||||||
|
val isChatBubble: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ViewerState(
|
data class ViewerState(
|
||||||
|
|
|
@ -15,7 +15,6 @@ import fake.FakeChatEngine
|
||||||
import fake.FakeJobBag
|
import fake.FakeJobBag
|
||||||
import fake.FakeMessageOptionsStore
|
import fake.FakeMessageOptionsStore
|
||||||
import fixture.*
|
import fixture.*
|
||||||
import io.mockk.coEvery
|
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
@ -77,6 +76,7 @@ class MessengerReducerTest {
|
||||||
composerState = ComposerState.Text(value = "", reply = null),
|
composerState = ComposerState.Text(value = "", reply = null),
|
||||||
viewerState = null,
|
viewerState = null,
|
||||||
dialogState = null,
|
dialogState = null,
|
||||||
|
appRoomState = Lce.Loading(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ class MessengerReducerTest {
|
||||||
composerState = ComposerState.Text(value = "", reply = null),
|
composerState = ComposerState.Text(value = "", reply = null),
|
||||||
viewerState = null,
|
viewerState = null,
|
||||||
dialogState = null,
|
dialogState = null,
|
||||||
|
appRoomState = Lce.Loading(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -103,6 +104,7 @@ class MessengerReducerTest {
|
||||||
composerState = ComposerState.Attachments(listOf(A_MESSAGE_ATTACHMENT), reply = null),
|
composerState = ComposerState.Attachments(listOf(A_MESSAGE_ATTACHMENT), reply = null),
|
||||||
viewerState = null,
|
viewerState = null,
|
||||||
dialogState = null,
|
dialogState = null,
|
||||||
|
appRoomState = Lce.Loading(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue