This repository has been archived on 2023-11-19. You can view files and clone it, but cannot push or open issues or pull requests.
goober-bb10/assets/PostItem.qml

271 lines
11 KiB
QML
Raw Normal View History

2016-09-22 23:21:20 +00:00
/*
* Copyright (C) 2016 Morgan McMillian <gilag@monkeystew.com>
*
* This file is apart of the Goober application, a client for pnut.io
*
* 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.
*
* 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/>.
*/
import bb.cascades 1.4
import org.labsquare 1.0
import "moment.js" as Moment
Container {
id: postitem
leftPadding: ui.sdu(3.0)
rightPadding: ui.sdu(3.0)
topPadding: ui.sdu(2.0)
2016-09-24 15:13:45 +00:00
//bottomPadding: ui.sdu(2.0)
2016-09-22 23:21:20 +00:00
property string lorem: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse non enim tellus. Donec vestibulum enim urna, eget faucibus diam commodo a. Donec eget hendrerit metus. Pellentesque vehicula nisi nec vehicula ullamcorper. Aliquam a elit eget mi fringilla porta fermentum eget eros. Phasellus vestibulum nulla sed elit congue adipiscing. Cras imperdiet urna ac ipsum volutpat lobortis. Maecenas vehicula tortor at viverra convallis. Curabitur nibh massa, tristique id felis ut, venenatis faucibus dui. Donec fringilla, mi nec tincidunt dignissim, neque nunc semper mi, quis rutrum diam turpis sit amet erat. Cras a sodales nisi. Nunc sit amet diam sed lectus molestie cursus convallis et erat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis vitae varius leo. Mauris eu leo a nunc bibendum rutrum euismod et ipsum. "
property variant theme : Application.themeSupport.theme.colorTheme.style
2016-10-30 16:13:53 +00:00
enabled: (ListItemData.is_deleted) ? false : true
opacity: (ListItemData.is_deleted) ? 0.5 : 1.0
2016-09-22 23:21:20 +00:00
Container {
layout: DockLayout {}
horizontalAlignment: HorizontalAlignment.Fill
2016-09-22 23:21:20 +00:00
Container {
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
Container {
background: (theme === VisualStyle.Bright) ? Color.create("#e9e9e9") : Color.create("#282828")
WebImageView {
id: avatar
url: ListItemData.user.content.avatar_image.link
maxWidth: ui.du(12)
maxHeight: ui.du(12)
//imageSource: "asset:///icons/laughing_man.png"
}
2016-09-22 23:21:20 +00:00
}
Container {
leftMargin: ui.sdu(3.0)
Container {
Label {
id: name
text: ListItemData.user.name
textStyle.fontWeight: FontWeight.Bold
}
}
Container {
Label {
id: username
2016-11-12 00:10:08 +00:00
text: ListItemData.user.username
// text: "<a href=\"#profile\">" + ListItemData.user.username + "</a>"
// activeTextHandler: ActiveTextHandler {
// onTriggered: {
// postitem.ListItem.view.viewProfile(ListItemData.user)
// }
// }
// textFormat: TextFormat.Html
}
2016-09-22 23:21:20 +00:00
}
}
}
Container {
horizontalAlignment: HorizontalAlignment.Right
2016-09-22 23:21:20 +00:00
Container {
layout: StackLayout {
orientation: LayoutOrientation.RightToLeft
}
horizontalAlignment: HorizontalAlignment.Fill
topMargin: ui.sdu(1.0)
Container {
ImageView {
// (ListItemData.counts.threads > 0 || ListItemData.counts.replies > 0 || ListItemData.id !== ListItemData.thread_id)
visible: (ListItemData.counts.threads > 0 || ListItemData.id !== ListItemData.thread_id)
imageSource: "asset:///icons/comments.png"
filterColor: (theme == VisualStyle.Bright) ? Color.Black : false
maxWidth: ui.du(6)
maxHeight: ui.du(6)
accessibility.name: "thread"
}
}
Container {
verticalAlignment: VerticalAlignment.Bottom
Label {
text: (ListItemData.counts.bookmarks > 0) ? ListItemData.counts.bookmarks : ""
textStyle.fontSize: FontSize.XXSmall
}
}
Container {
ImageView {
visible: (ListItemData.counts.bookmarks > 0)
imageSource: "asset:///icons/ic_favorite.png"
filterColor: (theme == VisualStyle.Bright) ? Color.Black : false
maxWidth: ui.du(6)
maxHeight: ui.du(6)
accessibility.name: "favorite"
}
}
Container {
verticalAlignment: VerticalAlignment.Bottom
Label {
text: (ListItemData.counts.reposts > 0) ? ListItemData.counts.reposts : ""
textStyle.fontSize: FontSize.XXSmall
}
}
Container {
ImageView {
visible: (ListItemData.counts.reposts > 0)
imageSource: "asset:///icons/retweet.png"
filterColor: (theme == VisualStyle.Bright) ? Color.Black : false
maxWidth: ui.du(6)
maxHeight: ui.du(6)
accessibility.name: "repost"
}
2016-09-22 23:21:20 +00:00
}
}
}
}
Container {
topMargin: ui.sdu(2.0)
bottomMargin: ui.sdu(2.0)
2016-09-22 23:21:20 +00:00
Label {
2016-10-30 16:13:53 +00:00
text: (ListItemData.is_deleted) ? qsTr("<i>{{POST DELETED}}</i>") : ListItemData.content.html
2016-09-22 23:21:20 +00:00
multiline: true
2016-09-24 15:13:45 +00:00
textFormat: TextFormat.Html
2016-09-22 23:21:20 +00:00
}
}
Container {
layout: DockLayout {}
horizontalAlignment: HorizontalAlignment.Fill
Container {
horizontalAlignment: HorizontalAlignment.Left
Label { // "Sep 23, 2016 7:17 AM"
2016-09-22 23:21:20 +00:00
text: Moment.moment(ListItemData.created_at).format("lll")
textStyle.fontSize: FontSize.XSmall
}
}
Container {
horizontalAlignment: HorizontalAlignment.Right
Label { // "Broadsword Hack"
2016-09-22 23:21:20 +00:00
text: ListItemData.source.name
textStyle.fontSize: FontSize.XSmall
}
}
}
Divider {
accessibility.name: "divider"
}
2016-09-22 23:21:20 +00:00
contextActions: [
ActionSet {
title: ListItemData.user.username
ActionItem {
title: qsTr("Reply")
onTriggered: {
replySheet.text = "@" + ListItemData.user.username + " ";
replySheet.open();
replySheet.input.requestFocus();
}
imageSource: "asset:///icons/ic_reply.png"
}
ActionItem {
title: qsTr("Reply All")
2016-09-22 23:21:20 +00:00
onTriggered: {
replySheet.text = "@" + ListItemData.user.username + " " + parseMentions(ListItemData.content.entities.mentions);
console.log(JSON.stringify(ListItemData.content.entities.mentions))
replySheet.open();
replySheet.input.requestFocus();
}
imageSource: "asset:///icons/ic_reply_all.png"
}
2016-09-24 15:13:45 +00:00
ActionItem {
title: (ListItemData.you_bookmarked) ? qsTr("Delete Bookmark") : qsTr("Add Bookmark")
imageSource: "asset:///icons/ic_favorite.png" //(ListItemData.you_bookmarked) ? "asset:///icons/star.png" : "asset:///icons/star-o.png"
onTriggered: {
if (ListItemData.you_bookmarked) {
postitem.ListItem.view.delBookmark(ListItemData.id);
} else {
postitem.ListItem.view.addBookmark(ListItemData.id);
}
}
}
ActionItem {
title: (ListItemData.you_reposted) ? qsTr("Delete Repost") : qsTr("Repost")
imageSource: "asset:///icons/retweet.png"
2016-09-24 15:13:45 +00:00
onTriggered: {
if (ListItemData.you_reposted) {
postitem.ListItem.view.delRepost(ListItemData.id);
} else {
postitem.ListItem.view.repost(ListItemData.id);
}
}
}
ActionItem {
title: qsTr("Quote")
imageSource: "asset:///icons/quote-left.png"
onTriggered: {
replySheet.text = " >> @" + ListItemData.user.username + ": " + ListItemData.content.text;
replySheet.open();
// replySheet.input.requestFocus();
2016-09-24 15:13:45 +00:00
}
}
ActionItem {
title: qsTr("View Profile")
imageSource: "asset:///icons/ic_contact.png"
onTriggered: {
postitem.ListItem.view.viewProfile(ListItemData.user)
}
}
// ActionItem {
// id: edItem
// enabled: (ListItemData.user.username === postitem.ListItem.view.getUserName())
// title: qsTr("Edit")
// imageSource: "asset:///icons/ic_edit.png"
// onTriggered: {
// // do an edit
// }
// }
DeleteActionItem {
id: delItem
enabled: (ListItemData.user.username === postitem.ListItem.view.getUserName())
title: qsTr("Delete")
onTriggered: {
postitem.ListItem.view.delPost(ListItemData.id)
}
}
2016-09-22 23:21:20 +00:00
}
]
attachedObjects: [
NewPostSheet {
id: replySheet
onSendPost: {
postitem.ListItem.view.sendReply(text, ListItemData.id);
}
}
]
function parseMentions(mentions) {
var mtext = ""
for(var i = 0; i < mentions.length; i++) {
var mu = mentions[i].text
if (mu !== postitem.ListItem.view.getUserName()) {
2016-09-22 23:21:20 +00:00
mtext += "@" + mu + " "
}
}
if (mtext.length > 0) {
2016-11-04 21:16:03 +00:00
if (postitem.ListItem.view.ccOnReply()) {
return "\n/" + mtext
} else {
return mtext
}
2016-09-22 23:21:20 +00:00
} else {
return ""
}
}
}