Friendiqa/source-linux/qml/newsqml/Newsitem.qml

513 lines
21 KiB
QML
Raw Normal View History

2018-02-19 22:36:00 +01:00
// This file is part of Friendiqa
2018-11-09 22:06:13 +01:00
// https://git.friendi.ca/lubuwest/Friendiqa
2018-02-19 22:36:00 +01:00
// Copyright (C) 2017 Marco R. <thomasschmidt45@gmx.net>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations including
// the two.
//
// You must obey the GNU General Public License in all respects for all
// of the code used other than OpenSSL. If you modify file(s) with this
// exception, you may extend this exception to your version of the
// file(s), but you are not obligated to do so. If you do not wish to do
// so, delete this exception statement from your version. If you delete
// this exception statement from all source files in the program, then
// also delete it here.
//
// 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-01-26 21:55:31 +01:00
import QtQuick 2.0
2019-06-25 20:59:10 +02:00
import QtQuick.Controls 2.4
2017-01-26 21:55:31 +01:00
import "qrc:/js/news.js" as Newsjs
2017-03-25 23:36:14 +01:00
import "qrc:/js/helper.js" as Helperjs
2018-04-11 21:50:43 +02:00
import "qrc:/qml/genericqml"
2017-01-26 21:55:31 +01:00
Item {
id: newsitem
2017-05-11 22:15:34 +02:00
width: parent.width
2020-01-27 21:53:51 +01:00
height:toprow.height+friendicaActivities.height+controlrow.height+conversationColumn.height+1//Math.max((itemMessage.height+topFlow.height+friendicaActivities.height+4*mm),profileImage.height+user_name.height+mm)
2018-04-11 21:50:43 +02:00
property int itemindex: index
2020-01-27 21:53:51 +01:00
property var newsitemobject:model.newsitemobject
2017-01-26 21:55:31 +01:00
property string attending: ""
onAttendingChanged: {attendLabel.visible=true;
attendLabel.text= qsTr("attending: ")+ qsTr(attending)}
2017-01-26 21:55:31 +01:00
signal replyto(string parent_id)
2017-03-25 23:36:14 +01:00
function showActivityContacts(contacts){
var component = Qt.createComponent("qrc:/qml/newsqml/FriendicaActivities.qml");
var imagedialog = component.createObject(friendicaActivities,{"activitymembers": contacts});
}
2018-07-01 15:09:21 +02:00
function findTags(fulltext){
return fulltext.match(/\s+[#]+[A-Za-z0-9-_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]+/g)
}
2020-01-27 21:53:51 +01:00
function pushConversation(){
if (model.newsitemobject.hasOwnProperty("currentconversation")){
newsStack.push("qrc:/qml/newsqml/Conversation.qml",{"news": model.newsitemobject.currentconversation})}
else{newsStack.push("qrc:/qml/newsqml/Conversation.qml")};
showConversation(index,newsitemobject)
}
2017-01-26 21:55:31 +01:00
Rectangle{width:newsitem.width; height: 1; anchors.bottom: newsitem.bottom; color:"light grey"}
2017-01-26 21:55:31 +01:00
Rectangle{
width:newsitem.width
height:newsitem.height-1
2019-06-25 20:59:10 +02:00
color: "white"//(newsitemobject.messagetype==1)?"#ffe6e6" : "white"
2017-01-26 21:55:31 +01:00
2020-01-27 21:53:51 +01:00
// Row{id:toprow
// Column {
// id: authorcolumn
// width: 8*mm
// }
Column {
id:toprow //newscolumn
width: newsitem.width//-8*mm
2017-01-26 21:55:31 +01:00
2020-01-27 21:53:51 +01:00
Item{
height: Math.max(profileImage.height+mm,topFlow.implicitHeight+mm)
width: parent.width
2017-01-26 21:55:31 +01:00
MouseArea{
anchors.fill: parent
2018-07-01 15:09:21 +02:00
onClicked:{
showContact(newsitemobject.user)}
2017-01-26 21:55:31 +01:00
}
2020-01-27 21:53:51 +01:00
Image {
id:profileImage
source: ((newsitemobject.user.profile_image!="") && (typeof(newsitemobject.user.profile_image)=="string"))? "file://"+newsitemobject.user.profile_image : newsitemobject.user.profile_image_url
x:1
y:1
width: 7*mm
height: 7*mm
//radius:mm
2017-01-26 21:55:31 +01:00
2020-01-27 21:53:51 +01:00
onStatusChanged: if (profileImage.status == Image.Error) {source="qrc:/images/defaultcontact.jpg"}
2017-01-26 21:55:31 +01:00
}
2020-01-27 21:53:51 +01:00
Flow{
id:topFlow
spacing: mm
width:parent.width-8*mm
anchors.left: profileImage.right
anchors.margins: mm
Label {
id:user_name
//color: "grey"
width:parent.width
font.bold: true
font.pixelSize: 2.5*mm
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
text: newsitemobject.user.name+" (@"+newsitemobject.user.screen_name+")"+newsitemobject.forumname
2017-01-26 21:55:31 +01:00
}
2020-01-27 21:53:51 +01:00
Label {
id:messageTypeLabel
color: "grey"
text: if (newsitemobject.messagetype==1){ qsTr("Direct Message")} else if(newsitemobject.messagetype==2) {" Notification"} else {qsTr("Source: ")+newsitemobject.source}
font.pixelSize: 1.5*mm
}
Label {
id:createdAtLabel
color: "grey"
font.pixelSize: 1.5*mm
horizontalAlignment: Label.AlignRight
text: newsitemobject.dateDiff
2017-01-26 21:55:31 +01:00
}
2020-01-27 21:53:51 +01:00
Label {
id:replytoLabel
color: "grey"
font.pixelSize: 1.5*mm
font.family: "Noto Sans"
horizontalAlignment: Label.AlignRight
text: try {qsTr("In reply to ")+newsitemobject.reply_user.screen_name
}catch(e){" "}
}
// Label {
// id:newscountLabel
// visible:((newstabstatus=="Conversations")&&(newsitemobject.newscount>1))?true:false
// color: "grey"
// height:3.5*mm
// font.pixelSize: 1.5*mm
// font.bold: true
// horizontalAlignment: Label.AlignRight
// text: try {(newsitemobject.newscount-1)+qsTr(" comments") }catch(e){" "}
// MouseArea{
// anchors.fill:parent
// onClicked: {
// pushConversation();
// }
// }
// }
2017-01-26 21:55:31 +01:00
}
}
2020-01-27 21:53:51 +01:00
// Column{ id: messageColumn
// //anchors.top:topFlow.bottom
// width:parent.width
// spacing:mm
// clip:true
// height: newsitemobject.nsfw?5*mm:Math.min(implicitHeight,3/4*root.height)
MouseArea{
width: newsitem.width-8*mm-2
height: itemMessage.height
onPressAndHold: {
pushConversation();
}
2018-07-20 21:15:54 +02:00
Text {
2017-01-26 21:55:31 +01:00
color: "#404040"
linkColor: "light green"
id: itemMessage
textFormat: Text.RichText
2019-06-25 20:59:10 +02:00
font.family: "Noto Sans"
2018-08-25 16:17:09 +02:00
text: newsitemobject.statusnet_html//newsitemobject.attachmentList.length>0?newsitemobject.text : newsitemobject.statusnet_html
2020-01-27 21:53:51 +01:00
width: newsitem.width-2
height:newsitemobject.nsfw?5*mm:Math.min(implicitHeight,3/4*root.height)
//height: implicitHeight
2017-01-26 21:55:31 +01:00
wrapMode: Text.Wrap
2018-04-11 21:50:43 +02:00
clip:true
2020-01-27 21:53:51 +01:00
onLinkActivated:{
2017-01-26 21:55:31 +01:00
Qt.openUrlExternally(link)}
2017-05-11 22:15:34 +02:00
Component.onCompleted:{
2018-07-01 15:09:21 +02:00
if (newsitemobject.messagetype==0){
var hashtags=[];
hashtags=findTags(newsitemobject.text);
var component = Qt.createComponent("qrc:/qml/newsqml/Hashtag.qml");
for (var tags in hashtags){
var hashtagQml = component.createObject(friendicaActivities,{"text":hashtags[tags].trim()});
}}
2017-05-11 22:15:34 +02:00
if (newsitemobject.attachmentList.length>0){
for(var attachments in newsitemobject.attachmentList){// (newsitemobject.attachmentList[attachments].url);
2018-08-25 16:17:09 +02:00
if(newsitemobject.attachmentList[attachments].mimetype.substring(0,5)=="image"){
var component = Qt.createComponent("qrc:/qml/newsqml/NewsImage.qml");
2020-01-27 21:53:51 +01:00
var imageQml = component.createObject(toprow,{"source":newsitemobject.attachmentList[attachments].url,"mimetype":newsitemobject.attachmentList[attachments].mimetype});
2018-11-09 22:06:13 +01:00
}
2019-01-09 22:03:16 +01:00
else if(newsitemobject.attachmentList[attachments].mimetype=="text/html"){
var component = Qt.createComponent("qrc:/qml/newsqml/NewsLink.qml");
2020-01-27 21:53:51 +01:00
var linkQml = component.createObject(toprow,{"url":newsitemobject.attachmentList[attachments].url});
2019-01-09 22:03:16 +01:00
}
2019-12-10 21:12:32 +01:00
else {
2018-08-25 16:17:09 +02:00
var component = Qt.createComponent("qrc:/qml/newsqml/NewsVideo.qml");
2019-12-10 21:12:32 +01:00
//var videoQml = component.createObject(messageColumn,{"source":newsitemobject.attachmentList[attachments].url,"mimetype":newsitemobject.attachmentList[attachments].mimetype});
2020-01-27 21:53:51 +01:00
var videoQml = component.createObject(toprow,{"attachment":newsitemobject.attachmentList[attachments]});
2019-06-25 20:59:10 +02:00
}
2018-08-25 16:17:09 +02:00
}
2017-05-11 22:15:34 +02:00
}
2020-01-27 21:53:51 +01:00
if (newsitemobject.hasOwnProperty("lastcomment")){
var moreComponent = Qt.createComponent("qrc:/qml/newsqml/MoreComments.qml");
var conversationQml = moreComponent.createObject(conversationColumn,{"comments":newsitemobject.newscount-1});
var commentComponent = Qt.createComponent("qrc:/qml/newsqml/Newsitem.qml");
var conversationQml = commentComponent.createObject(conversationColumn,{"newsitemobject":newsitemobject.lastcomment});
}
2017-05-11 22:15:34 +02:00
}
2018-07-20 21:15:54 +02:00
}}
2020-01-27 21:53:51 +01:00
//}
2018-07-20 21:15:54 +02:00
BlueButton{
width: newsitem.width-8*mm-2
height:5*mm
//anchors.bottom: messageColumn.bottom//itemMessage.bottom
2020-01-27 21:53:51 +01:00
visible: itemMessage.implicitHeight>3/4*root.height || newsitemobject.nsfw//messageColumn.implicitHeight>3/4*root.height || newsitemobject.nsfw//itemMessage.implicitHeight>3/4*root.height
2018-07-20 21:15:54 +02:00
text:"\uf078"
fontColor:"grey"
border.color: "transparent"
color:"white"
// gradient: Gradient {
// GradientStop { position: 0.0; color: "transparent" }
// GradientStop { position: 0.5; color: "white" }
// }
radius:0
onClicked: {
if (text=="\uf078"){
2020-01-27 21:53:51 +01:00
itemMessage.height=itemMessage.implicitHeight+10*mm;text="\uf077"
2018-07-20 21:15:54 +02:00
} else {
2020-01-27 21:53:51 +01:00
itemMessage.height=Math.min(itemMessage.implicitHeight,3/4*root.height);
2018-07-20 21:15:54 +02:00
text="\uf078";
newsView.positionViewAtIndex(index,ListView.Beginning);
}
}
}
2020-01-27 21:53:51 +01:00
//}
2017-05-11 22:15:34 +02:00
}
Flow{
id:friendicaActivities
2017-05-11 22:15:34 +02:00
anchors.top:toprow.bottom
2017-03-25 23:36:14 +01:00
width:parent.width
2017-01-26 21:55:31 +01:00
spacing:mm
2017-05-11 22:15:34 +02:00
2017-01-26 21:55:31 +01:00
Label{color: "grey"
2017-11-07 21:57:40 +01:00
height:3.5*mm
2017-01-26 21:55:31 +01:00
font.pixelSize: 1.5*mm
2020-01-27 21:53:51 +01:00
text: newsitemobject.friendica_activities_view.likeText
2017-03-25 23:36:14 +01:00
MouseArea{
anchors.fill: parent
2018-07-01 15:09:21 +02:00
onClicked: { showActivityContacts(newsitemobject.friendica_activities.like)}
2017-03-25 23:36:14 +01:00
}
}
2017-01-26 21:55:31 +01:00
Label{color: "grey"
2017-11-07 21:57:40 +01:00
height:3.5*mm
2017-01-26 21:55:31 +01:00
font.pixelSize: 1.5*mm
2020-01-27 21:53:51 +01:00
text: newsitemobject.friendica_activities_view.dislikeText
2017-03-25 23:36:14 +01:00
MouseArea{
anchors.fill: parent
2018-07-01 15:09:21 +02:00
onClicked: { showActivityContacts(newsitemobject.friendica_activities.dislike)}
2017-03-25 23:36:14 +01:00
}
}
2020-01-27 21:53:51 +01:00
Label{color: "grey"
height:3.5*mm
font.pixelSize: 1.5*mm
text: newsitemobject.friendica_activities_view.attendyesText
MouseArea{
anchors.fill: parent
onClicked: { showActivityContacts(newsitemobject.friendica_activities.attendyes)}
}}
Label{color: "grey"
height:3.5*mm
font.pixelSize: 1.5*mm
text: newsitemobject.friendica_activities_view.attendnoText
MouseArea{
anchors.fill: parent
onClicked: { showActivityContacts(newsitemobject.friendica_activities.attendno)}
}
}
Label{color: "grey"
height:3.5*mm
font.pixelSize: 1.5*mm
text: newsitemobject.friendica_activities_view.attendmaybeText
MouseArea{
anchors.fill: parent
onClicked: { showActivityContacts(newsitemobject.friendica_activities.attendmaybe)}
}
}
Label{
id:attendLabel
color: "grey"
height:3.5*mm
font.pixelSize: 1.5*mm
horizontalAlignment: Label.AlignRight
text: (newsitemobject.friendica_activities_view.self.attending)?(qsTr("Attending: ")+ qsTr(newsitemobject.friendica_activities_view.self.attending)):""
}
}
Row{id:controlrow
anchors.top:friendicaActivities.bottom
height: 4*mm
CheckBox{
id:likeCheckbox
width:newsitem.width/5 //10*mm
height: parent.height
visible: ((newsitemobject.messagetype==0)||(newsitemobject.messagetype==3))? true:false
checked:(newsitemobject.friendica_activities_view.self.liked==1)?true:false
indicator: Rectangle{
implicitWidth: newsitem.width/5 //10*mm
implicitHeight:4*mm
Text{
anchors.centerIn: parent
font.pixelSize: 3*mm
font.family:fontAwesome.name
color:likeCheckbox.checked?"black": "grey"
text:likeCheckbox.checked?"\uf118"+"!":"\uf118"
2017-11-07 21:57:40 +01:00
}
2020-01-27 21:53:51 +01:00
}
onClicked: {
if(likeCheckbox.checked==true){Newsjs.like(root.login,root.db,1,"like",newsitemobject.id,root);dislikeCheckbox.checked=false; model.newsitemobject.friendica_activities_view.self.liked=0 }
else{Newsjs.like(root.login,root.db,0,"like",newsitemobject.id,root); model.newsitemobject.friendica_activities_view.self.liked=1}}
}
CheckBox{
id: dislikeCheckbox
width:newsitem.width/5 //10*mm
height: parent.height
visible: ((newsitemobject.messagetype==0)||(newsitemobject.messagetype==3))? true:false
checked: (newsitemobject.friendica_activities_view.self.disliked==1)?true:false
indicator: Rectangle{
2020-01-27 21:53:51 +01:00
implicitWidth: newsitem.width/5 //10*mm
implicitHeight:4*mm
Text{
2017-01-29 17:57:55 +01:00
anchors.centerIn: parent
2020-01-27 21:53:51 +01:00
font.pixelSize: 3*mm
2017-03-25 23:36:14 +01:00
font.family:fontAwesome.name
2019-06-25 20:59:10 +02:00
color:dislikeCheckbox.checked?"black": "grey"
text: dislikeCheckbox.checked?"\uf119"+"!":"\uf119"
2017-11-07 21:57:40 +01:00
}
2017-01-26 21:55:31 +01:00
}
2020-01-27 21:53:51 +01:00
onClicked: {
if (dislikeCheckbox.checked==true){Newsjs.like(root.login,root.db,1,"dislike",newsitemobject.id,root);likeCheckbox.checked=false; model.newsitemobject.friendica_activities_view.self.disliked=0}
else {Newsjs.like(root.login,root.db,0,"dislike",newsitemobject.id,root); model.newsitemobject.friendica_activities_view.self.disliked=1}}
}
2017-05-11 22:15:34 +02:00
2020-01-27 21:53:51 +01:00
CheckBox {
id:favoritedCheckbox
visible:((newsitemobject.messagetype==0)||(newsitemobject.messagetype==3))
width: newsitem.width/5 // 10*mm
height: parent.height
indicator:Rectangle{
implicitWidth: newsitem.width/5 //10*mm
implicitHeight:4*mm
Text{
anchors.centerIn: parent
font.pixelSize: 3*mm
font.family:fontAwesome.name
color: favoritedCheckbox.checked?"black":"grey"
text:"\uf005"
}
}
checked:(newsitemobject.favorited>0)
onClicked:{
if(favoritedCheckbox.checkedState==Qt.Checked){
Newsjs.favorite(login,true,newsitemobject.id,root); model.newsitemobject.favorited=1}
else if(favoritedCheckbox.checkedState==Qt.Unchecked){
Newsjs.favorite(login,false,newsitemobject.id,root);model.newsitemobject.favorited=0}
}
}
Rectangle{
width: newsitem.width/5 //10*mm
height: parent.height
2018-07-01 15:09:21 +02:00
visible:(newsitemobject.messagetype!==2)
color:"transparent"
Text{
id:newsmenusymbol
color: "grey"
anchors.centerIn: parent
2020-01-27 21:53:51 +01:00
font.pixelSize: 3*mm
2018-07-01 15:09:21 +02:00
font.family:fontAwesome.name
text: "\uf142"
2017-01-26 21:55:31 +01:00
}
MouseArea{
2017-01-26 21:55:31 +01:00
anchors.fill:parent
onClicked: {newsmenu.popup()}}
}
2020-01-27 21:53:51 +01:00
// Rectangle{
// width: 10*mm
// height: 4*mm
// visible:(newsitemobject.messagetype!==2)&&(newstab.newstabstatus!="Conversation")
// color:"transparent"
// Text{
// id:conversationsymbol
// color: "grey"
// anchors.centerIn: parent
// font.pixelSize: 2.5*mm
// font.family: fontAwesome.name
// text: "\uf086"
// }
// MouseArea{
// anchors.fill:parent
// onClicked:{
// if (newsitemobject.hasOwnProperty("currentconversation")){newsStack.push("qrc:/qml/newsqml/Conversation.qml",{"news": newsitemobject.currentconversation})}
// else{newsStack.push("qrc:/qml/newsqml/Conversation.qml")};
// showConversation(index,newsitemobject)
// }
// }
// }
2017-05-11 22:15:34 +02:00
2017-01-26 21:55:31 +01:00
}
2017-05-11 22:15:34 +02:00
2017-01-26 21:55:31 +01:00
Menu {
id:newsmenu
2019-06-25 20:59:10 +02:00
width: 30*mm
delegate: MenuItem{
contentItem: Text{
font.pixelSize: 3*mm
text: parent.text
}
}
Action{
text: qsTr("Reply")
onTriggered: {
var directmessage=0;
if (newsitemobject.messagetype==1){ directmessage=1}
2019-12-10 21:12:32 +01:00
var replycomp=Qt.createComponent("qrc:/qml/newsqml/MessageSend.qml");
var conversation;newsitem.ListView.view.viewtype=="conversation"?true:false;
var reply=replycomp.createObject(friendicaActivities,{parentId:newsitemobject.id,reply_to_user:newsitemobject.user.screen_name, state:"reply",conversation:conversation,textfocus:true})
//replySignal(newsitemobject)
2019-06-25 20:59:10 +02:00
//newsStack.push("qrc:/qml/newsqml/MessageSend.qml",{"reply_to_user": newsitemobject.user.screen_name,"parentId":newsitemobject.id,"login":root.login,"directmessage":directmessage});
}
2017-01-26 21:55:31 +01:00
}
2019-06-25 20:59:10 +02:00
Action {
text: qsTr("DM")
onTriggered: {
root.directmessageSignal(newsitemobject.user.screen_name);
}
2017-01-26 21:55:31 +01:00
}
2019-06-25 20:59:10 +02:00
Action {
text: qsTr("Repost")
onTriggered: {
2018-07-01 15:09:21 +02:00
Newsjs.retweetNews(root.login,db,newsitemobject.id,root,function(reply){
2018-02-19 22:36:00 +01:00
Helperjs.showMessage("Repost",qsTr("Success!"),root)
})
}
}
2019-06-25 20:59:10 +02:00
Action {
text: qsTr("Conversation")
2017-11-07 21:57:40 +01:00
onTriggered: {
2020-01-27 21:53:51 +01:00
pushConversation();
2017-11-07 21:57:40 +01:00
}
2017-01-26 21:55:31 +01:00
}
Menu{
title: qsTr("Attending")
2019-06-25 20:59:10 +02:00
width: 20*mm
delegate: MenuItem{
contentItem: Text{
font.pixelSize: 3*mm
text: parent.text
}
}
Action{
text:qsTr("yes")
2018-07-01 15:09:21 +02:00
onTriggered: {Newsjs.attend(root.login,db,"yes",newsitemobject.id,root,function(){
2020-01-27 21:53:51 +01:00
model.newsitemobject.friendica_activities_view.self.attending="yes";attending="yes"})
2017-01-26 21:55:31 +01:00
}
}
2019-06-25 20:59:10 +02:00
Action{text:qsTr("maybe")
2018-07-01 15:09:21 +02:00
onTriggered: {Newsjs.attend(root.login,db,"maybe",newsitemobject.id,root,function(){
2020-01-27 21:53:51 +01:00
model.newsitemobject.friendica_activities_view.self.attending="maybe";attending="maybe"})
}
}
2019-06-25 20:59:10 +02:00
Action{text:qsTr("no")
2018-07-01 15:09:21 +02:00
onTriggered: {Newsjs.attend(root.login,db,"no",newsitemobject.id,root,function(){
2020-01-27 21:53:51 +01:00
model.newsitemobject.friendica_activities_view.self.attending="no";attending="no"})}
2017-01-26 21:55:31 +01:00
}
}
2019-06-25 20:59:10 +02:00
Action {
text: qsTr("Delete")
onTriggered: {
2018-07-01 15:09:21 +02:00
Newsjs.deleteNews(root.login,root.db,newsitemobject.id,newsitemobject.messagetype,root,function(reply){
2017-11-07 21:57:40 +01:00
var msg = {'deleteId': index, 'model': newsModel};
newsWorker.sendMessage(msg);
})
}
2017-01-26 21:55:31 +01:00
}
2018-11-09 22:06:13 +01:00
2017-11-07 21:57:40 +01:00
//MenuItem{
// text:qsTr("Show on website")
// onTriggered:Qt.openUrlExternally(login.server+"/display/"+newsitemobject
//}
2017-01-26 21:55:31 +01:00
}
2020-01-27 21:53:51 +01:00
Column{
id:conversationColumn
anchors.top:controlrow.bottom
anchors.right: parent.right
width: newsitem.width-5*mm
}
}
}