2016-09-15 07:07:13 -04:00
|
|
|
/*
|
|
|
|
* RetroShare Android QML App
|
2017-03-17 12:22:58 -04:00
|
|
|
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
2016-09-15 07:07:13 -04:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-04-16 08:46:43 -04:00
|
|
|
import QtQuick 2.7
|
2017-03-24 07:02:13 -04:00
|
|
|
import QtQuick.Controls 2.0
|
2016-09-15 07:07:13 -04:00
|
|
|
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
2017-04-11 09:48:16 -04:00
|
|
|
import "." //Needed for TokensManager singleton
|
2017-04-19 08:23:29 -04:00
|
|
|
import Qt.labs.settings 1.0
|
2016-09-15 07:07:13 -04:00
|
|
|
|
|
|
|
Item
|
|
|
|
{
|
2016-12-08 09:56:23 -05:00
|
|
|
id: contactsView
|
|
|
|
property string own_gxs_id: ""
|
|
|
|
property string own_nick: ""
|
2017-03-24 07:02:13 -04:00
|
|
|
property bool searching: false
|
2017-04-03 15:51:03 -04:00
|
|
|
onSearchingChanged: !searching && contactsSortWorker.sendMessage({})
|
2016-09-15 07:07:13 -04:00
|
|
|
|
2017-04-03 15:51:03 -04:00
|
|
|
Component.onCompleted: refreshAll()
|
|
|
|
onFocusChanged: focus && refreshAll()
|
2016-09-15 07:07:13 -04:00
|
|
|
|
2017-04-03 15:51:03 -04:00
|
|
|
WorkerScript
|
2017-03-17 12:22:58 -04:00
|
|
|
{
|
2017-04-03 15:51:03 -04:00
|
|
|
id: contactsSortWorker
|
2017-04-13 10:47:27 -04:00
|
|
|
source: "qrc:/ContactSort.js"
|
2017-04-03 15:51:03 -04:00
|
|
|
onMessage: contactsListModel.json = JSON.stringify(messageObject)
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshAll()
|
|
|
|
{
|
|
|
|
refreshOwn()
|
|
|
|
refreshContacts()
|
|
|
|
refreshUnread()
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshContactsCallback(par)
|
|
|
|
{
|
|
|
|
console.log("contactsView.refreshContactsCB()", visible)
|
|
|
|
var token = JSON.parse(par.response).statetoken
|
2017-06-21 10:31:20 -04:00
|
|
|
ChatCache.contactsCache.contactsList = JSON.parse(par.response).data
|
2017-04-11 09:48:16 -04:00
|
|
|
TokensManager.registerToken(token, refreshContacts)
|
2017-04-03 15:51:03 -04:00
|
|
|
contactsSortWorker.sendMessage(
|
|
|
|
{'action': 'refreshContacts', 'response': par.response})
|
|
|
|
}
|
|
|
|
function refreshContacts()
|
|
|
|
{
|
|
|
|
console.log("contactsView.refreshContacts()", visible)
|
|
|
|
if(!visible) return
|
|
|
|
rsApi.request("/identity/*/", "", refreshContactsCallback)
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshOwnCallback(par)
|
|
|
|
{
|
|
|
|
console.log("contactsView.refreshOwnCallback(par)", visible)
|
|
|
|
var json = JSON.parse(par.response)
|
|
|
|
var token = json.statetoken
|
2017-04-11 09:48:16 -04:00
|
|
|
TokensManager.registerToken(token, refreshOwn)
|
2017-04-03 15:51:03 -04:00
|
|
|
|
|
|
|
if(json.data.length > 0)
|
2017-03-17 12:22:58 -04:00
|
|
|
{
|
2017-04-03 15:51:03 -04:00
|
|
|
contactsView.own_gxs_id = json.data[0].gxs_id
|
|
|
|
contactsView.own_nick = json.data[0].name
|
2017-04-20 15:39:59 -04:00
|
|
|
if(mainWindow.user_name.length === 0)
|
|
|
|
mainWindow.user_name = json.data[0].name
|
2017-03-17 12:22:58 -04:00
|
|
|
}
|
2017-04-19 08:23:29 -04:00
|
|
|
else if (!settings.defaultIdentityCreated)
|
2017-04-07 12:26:08 -04:00
|
|
|
{
|
2017-04-18 07:05:07 -04:00
|
|
|
console.log("refreshOwnCallback(par)", "creating new identity" )
|
2017-04-19 08:23:29 -04:00
|
|
|
settings.defaultIdentityCreated = true
|
2017-04-18 07:05:07 -04:00
|
|
|
|
2017-04-20 15:39:59 -04:00
|
|
|
var jsonData = { "name": mainWindow.user_name, "pgp_linked": false }
|
2017-04-07 12:26:08 -04:00
|
|
|
rsApi.request(
|
|
|
|
"/identity/create_identity",
|
|
|
|
JSON.stringify(jsonData),
|
|
|
|
refreshOwn)
|
|
|
|
}
|
2017-03-17 12:22:58 -04:00
|
|
|
}
|
2016-12-08 09:56:23 -05:00
|
|
|
function refreshOwn()
|
2016-09-15 07:07:13 -04:00
|
|
|
{
|
2017-04-03 15:51:03 -04:00
|
|
|
console.log("contactsView.refreshOwn()", visible)
|
|
|
|
rsApi.request("/identity/own", "", refreshOwnCallback)
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
2017-04-03 15:51:03 -04:00
|
|
|
|
|
|
|
function refreshUnreadCallback(par)
|
2017-03-17 12:22:58 -04:00
|
|
|
{
|
2017-04-03 15:51:03 -04:00
|
|
|
console.log("contactsView.refreshUnreadCB()", visible)
|
|
|
|
var json = JSON.parse(par.response)
|
2017-04-11 09:48:16 -04:00
|
|
|
TokensManager.registerToken(json.statetoken, refreshUnread)
|
2017-04-03 15:51:03 -04:00
|
|
|
contactsSortWorker.sendMessage(
|
|
|
|
{'action': 'refreshUnread', 'response': par.response})
|
2017-06-13 08:51:53 -04:00
|
|
|
json.data.forEach (function (chat)
|
|
|
|
{
|
2017-06-03 11:58:53 -04:00
|
|
|
ChatCache.lastMessageCache.updateLastMessageCache(chat.chat_id)
|
2017-06-12 09:44:07 -04:00
|
|
|
ChatCache.lastMessageCache.setRemoteGXS (chat.chat_id, { gxs: chat.remote_author_id, name: chat.remote_author_name})
|
2017-06-03 11:58:53 -04:00
|
|
|
})
|
2017-03-17 12:22:58 -04:00
|
|
|
}
|
2017-03-24 07:02:13 -04:00
|
|
|
function refreshUnread()
|
|
|
|
{
|
2017-04-03 15:51:03 -04:00
|
|
|
console.log("contactsView.refreshUnread()", visible)
|
|
|
|
if(!visible) return
|
|
|
|
rsApi.request("/chat/unread_msgs", "", refreshUnreadCallback)
|
|
|
|
}
|
2017-03-24 07:02:13 -04:00
|
|
|
|
2017-04-03 15:51:03 -04:00
|
|
|
function startChatCallback(par)
|
|
|
|
{
|
|
|
|
var chId = JSON.parse(par.response).data.chat_id
|
2017-04-13 10:47:27 -04:00
|
|
|
stackView.push("qrc:/ChatView.qml", {'chatId': chId})
|
2017-03-24 07:02:13 -04:00
|
|
|
}
|
|
|
|
|
2017-04-03 15:51:03 -04:00
|
|
|
|
2017-03-24 07:02:13 -04:00
|
|
|
/** This must be equivalent to
|
|
|
|
p3GxsTunnelService::makeGxsTunnelId(...) */
|
|
|
|
function getChatId(from_gxs, to_gxs)
|
|
|
|
{
|
|
|
|
return from_gxs < to_gxs ? from_gxs + to_gxs : to_gxs + from_gxs
|
|
|
|
}
|
|
|
|
|
2016-09-15 07:07:13 -04:00
|
|
|
JSONListModel
|
|
|
|
{
|
2017-04-03 15:51:03 -04:00
|
|
|
id: contactsListModel
|
2016-09-15 07:07:13 -04:00
|
|
|
query: "$.data[*]"
|
|
|
|
}
|
|
|
|
|
2017-03-24 07:02:13 -04:00
|
|
|
ListView
|
|
|
|
{
|
2017-05-08 14:35:15 -04:00
|
|
|
id: contactsListView
|
2017-03-24 07:02:13 -04:00
|
|
|
width: parent.width
|
|
|
|
height: contactsView.searching ?
|
|
|
|
parent.height - searchBox.height : parent.height
|
2017-04-03 15:51:03 -04:00
|
|
|
model: contactsListModel.model
|
2017-03-24 07:02:13 -04:00
|
|
|
anchors.top: contactsView.searching ? searchBox.bottom : parent.top
|
2017-04-03 15:51:03 -04:00
|
|
|
delegate: GxsIdentityDelegate {}
|
2017-03-24 07:02:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle
|
|
|
|
{
|
|
|
|
id: searchBox
|
|
|
|
visible: contactsView.searching
|
|
|
|
|
2017-06-06 11:37:33 -04:00
|
|
|
height: searchText.height + 10
|
|
|
|
width: parent.width * 0.9
|
2017-03-24 07:02:13 -04:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.top: parent.top
|
2017-06-06 11:37:33 -04:00
|
|
|
anchors.leftMargin: 5
|
|
|
|
anchors.rightMargin: 5
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
color: "white"
|
2017-03-24 07:02:13 -04:00
|
|
|
|
|
|
|
Image
|
|
|
|
{
|
|
|
|
id: searchIcon
|
2017-06-06 11:37:33 -04:00
|
|
|
height: searchText.height / 2
|
|
|
|
width: searchText.height / 2
|
2017-03-24 07:02:13 -04:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2017-04-13 10:47:27 -04:00
|
|
|
source: "qrc:/icons/edit-find.png"
|
2017-03-24 07:02:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TextField
|
|
|
|
{
|
|
|
|
id: searchText
|
|
|
|
anchors.left: searchIcon.right
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2017-06-06 11:37:33 -04:00
|
|
|
placeholderText : "Search contacts..."
|
|
|
|
width: parent.width - searchIcon.width - 5
|
|
|
|
anchors.leftMargin: 5
|
|
|
|
|
2017-06-13 08:51:53 -04:00
|
|
|
background: Rectangle
|
|
|
|
{
|
2017-06-06 11:37:33 -04:00
|
|
|
border.width: 2
|
|
|
|
radius: 5
|
|
|
|
border.color: searchText.focus ? "cornflowerblue" : "lightgrey"
|
2017-06-12 12:18:17 -04:00
|
|
|
color: searchText.focus ? "white" : "ghostwhite"
|
2017-06-06 11:37:33 -04:00
|
|
|
}
|
2017-06-13 08:51:53 -04:00
|
|
|
|
2017-04-03 15:51:03 -04:00
|
|
|
onTextChanged:
|
|
|
|
contactsSortWorker.sendMessage(
|
|
|
|
{'action': 'searchContact', 'sexp': text})
|
2017-03-24 07:02:13 -04:00
|
|
|
}
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|
|
|
|
|
2017-03-21 09:47:34 -04:00
|
|
|
Text
|
|
|
|
{
|
2016-12-08 09:56:23 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-04-19 08:23:29 -04:00
|
|
|
Settings
|
|
|
|
{
|
|
|
|
id: settings
|
|
|
|
category: "contactsView"
|
|
|
|
|
|
|
|
property bool defaultIdentityCreated: false
|
|
|
|
}
|
2017-06-03 11:58:53 -04:00
|
|
|
|
2016-09-15 07:07:13 -04:00
|
|
|
}
|