2020-09-02 23:49:15 +03:00
|
|
|
/*
|
2020-10-19 20:34:47 +03:00
|
|
|
Copyright (C) 2020 Sebastian J. Wolf and other contributors
|
2020-09-02 23:49:15 +03:00
|
|
|
|
|
|
|
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"
|
2020-10-03 23:58:45 +03:00
|
|
|
#include "fernschreiberutils.h"
|
2020-11-20 22:39:23 +03:00
|
|
|
#include "chatmodel.h"
|
2020-09-04 00:20:46 +03:00
|
|
|
#include <sailfishapp.h>
|
|
|
|
#include <QListIterator>
|
|
|
|
#include <QUrl>
|
2020-09-13 00:22:33 +03:00
|
|
|
#include <QDateTime>
|
2020-09-13 22:54:36 +03:00
|
|
|
#include <QDBusConnection>
|
2020-11-21 01:26:32 +03:00
|
|
|
#include <QGuiApplication>
|
2020-09-02 23:49:15 +03:00
|
|
|
|
2020-11-22 06:58:47 +03:00
|
|
|
#define DEBUG_MODULE NotificationManager
|
|
|
|
#include "debuglog.h"
|
2020-10-10 16:48:12 +03:00
|
|
|
|
2020-10-28 02:58:41 +03:00
|
|
|
namespace {
|
|
|
|
const QString _TYPE("@type");
|
|
|
|
const QString TYPE("type");
|
|
|
|
const QString ID("id");
|
|
|
|
const QString CHAT_ID("chat_id");
|
|
|
|
const QString IS_CHANNEL("is_channel");
|
|
|
|
const QString TOTAL_COUNT("total_count");
|
|
|
|
const QString DATE("date");
|
|
|
|
const QString TITLE("title");
|
|
|
|
const QString CONTENT("content");
|
|
|
|
const QString MESSAGE("message");
|
|
|
|
const QString FIRST_NAME("first_name");
|
|
|
|
const QString LAST_NAME("last_name");
|
2022-01-07 21:18:04 +03:00
|
|
|
const QString SENDER_ID("sender_id");
|
2020-12-07 23:43:09 +03:00
|
|
|
const QString USER_ID("user_id");
|
2020-10-28 02:58:41 +03:00
|
|
|
const QString NOTIFICATIONS("notifications");
|
|
|
|
const QString NOTIFICATION_GROUP_ID("notification_group_id");
|
|
|
|
const QString ADDED_NOTIFICATIONS("added_notifications");
|
|
|
|
const QString REMOVED_NOTIFICATION_IDS("removed_notification_ids");
|
|
|
|
|
|
|
|
const QString CHAT_TYPE_BASIC_GROUP("chatTypeBasicGroup");
|
|
|
|
const QString CHAT_TYPE_SUPERGROUP("chatTypeSupergroup");
|
|
|
|
|
|
|
|
const QString APP_NAME("Fernschreiber");
|
2020-10-28 05:18:34 +03:00
|
|
|
|
|
|
|
// Notification hints
|
|
|
|
const QString HINT_GROUP_ID("x-fernschreiber.group_id"); // int
|
|
|
|
const QString HINT_CHAT_ID("x-fernschreiber.chat_id"); // qlonglong
|
|
|
|
const QString HINT_TOTAL_COUNT("x-fernschreiber.total_count"); // int
|
2020-11-20 22:39:23 +03:00
|
|
|
|
2021-02-01 03:04:18 +03:00
|
|
|
const QString HINT_IMAGE_PATH("image-path"); // QString
|
2020-11-20 22:39:23 +03:00
|
|
|
const QString HINT_VIBRA("x-nemo-vibrate"); // bool
|
2021-01-19 23:48:28 +03:00
|
|
|
const QString HINT_SUPPRESS_SOUND("suppress-sound"); // bool
|
2020-11-20 22:39:23 +03:00
|
|
|
const QString HINT_DISPLAY_ON("x-nemo-display-on"); // bool
|
|
|
|
const QString HINT_VISIBILITY("x-nemo-visibility"); // QString
|
|
|
|
const QString VISIBILITY_PUBLIC("public");
|
2020-10-28 05:18:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class NotificationManager::ChatInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ChatInfo(const QVariantMap &info);
|
|
|
|
|
|
|
|
void setChatInfo(const QVariantMap &info);
|
|
|
|
|
|
|
|
public:
|
|
|
|
TDLibWrapper::ChatType type;
|
|
|
|
bool isChannel;
|
|
|
|
QString title;
|
|
|
|
};
|
|
|
|
|
|
|
|
NotificationManager::ChatInfo::ChatInfo(const QVariantMap &chatInfo)
|
|
|
|
{
|
|
|
|
setChatInfo(chatInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationManager::ChatInfo::setChatInfo(const QVariantMap &chatInfo)
|
|
|
|
{
|
|
|
|
const QVariantMap chatTypeInformation = chatInfo.value(TYPE).toMap();
|
|
|
|
type = TDLibWrapper::chatTypeFromString(chatTypeInformation.value(_TYPE).toString());
|
|
|
|
isChannel = chatTypeInformation.value(IS_CHANNEL).toBool();
|
|
|
|
title = chatInfo.value(TITLE).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
class NotificationManager::NotificationGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NotificationGroup(int groupId, qlonglong chatId, int count, Notification *notification);
|
|
|
|
NotificationGroup(Notification *notification);
|
|
|
|
~NotificationGroup();
|
|
|
|
|
|
|
|
public:
|
|
|
|
int notificationGroupId;
|
|
|
|
qlonglong chatId;
|
|
|
|
int totalCount;
|
|
|
|
Notification *nemoNotification;
|
|
|
|
QMap<int,QVariantMap> activeNotifications;
|
|
|
|
QList<int> notificationOrder;
|
|
|
|
};
|
|
|
|
|
|
|
|
NotificationManager::NotificationGroup::NotificationGroup(int group, qlonglong chat, int count, Notification *notification) :
|
|
|
|
notificationGroupId(group),
|
|
|
|
chatId(chat),
|
|
|
|
totalCount(count),
|
|
|
|
nemoNotification(notification)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationManager::NotificationGroup::~NotificationGroup()
|
|
|
|
{
|
|
|
|
delete nemoNotification;
|
2020-10-28 02:58:41 +03:00
|
|
|
}
|
|
|
|
|
2020-11-23 01:32:00 +03:00
|
|
|
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings, MceInterface *mceInterface, ChatModel *chatModel) :
|
2020-10-28 02:58:41 +03:00
|
|
|
appIconFile(SailfishApp::pathTo("images/fernschreiber-notification.png").toLocalFile())
|
2020-09-02 23:49:15 +03:00
|
|
|
{
|
2020-10-10 16:48:12 +03:00
|
|
|
LOG("Initializing...");
|
2020-09-02 23:49:15 +03:00
|
|
|
this->tdLibWrapper = tdLibWrapper;
|
2020-10-10 18:46:08 +03:00
|
|
|
this->appSettings = appSettings;
|
2020-11-23 01:32:00 +03:00
|
|
|
this->mceInterface = mceInterface;
|
2020-11-20 22:39:23 +03:00
|
|
|
this->chatModel = chatModel;
|
2020-09-02 23:49:15 +03:00
|
|
|
|
|
|
|
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)));
|
2020-09-03 00:05:09 +03:00
|
|
|
connect(this->tdLibWrapper, SIGNAL(newChatDiscovered(QString, QVariantMap)), this, SLOT(handleChatDiscovered(QString, QVariantMap)));
|
2020-10-28 05:18:34 +03:00
|
|
|
connect(this->tdLibWrapper, SIGNAL(chatTitleUpdated(QString, QString)), this, SLOT(handleChatTitleUpdated(QString, QString)));
|
2020-09-13 22:54:36 +03:00
|
|
|
|
|
|
|
this->controlLedNotification(false);
|
2020-10-28 05:18:34 +03:00
|
|
|
|
|
|
|
// Restore notifications
|
|
|
|
QList<QObject*> notifications = Notification::notifications();
|
|
|
|
const int n = notifications.count();
|
|
|
|
LOG("Found" << n << "existing notifications");
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
QObject *notificationObject = notifications.at(i);
|
|
|
|
Notification *notification = qobject_cast<Notification *>(notificationObject);
|
|
|
|
if (notification) {
|
|
|
|
bool groupOk, chatOk, countOk;
|
|
|
|
const int groupId = notification->hintValue(HINT_GROUP_ID).toInt(&groupOk);
|
|
|
|
const qlonglong chatId = notification->hintValue(HINT_CHAT_ID).toLongLong(&chatOk);
|
|
|
|
const int totalCount = notification->hintValue(HINT_TOTAL_COUNT).toInt(&countOk);
|
|
|
|
if (groupOk && chatOk && countOk && !notificationGroups.contains(groupId)) {
|
|
|
|
LOG("Restoring notification group" << groupId << "chatId" << chatId << "count" << totalCount);
|
|
|
|
notificationGroups.insert(groupId, new NotificationGroup(groupId, chatId, totalCount, notification));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete notificationObject;
|
|
|
|
}
|
2020-09-02 23:49:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NotificationManager::~NotificationManager()
|
|
|
|
{
|
2020-10-10 16:48:12 +03:00
|
|
|
LOG("Destroying myself...");
|
2020-10-28 05:18:34 +03:00
|
|
|
qDeleteAll(chatMap.values());
|
|
|
|
qDeleteAll(notificationGroups.values());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationManager::handleUpdateActiveNotifications(const QVariantList ¬ificationGroups)
|
|
|
|
{
|
|
|
|
const int n = notificationGroups.size();
|
|
|
|
LOG("Received active notifications, number of groups:" << n);
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
const QVariantMap notificationGroupInfo(notificationGroups.at(i).toMap());
|
|
|
|
updateNotificationGroup(notificationGroupInfo.value(ID).toInt(),
|
|
|
|
notificationGroupInfo.value(CHAT_ID).toLongLong(),
|
|
|
|
notificationGroupInfo.value(TOTAL_COUNT).toInt(),
|
|
|
|
notificationGroupInfo.value(NOTIFICATIONS).toList());
|
|
|
|
}
|
2020-09-02 23:49:15 +03:00
|
|
|
}
|
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
void NotificationManager::handleUpdateNotificationGroup(const QVariantMap ¬ificationGroupUpdate)
|
2020-09-02 23:49:15 +03:00
|
|
|
{
|
2020-10-28 05:18:34 +03:00
|
|
|
const int notificationGroupId = notificationGroupUpdate.value(NOTIFICATION_GROUP_ID).toInt();
|
|
|
|
const int totalCount = notificationGroupUpdate.value(TOTAL_COUNT).toInt();
|
|
|
|
LOG("Received notification group update, group ID:" << notificationGroupId << "total count" << totalCount);
|
|
|
|
updateNotificationGroup(notificationGroupId,
|
|
|
|
notificationGroupUpdate.value(CHAT_ID).toLongLong(), totalCount,
|
|
|
|
notificationGroupUpdate.value(ADDED_NOTIFICATIONS).toList(),
|
|
|
|
notificationGroupUpdate.value(REMOVED_NOTIFICATION_IDS).toList(),
|
|
|
|
appSettings->notificationFeedback());
|
2020-09-02 23:49:15 +03:00
|
|
|
}
|
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
void NotificationManager::updateNotificationGroup(int groupId, qlonglong chatId, int totalCount,
|
|
|
|
const QVariantList &addedNotifications, const QVariantList & removedNotificationIds,
|
|
|
|
AppSettings::NotificationFeedback feedback)
|
2020-09-02 23:49:15 +03:00
|
|
|
{
|
2020-10-28 05:18:34 +03:00
|
|
|
bool needFeedback = false;
|
|
|
|
NotificationGroup* notificationGroup = notificationGroups.value(groupId);
|
|
|
|
|
|
|
|
LOG("Received notification group update, group ID:" << groupId << "total count" << totalCount);
|
|
|
|
if (totalCount) {
|
|
|
|
if (notificationGroup) {
|
|
|
|
// Notification group already exists
|
|
|
|
notificationGroup->totalCount = totalCount;
|
|
|
|
} else {
|
|
|
|
// New notification
|
|
|
|
Notification *notification = new Notification(this);
|
2021-01-19 23:48:28 +03:00
|
|
|
notification->setCategory("x-nemo.messaging.im");
|
2020-10-28 05:18:34 +03:00
|
|
|
notification->setAppName(APP_NAME);
|
|
|
|
notification->setAppIcon(appIconFile);
|
2021-01-19 23:48:28 +03:00
|
|
|
notification->setIcon(appIconFile);
|
2020-10-28 05:18:34 +03:00
|
|
|
notification->setHintValue(HINT_GROUP_ID, groupId);
|
|
|
|
notification->setHintValue(HINT_CHAT_ID, chatId);
|
|
|
|
notification->setHintValue(HINT_TOTAL_COUNT, totalCount);
|
|
|
|
notificationGroups.insert(groupId, notificationGroup =
|
|
|
|
new NotificationGroup(groupId, chatId, totalCount, notification));
|
2020-09-09 00:44:57 +03:00
|
|
|
}
|
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
QListIterator<QVariant> addedNotificationIterator(addedNotifications);
|
|
|
|
while (addedNotificationIterator.hasNext()) {
|
|
|
|
const QVariantMap addedNotification = addedNotificationIterator.next().toMap();
|
|
|
|
const int addedId = addedNotification.value(ID).toInt();
|
|
|
|
notificationGroup->activeNotifications.insert(addedId, addedNotification);
|
|
|
|
notificationGroup->notificationOrder.append(addedId);
|
2020-09-10 00:44:02 +03:00
|
|
|
}
|
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
QListIterator<QVariant> removedNotificationIdsIterator(removedNotificationIds);
|
|
|
|
while (removedNotificationIdsIterator.hasNext()) {
|
|
|
|
const int removedId = removedNotificationIdsIterator.next().toInt();
|
|
|
|
notificationGroup->activeNotifications.remove(removedId);
|
|
|
|
notificationGroup->notificationOrder.removeOne(removedId);
|
|
|
|
}
|
|
|
|
|
2020-11-20 22:39:23 +03:00
|
|
|
// Make sure that if there's no notifications, order is empty too.
|
|
|
|
// That's usually already the case but double-check won't wort. It's cheap.
|
|
|
|
if (notificationGroup->activeNotifications.isEmpty()) {
|
|
|
|
notificationGroup->notificationOrder.clear();
|
|
|
|
}
|
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
// Decide if we need a bzzz
|
|
|
|
switch (feedback) {
|
|
|
|
case AppSettings::NotificationFeedbackNone:
|
|
|
|
break;
|
|
|
|
case AppSettings::NotificationFeedbackNew:
|
|
|
|
// Non-zero replacesId means that notification has already been published
|
|
|
|
needFeedback = !notificationGroup->nemoNotification->replacesId();
|
|
|
|
break;
|
|
|
|
case AppSettings::NotificationFeedbackAll:
|
|
|
|
// Even in this case don't alert the user just about removals
|
|
|
|
needFeedback = !addedNotifications.isEmpty();
|
|
|
|
break;
|
|
|
|
}
|
2020-09-13 22:54:36 +03:00
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
// Publish new or update the existing notification
|
2020-11-20 22:39:23 +03:00
|
|
|
LOG("Feedback" << needFeedback);
|
2020-10-28 05:18:34 +03:00
|
|
|
publishNotification(notificationGroup, needFeedback);
|
|
|
|
} else if (notificationGroup) {
|
|
|
|
// No active notifications left in this group
|
|
|
|
notificationGroup->nemoNotification->close();
|
|
|
|
notificationGroups.remove(groupId);
|
|
|
|
delete notificationGroup;
|
2020-09-04 00:20:46 +03:00
|
|
|
}
|
2020-09-09 00:44:57 +03:00
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
if (notificationGroups.isEmpty()) {
|
|
|
|
// No active notifications left at all
|
|
|
|
controlLedNotification(false);
|
|
|
|
} else if (needFeedback) {
|
|
|
|
controlLedNotification(true);
|
|
|
|
}
|
2020-09-02 23:49:15 +03:00
|
|
|
}
|
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
void NotificationManager::handleUpdateNotification(const QVariantMap &updatedNotification)
|
2020-09-02 23:49:15 +03:00
|
|
|
{
|
2020-10-28 02:58:41 +03:00
|
|
|
LOG("Received notification update, group ID:" << updatedNotification.value(NOTIFICATION_GROUP_ID).toInt());
|
2020-09-02 23:49:15 +03:00
|
|
|
}
|
2020-09-03 00:05:09 +03:00
|
|
|
|
|
|
|
void NotificationManager::handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation)
|
|
|
|
{
|
2020-10-28 05:18:34 +03:00
|
|
|
const qlonglong id = chatId.toLongLong();
|
|
|
|
ChatInfo *chat = chatMap.value(id);
|
|
|
|
if (chat) {
|
|
|
|
chat->setChatInfo(chatInformation);
|
|
|
|
LOG("Updated chat information" << id << chat->title);
|
|
|
|
} else {
|
|
|
|
chat = new ChatInfo(chatInformation);
|
|
|
|
chatMap.insert(id, chat);
|
|
|
|
LOG("New chat" << id << chat->title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationManager::handleChatTitleUpdated(const QString &chatId, const QString &title)
|
|
|
|
{
|
|
|
|
const qlonglong id = chatId.toLongLong();
|
|
|
|
ChatInfo *chat = chatMap.value(id);
|
|
|
|
if (chat) {
|
|
|
|
LOG("Chat" << id << "title changed to" << title);
|
|
|
|
chat->title = title;
|
|
|
|
|
|
|
|
// Silently update notification summary
|
|
|
|
QListIterator<NotificationGroup*> groupsIterator(notificationGroups.values());
|
|
|
|
while (groupsIterator.hasNext()) {
|
|
|
|
const NotificationGroup *group = groupsIterator.next();
|
|
|
|
if (group->chatId == id) {
|
|
|
|
LOG("Updating summary for group ID" << group->notificationGroupId);
|
|
|
|
publishNotification(group, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-03 00:05:09 +03:00
|
|
|
}
|
2020-09-04 00:20:46 +03:00
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
void NotificationManager::publishNotification(const NotificationGroup *notificationGroup, bool needFeedback)
|
2020-09-04 00:20:46 +03:00
|
|
|
{
|
2020-10-28 05:18:34 +03:00
|
|
|
QVariantMap messageMap;
|
|
|
|
const ChatInfo *chatInformation = chatMap.value(notificationGroup->chatId);
|
|
|
|
if (!notificationGroup->notificationOrder.isEmpty()) {
|
|
|
|
const int lastNotificationId = notificationGroup->notificationOrder.last();
|
|
|
|
const QVariantMap lastNotification(notificationGroup->activeNotifications.value(lastNotificationId));
|
|
|
|
messageMap = lastNotification.value(TYPE).toMap().value(MESSAGE).toMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
Notification *nemoNotification = notificationGroup->nemoNotification;
|
|
|
|
if (!messageMap.isEmpty()) {
|
|
|
|
nemoNotification->setTimestamp(QDateTime::fromMSecsSinceEpoch(messageMap.value(DATE).toLongLong() * 1000));
|
|
|
|
|
|
|
|
QVariantList remoteActionArguments;
|
|
|
|
remoteActionArguments.append(QString::number(notificationGroup->chatId));
|
|
|
|
remoteActionArguments.append(messageMap.value(ID).toString());
|
|
|
|
nemoNotification->setRemoteAction(Notification::remoteAction("default", "openMessage",
|
|
|
|
"de.ygriega.fernschreiber", "/de/ygriega/fernschreiber", "de.ygriega.fernschreiber",
|
|
|
|
"openMessage", remoteActionArguments));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString notificationBody;
|
2022-01-07 21:18:04 +03:00
|
|
|
const QVariantMap senderInformation = messageMap.value(SENDER_ID).toMap();
|
2020-10-28 05:18:34 +03:00
|
|
|
if (notificationGroup->totalCount == 1 && !messageMap.isEmpty()) {
|
|
|
|
LOG("Group" << notificationGroup->notificationGroupId << "has 1 notification");
|
|
|
|
if (chatInformation && (chatInformation->type == TDLibWrapper::ChatTypeBasicGroup ||
|
|
|
|
(chatInformation->type == TDLibWrapper::ChatTypeSupergroup && !chatInformation->isChannel))) {
|
|
|
|
// Add author
|
2020-12-07 23:43:09 +03:00
|
|
|
QString fullName;
|
|
|
|
if (senderInformation.value(_TYPE).toString() == "messageSenderChat") {
|
|
|
|
fullName = tdLibWrapper->getChat(senderInformation.value(CHAT_ID).toString()).value(TITLE).toString();
|
|
|
|
} else {
|
2020-12-29 18:32:39 +03:00
|
|
|
fullName = FernschreiberUtils::getUserName(tdLibWrapper->getUserInformation(senderInformation.value(USER_ID).toString()));
|
2020-12-07 23:43:09 +03:00
|
|
|
}
|
|
|
|
|
2020-09-13 00:22:33 +03:00
|
|
|
notificationBody = notificationBody + fullName.trimmed() + ": ";
|
|
|
|
}
|
2020-12-29 18:32:39 +03:00
|
|
|
notificationBody += FernschreiberUtils::getMessageShortText(tdLibWrapper, messageMap.value(CONTENT).toMap(), (chatInformation ? chatInformation->isChannel : false), tdLibWrapper->getUserInformation().value(ID).toLongLong(), senderInformation );
|
2020-10-28 05:18:34 +03:00
|
|
|
nemoNotification->setBody(notificationBody);
|
2020-09-10 00:44:02 +03:00
|
|
|
} else {
|
2020-10-28 05:18:34 +03:00
|
|
|
// Either we have more than one notification or we have no content to display
|
|
|
|
LOG("Group" << notificationGroup->notificationGroupId << "has" << notificationGroup->totalCount << "notifications");
|
2020-11-19 11:32:05 +03:00
|
|
|
notificationBody = tr("%Ln unread messages", "", notificationGroup->totalCount);
|
2020-10-10 18:46:08 +03:00
|
|
|
}
|
|
|
|
|
2020-11-20 22:39:23 +03:00
|
|
|
const QString summary(chatInformation ? chatInformation->title : QString());
|
2020-10-28 05:18:34 +03:00
|
|
|
nemoNotification->setBody(notificationBody);
|
2020-11-20 22:39:23 +03:00
|
|
|
nemoNotification->setSummary(summary);
|
|
|
|
nemoNotification->setHintValue(HINT_VIBRA, needFeedback);
|
2021-02-01 03:04:18 +03:00
|
|
|
nemoNotification->setHintValue(HINT_IMAGE_PATH, QString());
|
2020-11-20 22:39:23 +03:00
|
|
|
|
|
|
|
// Don't show popup for the currently open chat
|
|
|
|
if (!needFeedback || (chatModel->getChatId() == notificationGroup->chatId &&
|
|
|
|
qGuiApp->applicationState() == Qt::ApplicationActive)) {
|
2021-01-19 23:48:28 +03:00
|
|
|
nemoNotification->setHintValue(HINT_SUPPRESS_SOUND, true);
|
2020-11-20 22:39:23 +03:00
|
|
|
nemoNotification->setHintValue(HINT_DISPLAY_ON, false);
|
2020-11-21 02:15:13 +03:00
|
|
|
nemoNotification->setHintValue(HINT_VISIBILITY, QString());
|
2020-11-20 22:39:23 +03:00
|
|
|
nemoNotification->setUrgency(Notification::Low);
|
2020-10-28 05:18:34 +03:00
|
|
|
} else {
|
2021-01-19 23:48:28 +03:00
|
|
|
nemoNotification->setPreviewBody(notificationBody);
|
|
|
|
nemoNotification->setPreviewSummary(summary);
|
2021-01-30 19:21:42 +03:00
|
|
|
nemoNotification->setHintValue(HINT_SUPPRESS_SOUND, !appSettings->notificationSoundsEnabled());
|
2020-11-21 02:15:13 +03:00
|
|
|
nemoNotification->setHintValue(HINT_DISPLAY_ON, appSettings->notificationTurnsDisplayOn());
|
2020-11-20 22:39:23 +03:00
|
|
|
nemoNotification->setHintValue(HINT_VISIBILITY, VISIBILITY_PUBLIC);
|
|
|
|
nemoNotification->setUrgency(Notification::Normal);
|
2020-09-10 00:44:02 +03:00
|
|
|
}
|
2020-09-09 00:44:57 +03:00
|
|
|
|
2020-10-28 05:18:34 +03:00
|
|
|
nemoNotification->publish();
|
2020-09-09 00:44:57 +03:00
|
|
|
}
|
|
|
|
|
2020-10-28 02:36:14 +03:00
|
|
|
void NotificationManager::controlLedNotification(bool enabled)
|
2020-09-13 22:54:36 +03:00
|
|
|
{
|
2020-10-10 16:55:46 +03:00
|
|
|
static const QString PATTERN("PatternCommunicationIM");
|
2020-11-23 01:32:00 +03:00
|
|
|
if (enabled) {
|
|
|
|
mceInterface->ledPatternActivate(PATTERN);
|
|
|
|
} else {
|
|
|
|
mceInterface->ledPatternDeactivate(PATTERN);
|
|
|
|
}
|
2020-09-13 22:54:36 +03:00
|
|
|
}
|