diff --git a/Message.cpp b/Message.cpp index 66c7885..8dafabe 100644 --- a/Message.cpp +++ b/Message.cpp @@ -105,3 +105,11 @@ QByteArray Message::toJson() const { QJsonDocument d(o); return d.toJson(QJsonDocument::Compact); } + +QVariantMap Message::toVariantMap() const { + QVariantMap m; + m["type"] = QVariant(type_); + m["value"] = QVariant(value_); + m["params"] = QVariant(params_); + return m; +} diff --git a/Message.h b/Message.h index 1cbd2ce..efe4c38 100644 --- a/Message.h +++ b/Message.h @@ -23,6 +23,7 @@ public: void write(QJsonObject &json) const; QByteArray toJson() const; + QVariantMap toVariantMap() const; QString type() const { return type_; } void setType(QString type){ type_ = type; } diff --git a/mainwindow.cpp b/mainwindow.cpp index c7a0851..a2de95b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -12952,6 +12952,67 @@ void MainWindow::networkMessage(Message const &message) return; } + // INBOX.GET_MESSAGES + // INBOX.STORE_MESSAGE + if(type == "INBOX.GET_MESSAGES"){ + QString selectedCall = message.params().value("CALLSIGN", "").toString(); + if(selectedCall.isEmpty()){ + selectedCall = "%"; + } + + Inbox inbox(inboxPath()); + if(!inbox.open()){ + return; + } + + QList > msgs; + msgs.append(inbox.values("STORE", "$.params.TO", selectedCall, 0, 1000)); + msgs.append(inbox.values("READ", "$.params.FROM", selectedCall, 0, 1000)); + foreach(auto pair, inbox.values("UNREAD", "$.params.FROM", selectedCall, 0, 1000)){ + msgs.append(pair); + } + qStableSort(msgs.begin(), msgs.end(), [](QPair const &a, QPair const &b){ + return a.second.params().value("UTC") > b.second.params().value("UTC"); + }); + + QVariantList l; + foreach(auto pair, msgs){ + l << pair.second.toVariantMap(); + } + + sendNetworkMessage("INBOX.MESSAGES", "", { + {"_ID", id}, + {"MESSAGES", l}, + }); + } + + if(type == "INBOX.STORE_MESSAGE"){ + QString selectedCall = message.params().value("CALLSIGN", "").toString(); + if(selectedCall.isEmpty()){ + return; + } + + QString text = message.params().value("TEXT", "").toString(); + if(text.isEmpty()){ + return; + } + + CommandDetail d = {}; + d.cmd = " MSG "; + d.to = selectedCall; + d.from = m_config.my_callsign(); + d.relayPath = d.from; + d.text = text; + d.utcTimestamp = DriftingDateTime::currentDateTimeUtc(); + d.submode = m_nSubMode; + + auto mid = addCommandToStorage("STORE", d); + + sendNetworkMessage("INBOX.MESSAGE", "", { + {"_ID", id}, + {"ID", mid}, + }); + } // WINDOW.RAISE