From 8461564c0c8671cd0d62d7fbcf585007a5823aed Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 14 Apr 2018 16:33:34 -0700 Subject: [PATCH] Convert normal post to long post when length exceeds maximum to resolve #39 --- assets/NewPostSheet.qml | 9 +++++++-- assets/StreamTab.qml | 4 ++-- assets/ThreadPage.qml | 2 +- src/Pnut.cpp | 29 ++++++++++++++++++++++++++++- src/Pnut.h | 2 +- translations/Goober.ts | 6 +++--- 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/assets/NewPostSheet.qml b/assets/NewPostSheet.qml index 1b55cfb..cf15d20 100644 --- a/assets/NewPostSheet.qml +++ b/assets/NewPostSheet.qml @@ -25,6 +25,7 @@ Sheet { property alias input: postText property alias text: postText.text property int count: 256 + property string counttext signal sendPost(string text) @@ -62,14 +63,18 @@ Sheet { sendAction.enabled = false; } count = 256 - postText.text.length - if (count < 0) sendAction.enabled = false; + if (count < 0) { + counttext = "longpost" + } else { + counttext = count.toString() + } } } } Container { horizontalAlignment: HorizontalAlignment.Right Label { - text: count.toString() + text: counttext } } } diff --git a/assets/StreamTab.qml b/assets/StreamTab.qml index 6ca80e2..4e18332 100644 --- a/assets/StreamTab.qml +++ b/assets/StreamTab.qml @@ -90,7 +90,7 @@ NavigationPane { nav.push(page); } function sendReply(text, pid) { - pnut.sendReply(text, pid); + pnut.sendPost(text, pid); } function getUserName() { return _app.setting("username"); @@ -251,7 +251,7 @@ NavigationPane { id: newPostSheet onSendPost: { console.log("send: " + text) - pnut.sendPost(text) + pnut.sendPost(text, 0) } }, WebViewSheet { diff --git a/assets/ThreadPage.qml b/assets/ThreadPage.qml index 0b64f2a..6e74f71 100644 --- a/assets/ThreadPage.qml +++ b/assets/ThreadPage.qml @@ -44,7 +44,7 @@ Page { } ] function sendReply(text, pid) { - pnut.sendReply(text, pid); + pnut.sendPost(text, pid); } function getUserName() { return _app.setting("username") diff --git a/src/Pnut.cpp b/src/Pnut.cpp index cf7bcc0..9b0b05a 100644 --- a/src/Pnut.cpp +++ b/src/Pnut.cpp @@ -20,6 +20,7 @@ #include "Pnut.h" #include "globals.h" #include +#include #include const QString Pnut::PNUT_API_ROOT = QString("https://api.pnut.io/v0"); @@ -352,11 +353,37 @@ void Pnut::getStream(QString endpoint, Pnut::RequestType rtype) getRequest(url, parameters, req_id); } -void Pnut::sendPost(QString text) +void Pnut::sendPost(QString text, int pid=0) { QByteArray post; QVariantMap map; + QVariantList raw; + + if (text.length() > 254) + { + QVariantMap longpost; + QVariantMap rawobj; + longpost["title"] = ""; + longpost["body"] = text; + longpost["tstamp"] = QDateTime::currentMSecsSinceEpoch(); + rawobj["type"] = "nl.chimpnut.blog.post"; + rawobj["value"] = longpost; + raw.append(rawobj); + text.truncate(80); + text = text + "... - http://chimpnut.nl/u/"; + text = text + m_appSettings->value("username").toString(); + text = text + "/lp/{object_id} - #longpost"; + } map["text"] = text; + if (pid > 0) + { + map["reply_to"] = pid; + } + if (raw.length() > 0) + { + map["raw"] = raw; + } + QVariant data(map); bb::data::JsonDataAccess jda; jda.saveToBuffer(data, &post); diff --git a/src/Pnut.h b/src/Pnut.h index a2eab00..7392032 100644 --- a/src/Pnut.h +++ b/src/Pnut.h @@ -67,7 +67,7 @@ public: Q_INVOKABLE void authorize(); Q_INVOKABLE void getStream(QString endpoint, Pnut::RequestType rtype); - Q_INVOKABLE void sendPost(QString text); + Q_INVOKABLE void sendPost(QString text, int pid); Q_INVOKABLE void sendReply(QString text, int pid); Q_INVOKABLE void getUser(QString uid); Q_INVOKABLE void followUser(QString uid); diff --git a/translations/Goober.ts b/translations/Goober.ts index bb96a17..49411e7 100644 --- a/translations/Goober.ts +++ b/translations/Goober.ts @@ -25,17 +25,17 @@ NewPostSheet - + Send - + Cancel - + New Post