do not count markdown links against total post text length.

resolves issue #52
This commit is contained in:
Morgan McMillian 2019-10-13 14:39:42 -07:00
parent ecfc81e79c
commit c024f45348
6 changed files with 69 additions and 63 deletions

View file

@ -1,51 +1,51 @@
1
49
WebViewSheet.qml
PostItem.qml
RefreshItem.qml
icons/ic_favorite.png
icons/ic_cancel.png
icons/bookmark.png
icons/laughing_man.png
icons/at.png
icons/home.png
icons/ic_edit.png
icons/ic_doctype_picture.png
icons/globe.png
icons/ic_add_bookmarks.png
icons/ic_copy.png
icons/ic_to_top.png
icons/sign-out.png
icons/bell.png
icons/quote-left.png
icons/bell-slash.png
icons/ic_reply.png
icons/messages.png
icons/star-o.png
icons/ic_contact.png
icons/comments.png
icons/ic_info.png
icons/ic_to_bottom.png
icons/ic_add.png
icons/retweet.png
icons/ic_del_bookmarks.png
icons/minus-circle.png
icons/star.png
icons/ic_reload.png
icons/ic_reply_all.png
icons/refresh.png
icons/ic_compose.png
icons/default_cover.png
LoginSheet.qml
UserItem.qml
main.qml
StreamTab.qml
ThreadPage.qml
AboutPage.qml
parser.js
UserPage.qml
AppCover.qml
moment.js
NewPostSheet.qml
RefreshItem.qml
PostItem.qml
WebViewSheet.qml
UserItem.qml
icons/messages.png
icons/comments.png
icons/ic_add.png
icons/bell.png
icons/minus-circle.png
icons/ic_info.png
icons/laughing_man.png
icons/default_cover.png
icons/star.png
icons/ic_reply.png
icons/ic_reply_all.png
icons/sign-out.png
icons/ic_doctype_picture.png
icons/bookmark.png
icons/star-o.png
icons/ic_cancel.png
icons/at.png
icons/ic_reload.png
icons/home.png
icons/ic_copy.png
icons/retweet.png
icons/bell-slash.png
icons/ic_favorite.png
icons/ic_contact.png
icons/refresh.png
icons/quote-left.png
icons/globe.png
icons/ic_del_bookmarks.png
icons/ic_add_bookmarks.png
icons/ic_to_top.png
icons/ic_edit.png
icons/ic_compose.png
icons/ic_to_bottom.png
StreamTab.qml
ProfilePage.qml
ThreadPage.qml
parser.js
AboutPage.qml
LoginSheet.qml
AppCover.qml
SettingsPage.qml
main.qml
NewPostSheet.qml
UserPage.qml

View file

@ -28,6 +28,7 @@ Sheet {
property string counttext
signal sendPost(string text)
signal postChanging(string text)
Page {
titleBar: TitleBar {
@ -56,19 +57,7 @@ Sheet {
TextArea {
id: postText
preferredHeight: 350.0
onTextChanging: {
if (postText.text.length > 0) {
sendAction.enabled = true;
} else {
sendAction.enabled = false;
}
count = 256 - postText.text.length
if (count < 0) {
counttext = "longpost"
} else {
counttext = count.toString()
}
}
onTextChanging: postChanging(text)
}
}
Container {

View file

@ -253,6 +253,14 @@ NavigationPane {
console.log("send: " + text)
pnut.sendPost(text, 0)
}
onPostChanging: {
newPostSheet.count = 256 - pnut.postLength(text)
if (newPostSheet.count < 0) {
newPostSheet.counttext = "longpost"
} else {
newPostSheet.counttext = newPostSheet.count.toString()
}
}
},
WebViewSheet {
id: webViewSheet

View file

@ -21,6 +21,7 @@
#include "globals.h"
#include <QDebug>
#include <QDateTime>
#include <QRegExp>
#include <bb/data/JsonDataAccess>
const QString Pnut::PNUT_API_ROOT = QString("https://api.pnut.io/v0");
@ -359,7 +360,7 @@ void Pnut::sendPost(QString text, int pid=0)
QVariantMap map;
QVariantList raw;
if (text.length() > 254)
if (postLength(text) > 254)
{
QVariantMap longpost;
QVariantMap rawobj;
@ -569,6 +570,13 @@ void Pnut::getFollowing(QString uid)
getRequest(url, parameters, req_id);
}
int Pnut::postLength(QString text)
{
QRegExp mdlink("\\[([^\\]]+)\\][^\\)]+\\)");
text.replace(mdlink, "\\1");
return text.length();
}
void Pnut::onOpenBrowser(QUrl url)
{
qDebug() << "_onOpenBrowser_";

View file

@ -88,6 +88,7 @@ public:
Q_INVOKABLE void getUserStream(QString uid);
Q_INVOKABLE void getFollowers(QString uid);
Q_INVOKABLE void getFollowing(QString uid);
Q_INVOKABLE int postLength(QString text);
public slots:
void onRequestReady(QByteArray data);

View file

@ -25,17 +25,17 @@
<context>
<name>NewPostSheet</name>
<message>
<location filename="../assets/NewPostSheet.qml" line="36"/>
<location filename="../assets/NewPostSheet.qml" line="37"/>
<source>Send</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/NewPostSheet.qml" line="45"/>
<location filename="../assets/NewPostSheet.qml" line="46"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/NewPostSheet.qml" line="51"/>
<location filename="../assets/NewPostSheet.qml" line="52"/>
<source>New Post</source>
<translation type="unfinished"></translation>
</message>