diff --git a/retroshare-qml-app/src/qml.qrc b/retroshare-qml-app/src/qml.qrc
index dff5a5eb3..750787fca 100644
--- a/retroshare-qml-app/src/qml.qrc
+++ b/retroshare-qml-app/src/qml.qrc
@@ -22,5 +22,7 @@
qml/icons/emblem-locked.png
qml/BusyOverlay.qml
qml/URI.js
+ qml/TokensManager.qml
+ qml/qmldir
diff --git a/retroshare-qml-app/src/qml/ChatView.qml b/retroshare-qml-app/src/qml/ChatView.qml
index 27b40461b..cdaed2d36 100644
--- a/retroshare-qml-app/src/qml/ChatView.qml
+++ b/retroshare-qml-app/src/qml/ChatView.qml
@@ -19,6 +19,7 @@
import QtQuick 2.0
import QtQuick.Controls 2.0
import org.retroshare.qml_components.LibresapiLocalClient 1.0
+import "." //Needed for TokensManager singleton
Item
{
@@ -35,7 +36,7 @@ Item
{
chatModel.json = par.response
token = JSON.parse(par.response).statetoken
- mainWindow.registerToken(token, refreshData)
+ TokensManager.registerToken(token, refreshData)
if(chatListView.visible)
{
diff --git a/retroshare-qml-app/src/qml/Contacts.qml b/retroshare-qml-app/src/qml/Contacts.qml
index a9052df28..c7fe75783 100644
--- a/retroshare-qml-app/src/qml/Contacts.qml
+++ b/retroshare-qml-app/src/qml/Contacts.qml
@@ -21,6 +21,7 @@ import QtQuick.Controls 2.0
import QtQuick.Dialogs 1.2
import QtQml.Models 2.2
import org.retroshare.qml_components.LibresapiLocalClient 1.0
+import "." //Needed for TokensManager singleton
Item
{
@@ -53,7 +54,7 @@ Item
if (contactsListModel.model.count < 1)
contactsListModel.json = par.response
var token = JSON.parse(par.response).statetoken
- mainWindow.registerToken(token, refreshContacts)
+ TokensManager.registerToken(token, refreshContacts)
contactsSortWorker.sendMessage(
{'action': 'refreshContacts', 'response': par.response})
}
@@ -69,7 +70,7 @@ Item
console.log("contactsView.refreshOwnCallback(par)", visible)
var json = JSON.parse(par.response)
var token = json.statetoken
- mainWindow.registerToken(token, refreshOwn)
+ TokensManager.registerToken(token, refreshOwn)
if(json.data.length > 0)
{
@@ -95,7 +96,7 @@ Item
{
console.log("contactsView.refreshUnreadCB()", visible)
var json = JSON.parse(par.response)
- mainWindow.registerToken(json.statetoken, refreshUnread)
+ TokensManager.registerToken(json.statetoken, refreshUnread)
contactsSortWorker.sendMessage(
{'action': 'refreshUnread', 'response': par.response})
}
diff --git a/retroshare-qml-app/src/qml/TokensManager.qml b/retroshare-qml-app/src/qml/TokensManager.qml
new file mode 100644
index 000000000..5ccb35014
--- /dev/null
+++ b/retroshare-qml-app/src/qml/TokensManager.qml
@@ -0,0 +1,108 @@
+/*
+ * RetroShare Android QML App
+ * Copyright (C) 2017 Gioacchino Mazzurco
+ *
+ * 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 .
+ */
+
+pragma Singleton
+
+import QtQml 2.2
+import org.retroshare.qml_components.LibresapiLocalClient 1.0
+
+QtObject
+{
+ id: tokensManager
+
+ property var tokens: ({})
+ function registerToken(token, callback)
+ {
+ if (Array.isArray(tokens[token]))
+ {
+ // Do not register if it is registered already
+ var arrLen = tokens[token].length
+ for(var i=0; i