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
|
2017-11-16 16:42:30 +00:00
|
|
|
import com.netimage 1.0
|
2016-09-22 23:21:20 +00:00
|
|
|
import "moment.js" as Moment
|
2017-02-06 04:28:11 +00:00
|
|
|
import "parser.js" as Parser
|
2016-09-22 23:21:20 +00:00
|
|
|
|
|
|
|
Container {
|
|
|
|
id: postitem
|
|
|
|
|
2016-09-23 19:33:16 +00:00
|
|
|
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
|
|
|
|
2016-09-23 19:33:16 +00:00
|
|
|
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
|
2017-02-06 04:28:11 +00:00
|
|
|
visible: (ListItemData.is_deleted) ? false : true
|
2016-10-30 16:13:53 +00:00
|
|
|
|
2018-04-08 01:31:32 +00:00
|
|
|
Container { // post header
|
2016-09-23 19:33:16 +00:00
|
|
|
layout: DockLayout {}
|
|
|
|
horizontalAlignment: HorizontalAlignment.Fill
|
2016-09-22 23:21:20 +00:00
|
|
|
Container {
|
2016-09-23 19:33:16 +00:00
|
|
|
layout: StackLayout {
|
|
|
|
orientation: LayoutOrientation.LeftToRight
|
|
|
|
}
|
2018-04-08 01:31:32 +00:00
|
|
|
Container { // user avatar
|
2016-10-21 13:09:02 +00:00
|
|
|
background: (theme === VisualStyle.Bright) ? Color.create("#e9e9e9") : Color.create("#282828")
|
2018-02-28 06:19:32 +00:00
|
|
|
ImageButton {
|
2016-09-23 19:33:16 +00:00
|
|
|
id: avatar
|
2017-11-17 22:46:07 +00:00
|
|
|
minWidth: ui.du(12)
|
|
|
|
minHeight: ui.du(12)
|
2016-10-21 13:09:02 +00:00
|
|
|
maxWidth: ui.du(12)
|
|
|
|
maxHeight: ui.du(12)
|
2016-09-23 19:33:16 +00:00
|
|
|
//imageSource: "asset:///icons/laughing_man.png"
|
2018-02-28 06:19:32 +00:00
|
|
|
defaultImage: tracker.image
|
|
|
|
onClicked: {
|
|
|
|
postitem.ListItem.view.viewProfile(ListItemData.user)
|
|
|
|
}
|
2017-11-16 16:42:30 +00:00
|
|
|
attachedObjects: [
|
|
|
|
NetImageTracker {
|
|
|
|
id: tracker
|
2017-11-17 17:46:10 +00:00
|
|
|
source: (postitem.ListItem.view.hideAvatar()) ? "" : ListItemData.user.content.avatar_image.link
|
2017-11-19 00:58:57 +00:00
|
|
|
manager: postitem.ListItem.view.userImageManager
|
2017-11-16 16:42:30 +00:00
|
|
|
}
|
|
|
|
]
|
2016-09-23 19:33:16 +00:00
|
|
|
}
|
2016-09-22 23:21:20 +00:00
|
|
|
}
|
2018-04-08 01:31:32 +00:00
|
|
|
Container { // user name
|
2016-09-23 19:33:16 +00:00
|
|
|
leftMargin: ui.sdu(3.0)
|
|
|
|
Container {
|
|
|
|
Label {
|
|
|
|
id: name
|
|
|
|
text: ListItemData.user.name
|
|
|
|
textStyle.fontWeight: FontWeight.Bold
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Container {
|
|
|
|
Label {
|
|
|
|
id: username
|
2018-02-28 06:19:32 +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-23 19:33:16 +00:00
|
|
|
}
|
2016-09-22 23:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-23 19:33:16 +00:00
|
|
|
}
|
2018-04-08 01:31:32 +00:00
|
|
|
Container { // post counts
|
2016-09-23 19:33:16 +00:00
|
|
|
horizontalAlignment: HorizontalAlignment.Right
|
2016-09-22 23:21:20 +00:00
|
|
|
Container {
|
2016-09-23 19:33:16 +00:00
|
|
|
layout: StackLayout {
|
|
|
|
orientation: LayoutOrientation.RightToLeft
|
|
|
|
}
|
|
|
|
horizontalAlignment: HorizontalAlignment.Fill
|
|
|
|
topMargin: ui.sdu(1.0)
|
|
|
|
Container {
|
|
|
|
ImageView {
|
2016-10-01 13:40:48 +00:00
|
|
|
// (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"
|
2016-09-23 19:33:16 +00:00
|
|
|
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"
|
|
|
|
}
|
2016-10-01 13:40:48 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-08 01:31:32 +00:00
|
|
|
Container { // post text
|
2016-09-23 19:33:16 +00:00
|
|
|
topMargin: ui.sdu(2.0)
|
|
|
|
bottomMargin: ui.sdu(2.0)
|
2016-09-22 23:21:20 +00:00
|
|
|
Label {
|
2018-01-15 16:23:46 +00:00
|
|
|
text: Parser.parsePostText(ListItemData.content)
|
2016-09-22 23:21:20 +00:00
|
|
|
multiline: true
|
2017-02-05 03:54:02 +00:00
|
|
|
textFormat: TextFormat.Html
|
2017-02-07 01:08:04 +00:00
|
|
|
navigation.focusPolicy: NavigationFocusPolicy.NotFocusable
|
2016-09-22 23:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-14 20:01:58 +00:00
|
|
|
Container { // long post body
|
|
|
|
topMargin: ui.sdu(2.0)
|
|
|
|
bottomMargin: ui.sdu(2.0)
|
2018-04-14 20:19:51 +00:00
|
|
|
visible: {
|
|
|
|
if (postitem.ListItem.view.hideLongPosts()) {
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
if (typeof ListItemData.longpost_body !== "undefined") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2018-04-14 20:01:58 +00:00
|
|
|
Divider {
|
|
|
|
}
|
|
|
|
Label {
|
|
|
|
text: (typeof ListItemData.longpost_body !== "undefined") ? ListItemData.longpost_body : ""
|
|
|
|
multiline: true
|
|
|
|
textFormat: TextFormat.Html
|
|
|
|
navigation.focusPolicy: NavigationFocusPolicy.NotFocusable
|
|
|
|
}
|
|
|
|
}
|
2018-04-08 01:31:32 +00:00
|
|
|
Container { // post embeds
|
2017-11-05 17:50:22 +00:00
|
|
|
// TODO: add tab to open full image in a page
|
2017-02-17 20:53:16 +00:00
|
|
|
horizontalAlignment: HorizontalAlignment.Center
|
|
|
|
bottomMargin: ui.sdu(2.0)
|
2017-11-16 20:35:30 +00:00
|
|
|
ImageButton {
|
|
|
|
id: pimage
|
2017-11-17 22:10:41 +00:00
|
|
|
maxWidth: ui.du(20)
|
|
|
|
maxHeight: ui.du(20)
|
2017-11-16 19:02:41 +00:00
|
|
|
visible: {
|
|
|
|
var isphoto = false
|
2017-02-18 01:39:50 +00:00
|
|
|
if (typeof ListItemData.raw !== "undefined") {
|
|
|
|
ListItemData.raw.forEach(function (item) {
|
|
|
|
if (item["type"] == "io.pnut.core.oembed") {
|
2017-11-16 19:02:41 +00:00
|
|
|
if (item["value"]["type"] == "photo") {
|
|
|
|
isphoto = true
|
|
|
|
}
|
2017-02-18 01:39:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-11-16 19:02:41 +00:00
|
|
|
return isphoto
|
2017-02-17 20:53:16 +00:00
|
|
|
}
|
2018-02-25 15:26:10 +00:00
|
|
|
defaultImage: (postitem.ListItem.view.hidePhoto()) ? "" : thumbtracker.image
|
2017-11-16 20:35:30 +00:00
|
|
|
onClicked: {
|
|
|
|
postitem.ListItem.view.showImage(ptracker.imageSource)
|
|
|
|
}
|
2017-11-16 19:02:41 +00:00
|
|
|
attachedObjects: [
|
|
|
|
NetImageTracker {
|
|
|
|
id: ptracker
|
|
|
|
manager: postitem.ListItem.view.listImageManager
|
|
|
|
source: {
|
|
|
|
var photo_url = ""
|
2017-11-17 01:03:29 +00:00
|
|
|
if (typeof ListItemData.raw !== "undefined" && !postitem.ListItem.view.hidePhoto()) {
|
2017-11-16 19:02:41 +00:00
|
|
|
ListItemData.raw.forEach(function (item) {
|
|
|
|
if (item["type"] == "io.pnut.core.oembed") {
|
|
|
|
if (item["value"]["type"] == "photo") {
|
|
|
|
photo_url = item["value"]["url"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return photo_url
|
|
|
|
}
|
2018-02-25 15:26:10 +00:00
|
|
|
},
|
|
|
|
NetImageTracker {
|
|
|
|
id: thumbtracker
|
|
|
|
manager: postitem.ListItem.view.listImageManager
|
|
|
|
source: {
|
|
|
|
var photo_url = ""
|
|
|
|
if (typeof ListItemData.raw !== "undefined" && !postitem.ListItem.view.hidePhoto()) {
|
|
|
|
ListItemData.raw.forEach(function (item) {
|
|
|
|
if (item["type"] == "io.pnut.core.oembed") {
|
|
|
|
if (item["value"]["type"] == "photo") {
|
|
|
|
if (item["value"]["thumbnail_url"]) {
|
|
|
|
photo_url = item["value"]["thumbnail_url"]
|
|
|
|
} else {
|
|
|
|
photo_url = item["value"]["url"]
|
|
|
|
}
|
|
|
|
// photo_url = item["value"]["url"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return photo_url
|
|
|
|
}
|
2017-11-16 19:02:41 +00:00
|
|
|
}
|
|
|
|
]
|
2017-02-17 20:53:16 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-08 01:31:32 +00:00
|
|
|
Container { // post footer
|
2016-09-22 23:21:20 +00:00
|
|
|
layout: DockLayout {}
|
|
|
|
horizontalAlignment: HorizontalAlignment.Fill
|
|
|
|
Container {
|
|
|
|
horizontalAlignment: HorizontalAlignment.Left
|
2016-09-23 19:33:16 +00:00
|
|
|
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
|
2016-09-23 19:33:16 +00:00
|
|
|
Label { // "Broadsword Hack"
|
2018-04-08 01:31:32 +00:00
|
|
|
text: {
|
|
|
|
if (ListItemData.reposted_by) {
|
|
|
|
return "reposted by @" + ListItemData.reposted_by
|
|
|
|
} else {
|
|
|
|
return ListItemData.source.name
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 23:21:20 +00:00
|
|
|
textStyle.fontSize: FontSize.XSmall
|
2018-04-08 01:31:32 +00:00
|
|
|
textStyle.fontStyle: FontStyle.Italic
|
2016-09-22 23:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-23 19:33:16 +00:00
|
|
|
Divider {
|
|
|
|
accessibility.name: "divider"
|
|
|
|
}
|
2016-09-22 23:21:20 +00:00
|
|
|
contextActions: [
|
|
|
|
ActionSet {
|
2017-02-06 04:28:11 +00:00
|
|
|
title: "[" + ListItemData.id + "] " + ListItemData.user.username
|
2016-09-22 23:21:20 +00:00
|
|
|
ActionItem {
|
|
|
|
title: qsTr("Reply")
|
|
|
|
onTriggered: {
|
2019-08-04 00:33:50 +00:00
|
|
|
replySheet.text = atMention(ListItemData.user.username);
|
2016-09-22 23:21:20 +00:00
|
|
|
replySheet.open();
|
|
|
|
replySheet.input.requestFocus();
|
|
|
|
}
|
|
|
|
imageSource: "asset:///icons/ic_reply.png"
|
|
|
|
}
|
|
|
|
ActionItem {
|
2016-09-23 19:33:16 +00:00
|
|
|
title: qsTr("Reply All")
|
2016-09-22 23:21:20 +00:00
|
|
|
onTriggered: {
|
2019-08-04 00:33:50 +00:00
|
|
|
replySheet.text = atMention(ListItemData.user.username) + parseMentions(ListItemData.content.entities.mentions);
|
2016-09-22 23:21:20 +00:00
|
|
|
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 {
|
2016-10-01 13:40:48 +00:00
|
|
|
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: {
|
2016-10-01 13:40:48 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2016-10-30 15:03:57 +00:00
|
|
|
ActionItem {
|
|
|
|
title: qsTr("View Profile")
|
|
|
|
imageSource: "asset:///icons/ic_contact.png"
|
|
|
|
onTriggered: {
|
|
|
|
postitem.ListItem.view.viewProfile(ListItemData.user)
|
|
|
|
}
|
|
|
|
}
|
2017-02-18 00:47:41 +00:00
|
|
|
ActionItem {
|
|
|
|
title: qsTr("Copy text")
|
|
|
|
imageSource: "asset:///icons/ic_copy.png"
|
|
|
|
onTriggered: {
|
|
|
|
postitem.ListItem.view.copyText(ListItemData.content.text)
|
|
|
|
}
|
|
|
|
}
|
2017-02-18 01:39:50 +00:00
|
|
|
InvokeActionItem {
|
|
|
|
title: "Share"
|
|
|
|
query {
|
|
|
|
mimeType: "text/plain"
|
|
|
|
invokeActionId: "bb.action.SHARE"
|
|
|
|
}
|
|
|
|
data: {
|
|
|
|
var text = "@" + ListItemData.user.username + ": " + ListItemData.content.text
|
|
|
|
text = text + "\n\n" + "https://posts.pnut.io/" + ListItemData.id
|
|
|
|
return text
|
|
|
|
}
|
|
|
|
}
|
2016-10-30 16:51:43 +00:00
|
|
|
// 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);
|
|
|
|
}
|
2019-10-14 00:23:47 +00:00
|
|
|
onPostChanging: {
|
|
|
|
replySheet.count = 256 - postitem.ListItem.view.postLength(text)
|
|
|
|
if (replySheet.count < 0) {
|
|
|
|
replySheet.counttext = "longpost"
|
|
|
|
} else {
|
|
|
|
replySheet.counttext = replySheet.count.toString()
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 23:21:20 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
function parseMentions(mentions) {
|
|
|
|
var mtext = ""
|
|
|
|
for(var i = 0; i < mentions.length; i++) {
|
|
|
|
var mu = mentions[i].text
|
2019-08-04 00:33:50 +00:00
|
|
|
mtext += atMention(mu)
|
2016-09-22 23:21:20 +00:00
|
|
|
}
|
|
|
|
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 ""
|
|
|
|
}
|
|
|
|
}
|
2019-08-04 00:33:50 +00:00
|
|
|
function atMention(username) {
|
|
|
|
var atname = ""
|
|
|
|
if (username !== postitem.ListItem.view.getUserName()) {
|
|
|
|
atname = "@" + username + " "
|
|
|
|
}
|
|
|
|
return atname
|
|
|
|
}
|
2016-09-22 23:21:20 +00:00
|
|
|
}
|