From f8fee791bc6bfe37e74034e521a6035943118c9c Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 7 Apr 2018 18:31:32 -0700 Subject: [PATCH] replace reposted items with the original post object and reference who did the repost resolves #40 --- assets/PostItem.qml | 23 +++++++++++++++-------- src/Pnut.cpp | 19 ++++++++++++++++++- src/Pnut.h | 1 + translations/Goober.ts | 20 ++++++++++---------- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/assets/PostItem.qml b/assets/PostItem.qml index f6cd053..3c2cda4 100644 --- a/assets/PostItem.qml +++ b/assets/PostItem.qml @@ -36,14 +36,14 @@ Container { opacity: (ListItemData.is_deleted) ? 0.5 : 1.0 visible: (ListItemData.is_deleted) ? false : true - Container { + Container { // post header layout: DockLayout {} horizontalAlignment: HorizontalAlignment.Fill Container { layout: StackLayout { orientation: LayoutOrientation.LeftToRight } - Container { + Container { // user avatar background: (theme === VisualStyle.Bright) ? Color.create("#e9e9e9") : Color.create("#282828") ImageButton { id: avatar @@ -65,7 +65,7 @@ Container { ] } } - Container { + Container { // user name leftMargin: ui.sdu(3.0) Container { Label { @@ -89,7 +89,7 @@ Container { } } } - Container { + Container { // post counts horizontalAlignment: HorizontalAlignment.Right Container { layout: StackLayout { @@ -145,7 +145,7 @@ Container { } } } - Container { + Container { // post text topMargin: ui.sdu(2.0) bottomMargin: ui.sdu(2.0) Label { @@ -155,7 +155,7 @@ Container { navigation.focusPolicy: NavigationFocusPolicy.NotFocusable } } - Container { + Container { // post embeds // TODO: add tab to open full image in a page horizontalAlignment: HorizontalAlignment.Center bottomMargin: ui.sdu(2.0) @@ -223,7 +223,7 @@ Container { ] } } - Container { + Container { // post footer layout: DockLayout {} horizontalAlignment: HorizontalAlignment.Fill Container { @@ -236,8 +236,15 @@ Container { Container { horizontalAlignment: HorizontalAlignment.Right Label { // "Broadsword Hack" - text: ListItemData.source.name + text: { + if (ListItemData.reposted_by) { + return "reposted by @" + ListItemData.reposted_by + } else { + return ListItemData.source.name + } + } textStyle.fontSize: FontSize.XSmall + textStyle.fontStyle: FontStyle.Italic } } } diff --git a/src/Pnut.cpp b/src/Pnut.cpp index e66d839..6b4fcc7 100644 --- a/src/Pnut.cpp +++ b/src/Pnut.cpp @@ -214,7 +214,8 @@ void Pnut::onAuthorizedRequestReady(QByteArray data, int id) endpoint == "/users/me/bookmarks") { Pnut::RequestType rtype = rtype_map[id]; - emit streamReceived(variant.toMap()["data"].toList(), rtype); + QVariantList streamlist = variant.toMap()["data"].toList(); + emit streamReceived(parseStream(streamlist), rtype); req_map.remove(id); rtype_map.remove(id); } @@ -546,3 +547,19 @@ void Pnut::onOpenBrowser(QUrl url) qDebug() << url; emit openBrowser(url); } + +QVariantList Pnut::parseStream(QVariantList stream) +{ + QVariantList pstream; + foreach (QVariant vitem, stream) { + QVariantMap item = vitem.toMap(); + if (item.find("repost_of") != item.end()) + { + QString username = item["user"].toMap()["username"].toString(); + item = item["repost_of"].toMap(); + item.insert("reposted_by", username); + } + pstream.append(item); + } + return pstream; // but not really +} diff --git a/src/Pnut.h b/src/Pnut.h index 7e7fdf8..a2eab00 100644 --- a/src/Pnut.h +++ b/src/Pnut.h @@ -131,6 +131,7 @@ private: void postRequest(QUrl url, KQOAuthParameters parameters, int id, QByteArray data); void putRequest(QUrl url, KQOAuthParameters parameters, int id); void deleteRequest(QUrl url, KQOAuthParameters parameters, int id); + QVariantList parseStream(QVariantList stream); }; #endif /* PNUT_H_ */ diff --git a/translations/Goober.ts b/translations/Goober.ts index 3cf90e8..d19322b 100644 --- a/translations/Goober.ts +++ b/translations/Goober.ts @@ -43,52 +43,52 @@ PostItem - + Reply - + Reply All - + Delete Bookmark - + Add Bookmark - + Delete Repost - + Repost - + Quote - + View Profile - + Copy text - + Delete