Convert normal post to long post when length exceeds maximum to resolve #39
This commit is contained in:
parent
0dc89f87fb
commit
8461564c0c
6 changed files with 42 additions and 10 deletions
|
@ -25,6 +25,7 @@ Sheet {
|
||||||
property alias input: postText
|
property alias input: postText
|
||||||
property alias text: postText.text
|
property alias text: postText.text
|
||||||
property int count: 256
|
property int count: 256
|
||||||
|
property string counttext
|
||||||
|
|
||||||
signal sendPost(string text)
|
signal sendPost(string text)
|
||||||
|
|
||||||
|
@ -62,14 +63,18 @@ Sheet {
|
||||||
sendAction.enabled = false;
|
sendAction.enabled = false;
|
||||||
}
|
}
|
||||||
count = 256 - postText.text.length
|
count = 256 - postText.text.length
|
||||||
if (count < 0) sendAction.enabled = false;
|
if (count < 0) {
|
||||||
|
counttext = "longpost"
|
||||||
|
} else {
|
||||||
|
counttext = count.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Container {
|
Container {
|
||||||
horizontalAlignment: HorizontalAlignment.Right
|
horizontalAlignment: HorizontalAlignment.Right
|
||||||
Label {
|
Label {
|
||||||
text: count.toString()
|
text: counttext
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ NavigationPane {
|
||||||
nav.push(page);
|
nav.push(page);
|
||||||
}
|
}
|
||||||
function sendReply(text, pid) {
|
function sendReply(text, pid) {
|
||||||
pnut.sendReply(text, pid);
|
pnut.sendPost(text, pid);
|
||||||
}
|
}
|
||||||
function getUserName() {
|
function getUserName() {
|
||||||
return _app.setting("username");
|
return _app.setting("username");
|
||||||
|
@ -251,7 +251,7 @@ NavigationPane {
|
||||||
id: newPostSheet
|
id: newPostSheet
|
||||||
onSendPost: {
|
onSendPost: {
|
||||||
console.log("send: " + text)
|
console.log("send: " + text)
|
||||||
pnut.sendPost(text)
|
pnut.sendPost(text, 0)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
WebViewSheet {
|
WebViewSheet {
|
||||||
|
|
|
@ -44,7 +44,7 @@ Page {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
function sendReply(text, pid) {
|
function sendReply(text, pid) {
|
||||||
pnut.sendReply(text, pid);
|
pnut.sendPost(text, pid);
|
||||||
}
|
}
|
||||||
function getUserName() {
|
function getUserName() {
|
||||||
return _app.setting("username")
|
return _app.setting("username")
|
||||||
|
|
29
src/Pnut.cpp
29
src/Pnut.cpp
|
@ -20,6 +20,7 @@
|
||||||
#include "Pnut.h"
|
#include "Pnut.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDateTime>
|
||||||
#include <bb/data/JsonDataAccess>
|
#include <bb/data/JsonDataAccess>
|
||||||
|
|
||||||
const QString Pnut::PNUT_API_ROOT = QString("https://api.pnut.io/v0");
|
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);
|
getRequest(url, parameters, req_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pnut::sendPost(QString text)
|
void Pnut::sendPost(QString text, int pid=0)
|
||||||
{
|
{
|
||||||
QByteArray post;
|
QByteArray post;
|
||||||
QVariantMap map;
|
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;
|
map["text"] = text;
|
||||||
|
if (pid > 0)
|
||||||
|
{
|
||||||
|
map["reply_to"] = pid;
|
||||||
|
}
|
||||||
|
if (raw.length() > 0)
|
||||||
|
{
|
||||||
|
map["raw"] = raw;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant data(map);
|
QVariant data(map);
|
||||||
bb::data::JsonDataAccess jda;
|
bb::data::JsonDataAccess jda;
|
||||||
jda.saveToBuffer(data, &post);
|
jda.saveToBuffer(data, &post);
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE void authorize();
|
Q_INVOKABLE void authorize();
|
||||||
Q_INVOKABLE void getStream(QString endpoint, Pnut::RequestType rtype);
|
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 sendReply(QString text, int pid);
|
||||||
Q_INVOKABLE void getUser(QString uid);
|
Q_INVOKABLE void getUser(QString uid);
|
||||||
Q_INVOKABLE void followUser(QString uid);
|
Q_INVOKABLE void followUser(QString uid);
|
||||||
|
|
|
@ -25,17 +25,17 @@
|
||||||
<context>
|
<context>
|
||||||
<name>NewPostSheet</name>
|
<name>NewPostSheet</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../assets/NewPostSheet.qml" line="35"/>
|
<location filename="../assets/NewPostSheet.qml" line="36"/>
|
||||||
<source>Send</source>
|
<source>Send</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../assets/NewPostSheet.qml" line="44"/>
|
<location filename="../assets/NewPostSheet.qml" line="45"/>
|
||||||
<source>Cancel</source>
|
<source>Cancel</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../assets/NewPostSheet.qml" line="50"/>
|
<location filename="../assets/NewPostSheet.qml" line="51"/>
|
||||||
<source>New Post</source>
|
<source>New Post</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
Reference in a new issue