From aa3a841fee2b109340dfb08b413741d68233c288 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Wed, 2 Sep 2020 22:49:15 +0200 Subject: [PATCH] Prepare notification manager --- harbour-fernschreiber.pro | 2 ++ src/chatlistmodel.cpp | 22 ++++++++++++++- src/chatlistmodel.h | 19 +++++++++++++ src/chatmodel.cpp | 21 ++++++++++++++- src/chatmodel.h | 19 +++++++++++++ src/harbour-fernschreiber.cpp | 4 +++ src/notificationmanager.cpp | 50 +++++++++++++++++++++++++++++++++++ src/notificationmanager.h | 48 +++++++++++++++++++++++++++++++++ src/tdlibreceiver.cpp | 20 ++++++++++++++ src/tdlibreceiver.h | 6 +++++ src/tdlibwrapper.cpp | 20 +++++++++++++- src/tdlibwrapper.h | 6 +++++ 12 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 src/notificationmanager.cpp create mode 100644 src/notificationmanager.h diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index febf2d7..990d921 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -19,6 +19,7 @@ QT += core dbus SOURCES += src/harbour-fernschreiber.cpp \ src/chatlistmodel.cpp \ src/chatmodel.cpp \ + src/notificationmanager.cpp \ src/tdlibreceiver.cpp \ src/tdlibwrapper.cpp @@ -86,6 +87,7 @@ INSTALLS += telegram 86.png 108.png 128.png 172.png 256.png \ HEADERS += \ src/chatlistmodel.h \ src/chatmodel.h \ + src/notificationmanager.h \ src/tdlibreceiver.h \ src/tdlibsecrets.h \ src/tdlibwrapper.h diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index 8a46a3b..02e47fe 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -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 . +*/ + #include "chatlistmodel.h" #include +#include ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) { @@ -15,7 +35,7 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) ChatListModel::~ChatListModel() { - + qDebug() << "[ChatListModel] Destroying myself..."; } int ChatListModel::rowCount(const QModelIndex &) const diff --git a/src/chatlistmodel.h b/src/chatlistmodel.h index 2fbc8d1..c0dee72 100644 --- a/src/chatlistmodel.h +++ b/src/chatlistmodel.h @@ -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 . +*/ + #ifndef CHATLISTMODEL_H #define CHATLISTMODEL_H diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 6731305..f593e25 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -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 . +*/ + #include "chatmodel.h" #include @@ -18,7 +37,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper) ChatModel::~ChatModel() { - + qDebug() << "[ChatModel] Destroying myself..."; } int ChatModel::rowCount(const QModelIndex &) const diff --git a/src/chatmodel.h b/src/chatmodel.h index 5a53eb7..30bb3d9 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -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 . +*/ + #ifndef CHATMODEL_H #define CHATMODEL_H diff --git a/src/harbour-fernschreiber.cpp b/src/harbour-fernschreiber.cpp index 886dfa5..5f078af 100644 --- a/src/harbour-fernschreiber.cpp +++ b/src/harbour-fernschreiber.cpp @@ -32,6 +32,7 @@ #include "tdlibwrapper.h" #include "chatlistmodel.h" #include "chatmodel.h" +#include "notificationmanager.h" int main(int argc, char *argv[]) { @@ -50,6 +51,9 @@ int main(int argc, char *argv[]) ChatModel chatModel(tdLibWrapper); context->setContextProperty("chatModel", &chatModel); + NotificationManager notificationManager(tdLibWrapper); + context->setContextProperty("notificationManager", ¬ificationManager); + view->setSource(SailfishApp::pathTo("qml/harbour-fernschreiber.qml")); view->show(); return app->exec(); diff --git a/src/notificationmanager.cpp b/src/notificationmanager.cpp new file mode 100644 index 0000000..a79139a --- /dev/null +++ b/src/notificationmanager.cpp @@ -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 . +*/ + +#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(); +} diff --git a/src/notificationmanager.h b/src/notificationmanager.h new file mode 100644 index 0000000..df8c0a1 --- /dev/null +++ b/src/notificationmanager.h @@ -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 . +*/ + +#ifndef NOTIFICATIONMANAGER_H +#define NOTIFICATIONMANAGER_H + +#include + +#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 diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index 381d585..d2089b3 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -75,6 +75,8 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc if (objectTypeName == "updateNewMessage") { this->processUpdateNewMessage(receivedInformation); } if (objectTypeName == "message") { this->processMessage(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) @@ -238,3 +240,21 @@ void TDLibReceiver::processMessageSendSucceeded(const QVariantMap &receivedInfor qDebug() << "[TDLibReceiver] Message send succeeded " << messageId << oldMessageId; 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); +} diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h index 1eb288f..eb6829c 100644 --- a/src/tdlibreceiver.h +++ b/src/tdlibreceiver.h @@ -57,6 +57,9 @@ signals: void newMessageReceived(const QString &chatId, const QVariantMap &message); void messageInformation(const QString &messageId, 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: void *tdLibClient; @@ -85,6 +88,9 @@ private: void processUpdateNewMessage(const QVariantMap &receivedInformation); void processMessage(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 diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 50b8b3b..e4dcd1a 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -62,7 +62,10 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent) 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(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(); @@ -507,6 +510,21 @@ void TDLibWrapper::handleMessageSendSucceeded(const QString &messageId, const QS 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() { qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib"; diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 85d6940..0fc1cfd 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -109,6 +109,9 @@ signals: void copyToDownloadsError(const QString &fileName, const QString &filePath); void receivedMessage(const QString &messageId, 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: void handleVersionDetected(const QString &version); @@ -132,6 +135,9 @@ public slots: void handleNewMessageReceived(const QString &chatId, const QVariantMap &message); void handleMessageInformation(const QString &messageId, 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: void *tdLibClient;