fix(Pairing): Added installation info to pairing results (#10418)

This commit is contained in:
Igor Sirotin 2023-04-29 13:33:08 +03:00 committed by GitHub
parent e1c9f2f93f
commit abf58b008f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 150 additions and 54 deletions

View File

@ -1,23 +1,32 @@
import json, tables import json, tables
import base import base
import ../../../../app_service/service/accounts/dto/accounts import ../../../../app_service/service/accounts/dto/accounts
import ../../../../app_service/service/devices/dto/installation
import ../../../../app_service/service/devices/dto/local_pairing_event
type LocalPairingSignal* = ref object of Signal type LocalPairingSignal* = ref object of Signal
eventType*: string eventType*: EventType
action*: int action*: Action
error*: string error*: string
account*: AccountDto account*: AccountDto
installation*: InstallationDto
proc fromEvent*(T: type LocalPairingSignal, event: JsonNode): LocalPairingSignal = proc fromEvent*(T: type LocalPairingSignal, event: JsonNode): LocalPairingSignal =
result = LocalPairingSignal() result = LocalPairingSignal()
let e = event["event"] let e = event["event"]
if e.contains("type"): if e.contains("type"):
result.eventType = e["type"].getStr result.eventType = e["type"].getStr().parse()
if e.contains("action"): if e.contains("action"):
result.action = e["action"].getInt result.action = e["action"].getInt().parse()
if e.contains("error"): if e.contains("error"):
result.error = e["error"].getStr result.error = e["error"].getStr()
if e.contains("data"): if not e.contains("data"):
return
case result.eventType:
of EventReceivedAccount:
result.account = e["data"].toAccountDto() result.account = e["data"].toAccountDto()
of EventReceivedInstallation:
result.installation = e["data"].toInstallationDto()
else:
discard

View File

@ -109,6 +109,24 @@ QtObject:
proc onLocalPairingEvent*(self: View, eventType: EventType, action: Action, error: string) = proc onLocalPairingEvent*(self: View, eventType: EventType, action: Action, error: string) =
self.localPairingEvent(ord(eventType), ord(action), error) self.localPairingEvent(ord(eventType), ord(action), error)
proc getLocalPairingInstallationId*(self: View): string {.slot.} =
return self.localPairingStatus.installation.id
QtProperty[string] localPairingInstallationId:
read = getLocalPairingInstallationId
notify = localPairingStatusChanged
proc getLocalPairingInstallationName*(self: View): string {.slot.} =
return self.localPairingStatus.installation.metadata.name
QtProperty[string] localPairingInstallationName:
read = getLocalPairingInstallationName
notify = localPairingStatusChanged
proc getLocalPairingInstallationDeviceType*(self: View): string {.slot.} =
return self.localPairingStatus.installation.metadata.deviceType
QtProperty[string] localPairingInstallationDeviceType:
read = getLocalPairingInstallationDeviceType
notify = localPairingStatusChanged
proc onLocalPairingStatusUpdate*(self: View, status: LocalPairingStatus) = proc onLocalPairingStatusUpdate*(self: View, status: LocalPairingStatus) =
self.localPairingStatus = status self.localPairingStatus = status
self.localPairingStatusChanged() self.localPairingStatusChanged()

View File

@ -349,6 +349,24 @@ QtObject:
read = getLocalPairingImage read = getLocalPairingImage
notify = localPairingStatusChanged notify = localPairingStatusChanged
proc getLocalPairingInstallationId*(self: View): string {.slot.} =
return self.localPairingStatus.installation.id
QtProperty[string] localPairingInstallationId:
read = getLocalPairingInstallationId
notify = localPairingStatusChanged
proc getLocalPairingInstallationName*(self: View): string {.slot.} =
return self.localPairingStatus.installation.metadata.name
QtProperty[string] localPairingInstallationName:
read = getLocalPairingInstallationName
notify = localPairingStatusChanged
proc getLocalPairingInstallationDeviceType*(self: View): string {.slot.} =
return self.localPairingStatus.installation.metadata.deviceType
QtProperty[string] localPairingInstallationDeviceType:
read = getLocalPairingInstallationDeviceType
notify = localPairingStatusChanged
proc onLocalPairingStatusUpdate*(self: View, status: LocalPairingStatus) = proc onLocalPairingStatusUpdate*(self: View, status: LocalPairingStatus) =
self.localPairingStatus = status self.localPairingStatus = status
self.localPairingStatusChanged() self.localPairingStatusChanged()

View File

@ -1,5 +1,6 @@
import ../../../../app/core/eventemitter import ../../../../app/core/eventemitter
import ../../accounts/dto/accounts import ../../accounts/dto/accounts
import installation
type type
EventType* {.pure.} = enum EventType* {.pure.} = enum
@ -9,8 +10,9 @@ type
EventTransferError = 2, EventTransferError = 2,
EventTransferSuccess = 3, EventTransferSuccess = 3,
EventReceivedAccount = 4, EventReceivedAccount = 4,
EventProcessSuccess = 5, EventReceivedInstallation = 5
EventProcessError = 6 EventProcessSuccess = 6,
EventProcessError = 7
type type
Action* {.pure.} = enum Action* {.pure.} = enum
@ -18,6 +20,7 @@ type
ActionConnect = 1, ActionConnect = 1,
ActionPairingAccount = 2, ActionPairingAccount = 2,
ActionSyncDevice = 3, ActionSyncDevice = 3,
ActionPairingInstallation = 4,
type type
LocalPairingEventArgs* = ref object of Args LocalPairingEventArgs* = ref object of Args
@ -25,6 +28,7 @@ type
action*: Action action*: Action
error*: string error*: string
account*: AccountDTO account*: AccountDTO
installation*: InstallationDto
proc parse*(self: string): EventType = proc parse*(self: string): EventType =
case self: case self:
@ -42,6 +46,8 @@ proc parse*(self: string): EventType =
return EventProcessError return EventProcessError
of "received-account": of "received-account":
return EventReceivedAccount return EventReceivedAccount
of "received-installation":
return EventReceivedInstallation
else: else:
return EventUnknown return EventUnknown
@ -53,5 +59,7 @@ proc parse*(self: int): Action =
return ActionPairingAccount return ActionPairingAccount
of 3: of 3:
return ActionSyncDevice return ActionSyncDevice
of 4:
return ActionPairingInstallation
else: else:
return ActionUnknown return ActionUnknown

View File

@ -1,11 +1,11 @@
import ../../../../app/core/eventemitter import ../../../../app/core/eventemitter
import ../../accounts/dto/accounts import ../../accounts/dto/accounts
import installation
import local_pairing_event import local_pairing_event
type type
LocalPairingState* {.pure.} = enum LocalPairingState* {.pure.} = enum
Idle = 0 Idle = 0
WaitingForConnection
Transferring Transferring
Error Error
Finished Finished
@ -13,20 +13,22 @@ type
type type
LocalPairingMode* {.pure.} = enum LocalPairingMode* {.pure.} = enum
Idle = 0 Idle = 0
BootstrapingOtherDevice Sender
BootstrapingThisDevice Receiver
type type
LocalPairingStatus* = ref object of Args LocalPairingStatus* = ref object of Args
mode*: LocalPairingMode mode*: LocalPairingMode
state*: LocalPairingState state*: LocalPairingState
account*: AccountDTO account*: AccountDTO
installation*: InstallationDto
error*: string error*: string
proc reset*(self: LocalPairingStatus) = proc reset*(self: LocalPairingStatus) =
self.mode = LocalPairingMode.Idle self.mode = LocalPairingMode.Idle
self.state = LocalPairingState.Idle self.state = LocalPairingState.Idle
self.error = "" self.error = ""
self.installation = InstallationDto()
proc setup(self: LocalPairingStatus) = proc setup(self: LocalPairingStatus) =
self.reset() self.reset()
@ -38,29 +40,41 @@ proc newLocalPairingStatus*(): LocalPairingStatus =
new(result, delete) new(result, delete)
result.setup() result.setup()
proc update*(self: LocalPairingStatus, eventType: EventType, action: Action, account: AccountDTO, error: string) = proc update*(self: LocalPairingStatus, data: LocalPairingEventArgs) =
case eventType:
of EventConnectionSuccess: self.error = data.error
self.state = LocalPairingState.WaitingForConnection
of EventTransferSuccess: # process any incoming data
self.state = case self.mode: case data.eventType:
of LocalPairingMode.BootstrapingOtherDevice: of EventReceivedAccount:
LocalPairingState.Finished # For servers, `transfer` is last event self.account = data.account
of LocalPairingMode.BootstrapingThisDevice: of EventReceivedInstallation:
LocalPairingState.Transferring # For clients, `process` is last event self.installation = data.installation
else:
LocalPairingState.Idle
of EventProcessSuccess:
self.state = LocalPairingState.Finished
of EventConnectionError: of EventConnectionError:
self.state = LocalPairingState.Error self.state = LocalPairingState.Error
of EventTransferError: of EventTransferError:
self.state = LocalPairingState.Error self.state = LocalPairingState.Error
of EventProcessError: of EventProcessError:
self.state = LocalPairingState.Error self.state = LocalPairingState.Error
of EventReceivedAccount:
self.account = account
else: else:
discard discard
self.error = error if self.state == LocalPairingState.Error:
return
# Detect finished state
if (self.mode == LocalPairingMode.Sender and
data.eventType == EventProcessSuccess and
data.action == ActionPairingInstallation):
self.state = LocalPairingState.Finished
if (self.mode == LocalPairingMode.Receiver and
data.eventType == EventTransferSuccess and
data.action == ActionPairingInstallation):
self.state = LocalPairingState.Finished
if self.state == LocalPairingState.Finished:
return
self.state = LocalPairingState.Transferring

View File

@ -76,7 +76,7 @@ QtObject:
proc updateLocalPairingStatus(self: Service, data: LocalPairingEventArgs) = proc updateLocalPairingStatus(self: Service, data: LocalPairingEventArgs) =
self.events.emit(SIGNAL_LOCAL_PAIRING_EVENT, data) self.events.emit(SIGNAL_LOCAL_PAIRING_EVENT, data)
self.localPairingStatus.update(data.eventType, data.action, data.account, data.error) self.localPairingStatus.update(data)
self.events.emit(SIGNAL_LOCAL_PAIRING_STATUS_UPDATE, self.localPairingStatus) self.events.emit(SIGNAL_LOCAL_PAIRING_STATUS_UPDATE, self.localPairingStatus)
proc doConnect(self: Service) = proc doConnect(self: Service) =
@ -90,9 +90,10 @@ QtObject:
self.events.on(SignalType.LocalPairing.event) do(e:Args): self.events.on(SignalType.LocalPairing.event) do(e:Args):
let signalData = LocalPairingSignal(e) let signalData = LocalPairingSignal(e)
let data = LocalPairingEventArgs( let data = LocalPairingEventArgs(
eventType: signalData.eventType.parse(), eventType: signalData.eventType,
action: signalData.action.parse(), action: signalData.action,
account: signalData.account, account: signalData.account,
installation: signalData.installation,
error: signalData.error) error: signalData.error)
self.updateLocalPairingStatus(data) self.updateLocalPairingStatus(data)
@ -187,7 +188,7 @@ QtObject:
"timeout": 5 * 60 * 1000, "timeout": 5 * 60 * 1000,
} }
} }
self.localPairingStatus.mode = LocalPairingMode.BootstrapingOtherDevice self.localPairingStatus.mode = LocalPairingMode.Sender
return status_go.getConnectionStringForBootstrappingAnotherDevice($configJSON) return status_go.getConnectionStringForBootstrappingAnotherDevice($configJSON)
proc inputConnectionStringForBootstrapping*(self: Service, connectionString: string): string = proc inputConnectionStringForBootstrapping*(self: Service, connectionString: string): string =
@ -203,7 +204,7 @@ QtObject:
}, },
"clientConfig": %* {} "clientConfig": %* {}
} }
self.localPairingStatus.mode = LocalPairingMode.BootstrapingThisDevice self.localPairingStatus.mode = LocalPairingMode.Receiver
let arg = AsyncInputConnectionStringArg( let arg = AsyncInputConnectionStringArg(
tptr: cast[ByteAddress](asyncInputConnectionStringTask), tptr: cast[ByteAddress](asyncInputConnectionStringTask),

View File

@ -33,6 +33,7 @@ Rectangle {
property var inlineTagModel: [] property var inlineTagModel: []
property Component inlineTagDelegate property Component inlineTagDelegate
property bool loading: false property bool loading: false
property bool loadingSubTitle: loading
property bool errorMode: false property bool errorMode: false
property StatusAssetSettings asset: StatusAssetSettings { property StatusAssetSettings asset: StatusAssetSettings {
@ -291,7 +292,7 @@ Rectangle {
Theme.palette.baseColor1 : Theme.palette.directColor1 Theme.palette.baseColor1 : Theme.palette.directColor1
visible: !!root.subTitle visible: !!root.subTitle
wrapMode: Text.WrapAtWordBoundaryOrAnywhere wrapMode: Text.WrapAtWordBoundaryOrAnywhere
loading: root.loading loading: root.loadingSubTitle
maximumLineCount: 3 maximumLineCount: 3
elide: Text.ElideRight elide: Text.ElideRight
} }

View File

@ -17,6 +17,9 @@ QtObject {
readonly property string localPairingImage: startupModuleInst ? startupModuleInst.localPairingImage : "" readonly property string localPairingImage: startupModuleInst ? startupModuleInst.localPairingImage : ""
readonly property int localPairingColorId: startupModuleInst ? startupModuleInst.localPairingColorId : 0 readonly property int localPairingColorId: startupModuleInst ? startupModuleInst.localPairingColorId : 0
readonly property string localPairingColorHash: startupModuleInst ? startupModuleInst.localPairingColorHash : "" readonly property string localPairingColorHash: startupModuleInst ? startupModuleInst.localPairingColorHash : ""
readonly property string localPairingInstallationId: startupModuleInst ? startupModuleInst.localPairingInstallationId : ""
readonly property string localPairingInstallationName: startupModuleInst ? startupModuleInst.localPairingInstallationName : ""
readonly property string localPairingInstallationDeviceType: startupModuleInst ? startupModuleInst.localPairingInstallationDeviceType : ""
function backAction() { function backAction() {
root.currentStartupState.backAction() root.currentStartupState.backAction()

View File

@ -50,6 +50,9 @@ Item {
userColorId: startupStore.localPairingColorId userColorId: startupStore.localPairingColorId
userColorHash: startupStore.localPairingColorHash userColorHash: startupStore.localPairingColorHash
installationId: startupStore.localPairingInstallationId
installationName: startupStore.localPairingInstallationName
installationDeviceType: startupStore.localPairingInstallationDeviceType
} }
StatusButton { StatusButton {

View File

@ -76,8 +76,6 @@ StatusDialog {
target: root.devicesStore target: root.devicesStore
function onLocalPairingStateChanged() { function onLocalPairingStateChanged() {
switch (root.devicesStore.localPairingState) { switch (root.devicesStore.localPairingState) {
case Constants.LocalPairingState.WaitingForConnection:
break;
case Constants.LocalPairingState.Transferring: case Constants.LocalPairingState.Transferring:
d.localPairingStarted() d.localPairingStarted()
break break
@ -220,6 +218,10 @@ StatusDialog {
localPairingState: root.devicesStore.localPairingState localPairingState: root.devicesStore.localPairingState
localPairingError: root.devicesStore.localPairingError localPairingError: root.devicesStore.localPairingError
installationId: root.devicesStore.localPairingInstallationId
installationName: root.devicesStore.localPairingInstallationName
installationDeviceType: root.devicesStore.localPairingInstallationDeviceType
} }
Views.ErrorMessage { Views.ErrorMessage {

View File

@ -42,6 +42,7 @@ StatusDialog {
onOpened: { onOpened: {
nameInput.text = deviceModel.name nameInput.text = deviceModel.name
nameInput.forceActiveFocus()
} }
contentItem: ColumnLayout { contentItem: ColumnLayout {

View File

@ -13,6 +13,9 @@ QtObject {
readonly property int localPairingState: devicesModule ? devicesModule.localPairingState : -1 readonly property int localPairingState: devicesModule ? devicesModule.localPairingState : -1
readonly property string localPairingError: devicesModule ? devicesModule.localPairingError : "" readonly property string localPairingError: devicesModule ? devicesModule.localPairingError : ""
readonly property string localPairingInstallationId: devicesModule ? devicesModule.localPairingInstallationId : ""
readonly property string localPairingInstallationName: devicesModule ? devicesModule.localPairingInstallationName : ""
readonly property string localPairingInstallationDeviceType: devicesModule ? devicesModule.localPairingInstallationDeviceType : ""
function loadDevices() { function loadDevices() {
return root.devicesModule.loadDevices() return root.devicesModule.loadDevices()

View File

@ -10,15 +10,20 @@ import shared.controls 1.0
import shared.controls.chat 1.0 import shared.controls.chat 1.0
import utils 1.0 import utils 1.0
import SortFilterProxyModel 0.2
Item { Item {
id: root id: root
property alias devicesModel: listView.model property alias devicesModel: sfpModel.sourceModel
property string userDisplayName property string userDisplayName
property string userColorId property string userColorId
property string userColorHash property string userColorHash
property string userPublicKey property string userPublicKey
property string userImage property string userImage
property string installationId
property string installationName
property string installationDeviceType
property int localPairingState: Constants.LocalPairingState.Idle property int localPairingState: Constants.LocalPairingState.Idle
property string localPairingError property string localPairingError
@ -66,7 +71,6 @@ Item {
active: root.userPublicKey == "" active: root.userPublicKey == ""
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
sourceComponent: UserImage { sourceComponent: UserImage {
opacity: name ? 1 : 0
name: root.userDisplayName name: root.userDisplayName
colorId: root.userColorId colorId: root.userColorId
colorHash: root.userColorHash colorHash: root.userColorHash
@ -74,10 +78,7 @@ Item {
interactive: false interactive: false
imageWidth: 80 imageWidth: 80
imageHeight: 80 imageHeight: 80
loading: name === ""
Behavior on opacity {
NumberAnimation { duration: 250 }
}
} }
} }
@ -130,10 +131,13 @@ Item {
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
implicitWidth: d.deviceDelegateWidth implicitWidth: d.deviceDelegateWidth
visible: !d.pairingFailed visible: !d.pairingFailed
subTitle: qsTr("Synced device") subTitle: d.pairingInProgress ? qsTr("Syncing with device")
: qsTr("Synced device")
enabled: false enabled: false
loading: d.pairingInProgress loading: d.pairingInProgress
deviceName: qsTr("No device name") loadingSubTitle: false
deviceName: root.installationName
deviceType: root.installationDeviceType
isCurrentDevice: false isCurrentDevice: false
showOnlineBadge: false showOnlineBadge: false
} }
@ -180,6 +184,18 @@ Item {
spacing: 4 spacing: 4
clip: true clip: true
model: SortFilterProxyModel {
id: sfpModel
filters: [
ValueFilter {
enabled: true
roleName: "installationId"
value: root.installationId
inverted: true
}
]
}
delegate: StatusSyncDeviceDelegate { delegate: StatusSyncDeviceDelegate {
width: ListView.view.width width: ListView.view.width
enabled: false enabled: false

View File

@ -676,10 +676,9 @@ QtObject {
enum LocalPairingState { enum LocalPairingState {
Idle = 0, Idle = 0,
WaitingForConnection = 1, Transferring = 1,
Transferring = 2, Error = 2,
Error = 3, Finished = 3
Finished = 4
} }
readonly property var socialLinkPrefixesByType: [ // NB order must match the "socialLinkType" enum above readonly property var socialLinkPrefixesByType: [ // NB order must match the "socialLinkType" enum above

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 4212dde28870479b23e84249937456917532db5a Subproject commit c8161a5fa4ba87f7ae9b1e1e50c2d2bc93123103