This commit is contained in:
Sarah Jamie Lewis 2019-02-01 16:12:44 -08:00
parent 7c6a1ab8f1
commit 95f674c064
5 changed files with 248 additions and 28 deletions

View File

@ -138,10 +138,13 @@ Item {
readonly property int groupProfilePane: 4
readonly property int addGroupPane: 5
property string title
Item {} // empty
OverlayPane { // messagePane
title: theStack.title
anchors.fill: parent
}

View File

@ -2,14 +2,17 @@ import QtGraphicalEffects 1.0
import QtQuick 2.7
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.0
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3
import "../widgets"
import "../widgets/controls" as Awesome
import "../fonts/Twemoji.js" as T
import "../utils.js" as Utils
ColumnLayout {
Layout.fillWidth: true
width:parent.width
Flickable { // THE MESSAGE LIST ITSELF
@ -18,10 +21,9 @@ ColumnLayout {
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true
Layout.minimumWidth: parent.width
Layout.maximumWidth: parent.width
Layout.fillWidth: true
contentWidth: colMessages.width
contentHeight: colMessages.height
contentWidth: bulletin.width
contentHeight: bulletin.height
boundsBehavior: Flickable.StopAtBounds
maximumFlickVelocity: 800
@ -30,11 +32,20 @@ ColumnLayout {
target: gcd
onClearMessages: function() {
messagesModel.clear()
//jsonModel4.clear()
}
onAppendMessage: function(handle, from, displayName, message, image, mid, fromMe, ts) {
messagesModel.append({
var msg
try {
msg = JSON.parse(message)
} catch (e) {
return
}
if (msg.o != 2) return
/** messagesModel.append({
"_handle": handle,
"_from": from,
"_displayName": displayName,
@ -43,7 +54,7 @@ ColumnLayout {
"_mid": mid,
"_fromMe": fromMe,
"_ts": ts,
})
})*/
if (sv.contentY + sv.height >= sv.contentHeight - colMessages.height && sv.contentHeight > sv.height) {
sv.contentY = sv.contentHeight - sv.height
@ -52,34 +63,148 @@ ColumnLayout {
}
ScrollBar.vertical: ScrollBar{
policy: ScrollBar.AlwaysOn
}
ColumnLayout {
id: colMessages
width: sv.width
ListModel { // MESSAGE OBJECTS ARE STORED HERE ...
id: messagesModel
}
Item { height: 6 }
Repeater { // ... AND DISPLAYED HERE
model: messagesModel
delegate: Message {
handle: _handle
from: _from
displayName: _displayName
message: "bulletinbulletinbulletin"
image: _image
messageID: _mid
fromMe: _fromMe
timestamp: _ts
ListView {
id: bulletinView
anchors.left: parent.left
width: parent.width
height: parent.height
orientation: Qt.Vertical
spacing: 10
model: jsonModel4
property string filter: ""
delegate:
Item {
width: parent.width
height: title.indexOf(bulletinView.filter) >= 0 ? (bulletinView.currentIndex == index ? texttitle.height + textbody.height + replybtn.height + 8 : texttitle.height * 2) : 0
visible: title.indexOf(bulletinView.filter) >= 0
Column {
width: parent.width
Text { id: texttitle
text: '<b>' + Utils.htmlEscaped(title) + '</b>'
MouseArea {
anchors.fill: parent
onClicked: bulletinView.currentIndex = index
}
}
Text {
id: textbody
visible: bulletinView.currentIndex == index
text: Utils.htmlEscaped(body)
wrapMode: TextEdit.Wrap
width: parent.width - 10
}
SimpleButton {
id: replybtn
visible: bulletinView.currentIndex == index
text: "Reply"
anchors.right: parent.right
onClicked: {
console.log("REPLYING!!!")
gcd.broadcast("ResetMessagePane")
theStack.pane = theStack.messagePane
gcd.loadMessagesPane("e6c6dyzqojonomkxzm36lbme4cox4jhtiga5yln6cltusb5ujkcjb4yd")
overlayStack.overlay = overlayStack.chatOverlay
}
}
}
}
highlight: Rectangle {
visible: title.indexOf(bulletinView.filter) >= 0
color: '#B09CBC'
}
focus: true
onCurrentItemChanged: console.log(model.get(bulletinView.currentIndex).title + ' selected')
ListModel {
id: jsonModel4
}
Component.onCompleted: {
jsonModel4.append({"title":"w4w for friends and other stuff","body":"Hi I'm a really <br/> cool person who has just moved to Vancouver and I would really like to find some nice people to be friends with", "done":true})
jsonModel4.append({"title":"m4mw everyone is great","body":"I would just like to say that everyone is great I would just like to say that everyone is great I would just like to say that everyone is greatI would just like to say that everyone is greatI would just like to say that everyone is great I would just like to say that everyone is great I would just like to say that everyone is great I would just like to say that everyone is great I would just like to say that everyone is great", "done":true,})
jsonModel4.append({"title":"w4w for friends and other stuff","body":"Hi I'm a really <br/> cool person who has just moved to Vancouver and I would really like to find some nice people to be friends with", "done":true})
jsonModel4.append({"title":"w4w for friends and other stuff","body":"Hi I'm a really <br/> cool person who has just moved to Vancouver and I would really like to find some nice people to be friends with", "done":true})
jsonModel4.append({"title":"w4w for friends and other stuff","body":"Hi I'm a really <br/> cool person who has just moved to Vancouver and I would really like to find some nice people to be friends with", "done":true})
jsonModel4.append({"title":"w4w for friends and other stuff","body":"Hi I'm a really <br/> cool person who has just moved to Vancouver and I would really like to find some nice people to be friends with", "done":true})
}
}
}
TextField {
id: filter
placeholderText: "Filter.."
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 10
onTextChanged: {
bulletinView.filter = text
if (bulletinView.model.get(bulletinView.currentIndex).title.indexOf(text) == -1) {
bulletinView.currentIndex = -1
}
}
}
ColumnLayout {
Layout.fillWidth: true
SimpleButton { // SEND MESSAGE BUTTON
id: btnSend
icon: "regular/paper-plane"
text: "send"
anchors.right: parent.right
anchors.rightMargin: 2
property int nextMessageID: 1
onClicked: {
if (txtMessage.text != "") {
txtHidden.text = restoreEmoji(txtMessage.text)
var msg = JSON.stringify({"o":2, "d":txtHidden.getText(0, txtHidden.text.length)})
gcd.sendMessage(msg, nextMessageID++)
}
txtMessage.text = ""
}
}
}
}
}
}
}

View File

@ -9,10 +9,12 @@ import "../overlays"
ColumnLayout {
Layout.fillWidth: true
property alias title: toolbar.text
StackToolbar {
text: "open privacy exec"
id: toolbar
//text: "open privacy exec"
aux.onClicked: {
theStack.pane = gcd.currentOpenConversation.length == 32 ? theStack.groupProfilePane : theStack.userProfilePane

View File

@ -87,6 +87,7 @@ RowLayout { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
isActive = true
theStack.pane = theStack.messagePane
gcd.loadMessagesPane(handle)
theStack.overlaypane.toolbar.lbl.text = handle
}
onEntered: {

89
qml/widgets/jsonpath.js Normal file
View File

@ -0,0 +1,89 @@
/* JSONPath 0.8.5 - XPath for JSON
*
* Copyright (c) 2007 Stefan Goessner (goessner.net)
* Licensed under the MIT (MIT-LICENSE.txt) licence.
*
*/
function jsonPath(obj, expr, arg) {
var P = {
resultType: arg && arg.resultType || "VALUE",
result: [],
normalize: function(expr) {
var subx = [];
return expr.replace(/[\['](\??\(.*?\))[\]']|\['(.*?)'\]/g, function($0,$1,$2){return "[#"+(subx.push($1||$2)-1)+"]";}) /* http://code.google.com/p/jsonpath/issues/detail?id=4 */
.replace(/'?\.'?|\['?/g, ";")
.replace(/;;;|;;/g, ";..;")
.replace(/;$|'?\]|'$/g, "")
.replace(/#([0-9]+)/g, function($0,$1){return subx[$1];});
},
asPath: function(path) {
var x = path.split(";"), p = "$";
for (var i=1,n=x.length; i<n; i++)
p += /^[0-9*]+$/.test(x[i]) ? ("["+x[i]+"]") : ("['"+x[i]+"']");
return p;
},
store: function(p, v) {
if (p) P.result[P.result.length] = P.resultType == "PATH" ? P.asPath(p) : v;
return !!p;
},
trace: function(expr, val, path) {
if (expr !== "") {
var x = expr.split(";"), loc = x.shift();
x = x.join(";");
if (val && val.hasOwnProperty(loc))
P.trace(x, val[loc], path + ";" + loc);
else if (loc === "*")
P.walk(loc, x, val, path, function(m,l,x,v,p) { P.trace(m+";"+x,v,p); });
else if (loc === "..") {
P.trace(x, val, path);
P.walk(loc, x, val, path, function(m,l,x,v,p) { typeof v[m] === "object" && P.trace("..;"+x,v[m],p+";"+m); });
}
else if (/^\(.*?\)$/.test(loc)) // [(expr)]
P.trace(P.eval(loc, val, path.substr(path.lastIndexOf(";")+1))+";"+x, val, path);
else if (/^\?\(.*?\)$/.test(loc)) // [?(expr)]
P.walk(loc, x, val, path, function(m,l,x,v,p) { if (P.eval(l.replace(/^\?\((.*?)\)$/,"$1"), v instanceof Array ? v[m] : v, m)) P.trace(m+";"+x,v,p); }); // issue 5 resolved
else if (/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(loc)) // [start:end:step] phyton slice syntax
P.slice(loc, x, val, path);
else if (/,/.test(loc)) { // [name1,name2,...]
for (var s=loc.split(/'?,'?/),i=0,n=s.length; i<n; i++)
P.trace(s[i]+";"+x, val, path);
}
}
else
P.store(path, val);
},
walk: function(loc, expr, val, path, f) {
if (val instanceof Array) {
for (var i=0,n=val.length; i<n; i++)
if (i in val)
f(i,loc,expr,val,path);
}
else if (typeof val === "object") {
for (var m in val)
if (val.hasOwnProperty(m))
f(m,loc,expr,val,path);
}
},
slice: function(loc, expr, val, path) {
if (val instanceof Array) {
var len=val.length, start=0, end=len, step=1;
loc.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g, function($0,$1,$2,$3){start=parseInt($1||start);end=parseInt($2||end);step=parseInt($3||step);});
start = (start < 0) ? Math.max(0,start+len) : Math.min(len,start);
end = (end < 0) ? Math.max(0,end+len) : Math.min(len,end);
for (var i=start; i<end; i+=step)
P.trace(i+";"+expr, val, path);
}
},
eval: function(x, _v, _vname) {
try { return $ && _v && eval(x.replace(/(^|[^\\])@/g, "$1_v").replace(/\\@/g, "@")); } // issue 7 : resolved ..
catch(e) { throw new SyntaxError("jsonPath: " + e.message + ": " + x.replace(/(^|[^\\])@/g, "$1_v").replace(/\\@/g, "@")); } // issue 7 : resolved ..
}
};
var $ = obj;
if (expr && obj && (P.resultType == "VALUE" || P.resultType == "PATH")) {
P.trace(P.normalize(expr).replace(/^\$;?/,""), obj, "$"); // issue 6 resolved
return P.result.length ? P.result : false;
}
}