diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7ce0ae2..b8f7cce 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -458,6 +458,18 @@ void MainWindow::postToZBoard() { } } + QMap topics; + // Insert the main topic automatically + topics.insert("#Main_Area", Utils::getZboardAddr()); + zb.topicsList->addItem(topics.firstKey()); + // Then call the API to get topics, and if it returns successfully, then add the rest of the topics + rpc->getZboardTopics([&](QMap topicsMap) { + for (auto t : topicsMap.keys()) { + topics.insert(t, topicsMap[t]); + zb.topicsList->addItem(t); + } + }); + // Testnet warning if (Settings::getInstance()->isTestnet()) { zb.testnetWarning->setText("You are on testnet, your post won't actually appear on z-board.net"); @@ -524,7 +536,8 @@ void MainWindow::postToZBoard() { if (!zb.postAs->text().trimmed().isEmpty()) memo = zb.postAs->text().trimmed() + ":: " + memo; - tx.toAddrs.push_back(ToFields{ Utils::getZboardAddr(), Utils::getZboardAmount(), memo, memo.toUtf8().toHex() }); + auto toAddr = topics[zb.topicsList->currentText()]; + tx.toAddrs.push_back(ToFields{ toAddr, Utils::getZboardAmount(), memo, memo.toUtf8().toHex() }); tx.fee = Utils::getMinerFee(); json params = json::array(); @@ -543,7 +556,6 @@ void MainWindow::postToZBoard() { } void MainWindow::doImport(QList* keys) { - qDebug() << keys->size(); if (keys->isEmpty()) { delete keys; ui->statusBar->showMessage("Private key import rescan finished"); diff --git a/src/rpc.cpp b/src/rpc.cpp index e739c80..552eee6 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -807,3 +807,57 @@ void RPC::refreshZECPrice() { Settings::getInstance()->setZECPrice(0); }); } + +// Fetch the Z-board topics list +void RPC::getZboardTopics(std::function)> cb) { + if (conn == nullptr) + return noConnection(); + + QUrl cmcURL("http://z-board.net/listTopics"); + + QNetworkRequest req; + req.setUrl(cmcURL); + + QNetworkReply *reply = conn->restclient->get(req); + + QObject::connect(reply, &QNetworkReply::finished, [=] { + reply->deleteLater(); + + try { + if (reply->error() != QNetworkReply::NoError) { + auto parsed = json::parse(reply->readAll(), nullptr, false); + if (!parsed.is_discarded() && !parsed["error"]["message"].is_null()) { + qDebug() << QString::fromStdString(parsed["error"]["message"]); + } + else { + qDebug() << reply->errorString(); + } + return; + } + + auto all = reply->readAll(); + + auto parsed = json::parse(all, nullptr, false); + if (parsed.is_discarded()) { + return; + } + + QMap topics; + for (const json& item : parsed["topics"].get()) { + if (item.find("addr") == item.end() || item.find("topicName") == item.end()) + return; + + QString addr = QString::fromStdString(item["addr"].get()); + QString topic = QString::fromStdString(item["topicName"].get()); + + topics.insert(topic, addr); + } + + cb(topics); + } + catch (...) { + // If anything at all goes wrong, just set the price to 0 and move on. + qDebug() << QString("Caught something nasty"); + } + }); +} diff --git a/src/rpc.h b/src/rpc.h index 6ec7df7..6ce2fc8 100644 --- a/src/rpc.h +++ b/src/rpc.h @@ -36,7 +36,9 @@ public: void refresh(bool force = false); void refreshAddresses(); + void refreshZECPrice(); + void getZboardTopics(std::function)> cb); void fillTxJsonParams(json& params, Tx tx); void sendZTransaction (json params, const std::function& cb); diff --git a/src/zboard.ui b/src/zboard.ui index 7b8e466..8a16047 100644 --- a/src/zboard.ui +++ b/src/zboard.ui @@ -82,7 +82,7 @@ - <html><head/><body><p>ZBoard: Fully anonymous and untraceable chat messages based on the ZCash blockchain. <a href="http://www.z-board.net/"><span style=" text-decoration: underline; color:#0000ff;">http://www.z-board.net/</span></a></p><p>Posting to ZBoard: #Main_Area</p></body></html> + <html><head/><body><p>ZBoard: Fully anonymous and untraceable chat messages based on the ZCash blockchain. <a href="http://www.z-board.net/"><span style=" text-decoration: underline; color:#0000ff;">http://www.z-board.net/</span></a></p></body></html> true @@ -115,6 +115,16 @@ + + + + + + + Posting to Board + + +