Skip to content

Commit

Permalink
Sending messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiebe committed Apr 14, 2024
1 parent 7873dd9 commit 0a223b6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ wear_sdk-compile = "33"

ios_target = "11.0"

magister = "1.2.0"
magister = "1.3.0"

work-android = "2.9.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package nl.tiebe.otarium.logic.default.home.children.messages.children.composing
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.value.MutableValue
import dev.tiebe.magisterapi.api.account.ProfileInfoFlow
import dev.tiebe.magisterapi.api.messages.MessageFlow
import dev.tiebe.magisterapi.response.profileinfo.Contact
import io.ktor.http.*
import kotlinx.coroutines.launch
import nl.tiebe.otarium.Data
import nl.tiebe.otarium.logic.default.componentCoroutineScope
Expand All @@ -30,8 +32,16 @@ class DefaultMessageComposeComponent(
override val subject: MutableValue<String> = MutableValue(prefilledSubject ?: "")
override val body: MutableValue<String> = MutableValue(prefilledBody ?: "")

override fun send() {
TODO("Not yet implemented")
override suspend fun send() {
MessageFlow.sendMessage(
Url(Data.selectedAccount.tenantUrl),
Data.selectedAccount.tokens.accessToken,
subject.value,
body.value,
toList.chips.map { it.contact.id },
ccList.chips.map { it.contact.id },
bccList.chips.map { it.contact.id }
)
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ interface MessageComposeComponent {

fun back() = parentComponent::back

fun send()
suspend fun send()

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ private fun FolderContent(
component: MessagesComponent,
drawerState: DrawerState
) {
val scope = rememberCoroutineScope()

Scaffold(
topBar = {
when (val instance = screen.value.active.instance) {
Expand All @@ -129,23 +131,23 @@ private fun FolderContent(
}
},
floatingActionButton = {
// if (screen.value.active.instance is MessagesComponent.Child.FolderChild) {
// FloatingActionButton(
// onClick = {
// scope.launch {
// component.navigate(MessagesComponent.Config.Compose(listOf(), "", ""))
// }
// },
// content = {
// Icon(
// imageVector = OtariumIcons.Email.Pencil,
// contentDescription = "Compose new message"
// )
// },
// containerColor = MaterialTheme.colorScheme.primary,
// contentColor = MaterialTheme.colorScheme.onPrimary
// )
// }
if (screen.value.active.instance is MessagesComponent.Child.FolderChild) {
FloatingActionButton(
onClick = {
scope.launch {
component.navigate(MessagesComponent.Config.Compose(listOf(), "", ""))
}
},
content = {
Icon(
imageVector = OtariumIcons.Email.Pencil,
contentDescription = "Compose new message"
)
},
containerColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary
)
}
},
contentWindowInsets = WindowInsets(0)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import kotlinx.coroutines.launch
import nl.tiebe.otarium.logic.root.home.children.messages.children.composing.MessageComposeComponent

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MessageComposeTopAppBar(component: MessageComposeComponent) {
val scope = rememberCoroutineScope()

TopAppBar(
title = {},
navigationIcon = {
Expand All @@ -23,7 +27,10 @@ fun MessageComposeTopAppBar(component: MessageComposeComponent) {
},
actions = {
// send
IconButton(onClick = { component.send() }) {
IconButton(onClick = { scope.launch {
component.parentComponent.back()
component.send()
}}) {
Icon(Icons.Default.Send, contentDescription = "Send")
}
},
Expand Down

0 comments on commit 0a223b6

Please sign in to comment.