Prepare notification manager

This commit is contained in:
Sebastian J. Wolf 2020-09-02 22:49:15 +02:00
parent 436bce0966
commit aa3a841fee
12 changed files with 234 additions and 3 deletions

View file

@ -19,6 +19,7 @@ QT += core dbus
SOURCES += src/harbour-fernschreiber.cpp \ SOURCES += src/harbour-fernschreiber.cpp \
src/chatlistmodel.cpp \ src/chatlistmodel.cpp \
src/chatmodel.cpp \ src/chatmodel.cpp \
src/notificationmanager.cpp \
src/tdlibreceiver.cpp \ src/tdlibreceiver.cpp \
src/tdlibwrapper.cpp src/tdlibwrapper.cpp
@ -86,6 +87,7 @@ INSTALLS += telegram 86.png 108.png 128.png 172.png 256.png \
HEADERS += \ HEADERS += \
src/chatlistmodel.h \ src/chatlistmodel.h \
src/chatmodel.h \ src/chatmodel.h \
src/notificationmanager.h \
src/tdlibreceiver.h \ src/tdlibreceiver.h \
src/tdlibsecrets.h \ src/tdlibsecrets.h \
src/tdlibwrapper.h src/tdlibwrapper.h

View file

@ -1,5 +1,25 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#include "chatlistmodel.h" #include "chatlistmodel.h"
#include <QListIterator> #include <QListIterator>
#include <QDebug>
ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper)
{ {
@ -15,7 +35,7 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper)
ChatListModel::~ChatListModel() ChatListModel::~ChatListModel()
{ {
qDebug() << "[ChatListModel] Destroying myself...";
} }
int ChatListModel::rowCount(const QModelIndex &) const int ChatListModel::rowCount(const QModelIndex &) const

View file

@ -1,3 +1,22 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CHATLISTMODEL_H #ifndef CHATLISTMODEL_H
#define CHATLISTMODEL_H #define CHATLISTMODEL_H

View file

@ -1,3 +1,22 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#include "chatmodel.h" #include "chatmodel.h"
#include <QListIterator> #include <QListIterator>
@ -18,7 +37,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper)
ChatModel::~ChatModel() ChatModel::~ChatModel()
{ {
qDebug() << "[ChatModel] Destroying myself...";
} }
int ChatModel::rowCount(const QModelIndex &) const int ChatModel::rowCount(const QModelIndex &) const

View file

@ -1,3 +1,22 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CHATMODEL_H #ifndef CHATMODEL_H
#define CHATMODEL_H #define CHATMODEL_H

View file

@ -32,6 +32,7 @@
#include "tdlibwrapper.h" #include "tdlibwrapper.h"
#include "chatlistmodel.h" #include "chatlistmodel.h"
#include "chatmodel.h" #include "chatmodel.h"
#include "notificationmanager.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -50,6 +51,9 @@ int main(int argc, char *argv[])
ChatModel chatModel(tdLibWrapper); ChatModel chatModel(tdLibWrapper);
context->setContextProperty("chatModel", &chatModel); context->setContextProperty("chatModel", &chatModel);
NotificationManager notificationManager(tdLibWrapper);
context->setContextProperty("notificationManager", &notificationManager);
view->setSource(SailfishApp::pathTo("qml/harbour-fernschreiber.qml")); view->setSource(SailfishApp::pathTo("qml/harbour-fernschreiber.qml"));
view->show(); view->show();
return app->exec(); return app->exec();

View file

