diff --git a/assets/StreamTab.qml b/assets/StreamTab.qml index 31a8514..4800ad7 100644 --- a/assets/StreamTab.qml +++ b/assets/StreamTab.qml @@ -102,6 +102,9 @@ NavigationPane { function delPost(pid) { pnut.deletePost(pid); } + function getPost(pid) { + pnut.getPost(pid) + } attachedObjects: [ ListScrollStateHandler { onAtEndChanged: { @@ -235,6 +238,17 @@ NavigationPane { pnut.beforeId = postModel.value(postModel.size() - 1).id; pnut.sinceId = postModel.value(0).id; } + + onPostReceived: { + var idx + for (var i = 0; i< postModel.size(); i++) { + if (postModel.value(i).id === post.id) { + idx = i + break + } + } + postModel.replace(idx, post) + } onAuthorizationRequired: { console.log("__Got a auth required thingy") diff --git a/buildnum b/buildnum index b7c52fb..e99fdcc 100644 --- a/buildnum +++ b/buildnum @@ -1 +1 @@ -212 \ No newline at end of file +217 \ No newline at end of file diff --git a/src/Pnut.cpp b/src/Pnut.cpp index 15da49e..f392d94 100644 --- a/src/Pnut.cpp +++ b/src/Pnut.cpp @@ -262,6 +262,19 @@ void Pnut::onAuthorizedRequestReady(QByteArray data, int id) req_map.remove(id); emit unmuteSuccess(variant.toMap()["data"].toMap()); } + else if (endpoint.startsWith(":getpost:")) + { + qDebug() << "Got a post!"; + req_map.remove(id); + emit postReceived(variant.toMap()["data"].toMap()); + } + else if (endpoint.startsWith(":deletepost:")) + { + qDebug() << "Delete successful!"; + req_map.remove(id); + QString gpid = endpoint.replace(":deletepost:",""); + getPost(gpid); + } else { qDebug() << "GOT SOMETHING NEW!"; qDebug() << endpoint; @@ -455,6 +468,14 @@ void Pnut::deletePost(QString pid) { QUrl url(PNUT_API_ROOT + "/posts/" + pid); KQOAuthParameters parameters; - req_map[++req_id] = ":post"; + req_map[++req_id] = ":deletepost:" + pid; deleteRequest(url, parameters, req_id); } + +void Pnut::getPost(QString pid) +{ + QUrl url(PNUT_API_ROOT + "/posts/" + pid); + KQOAuthParameters parameters; + req_map[++req_id] = ":getpost:" + pid; + getRequest(url, parameters, req_id); +} diff --git a/src/Pnut.h b/src/Pnut.h index adade16..3176981 100644 --- a/src/Pnut.h +++ b/src/Pnut.h @@ -84,6 +84,7 @@ public: Q_INVOKABLE void deleteRepost(QString pid); Q_INVOKABLE void logout(); Q_INVOKABLE void deletePost(QString pid); + Q_INVOKABLE void getPost(QString pid); public slots: void onRequestReady(QByteArray data); @@ -101,6 +102,7 @@ Q_SIGNALS: void unblockSuccess(QVariantMap user); void muteSuccess(QVariantMap user); void unmuteSuccess(QVariantMap user); + void postReceived(QVariantMap post); private: static const QString PNUT_API_ROOT; diff --git a/translations/Goober.ts b/translations/Goober.ts index f6f5b43..076952f 100644 --- a/translations/Goober.ts +++ b/translations/Goober.ts @@ -162,22 +162,22 @@ StreamTab - + New Post - + To Top - + To Bottom - + Reload