From cb820fa02315cbf5ecc7f87435bc724460104f19 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 6 Apr 2013 20:34:56 +0200 Subject: support replying to posts --- newpostaction.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 newpostaction.cpp (limited to 'newpostaction.cpp') diff --git a/newpostaction.cpp b/newpostaction.cpp new file mode 100644 index 0000000..4ad6244 --- /dev/null +++ b/newpostaction.cpp @@ -0,0 +1,63 @@ +#include +#include +#include + +#include "global.h" +#include "board.h" +#include "xmlrpcinterface.h" +#include "xmlrpcreply.h" +#include "newpostaction.h" +#include "fetchpostsaction.h" + +NewPostAction::NewPostAction(int topicId, const QString &text, Board *board) + : Action(board), _topicId(topicId), _text(text) +{ +} + +bool NewPostAction::isSupersetOf(Action *action) const +{ + return false; +} + +void NewPostAction::execute() +{ + int forum_id = _board->getTopicForumId(_topicId); + + _call = _board->service()->asyncCall("reply_post", + QString::number(forum_id), + QString::number(_topicId), + QByteArray(), // Empty subject + _text.toUtf8() + ); + _call->setParent(this); + connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall())); +} + +void NewPostAction::handleFinishedCall() +{ + XmlRpcReply result(_call); + if (result.isValid()) { + QVariantMap map = result; + bool post_ok = map["result"].toBool(); + if (post_ok) { + int state = map["state"].toInt(); + if (state == 1) { + // Awaiting moderation + // TODO + } else { + // Refresh posts + _board->enqueueAction(new FetchPostsAction(_topicId, + FetchPostsAction::FetchUnreadPosts, + TOPIC_PAGE_SIZE, + _board)); + } + } else { + qWarning() << "Could not submit post:" << map["result_text"].toString(); + } + } else { + qWarning() << "Could not submit post"; + // TODO emit error ... + } + emit finished(this); + _call->deleteLater(); +} -- cgit v1.2.3