Parse WS messages

This commit is contained in:
Pierre HUBERT 2020-06-13 13:57:29 +02:00
parent ff955398b9
commit 68d8d1b5c7
2 changed files with 13 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include <QTimer>
#include <QJsonDocument>
#include "apirequest.h"
#include "wsclient.h"
@ -50,4 +51,14 @@ void WsClient::onConnected()
void WsClient::onMessage(const QString &msg)
{
qDebug() << "WS message: " << msg;
auto obj = QJsonDocument::fromJson(msg.toUtf8()).object();
auto title = obj.value("title").toString();
auto value = obj.value("data").toInt(-1);
if(title == "number_notifs")
emit newNumberNotifs(value);
else if(title == "number_unread_conversations")
emit newNumberConvs(value);
}

View File

@ -22,6 +22,8 @@ public slots:
void startConnect();
signals:
void newNumberNotifs(int num);
void newNumberConvs(int num);
private slots:
void onConnectionError();