diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt index 840d920ebf..0cab7ce8e9 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt @@ -3676,7 +3676,7 @@ sealed class UsageConditionsAction { @Serializable @SerialName("review") data class Review(val operators: List, val deadline: Instant?, val showNotice: Boolean) : UsageConditionsAction() @Serializable @SerialName("accepted") data class Accepted(val operators: List) : UsageConditionsAction() - val shouldSowNotice: Boolean + val shouldShowNotice: Boolean get() = when (this) { is Review -> showNotice else -> false diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ChatListView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ChatListView.kt index 0d2a850956..00a06caf1a 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ChatListView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/ChatListView.kt @@ -25,19 +25,20 @@ import androidx.compose.ui.unit.* import chat.simplex.common.AppLock import chat.simplex.common.model.* import chat.simplex.common.model.ChatController.appPrefs +import chat.simplex.common.model.ChatController.setConditionsNotified import chat.simplex.common.model.ChatController.stopRemoteHostAndReloadHosts import chat.simplex.common.ui.theme.* import chat.simplex.common.views.helpers.* -import chat.simplex.common.views.onboarding.WhatsNewView -import chat.simplex.common.views.onboarding.shouldShowWhatsNew import chat.simplex.common.platform.* import chat.simplex.common.views.call.Call import chat.simplex.common.views.chat.item.CIFileViewScope import chat.simplex.common.views.chat.topPaddingToContent import chat.simplex.common.views.mkValidName import chat.simplex.common.views.newchat.* +import chat.simplex.common.views.onboarding.* import chat.simplex.common.views.showInvalidNameAlert import chat.simplex.common.views.usersettings.* +import chat.simplex.common.views.usersettings.networkAndServers.UsageConditionsView import chat.simplex.res.MR import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableStateFlow @@ -115,12 +116,26 @@ fun ToggleChatListCard() { @Composable fun ChatListView(chatModel: ChatModel, userPickerState: MutableStateFlow, setPerformLA: (Boolean) -> Unit, stopped: Boolean) { val oneHandUI = remember { appPrefs.oneHandUI.state } + val rhId = chatModel.remoteHostId() + LaunchedEffect(Unit) { val showWhatsNew = shouldShowWhatsNew(chatModel) - val showOperatorsNotice = chatModel.conditions.value.conditionsAction?.shouldSowNotice ?: false - if (showWhatsNew || showOperatorsNotice) { + val showUpdatedConditions = chatModel.conditions.value.conditionsAction?.shouldShowNotice ?: false + if (showWhatsNew) { delay(1000L) - ModalManager.center.showCustomModal { close -> WhatsNewView(close = close, showWhatsNew = remember { mutableStateOf(showWhatsNew) }, showOperatorsNotice = showOperatorsNotice) } + ModalManager.center.showCustomModal { close -> WhatsNewView(close = close, showWhatsNew = remember { mutableStateOf(true) }, updatedConditions = showUpdatedConditions) } + } else if (showUpdatedConditions) { + ModalManager.center.showModalCloseable { close -> + LaunchedEffect(Unit) { + val conditionsId = chatModel.conditions.value.currentConditions.conditionsId + try { + setConditionsNotified(rh = rhId, conditionsId = conditionsId) + } catch (e: Exception) { + Log.d(TAG, "UsageConditionsView setConditionsNotified error: ${e.message}") + } + } + UsageConditionsView(userServers = mutableStateOf(emptyList()), currUserServers = mutableStateOf(emptyList()), close = close, rhId = rhId) + } } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/onboarding/WhatsNewView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/onboarding/WhatsNewView.kt index 24545c905f..8aee195dc8 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/onboarding/WhatsNewView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/onboarding/WhatsNewView.kt @@ -26,9 +26,9 @@ import dev.icerock.moko.resources.ImageResource import dev.icerock.moko.resources.StringResource @Composable -fun ModalData.WhatsNewView(showWhatsNew: MutableState = mutableStateOf(true), showOperatorsNotice: Boolean = false, viaSettings: Boolean = false, close: () -> Unit) { +fun ModalData.WhatsNewView(showWhatsNew: MutableState = mutableStateOf(true), updatedConditions: Boolean = false, viaSettings: Boolean = false, close: () -> Unit) { val currentVersion = remember { mutableStateOf(versionDescriptions.lastIndex) } - val showOperatorsNoticeModal = remember { stateGetOrPut("showOperatorsNoticeModal") { showOperatorsNotice } } + val showOperatorsNoticeModal = remember { stateGetOrPut("showOperatorsNoticeModal") { updatedConditions } } if (showOperatorsNoticeModal.value) { LaunchedEffect(Unit) { val conditionsId = chatModel.conditions.value.currentConditions.conditionsId @@ -155,9 +155,9 @@ fun ModalData.WhatsNewView(showWhatsNew: MutableState = mutableStateOf( Modifier.fillMaxWidth(), contentAlignment = Alignment.Center ) { Text( - if (showOperatorsNotice) generalGetString(MR.strings.server_operators_view_updated_conditions) else generalGetString(MR.strings.ok), + if (updatedConditions) generalGetString(MR.strings.server_operators_view_updated_conditions) else generalGetString(MR.strings.ok), modifier = Modifier.clickable(onClick = { - if (showOperatorsNotice) { + if (updatedConditions) { showWhatsNew.value = false } else { close()