@ -0,0 +1,50 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#include "notificationmanager.h"
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent)
{
qDebug() << "[NotificationManager] Initializing...";
this->tdLibWrapper = tdLibWrapper;
connect(this->tdLibWrapper, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList)));
connect(this->tdLibWrapper, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SLOT(handleUpdateNotificationGroup(QVariantMap)));
connect(this->tdLibWrapper, SIGNAL(notificationUpdated(QVariantMap)), this, SLOT(handleUpdateNotification(QVariantMap)));
}
NotificationManager::~NotificationManager()
{
qDebug() << "[NotificationManager] Destroying myself...";
}
void NotificationManager::handleUpdateActiveNotifications(const QVariantList notificationGroups)
{
qDebug() << "[NotificationManager] Received active notifications, number of groups:" << notificationGroups.size();
}
void NotificationManager::handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate)
{
qDebug() << "[NotificationManager] Received notification group update, group ID:" << notificationGroupUpdate.value("notification_group_id").toInt();
}
void NotificationManager::handleUpdateNotification(const QVariantMap updatedNotification)
{
qDebug() << "[NotificationManager] Received notification update, group ID:" << updatedNotification.value("notification_group_id").toInt();
}

48
src/notificationmanager.h Normal file
View file

@ -0,0 +1,48 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NOTIFICATIONMANAGER_H
#define NOTIFICATIONMANAGER_H
#include <QObject>
#include "tdlibwrapper.h"
class NotificationManager : public QObject
{
Q_OBJECT
public:
explicit NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent = nullptr);
~NotificationManager() override;
signals:
public slots:
void handleUpdateActiveNotifications(const QVariantList notificationGroups);
void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate);
void handleUpdateNotification(const QVariantMap updatedNotification);
private:
TDLibWrapper *tdLibWrapper;
};
#endif // NOTIFICATIONMANAGER_H

View file

@ -75,6 +75,8 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "updateNewMessage") { this->processUpdateNewMessage(receivedInformation); } if (objectTypeName == "updateNewMessage") { this->processUpdateNewMessage(receivedInformation); }
if (objectTypeName == "message") { this->processMessage(receivedInformation); } if (objectTypeName == "message") { this->processMessage(receivedInformation); }
if (objectTypeName == "updateMessageSendSucceeded") { this->processMessageSendSucceeded(receivedInformation); } if (objectTypeName == "updateMessageSendSucceeded") { this->processMessageSendSucceeded(receivedInformation); }
if (objectTypeName == "updateActiveNotifications") { this->processUpdateActiveNotifications(receivedInformation); }
if (objectTypeName == "updateNotificationGroup") { this->processUpdateNotificationGroup(receivedInformation); }
} }
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation) void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
@ -238,3 +240,21 @@ void TDLibReceiver::processMessageSendSucceeded(const QVariantMap &receivedInfor
qDebug() << "[TDLibReceiver] Message send succeeded " << messageId << oldMessageId; qDebug() << "[TDLibReceiver] Message send succeeded " << messageId << oldMessageId;
emit messageSendSucceeded(messageId, oldMessageId, message); emit messageSendSucceeded(messageId, oldMessageId, message);
} }
void TDLibReceiver::processUpdateActiveNotifications(const QVariantMap &receivedInformation)
{
qDebug() << "[TDLibReceiver] Received active notification groups";
emit activeNotificationsUpdated(receivedInformation.value("groups").toList());
}
void TDLibReceiver::processUpdateNotificationGroup(const QVariantMap &receivedInformation)
{
qDebug() << "[TDLibReceiver] Received updated notification group";
emit notificationGroupUpdated(receivedInformation);
}
void TDLibReceiver::processUpdateNotification(const QVariantMap &receivedInformation)
{
qDebug() << "[TDLibReceiver] Received notification update";
emit notificationUpdated(receivedInformation);
}

View file

