Implement a working Distant Chat prototype in Qml

Deprecate id field in JSON API as it may cause problems in Qml
Offer gxs_id field in JSON API as an id alternative
LibresapiLocalClient support callbacks now an instance may be shared for
  different tasks
Expose an instance of LibresapiLocalClient to Qml, type exposure is kept
  for retrocompatibility but deprecated
Qml app now has a tab that permit to exchange some message with selected
  distant peer
This commit is contained in:
Gio 2016-12-08 15:56:23 +01:00
parent 242338d10c
commit c3aca0cf26
11 changed files with 259 additions and 170 deletions

View file

@ -22,17 +22,33 @@ import org.retroshare.qml_components.LibresapiLocalClient 1.0
Item
{
function refreshData() { rsApi.request("/identity/*/", "") }
id: contactsView
property string own_gxs_id: ""
property string own_nick: ""
Component.onCompleted: refreshOwn()
function refreshData() { rsApi.request("/identity/*/", "", function(par) { locationsModel.json = par.response; if(contactsView.own_gxs_id == "") refreshOwn() }) }
function refreshOwn()
{
rsApi.request("/identity/own", "", function(par)
{
var json = JSON.parse(par.response)
if(json.data.length > 0)
{
contactsView.own_gxs_id = json.data[0].gxs_id
contactsView.own_nick = json.data[0].name
}
else
{
selectedOwnIdentityView.color = "red"
selectedOwnIdentityView.text = "You need to create a GXS identity to chat!"
}
})
}
onFocusChanged: focus && refreshData()
LibresapiLocalClient
{
id: rsApi
onGoodResponseReceived: locationsModel.json = msg
Component.onCompleted: { openConnection(apiSocketPath) }
}
JSONListModel
{
id: locationsModel
@ -45,8 +61,48 @@ Item
width: parent.width
height: 300
model: locationsModel.model
delegate: Text { text: model.name }
delegate: Item
{
height: 20
width: parent.width
MouseArea
{
anchors.fill: parent
onClicked:
{
if(model.own) contactsView.own_gxs_id = model.gxs_id
else
{
var jsonData = { "own_gxs_hex": contactsView.own_gxs_id, "remote_gxs_hex": model.gxs_id }
rsApi.request("/chat/initiate_distant_chat", JSON.stringify(jsonData), function (par) { mainWindow.activeChatId = JSON.parse(par.response).data.chat_id })
}
}
Text
{
color: model.own ? "blue" : "black"
text: model.name + " " + model.gxs_id
}
}
}
}
Text { text: "Contacts View"; anchors.bottom: parent.bottom }
Text
{
id: selectedOwnIdentityView
color: "green"
anchors.bottom: parent.bottom
anchors.left: parent.left
width: parent.width
text: "Open Chat as: " + contactsView.own_nick + " " + contactsView.own_gxs_id
}
Timer
{
id: refreshTimer
interval: 5000
repeat: true
onTriggered: if(contactsView.visible) contactsView.refreshData()
Component.onCompleted: start()
}
}