Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(notification): implement review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sudden6 committed Mar 24, 2019
1 parent 9f8d091 commit cd50376
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void Settings::loadGlobal()
{
showWindow = s.value("showWindow", true).toBool();
notify = s.value("notify", true).toBool();
desktopNotify = s.value("desktopNotify", false).toBool();
desktopNotify = s.value("desktopNotify", true).toBool();
groupAlwaysNotify = s.value("groupAlwaysNotify", true).toBool();
groupchatPosition = s.value("groupchatPosition", true).toBool();
separateWindow = s.value("separateWindow", false).toBool();
Expand Down
70 changes: 11 additions & 59 deletions src/platform/desktop_notifications/desktopnotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,85 +19,37 @@ DesktopNotify::DesktopNotify()
notifyCore.registerApplication(snoreApp);
}

DesktopNotify::NotificationPtr DesktopNotify::createNotification(const QString& title,
const QString& text,
Snore::Notification* old)
{
if (old == nullptr) {
return NotificationPtr(
new Snore::Notification(snoreApp, Snore::Alert(), title, text, snoreIcon));
} else {
return NotificationPtr(new Snore::Notification(*old, title, text, snoreIcon));
}
}

void DesktopNotify::notifyGroupMessage()
void DesktopNotify::createNotification(const QString& title)
{
const Settings& s = Settings::getInstance();
if(!(s.getNotify() && s.getDesktopNotify())) {
return;
}

const QString text{};
Snore::Notification notify{snoreApp, Snore::Alert(), title, {}, snoreIcon};
notifyCore.broadcastNotification(notify);
}

void DesktopNotify::notifyGroupMessage()
{
const QString title = tr("New group message received");
NotificationPtr newNote = createNotification(title, text);
if (!newNote) {
qDebug() << "Failed to allocate group message notification";
return;
}
groupInvite = std::move(newNote);
createNotification(title);
}

void DesktopNotify::notifyFriendRequest()
{
const Settings& s = Settings::getInstance();
if(!(s.getNotify() && s.getDesktopNotify())) {
return;
}

const QString title = tr("New friend request received");
const QString text{};
NotificationPtr newNote = createNotification(title, text);
if (!newNote) {
qDebug() << "Failed to allocate friend message notification";
return;
}
friendMessage = std::move(newNote);
notifyCore.broadcastNotification(*friendMessage);
createNotification(title);
}

void DesktopNotify::notifyGroupInvite()
{
const Settings& s = Settings::getInstance();
if(!(s.getNotify() && s.getDesktopNotify())) {
return;
}

const QString title = tr("New group invite received");
const QString text{};
NotificationPtr newNote = createNotification(title, text);
if (!newNote) {
qDebug() << "Failed to allocate friend message notification";
return;
}
friendMessage = std::move(newNote);
notifyCore.broadcastNotification(*friendMessage);
createNotification(title);
}

void DesktopNotify::notifyFriendMessage()
{
const Settings& s = Settings::getInstance();
if(!(s.getNotify() && s.getDesktopNotify())) {
return;
}

const QString title = tr("New message received");
const QString text{};
NotificationPtr newNote = createNotification(title, text);
if (!newNote) {
qDebug() << "Failed to allocate friend message notification";
return;
}
friendMessage = std::move(newNote);
notifyCore.broadcastNotification(*friendMessage);
createNotification(title);
}
9 changes: 1 addition & 8 deletions src/platform/desktop_notifications/desktopnotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@ public slots:
void notifyGroupInvite();

private:
using NotificationPtr = std::unique_ptr<Snore::Notification>;

NotificationPtr createNotification(const QString& title, const QString& text,
Snore::Notification* old = nullptr);
void createNotification(const QString& title);

private:
Snore::SnoreCore& notifyCore;
NotificationPtr groupInvite = {nullptr};
NotificationPtr groupMessage = {nullptr};
NotificationPtr friendRequest = {nullptr};
NotificationPtr friendMessage = {nullptr};
Snore::Application snoreApp;
Snore::Icon snoreIcon;
};
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/settings/userinterfaceform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ void UserInterfaceForm::on_notify_stateChanged()
bodyUI->groupOnlyNotfiyWhenMentioned->setEnabled(notify);
bodyUI->notifySound->setEnabled(notify);
bodyUI->busySound->setEnabled(notify && bodyUI->notifySound->isChecked());
bodyUI->desktopNotify->setEnabled(notify);
}

void UserInterfaceForm::on_notifySound_stateChanged()
Expand Down
6 changes: 6 additions & 0 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,13 @@ bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive, bool sound,

if (settings.getNotify()) {
if (inactiveWindow) {
#if DESKTOP_NOTIFICATIONS
if (!settings.getDesktopNotify()) {
QApplication::alert(currentWindow);
}
#else
QApplication::alert(currentWindow);
#endif
eventFlag = true;
}
bool isBusy = Nexus::getCore()->getStatus() == Status::Busy;
Expand Down

0 comments on commit cd50376

Please sign in to comment.