mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(notification): Notifications now always replace the previous one
This is a feature/fix to improve notification behavior when we receive over 3 messages. SnoreNotify prevents over 3 notifications from being displayed before a user clears the notification. This is presumably to avoid infinite notification spam. Unfortunately this results in the notifications just coming in _after_ the user clears them. This means if there are 100s of messages built up the user has to clear their notifications N messages / 3 times. This feature/fix folds all notifications into a single notification representing the current qTox notification state. See notificationgenerator_test.cpp for what the new messages look like.
This commit is contained in:
parent
a9f6543e43
commit
6e163ca5ed
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2020 by The qTox Project Contributors
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||||
|
|
||||||
|
qTox is libre 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.
|
||||||
|
|
||||||
|
qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2020 by The qTox Project Contributors
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||||
|
|
||||||
|
qTox is libre 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.
|
||||||
|
|
||||||
|
qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "notificationgenerator.h"
|
#include "notificationgenerator.h"
|
||||||
#include "src/chatlog/content/filetransferwidget.h"
|
#include "src/chatlog/content/filetransferwidget.h"
|
||||||
|
|
||||||
@ -24,8 +43,8 @@ namespace
|
|||||||
|
|
||||||
QString generateMultiChatTitle(size_t numChats, size_t numMessages)
|
QString generateMultiChatTitle(size_t numChats, size_t numMessages)
|
||||||
{
|
{
|
||||||
// FIXME: how do I tr this
|
//: e.g. 3 messages from 2 chats
|
||||||
return QObject::tr("%1 messages from %2 chats")
|
return QObject::tr("%1 message(s) from %2 chats")
|
||||||
.arg(numMessages)
|
.arg(numMessages)
|
||||||
.arg(numChats);
|
.arg(numChats);
|
||||||
}
|
}
|
||||||
@ -37,14 +56,14 @@ namespace
|
|||||||
{
|
{
|
||||||
if (numNotifications[contact] > 1)
|
if (numNotifications[contact] > 1)
|
||||||
{
|
{
|
||||||
return QObject::tr("%1 messages from %2")
|
//: e.g. 2 messages from Bob
|
||||||
|
return QObject::tr("%1 message(s) from %2")
|
||||||
.arg(numNotifications[contact])
|
.arg(numNotifications[contact])
|
||||||
.arg(contact->getDisplayedName());
|
.arg(contact->getDisplayedName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return QObject::tr("%1")
|
return contact->getDisplayedName();
|
||||||
.arg(contact->getDisplayedName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +219,8 @@ NotificationData NotificationGenerator::fileTransferNotification(const Friend* f
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret.title = f->getDisplayedName() + " - " + tr("File sent");
|
//: e.g. Bob - file transfer
|
||||||
|
ret.title = tr("%1 - file transfer").arg(f->getDisplayedName());
|
||||||
ret.message = filename + " (" + FileTransferWidget::getHumanReadableSize(fileSize) + ")";
|
ret.message = filename + " (" + FileTransferWidget::getHumanReadableSize(fileSize) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +238,7 @@ NotificationData NotificationGenerator::groupInvitationNotification(const Friend
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.title = from->getDisplayedName() + tr(" invites you to join a group.");
|
ret.title = tr("%1 invites you to join a group.").arg(from->getDisplayedName());
|
||||||
ret.message = "";
|
ret.message = "";
|
||||||
ret.pixmap = getSenderAvatar(profile, from->getPublicKey());
|
ret.pixmap = getSenderAvatar(profile, from->getPublicKey());
|
||||||
|
|
||||||
@ -234,7 +254,7 @@ NotificationData NotificationGenerator::friendRequestNotification(const ToxPk& s
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.title = sender.toString() + tr(" sent you a friend request.");
|
ret.title = tr("Friend request received from %1").arg(sender.toString());
|
||||||
ret.message = message;
|
ret.message = message;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2020 by The qTox Project Contributors
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||||
|
|
||||||
|
qTox is libre 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.
|
||||||
|
|
||||||
|
qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright © 2014-2019 by The qTox Project Contributors
|
Copyright © 2020 by The qTox Project Contributors
|
||||||
|
|
||||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||||
|
|
||||||
@ -17,8 +17,7 @@
|
|||||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef INOTIFICATION_SETTINGS_H
|
#pragma once
|
||||||
#define INOTIFICATION_SETTINGS_H
|
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
@ -46,5 +45,3 @@ public:
|
|||||||
virtual bool getGroupAlwaysNotify() const = 0;
|
virtual bool getGroupAlwaysNotify() const = 0;
|
||||||
virtual void setGroupAlwaysNotify(bool newValue) = 0;
|
virtual void setGroupAlwaysNotify(bool newValue) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*INOTIFICATION_SETTINGS_H*/
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <libsnore/snore.h>
|
#include <libsnore/snore.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
DesktopNotify::DesktopNotify()
|
DesktopNotify::DesktopNotify()
|
||||||
: notifyCore{Snore::SnoreCore::instance()}
|
: notifyCore{Snore::SnoreCore::instance()}
|
||||||
@ -37,43 +38,52 @@ DesktopNotify::DesktopNotify()
|
|||||||
snoreApp = Snore::Application("qTox", snoreIcon);
|
snoreApp = Snore::Application("qTox", snoreIcon);
|
||||||
|
|
||||||
notifyCore.registerApplication(snoreApp);
|
notifyCore.registerApplication(snoreApp);
|
||||||
|
|
||||||
|
connect(¬ifyCore, &Snore::SnoreCore::notificationClosed, this, &DesktopNotify::onNotificationClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotify::createNotification(const QString& title, const QString& text, Snore::Icon& icon)
|
void DesktopNotify::notifyMessage(const NotificationData& notificationData)
|
||||||
{
|
{
|
||||||
const Settings& s = Settings::getInstance();
|
const Settings& s = Settings::getInstance();
|
||||||
if(!(s.getNotify() && s.getDesktopNotify())) {
|
if(!(s.getNotify() && s.getDesktopNotify())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Snore::Notification notify{snoreApp, Snore::Alert(), title, text, icon};
|
auto icon = notificationData.pixmap.isNull() ? snoreIcon : Snore::Icon(notificationData.pixmap);
|
||||||
|
auto newNotification = Snore::Notification{snoreApp, Snore::Alert(), notificationData.title, notificationData.message, icon, 0};
|
||||||
|
latestId = newNotification.id();
|
||||||
|
|
||||||
notifyCore.broadcastNotification(notify);
|
if (lastNotification.isValid()) {
|
||||||
}
|
// Workaround for broken updating behavior in snore. Snore increments
|
||||||
|
// the message count when a notification is updated. Snore also caps the
|
||||||
void DesktopNotify::notifyMessage(const QString& title, const QString& message)
|
// number of outgoing messages at 3. This means that if we update
|
||||||
{
|
// notifications more than 3 times we do not get notifications until the
|
||||||
createNotification(title, message, snoreIcon);
|
// user activates the notification.
|
||||||
}
|
//
|
||||||
|
// We work around this by closing the existing notification and replacing
|
||||||
void DesktopNotify::notifyMessagePixmap(const QString& title, const QString& message, QPixmap avatar)
|
// it with a new one. We then only process the notification close if the
|
||||||
{
|
// latest notification id is the same as the one we are closing. This allows
|
||||||
Snore::Icon new_icon(avatar);
|
// us to continue counting how many unread messages a user has until they
|
||||||
createNotification(title, message, new_icon);
|
// close the notification themselves.
|
||||||
}
|
//
|
||||||
|
// I've filed a bug on the snorenotify mailing list but the project seems
|
||||||
void DesktopNotify::notifyMessageSimple(const MessageType type)
|
// pretty dead. I filed a ticket on March 11 2020, and as of April 5 2020
|
||||||
{
|
// the moderators have not even acknowledged the message. A previous message
|
||||||
QString message;
|
// got a response starting with "Snorenotify isn't that well maintained any more"
|
||||||
switch (type) {
|
// (see https://mail.kde.org/pipermail/snorenotify/2019-March/000004.html)
|
||||||
case MessageType::FRIEND: message = tr("New message"); break;
|
// so I don't have hope of this being fixed any time soon
|
||||||
case MessageType::FRIEND_FILE: message = tr("Incoming file transfer"); break;
|
notifyCore.requestCloseNotification(lastNotification, Snore::Notification::CloseReasons::Dismissed);
|
||||||
case MessageType::FRIEND_REQUEST: message = tr("Friend request received"); break;
|
|
||||||
case MessageType::GROUP: message = tr("New group message"); break;
|
|
||||||
case MessageType::GROUP_INVITE: message = tr("Group invite received"); break;
|
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createNotification(message, {}, snoreIcon);
|
notifyCore.broadcastNotification(newNotification);
|
||||||
|
lastNotification = newNotification;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesktopNotify::onNotificationClose(Snore::Notification notification)
|
||||||
|
{
|
||||||
|
if (notification.id() == latestId) {
|
||||||
|
lastNotification = {};
|
||||||
|
emit notificationClosed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,11 +19,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if DESKTOP_NOTIFICATIONS
|
#include "src/model/notificationdata.h"
|
||||||
|
|
||||||
#include <libsnore/snore.h>
|
#include <libsnore/snore.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
class DesktopNotify : public QObject
|
class DesktopNotify : public QObject
|
||||||
{
|
{
|
||||||
@ -31,25 +34,19 @@ class DesktopNotify : public QObject
|
|||||||
public:
|
public:
|
||||||
DesktopNotify();
|
DesktopNotify();
|
||||||
|
|
||||||
enum class MessageType {
|
|
||||||
FRIEND,
|
|
||||||
FRIEND_FILE,
|
|
||||||
FRIEND_REQUEST,
|
|
||||||
GROUP,
|
|
||||||
GROUP_INVITE
|
|
||||||
};
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void notifyMessage(const QString& title, const QString& message);
|
void notifyMessage(const NotificationData& notificationData);
|
||||||
void notifyMessagePixmap(const QString& title, const QString& message, QPixmap avatar);
|
|
||||||
void notifyMessageSimple(const MessageType type);
|
|
||||||
|
|
||||||
private:
|
signals:
|
||||||
void createNotification(const QString& title, const QString& text, Snore::Icon& icon);
|
void notificationClosed();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onNotificationClose(Snore::Notification notification);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Snore::SnoreCore& notifyCore;
|
Snore::SnoreCore& notifyCore;
|
||||||
Snore::Application snoreApp;
|
Snore::Application snoreApp;
|
||||||
Snore::Icon snoreIcon;
|
Snore::Icon snoreIcon;
|
||||||
|
Snore::Notification lastNotification;
|
||||||
|
uint latestId;
|
||||||
};
|
};
|
||||||
#endif // DESKTOP_NOTIFICATIONS
|
|
||||||
|
@ -294,6 +294,11 @@ void Widget::init()
|
|||||||
profileInfo = new ProfileInfo(core, profile);
|
profileInfo = new ProfileInfo(core, profile);
|
||||||
profileForm = new ProfileForm(profileInfo);
|
profileForm = new ProfileForm(profileInfo);
|
||||||
|
|
||||||
|
#if DESKTOP_NOTIFICATIONS
|
||||||
|
notificationGenerator.reset(new NotificationGenerator(settings, profile));
|
||||||
|
connect(¬ifier, &DesktopNotify::notificationClosed, notificationGenerator.get(), &NotificationGenerator::onNotificationActivated);
|
||||||
|
#endif
|
||||||
|
|
||||||
// connect logout tray menu action
|
// connect logout tray menu action
|
||||||
connect(actionLogout, &QAction::triggered, profileForm, &ProfileForm::onLogoutClicked);
|
connect(actionLogout, &QAction::triggered, profileForm, &ProfileForm::onLogoutClicked);
|
||||||
|
|
||||||
@ -1498,7 +1503,7 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog)
|
|||||||
emit widget->chatroomWidgetClicked(widget);
|
emit widget->chatroomWidgetClicked(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound, bool file)
|
bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound, QString filename, size_t filesize)
|
||||||
{
|
{
|
||||||
bool hasActive;
|
bool hasActive;
|
||||||
QWidget* currentWindow;
|
QWidget* currentWindow;
|
||||||
@ -1535,17 +1540,9 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b
|
|||||||
widget->updateStatusLight();
|
widget->updateStatusLight();
|
||||||
ui->friendList->trackWidget(widget);
|
ui->friendList->trackWidget(widget);
|
||||||
#if DESKTOP_NOTIFICATIONS
|
#if DESKTOP_NOTIFICATIONS
|
||||||
if (settings.getNotifyHide()) {
|
auto notificationData = filename.isEmpty() ? notificationGenerator->friendMessageNotification(f, text)
|
||||||
notifier.notifyMessageSimple(file ? DesktopNotify::MessageType::FRIEND_FILE
|
: notificationGenerator->fileTransferNotification(f, filename, filesize);
|
||||||
: DesktopNotify::MessageType::FRIEND);
|
notifier.notifyMessage(notificationData);
|
||||||
} else {
|
|
||||||
QString title = f->getDisplayedName();
|
|
||||||
if (file) {
|
|
||||||
title += " - " + tr("File sent");
|
|
||||||
}
|
|
||||||
notifier.notifyMessagePixmap(title, text,
|
|
||||||
Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (contentDialog == nullptr) {
|
if (contentDialog == nullptr) {
|
||||||
@ -1586,18 +1583,8 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk,
|
|||||||
g->setEventFlag(true);
|
g->setEventFlag(true);
|
||||||
widget->updateStatusLight();
|
widget->updateStatusLight();
|
||||||
#if DESKTOP_NOTIFICATIONS
|
#if DESKTOP_NOTIFICATIONS
|
||||||
if (settings.getNotifyHide()) {
|
auto notificationData = notificationGenerator->groupMessageNotification(g, authorPk, message);
|
||||||
notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP);
|
notifier.notifyMessage(notificationData);
|
||||||
} else {
|
|
||||||
Friend* f = FriendList::findFriend(authorPk);
|
|
||||||
QString title = g->getPeerList().value(authorPk) + " (" + g->getDisplayedName() + ")";
|
|
||||||
if (!f) {
|
|
||||||
notifier.notifyMessage(title, message);
|
|
||||||
} else {
|
|
||||||
notifier.notifyMessagePixmap(title, message,
|
|
||||||
Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (contentDialog == nullptr) {
|
if (contentDialog == nullptr) {
|
||||||
@ -1673,11 +1660,8 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa
|
|||||||
friendRequestsUpdate();
|
friendRequestsUpdate();
|
||||||
newMessageAlert(window(), isActiveWindow(), true, true);
|
newMessageAlert(window(), isActiveWindow(), true, true);
|
||||||
#if DESKTOP_NOTIFICATIONS
|
#if DESKTOP_NOTIFICATIONS
|
||||||
if (settings.getNotifyHide()) {
|
auto notificationData = notificationGenerator->friendRequestNotification(friendPk, message);
|
||||||
notifier.notifyMessageSimple(DesktopNotify::MessageType::FRIEND_REQUEST);
|
notifier.notifyMessage(notificationData);
|
||||||
} else {
|
|
||||||
notifier.notifyMessage(friendPk.toString() + tr(" sent you a friend request."), message);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1686,9 +1670,8 @@ void Widget::onFileReceiveRequested(const ToxFile& file)
|
|||||||
{
|
{
|
||||||
const ToxPk& friendPk = FriendList::id2Key(file.friendId);
|
const ToxPk& friendPk = FriendList::id2Key(file.friendId);
|
||||||
newFriendMessageAlert(friendPk,
|
newFriendMessageAlert(friendPk,
|
||||||
file.fileName + " ("
|
{},
|
||||||
+ FileTransferWidget::getHumanReadableSize(file.filesize) + ")",
|
true, file.fileName, file.filesize);
|
||||||
true, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::updateFriendActivity(const Friend& frnd)
|
void Widget::updateFriendActivity(const Friend& frnd)
|
||||||
@ -1934,12 +1917,8 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo)
|
|||||||
groupInvitesUpdate();
|
groupInvitesUpdate();
|
||||||
newMessageAlert(window(), isActiveWindow(), true, true);
|
newMessageAlert(window(), isActiveWindow(), true, true);
|
||||||
#if DESKTOP_NOTIFICATIONS
|
#if DESKTOP_NOTIFICATIONS
|
||||||
if (settings.getNotifyHide()) {
|
auto notificationData = notificationGenerator->groupInvitationNotification(f);
|
||||||
notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP_INVITE);
|
notifier.notifyMessage(notificationData);
|
||||||
} else {
|
|
||||||
notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."),
|
|
||||||
{}, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "src/model/friendmessagedispatcher.h"
|
#include "src/model/friendmessagedispatcher.h"
|
||||||
#include "src/model/groupmessagedispatcher.h"
|
#include "src/model/groupmessagedispatcher.h"
|
||||||
#if DESKTOP_NOTIFICATIONS
|
#if DESKTOP_NOTIFICATIONS
|
||||||
|
#include "src/model/notificationgenerator.h"
|
||||||
#include "src/platform/desktop_notifications/desktopnotify.h"
|
#include "src/platform/desktop_notifications/desktopnotify.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -127,7 +128,7 @@ public:
|
|||||||
void addFriendDialog(const Friend* frnd, ContentDialog* dialog);
|
void addFriendDialog(const Friend* frnd, ContentDialog* dialog);
|
||||||
void addGroupDialog(Group* group, ContentDialog* dialog);
|
void addGroupDialog(Group* group, ContentDialog* dialog);
|
||||||
bool newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound = true,
|
bool newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound = true,
|
||||||
bool file = false);
|
QString filename = QString(), size_t filesize = 0);
|
||||||
bool newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, const QString& message,
|
bool newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, const QString& message,
|
||||||
bool notify);
|
bool notify);
|
||||||
bool getIsWindowMinimized();
|
bool getIsWindowMinimized();
|
||||||
@ -360,6 +361,7 @@ private:
|
|||||||
|
|
||||||
MessageProcessor::SharedParams sharedMessageProcessorParams;
|
MessageProcessor::SharedParams sharedMessageProcessorParams;
|
||||||
#if DESKTOP_NOTIFICATIONS
|
#if DESKTOP_NOTIFICATIONS
|
||||||
|
std::unique_ptr<NotificationGenerator> notificationGenerator;
|
||||||
DesktopNotify notifier;
|
DesktopNotify notifier;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2020 by The qTox Project Contributors
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||||
|
|
||||||
|
qTox is libre 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.
|
||||||
|
|
||||||
|
qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "src/core/icoreidhandler.h"
|
#include "src/core/icoreidhandler.h"
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2020 by The qTox Project Contributors
|
||||||
|
|
||||||
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||||
|
|
||||||
|
qTox is libre 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.
|
||||||
|
|
||||||
|
qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "src/core/icoregroupquery.h"
|
#include "src/core/icoregroupquery.h"
|
||||||
|
@ -114,11 +114,11 @@ void TestNotificationGenerator::testMultipleFriendMessages()
|
|||||||
f.setName("friendName");
|
f.setName("friendName");
|
||||||
notificationGenerator->friendMessageNotification(&f, "test");
|
notificationGenerator->friendMessageNotification(&f, "test");
|
||||||
auto notificationData = notificationGenerator->friendMessageNotification(&f, "test2");
|
auto notificationData = notificationGenerator->friendMessageNotification(&f, "test2");
|
||||||
QVERIFY(notificationData.title == "2 messages from friendName");
|
QVERIFY(notificationData.title == "2 message(s) from friendName");
|
||||||
QVERIFY(notificationData.message == "test2");
|
QVERIFY(notificationData.message == "test2");
|
||||||
|
|
||||||
notificationData = notificationGenerator->friendMessageNotification(&f, "test3");
|
notificationData = notificationGenerator->friendMessageNotification(&f, "test3");
|
||||||
QVERIFY(notificationData.title == "3 messages from friendName");
|
QVERIFY(notificationData.title == "3 message(s) from friendName");
|
||||||
QVERIFY(notificationData.message == "test3");
|
QVERIFY(notificationData.message == "test3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +140,6 @@ void TestNotificationGenerator::testNotificationClear()
|
|||||||
void TestNotificationGenerator::testGroupMessage()
|
void TestNotificationGenerator::testGroupMessage()
|
||||||
{
|
{
|
||||||
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
||||||
g.setName("groupName");
|
|
||||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||||
g.updateUsername(sender, "sender1");
|
g.updateUsername(sender, "sender1");
|
||||||
|
|
||||||
@ -152,15 +151,17 @@ void TestNotificationGenerator::testGroupMessage()
|
|||||||
void TestNotificationGenerator::testMultipleGroupMessages()
|
void TestNotificationGenerator::testMultipleGroupMessages()
|
||||||
{
|
{
|
||||||
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
||||||
g.setName("groupName");
|
|
||||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||||
g.updateUsername(sender, "sender1");
|
g.updateUsername(sender, "sender1");
|
||||||
|
|
||||||
auto sender2 = groupQuery->getGroupPeerPk(0, 1);
|
auto sender2 = groupQuery->getGroupPeerPk(0, 1);
|
||||||
g.updateUsername(sender2, "sender2");
|
g.updateUsername(sender2, "sender2");
|
||||||
|
|
||||||
|
notificationGenerator->groupMessageNotification(&g, sender, "test1");
|
||||||
|
|
||||||
auto notificationData = notificationGenerator->groupMessageNotification(&g, sender2, "test2");
|
auto notificationData = notificationGenerator->groupMessageNotification(&g, sender2, "test2");
|
||||||
QVERIFY(notificationData.title == "groupName");
|
QVERIFY(notificationData.title == "2 message(s) from groupName");
|
||||||
QVERIFY(notificationData.message == "sender2: test2");
|
QVERIFY(notificationData.message == "sender2: test2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,17 +176,14 @@ void TestNotificationGenerator::testMultipleFriendSourceMessages()
|
|||||||
notificationGenerator->friendMessageNotification(&f, "test1");
|
notificationGenerator->friendMessageNotification(&f, "test1");
|
||||||
auto notificationData = notificationGenerator->friendMessageNotification(&f2, "test2");
|
auto notificationData = notificationGenerator->friendMessageNotification(&f2, "test2");
|
||||||
|
|
||||||
QVERIFY(notificationData.title == "2 messages from 2 chats");
|
QVERIFY(notificationData.title == "2 message(s) from 2 chats");
|
||||||
QVERIFY(notificationData.message == "friend1, friend2");
|
QVERIFY(notificationData.message == "friend1, friend2");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestNotificationGenerator::testMultipleGroupSourceMessages()
|
void TestNotificationGenerator::testMultipleGroupSourceMessages()
|
||||||
{
|
{
|
||||||
Group g(0, GroupId(QByteArray(32, 0)), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
Group g(0, GroupId(QByteArray(32, 0)), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
||||||
g.setName("groupName");
|
Group g2(1, GroupId(QByteArray(32, 1)), "groupName2", false, "selfName", *groupQuery, *coreIdHandler);
|
||||||
|
|
||||||
Group g2(1, GroupId(QByteArray(32, 1)), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
|
||||||
g.setName("groupName2");
|
|
||||||
|
|
||||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||||
g.updateUsername(sender, "sender1");
|
g.updateUsername(sender, "sender1");
|
||||||
@ -193,7 +191,7 @@ void TestNotificationGenerator::testMultipleGroupSourceMessages()
|
|||||||
notificationGenerator->groupMessageNotification(&g, sender, "test1");
|
notificationGenerator->groupMessageNotification(&g, sender, "test1");
|
||||||
auto notificationData = notificationGenerator->groupMessageNotification(&g2, sender, "test1");
|
auto notificationData = notificationGenerator->groupMessageNotification(&g2, sender, "test1");
|
||||||
|
|
||||||
QVERIFY(notificationData.title == "2 messages from 2 chats");
|
QVERIFY(notificationData.title == "2 message(s) from 2 chats");
|
||||||
QVERIFY(notificationData.message == "groupName, groupName2");
|
QVERIFY(notificationData.message == "groupName, groupName2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,8 +200,7 @@ void TestNotificationGenerator::testMixedSourceMessages()
|
|||||||
Friend f(0, ToxPk());
|
Friend f(0, ToxPk());
|
||||||
f.setName("friend");
|
f.setName("friend");
|
||||||
|
|
||||||
Group g(0, GroupId(QByteArray(32, 0)), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
Group g(0, GroupId(QByteArray(32, 0)), "group", false, "selfName", *groupQuery, *coreIdHandler);
|
||||||
g.setName("group");
|
|
||||||
|
|
||||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||||
g.updateUsername(sender, "sender1");
|
g.updateUsername(sender, "sender1");
|
||||||
@ -211,11 +208,11 @@ void TestNotificationGenerator::testMixedSourceMessages()
|
|||||||
notificationGenerator->friendMessageNotification(&f, "test1");
|
notificationGenerator->friendMessageNotification(&f, "test1");
|
||||||
auto notificationData = notificationGenerator->groupMessageNotification(&g, sender, "test2");
|
auto notificationData = notificationGenerator->groupMessageNotification(&g, sender, "test2");
|
||||||
|
|
||||||
QVERIFY(notificationData.title == "2 messages from 2 chats");
|
QVERIFY(notificationData.title == "2 message(s) from 2 chats");
|
||||||
QVERIFY(notificationData.message == "friend, group");
|
QVERIFY(notificationData.message == "friend, group");
|
||||||
|
|
||||||
notificationData = notificationGenerator->fileTransferNotification(&f, "file", 0);
|
notificationData = notificationGenerator->fileTransferNotification(&f, "file", 0);
|
||||||
QVERIFY(notificationData.title == "3 messages from 2 chats");
|
QVERIFY(notificationData.title == "3 message(s) from 2 chats");
|
||||||
QVERIFY(notificationData.message == "friend, group");
|
QVERIFY(notificationData.message == "friend, group");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +223,7 @@ void TestNotificationGenerator::testFileTransfer()
|
|||||||
|
|
||||||
auto notificationData = notificationGenerator->fileTransferNotification(&f, "file", 5 * 1024 * 1024 /* 5MB */);
|
auto notificationData = notificationGenerator->fileTransferNotification(&f, "file", 5 * 1024 * 1024 /* 5MB */);
|
||||||
|
|
||||||
QVERIFY(notificationData.title == "friend - File sent");
|
QVERIFY(notificationData.title == "friend - file transfer");
|
||||||
QVERIFY(notificationData.message == "file (5.00MiB)");
|
QVERIFY(notificationData.message == "file (5.00MiB)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +235,7 @@ void TestNotificationGenerator::testFileTransferAfterMessage()
|
|||||||
notificationGenerator->friendMessageNotification(&f, "test1");
|
notificationGenerator->friendMessageNotification(&f, "test1");
|
||||||
auto notificationData = notificationGenerator->fileTransferNotification(&f, "file", 5 * 1024 * 1024 /* 5MB */);
|
auto notificationData = notificationGenerator->fileTransferNotification(&f, "file", 5 * 1024 * 1024 /* 5MB */);
|
||||||
|
|
||||||
QVERIFY(notificationData.title == "2 messages from friend");
|
QVERIFY(notificationData.title == "2 message(s) from friend");
|
||||||
QVERIFY(notificationData.message == "Incoming file transfer");
|
QVERIFY(notificationData.message == "Incoming file transfer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +259,7 @@ void TestNotificationGenerator::testGroupInviteUncounted()
|
|||||||
notificationGenerator->groupInvitationNotification(&f);
|
notificationGenerator->groupInvitationNotification(&f);
|
||||||
auto notificationData = notificationGenerator->friendMessageNotification(&f, "test2");
|
auto notificationData = notificationGenerator->friendMessageNotification(&f, "test2");
|
||||||
|
|
||||||
QVERIFY(notificationData.title == "2 messages from friend");
|
QVERIFY(notificationData.title == "2 message(s) from friend");
|
||||||
QVERIFY(notificationData.message == "test2");
|
QVERIFY(notificationData.message == "test2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +269,7 @@ void TestNotificationGenerator::testFriendRequest()
|
|||||||
|
|
||||||
auto notificationData = notificationGenerator->friendRequestNotification(sender, "request");
|
auto notificationData = notificationGenerator->friendRequestNotification(sender, "request");
|
||||||
|
|
||||||
QVERIFY(notificationData.title == "0000000000000000000000000000000000000000000000000000000000000000 sent you a friend request.");
|
QVERIFY(notificationData.title == "Friend request received from 0000000000000000000000000000000000000000000000000000000000000000");
|
||||||
QVERIFY(notificationData.message == "request");
|
QVERIFY(notificationData.message == "request");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +283,7 @@ void TestNotificationGenerator::testFriendRequestUncounted()
|
|||||||
notificationGenerator->friendRequestNotification(sender, "request");
|
notificationGenerator->friendRequestNotification(sender, "request");
|
||||||
auto notificationData = notificationGenerator->friendMessageNotification(&f, "test2");
|
auto notificationData = notificationGenerator->friendMessageNotification(&f, "test2");
|
||||||
|
|
||||||
QVERIFY(notificationData.title == "2 messages from friend");
|
QVERIFY(notificationData.title == "2 message(s) from friend");
|
||||||
QVERIFY(notificationData.message == "test2");
|
QVERIFY(notificationData.message == "test2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,7 +316,6 @@ void TestNotificationGenerator::testSimpleFileTransfer()
|
|||||||
void TestNotificationGenerator::testSimpleGroupMessage()
|
void TestNotificationGenerator::testSimpleGroupMessage()
|
||||||
{
|
{
|
||||||
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
||||||
g.setName("groupName");
|
|
||||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||||
g.updateUsername(sender, "sender1");
|
g.updateUsername(sender, "sender1");
|
||||||
|
|
||||||
@ -367,7 +363,7 @@ void TestNotificationGenerator::testSimpleMessageToggle()
|
|||||||
|
|
||||||
auto notificationData = notificationGenerator->friendMessageNotification(&f, "test2");
|
auto notificationData = notificationGenerator->friendMessageNotification(&f, "test2");
|
||||||
|
|
||||||
QVERIFY(notificationData.title == "2 messages from friend");
|
QVERIFY(notificationData.title == "2 message(s) from friend");
|
||||||
QVERIFY(notificationData.message == "test2");
|
QVERIFY(notificationData.message == "test2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user