Added two inbox API functions

This commit is contained in:
Jordan Sherer 2020-04-05 14:33:10 -04:00
parent b8a26d5ec6
commit c4b2729021
3 changed files with 70 additions and 0 deletions

View File

@ -105,3 +105,11 @@ QByteArray Message::toJson() const {
QJsonDocument d(o); QJsonDocument d(o);
return d.toJson(QJsonDocument::Compact); 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;
}

View File

@ -23,6 +23,7 @@ public:
void write(QJsonObject &json) const; void write(QJsonObject &json) const;
QByteArray toJson() const; QByteArray toJson() const;
QVariantMap toVariantMap() const;
QString type() const { return type_; } QString type() const { return type_; }
void setType(QString type){ type_ = type; } void setType(QString type){ type_ = type; }

View File

@ -12952,6 +12952,67 @@ void MainWindow::networkMessage(Message const &message)
return; 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<QPair<int, Message> > 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<int, Message> const &a, QPair<int, Message> 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 // WINDOW.RAISE