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/>.
|
|
|
|
*/
|
|
|
|
|
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
|
2017-06-09 11:58:52 -04:00
|
|
|
import QtQuick.Layouts 1.2
|
2016-12-08 09:56:23 -05:00
|
|
|
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
2017-04-11 09:48:16 -04:00
|
|
|
import "." //Needed for TokensManager singleton
|
2017-06-08 13:11:37 -04:00
|
|
|
import "./components"
|
2016-12-08 09:56:23 -05:00
|
|
|
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-06-08 10:21:33 -04:00
|
|
|
property string objectName:"chatView"
|
|
|
|
|
2017-06-03 11:58:53 -04: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
|
2017-04-11 09:48:16 -04:00
|
|
|
TokensManager.registerToken(token, refreshData)
|
2017-04-03 15:48:01 -04:00
|
|
|
|
2017-06-03 11:58:53 -04:00
|
|
|
ChatCache.lastMessageCache.updateLastMessageCache(chatId, chatModel.json)
|
|
|
|
|
2017-04-03 15:48:01 -04:00
|
|
|
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[*]"
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView
|
|
|
|
{
|
2017-06-09 13:00:15 -04:00
|
|
|
property var styles: StyleChat.chat
|
2017-04-03 15:48:01 -04:00
|
|
|
id: chatListView
|
2017-06-09 13:00:15 -04:00
|
|
|
width: parent.width - styles.bubbleMargin
|
|
|
|
height: parent.height - inferiorPanel.height
|
2017-06-07 12:58:11 -04:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2016-12-08 09:56:23 -05:00
|
|
|
model: chatModel.model
|
2017-06-07 12:58:11 -04:00
|
|
|
delegate: ChatBubbleDelegate {}
|
2017-06-09 13:00:15 -04:00
|
|
|
spacing: styles.bubbleSpacing
|
2017-06-07 12:58:11 -04:00
|
|
|
preferredHighlightBegin: 1
|
|
|
|
|
2017-06-09 13:00:15 -04:00
|
|
|
onHeightChanged: {
|
|
|
|
chatListView.currentIndex = count - 1
|
|
|
|
}
|
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
}
|
|
|
|
|
2017-06-08 13:11:37 -04:00
|
|
|
Item {
|
2016-12-08 09:56:23 -05:00
|
|
|
|
2017-06-08 13:11:37 -04:00
|
|
|
property var styles: StyleChat.inferiorPanel
|
|
|
|
|
|
|
|
id: inferiorPanel
|
2017-06-09 13:00:15 -04:00
|
|
|
height: ( msgComposer.height > styles.height)? msgComposer.height: styles.height
|
2017-06-08 13:11:37 -04:00
|
|
|
width: parent.width
|
2016-12-08 09:56:23 -05:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
2017-06-08 13:11:37 -04:00
|
|
|
Rectangle {
|
2017-06-09 11:58:52 -04:00
|
|
|
id: backgroundRectangle
|
2017-06-08 13:11:37 -04:00
|
|
|
anchors.fill: parent.fill
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
|
|
|
color:inferiorPanel.styles.backgroundColor
|
|
|
|
border.color: inferiorPanel.styles.borderColor
|
|
|
|
}
|
|
|
|
|
|
|
|
BtnIcon {
|
|
|
|
|
|
|
|
id: attachButton
|
|
|
|
|
|
|
|
property var styles: StyleChat.inferiorPanel.btnIcon
|
|
|
|
|
|
|
|
height: styles.height
|
|
|
|
width: styles.width
|
|
|
|
|
|
|
|
anchors.left: parent.left
|
2017-06-09 11:58:52 -04:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
|
|
|
anchors.margins: styles.margin
|
2017-06-08 13:11:37 -04:00
|
|
|
|
|
|
|
imgUrl: styles.attachIconUrl
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-09 11:58:52 -04:00
|
|
|
TextArea
|
2016-12-08 09:56:23 -05:00
|
|
|
{
|
2017-06-08 13:11:37 -04:00
|
|
|
property var styles: StyleChat.inferiorPanel.msgComposer
|
|
|
|
id: msgComposer
|
2017-06-09 11:58:52 -04:00
|
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2017-06-08 13:11:37 -04:00
|
|
|
anchors.left: attachButton.right
|
|
|
|
|
2017-06-09 13:00:15 -04:00
|
|
|
height: setTextAreaHeight()
|
|
|
|
|
|
|
|
////
|
|
|
|
//// (contentHeight > font.pixelSize)? contentHeight +font.pixelSize : parent.styles.height
|
|
|
|
|
|
|
|
|
2017-06-09 11:58:52 -04:00
|
|
|
width: chatView.width -
|
|
|
|
(sendButton.width + sendButton.anchors.margins) -
|
|
|
|
(attachButton.width + attachButton.anchors.margins) -
|
|
|
|
(emojiButton.width + emojiButton.anchors.margins)
|
|
|
|
|
2017-06-09 13:00:15 -04:00
|
|
|
|
2017-06-08 13:11:37 -04:00
|
|
|
placeholderText: styles.placeHolder
|
|
|
|
background: styles.background
|
|
|
|
|
2017-06-09 11:58:52 -04:00
|
|
|
wrapMode: TextEdit.Wrap
|
|
|
|
|
2017-06-09 10:36:38 -04:00
|
|
|
onTextChanged: {
|
|
|
|
if (msgComposer.length == 0)
|
|
|
|
{
|
|
|
|
sendButton.state = ""
|
|
|
|
}
|
|
|
|
else if (msgComposer.length > 0)
|
|
|
|
{
|
|
|
|
sendButton.state = "SENDBTN"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-09 13:00:15 -04:00
|
|
|
function setTextAreaHeight (){
|
|
|
|
if (msgComposer.height >= chatView.height / msgComposer.styles.maxHeight)
|
|
|
|
{
|
|
|
|
return msgComposer.height
|
|
|
|
}
|
|
|
|
else if (contentHeight > font.pixelSize)
|
|
|
|
{
|
|
|
|
return msgComposer.contentHeight + msgComposer.font.pixelSize
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return parent.styles.height
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
}
|
2017-06-08 13:11:37 -04:00
|
|
|
|
|
|
|
BtnIcon {
|
|
|
|
|
2017-06-09 10:36:38 -04:00
|
|
|
id: emojiButton
|
2017-06-08 13:11:37 -04:00
|
|
|
|
|
|
|
property var styles: StyleChat.inferiorPanel.btnIcon
|
|
|
|
|
|
|
|
height: styles.height
|
|
|
|
width: styles.width
|
|
|
|
|
2017-06-09 11:58:52 -04:00
|
|
|
anchors.right: sendButton.left
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
|
|
|
anchors.margins: styles.margin
|
2017-06-08 13:11:37 -04:00
|
|
|
|
2017-06-09 10:36:38 -04:00
|
|
|
imgUrl: styles.emojiIconUrl
|
|
|
|
}
|
|
|
|
|
|
|
|
BtnIcon {
|
|
|
|
|
|
|
|
id: sendButton
|
|
|
|
|
|
|
|
property var styles: StyleChat.inferiorPanel.btnIcon
|
|
|
|
property alias icon: sendButton.imgUrl
|
|
|
|
|
|
|
|
height: styles.height
|
|
|
|
width: styles.width
|
|
|
|
|
2017-06-09 11:58:52 -04:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
|
|
|
anchors.margins: styles.margin
|
2017-06-09 10:36:38 -04:00
|
|
|
|
|
|
|
imgUrl: styles.microIconUrl
|
2017-06-08 13:11:37 -04:00
|
|
|
|
|
|
|
onClicked:
|
|
|
|
{
|
2017-06-09 10:36:38 -04:00
|
|
|
if (sendButton.state == "SENDBTN" ) {
|
|
|
|
var jsonData = {"chat_id":chatView.chatId, "msg":msgComposer.text}
|
|
|
|
rsApi.request( "/chat/send_message", JSON.stringify(jsonData),
|
|
|
|
function(par) { msgComposer.text = ""; } )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onPressed:
|
|
|
|
{
|
|
|
|
if (sendButton.state == "RECORDING" )
|
|
|
|
{
|
|
|
|
sendButton.state = ""
|
|
|
|
}
|
|
|
|
else if (sendButton.state == "" )
|
|
|
|
{
|
|
|
|
sendButton.state = "RECORDING"
|
|
|
|
}
|
2017-06-08 13:11:37 -04:00
|
|
|
}
|
2017-06-09 10:36:38 -04:00
|
|
|
|
|
|
|
onReleased:
|
|
|
|
{
|
|
|
|
if (sendButton.state == "RECORDING" )
|
|
|
|
{
|
|
|
|
sendButton.state = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: ""
|
|
|
|
PropertyChanges { target: sendButton; icon: styles.microIconUrl}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "RECORDING"
|
|
|
|
PropertyChanges { target: sendButton; icon: styles.microMuteIconUrl}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "SENDBTN"
|
|
|
|
PropertyChanges { target: sendButton; icon: styles.sendIconUrl}
|
|
|
|
}
|
|
|
|
]
|
2017-06-08 13:11:37 -04:00
|
|
|
}
|
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
}
|
|
|
|
}
|