Add mark as read feature to linux native notifications

This commit is contained in:
Ilya Fedin 2020-03-06 09:55:22 +04:00 committed by John Preston
parent fdf16d0aea
commit 7ac4c6e479
2 changed files with 24 additions and 16 deletions

View File

@ -169,13 +169,9 @@ NotificationData::NotificationData(
if (capabilities.contains(qsl("actions"))) { if (capabilities.contains(qsl("actions"))) {
_actions << qsl("default") << QString(); _actions << qsl("default") << QString();
_dbusConnection.connect( _actions
kService.utf16(), << qsl("mail-mark-read")
kObjectPath.utf16(), << tr::lng_context_mark_read(tr::now);
kInterface.utf16(),
qsl("ActionInvoked"),
this,
SLOT(notificationClicked(uint,QString)));
if (capabilities.contains(qsl("inline-reply")) && !hideReplyButton) { if (capabilities.contains(qsl("inline-reply")) && !hideReplyButton) {
_actions _actions
@ -195,6 +191,14 @@ NotificationData::NotificationData(
<< qsl("mail-reply-sender") << qsl("mail-reply-sender")
<< tr::lng_notification_reply(tr::now); << tr::lng_notification_reply(tr::now);
} }
_dbusConnection.connect(
kService.utf16(),
kObjectPath.utf16(),
kInterface.utf16(),
qsl("ActionInvoked"),
this,
SLOT(actionInvoked(uint,QString)));
} }
if (capabilities.contains(qsl("action-icons"))) { if (capabilities.contains(qsl("action-icons"))) {
@ -313,19 +317,23 @@ void NotificationData::notificationClosed(uint id) {
} }
} }
void NotificationData::notificationClicked(uint id, const QString &actionId) { void NotificationData::actionInvoked(uint id, const QString &actionName) {
if (id != _notificationId) { if (id != _notificationId) {
return; return;
} }
if (actionId != qsl("default") && actionId != qsl("mail-reply-sender")) { if (actionName == qsl("default")
return; || actionName == qsl("mail-reply-sender")) {
const auto manager = _manager;
crl::on_main(manager, [=] {
manager->notificationActivated(_peerId, _msgId);
});
} else if (actionName == qsl("mail-mark-read")) {
const auto manager = _manager;
crl::on_main(manager, [=] {
manager->notificationReplied(_peerId, _msgId, {});
});
} }
const auto manager = _manager;
crl::on_main(manager, [=] {
manager->notificationActivated(_peerId, _msgId);
});
} }
void NotificationData::notificationReplied(uint id, const QString &text) { void NotificationData::notificationReplied(uint id, const QString &text) {

View File

@ -68,7 +68,7 @@ private:
private slots: private slots:
void notificationClosed(uint id); void notificationClosed(uint id);
void notificationClicked(uint id, const QString &actionId); void actionInvoked(uint id, const QString &actionName);
void notificationReplied(uint id, const QString &text); void notificationReplied(uint id, const QString &text);
}; };