mirror of
https://gitlab.com/comunic/comunicwatcher
synced 2024-12-24 12:38:55 +00:00
Automatically get the number of new notifications
This commit is contained in:
parent
68d8d1b5c7
commit
38284bb2af
@ -20,6 +20,8 @@ SOURCES += \
|
||||
loginsuccessfuldialog.cpp \
|
||||
main.cpp \
|
||||
loginwindow.cpp \
|
||||
notificationshelper.cpp \
|
||||
notificationsnumber.cpp \
|
||||
refreshservice.cpp \
|
||||
wsclient.cpp
|
||||
|
||||
@ -30,6 +32,8 @@ HEADERS += \
|
||||
config.h \
|
||||
loginsuccessfuldialog.h \
|
||||
loginwindow.h \
|
||||
notificationshelper.h \
|
||||
notificationsnumber.h \
|
||||
refreshservice.h \
|
||||
wsclient.h
|
||||
|
||||
|
30
notificationshelper.cpp
Normal file
30
notificationshelper.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "apirequest.h"
|
||||
#include "notificationshelper.h"
|
||||
|
||||
NotificationsHelper::NotificationsHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationsHelper::getNewNotificationsNumbers()
|
||||
{
|
||||
APIRequest *req = new APIRequest("notifications/count_all_news");
|
||||
req->exec();
|
||||
connect(req, &APIRequest::done, this, &NotificationsHelper::getNotificationsNumberCallback);
|
||||
|
||||
}
|
||||
|
||||
void NotificationsHelper::getNotificationsNumberCallback(APIResponse response)
|
||||
{
|
||||
if(response.isError()) {
|
||||
qDebug() << "Could not get the number of unread conversations!";
|
||||
return;
|
||||
}
|
||||
|
||||
auto obj = response.getObject();
|
||||
NotificationsNumber n;
|
||||
n.setNewNotifs(obj.value("notifications").toInt());
|
||||
n.setUnreadConversations(obj.value("conversations").toInt());
|
||||
|
||||
emit onNewNumber(n);
|
||||
}
|
33
notificationshelper.h
Normal file
33
notificationshelper.h
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Notifications helper
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "notificationsnumber.h"
|
||||
#include "apiresponse.h"
|
||||
|
||||
class NotificationsHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NotificationsHelper(QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* Count the number of new notifications
|
||||
*/
|
||||
void getNewNotificationsNumbers();
|
||||
|
||||
signals:
|
||||
void onNewNumber(NotificationsNumber notifs);
|
||||
|
||||
|
||||
|
||||
private slots:
|
||||
void getNotificationsNumberCallback(APIResponse response);
|
||||
};
|
||||
|
26
notificationsnumber.cpp
Normal file
26
notificationsnumber.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "notificationsnumber.h"
|
||||
|
||||
NotificationsNumber::NotificationsNumber()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int NotificationsNumber::unreadConversations() const
|
||||
{
|
||||
return mUnreadConversations;
|
||||
}
|
||||
|
||||
void NotificationsNumber::setUnreadConversations(int unreadConversations)
|
||||
{
|
||||
mUnreadConversations = unreadConversations;
|
||||
}
|
||||
|
||||
int NotificationsNumber::newNotifs() const
|
||||
{
|
||||
return mNewNotifs;
|
||||
}
|
||||
|
||||
void NotificationsNumber::setNewNotifs(int newNotifs)
|
||||
{
|
||||
mNewNotifs = newNotifs;
|
||||
}
|
25
notificationsnumber.h
Normal file
25
notificationsnumber.h
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Notifications number
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
class NotificationsNumber
|
||||
{
|
||||
public:
|
||||
NotificationsNumber();
|
||||
|
||||
int unreadConversations() const;
|
||||
void setUnreadConversations(int unreadConversations);
|
||||
|
||||
int newNotifs() const;
|
||||
void setNewNotifs(int newNotifs);
|
||||
|
||||
private:
|
||||
int mNewNotifs;
|
||||
int mUnreadConversations;
|
||||
};
|
||||
|
@ -18,9 +18,16 @@ void RefreshService::stopService()
|
||||
svc = nullptr;
|
||||
}
|
||||
|
||||
void RefreshService::connectedToWebSocket()
|
||||
{
|
||||
mNotifsHelper.getNewNotificationsNumbers();
|
||||
}
|
||||
|
||||
RefreshService::RefreshService()
|
||||
{
|
||||
qDebug("Start refresh service");
|
||||
|
||||
connect(&mWsClient, &WsClient::connected, this, &RefreshService::connectedToWebSocket);
|
||||
}
|
||||
|
||||
RefreshService::~RefreshService()
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "notificationshelper.h"
|
||||
#include "wsclient.h"
|
||||
|
||||
#include <QObject>
|
||||
@ -18,11 +19,15 @@ public:
|
||||
static void startService();
|
||||
static void stopService();
|
||||
|
||||
private slots:
|
||||
void connectedToWebSocket();
|
||||
|
||||
private:
|
||||
RefreshService();
|
||||
~RefreshService();
|
||||
|
||||
// Class members
|
||||
static RefreshService *svc;
|
||||
WsClient client;
|
||||
WsClient mWsClient;
|
||||
NotificationsHelper mNotifsHelper;
|
||||
};
|
||||
|
@ -46,6 +46,8 @@ void WsClient::getTokenCallBack(APIResponse res)
|
||||
void WsClient::onConnected()
|
||||
{
|
||||
qDebug() << "Connected to WebSocket";
|
||||
|
||||
emit connected();
|
||||
}
|
||||
|
||||
void WsClient::onMessage(const QString &msg)
|
||||
|
@ -22,6 +22,7 @@ public slots:
|
||||
void startConnect();
|
||||
|
||||
signals:
|
||||
void connected();
|
||||
void newNumberNotifs(int num);
|
||||
void newNumberConvs(int num);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user