refresh post on delete

This commit is contained in:
Morgan McMillian 2016-10-30 10:53:58 -07:00
parent 564177a233
commit 5a4a48f46a
5 changed files with 43 additions and 6 deletions

View file

@ -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")

View file

@ -1 +1 @@
212
217

View file

@ -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);
}

View file

@ -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;

View file

@ -162,22 +162,22 @@
<context>
<name>StreamTab</name>
<message>
<location filename="../assets/StreamTab.qml" line="126"/>
<location filename="../assets/StreamTab.qml" line="129"/>
<source>New Post</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/StreamTab.qml" line="140"/>
<location filename="../assets/StreamTab.qml" line="143"/>
<source>To Top</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/StreamTab.qml" line="168"/>
<location filename="../assets/StreamTab.qml" line="171"/>
<source>To Bottom</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/StreamTab.qml" line="155"/>
<location filename="../assets/StreamTab.qml" line="158"/>
<source>Reload</source>
<translation type="unfinished"></translation>
</message>