2017-04-07 12:26:08 -04:00
|
|
|
/*
|
|
|
|
* RetroShare Android Autologin Service
|
|
|
|
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQml 2.2
|
|
|
|
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
2017-04-11 12:11:21 -04:00
|
|
|
import "." //Needed for TokensManager singleton
|
2017-04-07 12:26:08 -04:00
|
|
|
|
|
|
|
QtObject
|
|
|
|
{
|
2017-04-11 12:11:21 -04:00
|
|
|
id: notifyRoot
|
2017-04-07 12:26:08 -04:00
|
|
|
|
2017-04-11 12:11:21 -04:00
|
|
|
property alias coreReady: coreWatcher.coreReady
|
|
|
|
onCoreReadyChanged: if(coreReady) refreshUnread()
|
2017-04-07 12:26:08 -04:00
|
|
|
|
2017-04-12 12:55:23 -04:00
|
|
|
property AutologinManager coreWatcher: AutologinManager { id: coreWatcher }
|
|
|
|
|
2017-04-11 12:11:21 -04:00
|
|
|
function refreshUnreadCallback(par)
|
2017-04-07 12:26:08 -04:00
|
|
|
{
|
2017-04-11 12:11:21 -04:00
|
|
|
console.log("notifyRoot.refreshUnreadCB()")
|
|
|
|
var json = JSON.parse(par.response)
|
|
|
|
TokensManager.registerToken(json.statetoken, refreshUnread)
|
2017-04-12 12:55:23 -04:00
|
|
|
var convCnt = json.data.length
|
|
|
|
if(convCnt > 0)
|
2017-04-07 12:26:08 -04:00
|
|
|
{
|
2017-04-11 12:11:21 -04:00
|
|
|
console.log("notifyRoot.refreshUnreadCB() got", json.data.length,
|
2017-04-12 12:55:23 -04:00
|
|
|
"unread conversations")
|
|
|
|
notificationsBridge.notify(
|
|
|
|
qsTr("New message!"),
|
2017-07-31 10:11:21 -04:00
|
|
|
(convCnt > 1) ?
|
|
|
|
qsTr("Unread messages in %1 conversations").arg(convCnt):
|
|
|
|
qsTr("%1 Unread %2 from %3")
|
|
|
|
.arg(json.data[0].unread_count)
|
|
|
|
.arg(json.data[0].unread_count > 1 ? "messages" : "message")
|
2017-07-31 10:52:03 -04:00
|
|
|
.arg(json.data[0].remote_author_name),
|
2017-07-31 11:42:45 -04:00
|
|
|
qsTr("/contacts%1").arg(
|
|
|
|
convCnt == 1?
|
|
|
|
"?gxsId="+json.data[0].remote_author_id +
|
|
|
|
"&name="+json.data[0].remote_author_name
|
|
|
|
: "")
|
2017-04-12 12:55:23 -04:00
|
|
|
)
|
2017-04-07 12:26:08 -04:00
|
|
|
}
|
|
|
|
}
|
2017-04-11 12:11:21 -04:00
|
|
|
function refreshUnread()
|
2017-04-07 12:26:08 -04:00
|
|
|
{
|
2017-04-11 12:11:21 -04:00
|
|
|
console.log("notifyRoot.refreshUnread()")
|
|
|
|
rsApi.request("/chat/unread_msgs", "", refreshUnreadCallback)
|
2017-04-07 12:26:08 -04:00
|
|
|
}
|
|
|
|
}
|