@ -57,6 +57,9 @@ signals:
void newMessageReceived(const QString &chatId, const QVariantMap &message); void newMessageReceived(const QString &chatId, const QVariantMap &message);
void messageInformation(const QString &messageId, const QVariantMap &message); void messageInformation(const QString &messageId, const QVariantMap &message);
void messageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message); void messageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
void activeNotificationsUpdated(const QVariantList notificationGroups);
void notificationGroupUpdated(const QVariantMap notificationGroupUpdate);
void notificationUpdated(const QVariantMap updatedNotification);
private: private:
void *tdLibClient; void *tdLibClient;
@ -85,6 +88,9 @@ private:
void processUpdateNewMessage(const QVariantMap &receivedInformation); void processUpdateNewMessage(const QVariantMap &receivedInformation);
void processMessage(const QVariantMap &receivedInformation); void processMessage(const QVariantMap &receivedInformation);
void processMessageSendSucceeded(const QVariantMap &receivedInformation); void processMessageSendSucceeded(const QVariantMap &receivedInformation);
void processUpdateActiveNotifications(const QVariantMap &receivedInformation);
void processUpdateNotificationGroup(const QVariantMap &receivedInformation);
void processUpdateNotification(const QVariantMap &receivedInformation);
}; };
#endif // TDLIBRECEIVER_H #endif // TDLIBRECEIVER_H

View file

@ -62,7 +62,10 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(messagesReceived(QVariantList)), this, SLOT(handleMessagesReceived(QVariantList))); connect(this->tdLibReceiver, SIGNAL(messagesReceived(QVariantList)), this, SLOT(handleMessagesReceived(QVariantList)));
connect(this->tdLibReceiver, SIGNAL(newMessageReceived(QString, QVariantMap)), this, SLOT(handleNewMessageReceived(QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(newMessageReceived(QString, QVariantMap)), this, SLOT(handleNewMessageReceived(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageInformation(QString, QVariantMap)), this, SLOT(handleMessageInformation(QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(messageInformation(QString, QVariantMap)), this, SLOT(handleMessageInformation(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList)));
connect(this->tdLibReceiver, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SLOT(handleUpdateNotificationGroup(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(notificationUpdated(QVariantMap)), this, SLOT(handleUpdateNotification(QVariantMap)));
this->tdLibReceiver->start(); this->tdLibReceiver->start();
@ -507,6 +510,21 @@ void TDLibWrapper::handleMessageSendSucceeded(const QString &messageId, const QS
emit messageSendSucceeded(messageId, oldMessageId, message); emit messageSendSucceeded(messageId, oldMessageId, message);
} }
void TDLibWrapper::handleUpdateActiveNotifications(const QVariantList notificationGroups)
{
emit activeNotificationsUpdated(notificationGroups);
}
void TDLibWrapper::handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate)
{
emit notificationGroupUpdated(notificationGroupUpdate);
}
void TDLibWrapper::handleUpdateNotification(const QVariantMap updatedNotification)
{
emit notificationUpdated(updatedNotification);
}
void TDLibWrapper::setInitialParameters() void TDLibWrapper::setInitialParameters()
{ {
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib"; qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";

View file

@ -109,6 +109,9 @@ signals:
void copyToDownloadsError(const QString &fileName, const QString &filePath); void copyToDownloadsError(const QString &fileName, const QString &filePath);
void receivedMessage(const QString &messageId, const QVariantMap &message); void receivedMessage(const QString &messageId, const QVariantMap &message);
void messageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message); void messageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
void activeNotificationsUpdated(const QVariantList notificationGroups);
void notificationGroupUpdated(const QVariantMap notificationGroupUpdate);
void notificationUpdated(const QVariantMap updatedNotification);
public slots: public slots:
void handleVersionDetected(const QString &version); void handleVersionDetected(const QString &version);
@ -132,6 +135,9 @@ public slots:
void handleNewMessageReceived(const QString &chatId, const QVariantMap &message); void handleNewMessageReceived(const QString &chatId, const QVariantMap &message);
void handleMessageInformation(const QString &messageId, const QVariantMap &message); void handleMessageInformation(const QString &messageId, const QVariantMap &message);
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message); void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
void handleUpdateActiveNotifications(const QVariantList notificationGroups);
void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate);
void handleUpdateNotification(const QVariantMap updatedNotification);
private: private:
void *tdLibClient; void *tdLibClient;