2017-03-17 12:22:58 -04:00
|
|
|
/*
|
|
|
|
* RetroShare Android QML App
|
|
|
|
* Copyright (C) 2016-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/>.
|
|
|
|
*/
|
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
import QtQuick 2.0
|
2017-03-24 07:02:13 -04:00
|
|
|
import QtQuick.Controls 2.0
|
2016-12-08 09:56:23 -05:00
|
|
|
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
|
|
|
|
|
|
|
Item
|
|
|
|
{
|
|
|
|
id: chatView
|
|
|
|
property string chatId
|
2017-04-03 15:48:01 -04:00
|
|
|
property int token: 0
|
2016-12-08 09:56:23 -05:00
|
|
|
|
2017-03-15 18:11:50 -04:00
|
|
|
function refreshData()
|
|
|
|
{
|
2017-04-03 15:48:01 -04:00
|
|
|
console.log("chatView.refreshData()", visible)
|
|
|
|
if(!visible) return
|
|
|
|
|
2017-03-24 07:02:13 -04:00
|
|
|
rsApi.request( "/chat/messages/"+chatId, "", function(par)
|
|
|
|
{
|
|
|
|
chatModel.json = par.response
|
2017-04-03 15:48:01 -04:00
|
|
|
token = JSON.parse(par.response).statetoken
|
|
|
|
mainWindow.registerToken(token, refreshData)
|
|
|
|
|
|
|
|
if(chatListView.visible)
|
|
|
|
{
|
|
|
|
chatListView.positionViewAtEnd()
|
|
|
|
rsApi.request("/chat/mark_chat_as_read/"+chatId)
|
|
|
|
}
|
2017-03-24 07:02:13 -04:00
|
|
|
} )
|
2017-03-15 18:11:50 -04:00
|
|
|
}
|
2016-12-08 09:56:23 -05:00
|
|
|
|
2017-04-03 15:48:01 -04:00
|
|
|
Component.onCompleted: refreshData()
|
2016-12-08 09:56:23 -05:00
|
|
|
onFocusChanged: focus && refreshData()
|
|
|
|
|
|
|
|
JSONListModel
|
|
|
|
{
|
|
|
|
id: chatModel
|
|
|
|
query: "$.data[*]"
|
|
|
|
}
|
|
|
|
|
|
|
|
Component
|
|
|
|
{
|
|
|
|
id: chatMessageDelegate
|
|
|
|
Item
|
|
|
|
{
|
|
|
|
height: 20
|
|
|
|
Row
|
|
|
|
{
|
|
|
|
Text { text: author_name }
|
|
|
|
Text { text: ": " + msg }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView
|
|
|
|
{
|
2017-04-03 15:48:01 -04:00
|
|
|
id: chatListView
|
2016-12-08 09:56:23 -05:00
|
|
|
width: parent.width
|
|
|
|
height: 300
|
|
|
|
model: chatModel.model
|
|
|
|
delegate: chatMessageDelegate
|
|
|
|
}
|
|
|
|
|
2017-03-17 12:22:58 -04:00
|
|
|
TextField
|
2016-12-08 09:56:23 -05:00
|
|
|
{
|
|
|
|
id: msgComposer
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
width: chatView.width - sendButton.width
|
|
|
|
}
|
|
|
|
|
|
|
|
Button
|
|
|
|
{
|
|
|
|
id: sendButton
|
|
|
|
text: "Send"
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
|
|
|
onClicked:
|
|
|
|
{
|
|
|
|
var jsonData = {"chat_id":chatView.chatId, "msg":msgComposer.text}
|
2017-03-15 18:11:50 -04:00
|
|
|
rsApi.request( "/chat/send_message", JSON.stringify(jsonData),
|
|
|
|
function(par) { msgComposer.text = ""; } )
|
2016-12-08 09:56:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|