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) { function delPost(pid) {
pnut.deletePost(pid); pnut.deletePost(pid);
} }
function getPost(pid) {
pnut.getPost(pid)
}
attachedObjects: [ attachedObjects: [
ListScrollStateHandler { ListScrollStateHandler {
onAtEndChanged: { onAtEndChanged: {
@ -236,6 +239,17 @@ NavigationPane {
pnut.sinceId = postModel.value(0).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: { onAuthorizationRequired: {
console.log("__Got a auth required thingy") console.log("__Got a auth required thingy")
openLogin() openLogin()

View file

@ -1 +1 @@
212 217

View file

@ -262,6 +262,19 @@ void Pnut::onAuthorizedRequestReady(QByteArray data, int id)
req_map.remove(id); req_map.remove(id);
emit unmuteSuccess(variant.toMap()["data"].toMap()); 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 { else {
qDebug() << "GOT SOMETHING NEW!"; qDebug() << "GOT SOMETHING NEW!";
qDebug() << endpoint; qDebug() << endpoint;
@ -455,6 +468,14 @@ void Pnut::deletePost(QString pid)
{ {
QUrl url(PNUT_API_ROOT + "/posts/" + pid); QUrl url(PNUT_API_ROOT + "/posts/" + pid);
KQOAuthParameters parameters; KQOAuthParameters parameters;
req_map[++req_id] = ":post"; req_map[++req_id] = ":deletepost:" + pid;
deleteRequest(url, parameters, req_id); 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 deleteRepost(QString pid);
Q_INVOKABLE void logout(); Q_INVOKABLE void logout();
Q_INVOKABLE void deletePost(QString pid); Q_INVOKABLE void deletePost(QString pid);
Q_INVOKABLE void getPost(QString pid);
public slots: public slots:
void onRequestReady(QByteArray data); void onRequestReady(QByteArray data);
@ -101,6 +102,7 @@ Q_SIGNALS:
void unblockSuccess(QVariantMap user); void unblockSuccess(QVariantMap user);
void muteSuccess(QVariantMap user); void muteSuccess(QVariantMap user);
void unmuteSuccess(QVariantMap user); void unmuteSuccess(QVariantMap user);
void postReceived(QVariantMap post);
private: private:
static const QString PNUT_API_ROOT; static const QString PNUT_API_ROOT;

View file

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