mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
ui: offer to fix connection on call and message buttons (#5358)
This commit is contained in:
+48
-20
@@ -131,26 +131,14 @@ fun ChatInfoView(
|
||||
},
|
||||
syncContactConnection = {
|
||||
withBGApi {
|
||||
val cStats = chatModel.controller.apiSyncContactRatchet(chatRh, contact.contactId, force = false)
|
||||
connStats.value = cStats
|
||||
if (cStats != null) {
|
||||
withChats {
|
||||
updateContactConnectionStats(chatRh, contact, cStats)
|
||||
}
|
||||
}
|
||||
syncContactConnection(chatRh, contact, connStats, force = false)
|
||||
close.invoke()
|
||||
}
|
||||
},
|
||||
syncContactConnectionForce = {
|
||||
showSyncConnectionForceAlert(syncConnectionForce = {
|
||||
withBGApi {
|
||||
val cStats = chatModel.controller.apiSyncContactRatchet(chatRh, contact.contactId, force = true)
|
||||
connStats.value = cStats
|
||||
if (cStats != null) {
|
||||
withChats {
|
||||
updateContactConnectionStats(chatRh, contact, cStats)
|
||||
}
|
||||
}
|
||||
syncContactConnection(chatRh, contact, connStats, force = true)
|
||||
close.invoke()
|
||||
}
|
||||
})
|
||||
@@ -189,6 +177,16 @@ fun ChatInfoView(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun syncContactConnection(rhId: Long?, contact: Contact, connectionStats: MutableState<ConnectionStats?>, force: Boolean) {
|
||||
val cStats = chatModel.controller.apiSyncContactRatchet(rhId, contact.contactId, force = force)
|
||||
connectionStats.value = cStats
|
||||
if (cStats != null) {
|
||||
withChats {
|
||||
updateContactConnectionStats(rhId, contact, cStats)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class SendReceipts {
|
||||
object Yes: SendReceipts()
|
||||
object No: SendReceipts()
|
||||
@@ -505,7 +503,7 @@ fun ChatInfoLayout(
|
||||
currentUser: User,
|
||||
sendReceipts: State<SendReceipts>,
|
||||
setSendReceipts: (SendReceipts) -> Unit,
|
||||
connStats: State<ConnectionStats?>,
|
||||
connStats: MutableState<ConnectionStats?>,
|
||||
contactNetworkStatus: NetworkStatus,
|
||||
customUserProfile: Profile?,
|
||||
localAlias: String,
|
||||
@@ -553,8 +551,8 @@ fun ChatInfoLayout(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
SearchButton(modifier = Modifier.fillMaxWidth(0.25f), chat, contact, close, onSearchClicked)
|
||||
AudioCallButton(modifier = Modifier.fillMaxWidth(0.33f), chat, contact)
|
||||
VideoButton(modifier = Modifier.fillMaxWidth(0.5f), chat, contact)
|
||||
AudioCallButton(modifier = Modifier.fillMaxWidth(0.33f), chat, contact, connStats)
|
||||
VideoButton(modifier = Modifier.fillMaxWidth(0.5f), chat, contact, connStats)
|
||||
MuteButton(modifier = Modifier.fillMaxWidth(1f), chat, contact)
|
||||
}
|
||||
}
|
||||
@@ -825,12 +823,14 @@ fun MuteButton(
|
||||
fun AudioCallButton(
|
||||
modifier: Modifier,
|
||||
chat: Chat,
|
||||
contact: Contact
|
||||
contact: Contact,
|
||||
connectionStats: MutableState<ConnectionStats?>
|
||||
) {
|
||||
CallButton(
|
||||
modifier = modifier,
|
||||
chat,
|
||||
contact,
|
||||
connectionStats,
|
||||
icon = painterResource(MR.images.ic_call),
|
||||
title = generalGetString(MR.strings.info_view_call_button),
|
||||
mediaType = CallMediaType.Audio
|
||||
@@ -841,12 +841,14 @@ fun AudioCallButton(
|
||||
fun VideoButton(
|
||||
modifier: Modifier,
|
||||
chat: Chat,
|
||||
contact: Contact
|
||||
contact: Contact,
|
||||
connectionStats: MutableState<ConnectionStats?>
|
||||
) {
|
||||
CallButton(
|
||||
modifier = modifier,
|
||||
chat,
|
||||
contact,
|
||||
connectionStats,
|
||||
icon = painterResource(MR.images.ic_videocam),
|
||||
title = generalGetString(MR.strings.info_view_video_button),
|
||||
mediaType = CallMediaType.Video
|
||||
@@ -858,6 +860,7 @@ fun CallButton(
|
||||
modifier: Modifier,
|
||||
chat: Chat,
|
||||
contact: Contact,
|
||||
connectionStats: MutableState<ConnectionStats?>,
|
||||
icon: Painter,
|
||||
title: String,
|
||||
mediaType: CallMediaType
|
||||
@@ -879,7 +882,23 @@ fun CallButton(
|
||||
disabledLook = !canCall,
|
||||
onClick =
|
||||
when {
|
||||
canCall -> { { startChatCall(chat.remoteHostId, chat.chatInfo, mediaType) } }
|
||||
canCall -> { {
|
||||
val connStats = connectionStats.value
|
||||
if (connStats != null) {
|
||||
if (connStats.ratchetSyncState == RatchetSyncState.Ok) {
|
||||
startChatCall(chat.remoteHostId, chat.chatInfo, mediaType)
|
||||
} else if (connStats.ratchetSyncAllowed) {
|
||||
showFixConnectionAlert(syncConnection = {
|
||||
withBGApi { syncContactConnection(chat.remoteHostId, contact, connectionStats, force = false) }
|
||||
})
|
||||
} else {
|
||||
AlertManager.shared.showAlertMsg(
|
||||
generalGetString(MR.strings.cant_call_contact_alert_title),
|
||||
generalGetString(MR.strings.encryption_renegotiation_in_progress)
|
||||
)
|
||||
}
|
||||
}
|
||||
} }
|
||||
contact.nextSendGrpInv -> { { showCantCallContactSendMessageAlert() } }
|
||||
!contact.active -> { { showCantCallContactDeletedAlert() } }
|
||||
!contact.ready -> { { showCantCallContactConnectingAlert() } }
|
||||
@@ -1265,6 +1284,15 @@ fun showSyncConnectionForceAlert(syncConnectionForce: () -> Unit) {
|
||||
)
|
||||
}
|
||||
|
||||
fun showFixConnectionAlert(syncConnection: () -> Unit) {
|
||||
AlertManager.shared.showAlertDialog(
|
||||
title = generalGetString(MR.strings.sync_connection_question),
|
||||
text = generalGetString(MR.strings.sync_connection_desc),
|
||||
confirmText = generalGetString(MR.strings.sync_connection_confirm),
|
||||
onConfirm = syncConnection,
|
||||
)
|
||||
}
|
||||
|
||||
fun queueInfoText(info: Pair<RcvMsgInfo?, ServerQueueInfo>): String {
|
||||
val (rcvMsgInfo, qInfo) = info
|
||||
val msgInfo: String = if (rcvMsgInfo != null) json.encodeToString(rcvMsgInfo) else generalGetString(MR.strings.message_queue_info_none)
|
||||
|
||||
+49
-25
@@ -8,8 +8,6 @@ import SectionSpacer
|
||||
import SectionTextFooter
|
||||
import SectionView
|
||||
import androidx.compose.desktop.ui.tooling.preview.Preview
|
||||
import java.net.URI
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.text.InlineTextContent
|
||||
import androidx.compose.foundation.text.appendInlineContent
|
||||
@@ -58,6 +56,19 @@ fun GroupMemberInfoView(
|
||||
val developerTools = chatModel.controller.appPrefs.developerTools.get()
|
||||
var progressIndicator by remember { mutableStateOf(false) }
|
||||
|
||||
fun syncMemberConnection() {
|
||||
withBGApi {
|
||||
val r = chatModel.controller.apiSyncGroupMemberRatchet(rhId, groupInfo.apiId, member.groupMemberId, force = false)
|
||||
if (r != null) {
|
||||
connStats.value = r.second
|
||||
withChats {
|
||||
updateGroupMemberConnectionStats(rhId, groupInfo, r.first, r.second)
|
||||
}
|
||||
close.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chat != null) {
|
||||
val newRole = remember { mutableStateOf(member.memberRole) }
|
||||
GroupMemberInfoLayout(
|
||||
@@ -78,19 +89,30 @@ fun GroupMemberInfoView(
|
||||
}
|
||||
},
|
||||
createMemberContact = {
|
||||
withBGApi {
|
||||
progressIndicator = true
|
||||
val memberContact = chatModel.controller.apiCreateMemberContact(rhId, groupInfo.apiId, member.groupMemberId)
|
||||
if (memberContact != null) {
|
||||
val memberChat = Chat(remoteHostId = rhId, ChatInfo.Direct(memberContact), chatItems = arrayListOf())
|
||||
withChats {
|
||||
addChat(memberChat)
|
||||
openLoadedChat(memberChat)
|
||||
if (connectionStats != null) {
|
||||
if (connectionStats.ratchetSyncState == RatchetSyncState.Ok) {
|
||||
withBGApi {
|
||||
progressIndicator = true
|
||||
val memberContact = chatModel.controller.apiCreateMemberContact(rhId, groupInfo.apiId, member.groupMemberId)
|
||||
if (memberContact != null) {
|
||||
val memberChat = Chat(remoteHostId = rhId, ChatInfo.Direct(memberContact), chatItems = arrayListOf())
|
||||
withChats {
|
||||
addChat(memberChat)
|
||||
openLoadedChat(memberChat)
|
||||
}
|
||||
closeAll()
|
||||
chatModel.setContactNetworkStatus(memberContact, NetworkStatus.Connected())
|
||||
}
|
||||
progressIndicator = false
|
||||
}
|
||||
closeAll()
|
||||
chatModel.setContactNetworkStatus(memberContact, NetworkStatus.Connected())
|
||||
} else if (connectionStats.ratchetSyncAllowed) {
|
||||
showFixConnectionAlert(syncConnection = { syncMemberConnection() })
|
||||
} else {
|
||||
AlertManager.shared.showAlertMsg(
|
||||
generalGetString(MR.strings.cant_send_message_to_member_alert_title),
|
||||
generalGetString(MR.strings.encryption_renegotiation_in_progress)
|
||||
)
|
||||
}
|
||||
progressIndicator = false
|
||||
}
|
||||
},
|
||||
connectViaAddress = { connReqUri ->
|
||||
@@ -149,16 +171,7 @@ fun GroupMemberInfoView(
|
||||
})
|
||||
},
|
||||
syncMemberConnection = {
|
||||
withBGApi {
|
||||
val r = chatModel.controller.apiSyncGroupMemberRatchet(rhId, groupInfo.apiId, member.groupMemberId, force = false)
|
||||
if (r != null) {
|
||||
connStats.value = r.second
|
||||
withChats {
|
||||
updateGroupMemberConnectionStats(rhId, groupInfo, r.first, r.second)
|
||||
}
|
||||
close.invoke()
|
||||
}
|
||||
}
|
||||
syncMemberConnection()
|
||||
},
|
||||
syncMemberConnectionForce = {
|
||||
showSyncConnectionForceAlert(syncConnectionForce = {
|
||||
@@ -335,9 +348,20 @@ fun GroupMemberInfoLayout(
|
||||
val knownChat = if (contactId != null) knownDirectChat(contactId) else null
|
||||
if (knownChat != null) {
|
||||
val (chat, contact) = knownChat
|
||||
val knownContactConnectionStats: MutableState<ConnectionStats?> = remember { mutableStateOf(null) }
|
||||
|
||||
LaunchedEffect(contact.contactId) {
|
||||
withBGApi {
|
||||
val contactInfo = chatModel.controller.apiContactInfo(chat.remoteHostId, chat.chatInfo.apiId)
|
||||
if (contactInfo != null) {
|
||||
knownContactConnectionStats.value = contactInfo.first
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OpenChatButton(modifier = Modifier.fillMaxWidth(0.33f), onClick = { openDirectChat(contact.contactId) })
|
||||
AudioCallButton(modifier = Modifier.fillMaxWidth(0.5f), chat, contact)
|
||||
VideoButton(modifier = Modifier.fillMaxWidth(1f), chat, contact)
|
||||
AudioCallButton(modifier = Modifier.fillMaxWidth(0.5f), chat, contact, knownContactConnectionStats)
|
||||
VideoButton(modifier = Modifier.fillMaxWidth(1f), chat, contact, knownContactConnectionStats)
|
||||
} else if (groupInfo.fullGroupPreferences.directMessages.on(groupInfo.membership)) {
|
||||
if (contactId != null) {
|
||||
OpenChatButton(modifier = Modifier.fillMaxWidth(0.33f), onClick = { openDirectChat(contactId) }) // legacy - only relevant for direct contacts created when joining group
|
||||
|
||||
@@ -524,6 +524,10 @@
|
||||
<string name="sync_connection_force_question">Renegotiate encryption?</string>
|
||||
<string name="sync_connection_force_desc">The encryption is working and the new encryption agreement is not required. It may result in connection errors!</string>
|
||||
<string name="sync_connection_force_confirm">Renegotiate</string>
|
||||
<string name="sync_connection_question">Fix connection?</string>
|
||||
<string name="sync_connection_desc">Connection requires encryption renegotiation.</string>
|
||||
<string name="sync_connection_confirm">Fix</string>
|
||||
<string name="encryption_renegotiation_in_progress">Encryption renegotiation in progress.</string>
|
||||
<string name="view_security_code">View security code</string>
|
||||
<string name="verify_security_code">Verify security code</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user