mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-03 21:21:46 +00:00
Merge branch 'master' into master-ghc8107
This commit is contained in:
+6
-4
@@ -122,7 +122,7 @@ object ChatModel {
|
||||
}
|
||||
|
||||
private fun getUserIndex(user: User): Int =
|
||||
users.indexOfFirst { it.user.userId == user.userId }
|
||||
users.indexOfFirst { it.user.userId == user.userId && it.user.remoteHostId == user.remoteHostId }
|
||||
|
||||
fun updateUser(user: User) {
|
||||
val i = getUserIndex(user)
|
||||
@@ -616,7 +616,7 @@ enum class ChatType(val type: String) {
|
||||
|
||||
@Serializable
|
||||
data class User(
|
||||
val remoteHostId: Long? = null,
|
||||
val remoteHostId: Long?,
|
||||
override val userId: Long,
|
||||
val userContactId: Long,
|
||||
val localDisplayName: String,
|
||||
@@ -639,6 +639,7 @@ data class User(
|
||||
|
||||
companion object {
|
||||
val sampleData = User(
|
||||
remoteHostId = null,
|
||||
userId = 1,
|
||||
userContactId = 1,
|
||||
localDisplayName = "alice",
|
||||
@@ -715,8 +716,8 @@ interface SomeChat {
|
||||
}
|
||||
|
||||
@Serializable @Stable
|
||||
data class Chat (
|
||||
val remoteHostId: Long? = null,
|
||||
data class Chat(
|
||||
val remoteHostId: Long?,
|
||||
val chatInfo: ChatInfo,
|
||||
val chatItems: List<ChatItem>,
|
||||
val chatStats: ChatStats = ChatStats()
|
||||
@@ -749,6 +750,7 @@ data class Chat (
|
||||
|
||||
companion object {
|
||||
val sampleData = Chat(
|
||||
remoteHostId = null,
|
||||
chatInfo = ChatInfo.Direct.sampleData,
|
||||
chatItems = arrayListOf(ChatItem.getSampleData())
|
||||
)
|
||||
|
||||
+5
-2
@@ -2531,7 +2531,7 @@ data class UserProtocolServers(
|
||||
|
||||
@Serializable
|
||||
data class ServerCfg(
|
||||
val remoteHostId: Long? = null,
|
||||
val remoteHostId: Long?,
|
||||
val server: String,
|
||||
val preset: Boolean,
|
||||
val tested: Boolean? = null,
|
||||
@@ -2549,7 +2549,7 @@ data class ServerCfg(
|
||||
get() = server.isBlank()
|
||||
|
||||
companion object {
|
||||
val empty = ServerCfg(server = "", preset = false, tested = null, enabled = true)
|
||||
val empty = ServerCfg(remoteHostId = null, server = "", preset = false, tested = null, enabled = true)
|
||||
|
||||
class SampleData(
|
||||
val preset: ServerCfg,
|
||||
@@ -2559,18 +2559,21 @@ data class ServerCfg(
|
||||
|
||||
val sampleData = SampleData(
|
||||
preset = ServerCfg(
|
||||
remoteHostId = null,
|
||||
server = "smp://abcd@smp8.simplex.im",
|
||||
preset = true,
|
||||
tested = true,
|
||||
enabled = true
|
||||
),
|
||||
custom = ServerCfg(
|
||||
remoteHostId = null,
|
||||
server = "smp://abcd@smp9.simplex.im",
|
||||
preset = false,
|
||||
tested = false,
|
||||
enabled = false
|
||||
),
|
||||
untested = ServerCfg(
|
||||
remoteHostId = null,
|
||||
server = "smp://abcd@smp10.simplex.im",
|
||||
preset = false,
|
||||
tested = null,
|
||||
|
||||
+1
@@ -106,6 +106,7 @@ fun PreviewIncomingCallAlertLayout() {
|
||||
SimpleXTheme {
|
||||
IncomingCallAlertLayout(
|
||||
invitation = RcvCallInvitation(
|
||||
remoteHostId = null,
|
||||
user = User.sampleData,
|
||||
contact = Contact.sampleData,
|
||||
callType = CallType(media = CallMediaType.Audio, capabilities = CallCapabilities(encryption = false)),
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
data class Call(
|
||||
val remoteHostId: Long? = null,
|
||||
val remoteHostId: Long?,
|
||||
val contact: Contact,
|
||||
val callState: CallState,
|
||||
val localMedia: CallMediaType,
|
||||
@@ -97,7 +97,7 @@ sealed class WCallResponse {
|
||||
@Serializable data class WebRTCExtraInfo(val rtcIceCandidates: String)
|
||||
@Serializable data class CallType(val media: CallMediaType, val capabilities: CallCapabilities)
|
||||
@Serializable data class RcvCallInvitation(
|
||||
val remoteHostId: Long? = null,
|
||||
val remoteHostId: Long?,
|
||||
val user: User,
|
||||
val contact: Contact,
|
||||
val callType: CallType,
|
||||
|
||||
+1
@@ -718,6 +718,7 @@ fun PreviewChatInfoLayout() {
|
||||
SimpleXTheme {
|
||||
ChatInfoLayout(
|
||||
chat = Chat(
|
||||
remoteHostId = null,
|
||||
chatInfo = ChatInfo.Direct.sampleData,
|
||||
chatItems = arrayListOf()
|
||||
),
|
||||
|
||||
+2
@@ -1418,6 +1418,7 @@ fun PreviewChatLayout() {
|
||||
val searchValue = remember { mutableStateOf("") }
|
||||
ChatLayout(
|
||||
chat = Chat(
|
||||
remoteHostId = null,
|
||||
chatInfo = ChatInfo.Direct.sampleData,
|
||||
chatItems = chatItems,
|
||||
chatStats = Chat.ChatStats()
|
||||
@@ -1490,6 +1491,7 @@ fun PreviewGroupChatLayout() {
|
||||
val searchValue = remember { mutableStateOf("") }
|
||||
ChatLayout(
|
||||
chat = Chat(
|
||||
remoteHostId = null,
|
||||
chatInfo = ChatInfo.Group.sampleData,
|
||||
chatItems = chatItems,
|
||||
chatStats = Chat.ChatStats()
|
||||
|
||||
+1
@@ -524,6 +524,7 @@ fun PreviewGroupChatInfoLayout() {
|
||||
SimpleXTheme {
|
||||
GroupChatInfoLayout(
|
||||
chat = Chat(
|
||||
remoteHostId = null,
|
||||
chatInfo = ChatInfo.Direct.sampleData,
|
||||
chatItems = arrayListOf()
|
||||
),
|
||||
|
||||
+2
@@ -772,6 +772,7 @@ fun PreviewChatListNavLinkDirect() {
|
||||
chatLinkPreview = {
|
||||
ChatPreviewView(
|
||||
chat = Chat(
|
||||
remoteHostId = null,
|
||||
chatInfo = ChatInfo.Direct.sampleData,
|
||||
chatItems = listOf(
|
||||
ChatItem.getSampleData(
|
||||
@@ -815,6 +816,7 @@ fun PreviewChatListNavLinkGroup() {
|
||||
chatLinkPreview = {
|
||||
ChatPreviewView(
|
||||
Chat(
|
||||
remoteHostId = null,
|
||||
chatInfo = ChatInfo.Group.sampleData,
|
||||
chatItems = listOf(
|
||||
ChatItem.getSampleData(
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ fun ChatListView(chatModel: ChatModel, settingsState: SettingsViewState, setPerf
|
||||
if (searchInList.isEmpty()) {
|
||||
DesktopActiveCallOverlayLayout(newChatSheetState)
|
||||
// TODO disable this button and sheet for the duration of the switch
|
||||
NewChatSheet(chatModel, chatModel.remoteHostId, newChatSheetState, stopped, hideNewChatSheet)
|
||||
NewChatSheet(chatModel, newChatSheetState, stopped, hideNewChatSheet)
|
||||
}
|
||||
if (appPlatform.isAndroid) {
|
||||
UserPicker(chatModel, userPickerState, switchingUsersAndHosts) {
|
||||
|
||||
+6
-6
@@ -25,13 +25,13 @@ import chat.simplex.res.MR
|
||||
@Composable
|
||||
fun AddContactView(
|
||||
chatModel: ChatModel,
|
||||
rhId: Long?,
|
||||
rh: RemoteHostInfo?,
|
||||
connReqInvitation: String,
|
||||
contactConnection: MutableState<PendingContactConnection?>
|
||||
) {
|
||||
val clipboard = LocalClipboardManager.current
|
||||
AddContactLayout(
|
||||
rhId = rhId,
|
||||
rh = rh,
|
||||
chatModel = chatModel,
|
||||
incognitoPref = chatModel.controller.appPrefs.incognito,
|
||||
connReq = connReqInvitation,
|
||||
@@ -54,7 +54,7 @@ fun AddContactView(
|
||||
@Composable
|
||||
fun AddContactLayout(
|
||||
chatModel: ChatModel,
|
||||
rhId: Long?,
|
||||
rh: RemoteHostInfo?,
|
||||
incognitoPref: SharedPreference<Boolean>,
|
||||
connReq: String,
|
||||
contactConnection: MutableState<PendingContactConnection?>,
|
||||
@@ -66,9 +66,9 @@ fun AddContactLayout(
|
||||
withApi {
|
||||
val contactConnVal = contactConnection.value
|
||||
if (contactConnVal != null) {
|
||||
chatModel.controller.apiSetConnectionIncognito(rhId, contactConnVal.pccConnId, incognito.value)?.let {
|
||||
chatModel.controller.apiSetConnectionIncognito(rh?.remoteHostId, contactConnVal.pccConnId, incognito.value)?.let {
|
||||
contactConnection.value = it
|
||||
chatModel.updateContactConnection(rhId, it)
|
||||
chatModel.updateContactConnection(rh?.remoteHostId, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,7 +175,7 @@ fun sharedProfileInfo(
|
||||
fun PreviewAddContactView() {
|
||||
SimpleXTheme {
|
||||
AddContactLayout(
|
||||
rhId = null,
|
||||
rh = null,
|
||||
chatModel = ChatModel,
|
||||
incognitoPref = SharedPreference({ false }, {}),
|
||||
connReq = "https://simplex.chat/contact#/?v=1&smp=smp%3A%2F%2FPQUV2eL0t7OStZOoAsPEV2QYWt4-xilbakvGUGOItUo%3D%40smp6.simplex.im%2FK1rslx-m5bpXVIdMZg9NLUZ_8JBm8xTt%23MCowBQYDK2VuAyEALDeVe-sG8mRY22LsXlPgiwTNs9dbiLrNuA7f3ZMAJ2w%3D",
|
||||
|
||||
+2
-1
@@ -32,7 +32,8 @@ import kotlinx.coroutines.launch
|
||||
import java.net.URI
|
||||
|
||||
@Composable
|
||||
fun AddGroupView(chatModel: ChatModel, rhId: Long?, close: () -> Unit) {
|
||||
fun AddGroupView(chatModel: ChatModel, rh: RemoteHostInfo?, close: () -> Unit) {
|
||||
val rhId = rh?.remoteHostId
|
||||
AddGroupLayout(
|
||||
createGroup = { incognito, groupProfile ->
|
||||
withApi {
|
||||
|
||||
+2
-1
@@ -2,10 +2,11 @@ package chat.simplex.common.views.newchat
|
||||
|
||||
import androidx.compose.runtime.*
|
||||
import chat.simplex.common.model.ChatModel
|
||||
import chat.simplex.common.model.RemoteHostInfo
|
||||
|
||||
enum class ConnectViaLinkTab {
|
||||
SCAN, PASTE
|
||||
}
|
||||
|
||||
@Composable
|
||||
expect fun ConnectViaLinkView(m: ChatModel, rhId: Long?, close: () -> Unit)
|
||||
expect fun ConnectViaLinkView(m: ChatModel, rh: RemoteHostInfo?, close: () -> Unit)
|
||||
|
||||
+5
-6
@@ -9,8 +9,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import dev.icerock.moko.resources.compose.painterResource
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
import androidx.compose.ui.unit.sp
|
||||
import chat.simplex.common.model.ChatModel
|
||||
import chat.simplex.common.model.PendingContactConnection
|
||||
import chat.simplex.common.model.*
|
||||
import chat.simplex.common.views.helpers.*
|
||||
import chat.simplex.common.views.usersettings.UserAddressView
|
||||
import chat.simplex.res.MR
|
||||
@@ -20,7 +19,7 @@ enum class CreateLinkTab {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CreateLinkView(m: ChatModel, rhId: Long?, initialSelection: CreateLinkTab) {
|
||||
fun CreateLinkView(m: ChatModel, rh: RemoteHostInfo?, initialSelection: CreateLinkTab) {
|
||||
val selection = remember { mutableStateOf(initialSelection) }
|
||||
val connReqInvitation = rememberSaveable { m.connReqInv }
|
||||
val contactConnection: MutableState<PendingContactConnection?> = rememberSaveable(stateSaver = serializableSaver()) { mutableStateOf(null) }
|
||||
@@ -32,7 +31,7 @@ fun CreateLinkView(m: ChatModel, rhId: Long?, initialSelection: CreateLinkTab) {
|
||||
&& contactConnection.value == null
|
||||
&& !creatingConnReq.value
|
||||
) {
|
||||
createInvitation(m, rhId, creatingConnReq, connReqInvitation, contactConnection)
|
||||
createInvitation(m, rh?.remoteHostId, creatingConnReq, connReqInvitation, contactConnection)
|
||||
}
|
||||
}
|
||||
/** When [AddContactView] is open, we don't need to drop [chatModel.connReqInv].
|
||||
@@ -65,10 +64,10 @@ fun CreateLinkView(m: ChatModel, rhId: Long?, initialSelection: CreateLinkTab) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
when (selection.value) {
|
||||
CreateLinkTab.ONE_TIME -> {
|
||||
AddContactView(m, rhId,connReqInvitation.value ?: "", contactConnection)
|
||||
AddContactView(m, rh,connReqInvitation.value ?: "", contactConnection)
|
||||
}
|
||||
CreateLinkTab.LONG_TERM -> {
|
||||
UserAddressView(m, rhId, viaCreateLinkView = true, close = {})
|
||||
UserAddressView(m, rh?.remoteHostId, viaCreateLinkView = true, close = {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -33,7 +33,7 @@ import kotlinx.coroutines.launch
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Composable
|
||||
fun NewChatSheet(chatModel: ChatModel, rhId: Long?, newChatSheetState: StateFlow<AnimatedViewState>, stopped: Boolean, closeNewChatSheet: (animated: Boolean) -> Unit) {
|
||||
fun NewChatSheet(chatModel: ChatModel, newChatSheetState: StateFlow<AnimatedViewState>, stopped: Boolean, closeNewChatSheet: (animated: Boolean) -> Unit) {
|
||||
// TODO close new chat if remote host changes in model
|
||||
if (newChatSheetState.collectAsState().value.isVisible()) BackHandler { closeNewChatSheet(true) }
|
||||
NewChatSheetLayout(
|
||||
@@ -42,17 +42,17 @@ fun NewChatSheet(chatModel: ChatModel, rhId: Long?, newChatSheetState: StateFlow
|
||||
addContact = {
|
||||
closeNewChatSheet(false)
|
||||
ModalManager.center.closeModals()
|
||||
ModalManager.center.showModal { CreateLinkView(chatModel, rhId, CreateLinkTab.ONE_TIME) }
|
||||
ModalManager.center.showModal { CreateLinkView(chatModel, chatModel.currentRemoteHost.value, CreateLinkTab.ONE_TIME) }
|
||||
},
|
||||
connectViaLink = {
|
||||
closeNewChatSheet(false)
|
||||
ModalManager.center.closeModals()
|
||||
ModalManager.center.showModalCloseable { close -> ConnectViaLinkView(chatModel, rhId, close) }
|
||||
ModalManager.center.showModalCloseable { close -> ConnectViaLinkView(chatModel, chatModel.currentRemoteHost.value, close) }
|
||||
},
|
||||
createGroup = {
|
||||
closeNewChatSheet(false)
|
||||
ModalManager.center.closeModals()
|
||||
ModalManager.center.showCustomModal { close -> AddGroupView(chatModel, rhId, close) }
|
||||
ModalManager.center.showCustomModal { close -> AddGroupView(chatModel, chatModel.currentRemoteHost.value, close) }
|
||||
},
|
||||
closeNewChatSheet,
|
||||
)
|
||||
|
||||
+6
-7
@@ -14,8 +14,7 @@ import dev.icerock.moko.resources.compose.stringResource
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.unit.dp
|
||||
import chat.simplex.common.model.ChatModel
|
||||
import chat.simplex.common.model.SharedPreference
|
||||
import chat.simplex.common.model.*
|
||||
import chat.simplex.common.ui.theme.*
|
||||
import chat.simplex.common.views.helpers.*
|
||||
import chat.simplex.common.views.usersettings.IncognitoView
|
||||
@@ -24,12 +23,12 @@ import chat.simplex.res.MR
|
||||
import java.net.URI
|
||||
|
||||
@Composable
|
||||
fun PasteToConnectView(chatModel: ChatModel, rhId: Long?, close: () -> Unit) {
|
||||
fun PasteToConnectView(chatModel: ChatModel, rh: RemoteHostInfo?, close: () -> Unit) {
|
||||
val connectionLink = remember { mutableStateOf("") }
|
||||
val clipboard = LocalClipboardManager.current
|
||||
PasteToConnectLayout(
|
||||
chatModel = chatModel,
|
||||
rhId = rhId,
|
||||
rh = rh,
|
||||
incognitoPref = chatModel.controller.appPrefs.incognito,
|
||||
connectionLink = connectionLink,
|
||||
pasteFromClipboard = {
|
||||
@@ -42,14 +41,14 @@ fun PasteToConnectView(chatModel: ChatModel, rhId: Long?, close: () -> Unit) {
|
||||
@Composable
|
||||
fun PasteToConnectLayout(
|
||||
chatModel: ChatModel,
|
||||
rhId: Long?,
|
||||
rh: RemoteHostInfo?,
|
||||
incognitoPref: SharedPreference<Boolean>,
|
||||
connectionLink: MutableState<String>,
|
||||
pasteFromClipboard: () -> Unit,
|
||||
close: () -> Unit
|
||||
) {
|
||||
val incognito = remember { mutableStateOf(incognitoPref.get()) }
|
||||
|
||||
val rhId = rh?.remoteHostId
|
||||
fun connectViaLink(connReqUri: String) {
|
||||
try {
|
||||
val uri = URI(connReqUri)
|
||||
@@ -126,7 +125,7 @@ fun PreviewPasteToConnectTextbox() {
|
||||
SimpleXTheme {
|
||||
PasteToConnectLayout(
|
||||
chatModel = ChatModel,
|
||||
rhId = null,
|
||||
rh = null,
|
||||
incognitoPref = SharedPreference({ false }, {}),
|
||||
connectionLink = remember { mutableStateOf("") },
|
||||
pasteFromClipboard = {},
|
||||
|
||||
+4
-4
@@ -26,7 +26,7 @@ import chat.simplex.res.MR
|
||||
import java.net.URI
|
||||
|
||||
@Composable
|
||||
expect fun ScanToConnectView(chatModel: ChatModel, rhId: Long?, close: () -> Unit)
|
||||
expect fun ScanToConnectView(chatModel: ChatModel, rh: RemoteHostInfo?, close: () -> Unit)
|
||||
|
||||
enum class ConnectionLinkType {
|
||||
INVITATION, CONTACT, GROUP
|
||||
@@ -428,7 +428,7 @@ fun openKnownGroup(chatModel: ChatModel, rhId: Long?, close: (() -> Unit)?, grou
|
||||
@Composable
|
||||
fun ConnectContactLayout(
|
||||
chatModel: ChatModel,
|
||||
rhId: Long?,
|
||||
rh: RemoteHostInfo?,
|
||||
incognitoPref: SharedPreference<Boolean>,
|
||||
close: () -> Unit
|
||||
) {
|
||||
@@ -440,7 +440,7 @@ fun ConnectContactLayout(
|
||||
try {
|
||||
val uri = URI(connReqUri)
|
||||
withApi {
|
||||
planAndConnect(chatModel, rhId, uri, incognito = incognito.value, close)
|
||||
planAndConnect(chatModel, rh?.remoteHostId, uri, incognito = incognito.value, close)
|
||||
}
|
||||
} catch (e: RuntimeException) {
|
||||
AlertManager.shared.showAlertMsg(
|
||||
@@ -492,7 +492,7 @@ fun PreviewConnectContactLayout() {
|
||||
SimpleXTheme {
|
||||
ConnectContactLayout(
|
||||
chatModel = ChatModel,
|
||||
rhId = null,
|
||||
rh = null,
|
||||
incognitoPref = SharedPreference({ false }, {}),
|
||||
close = {},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user