From b50073d281a3555eab155a261deef5409479e1a7 Mon Sep 17 00:00:00 2001
From: kbroulik <kde@privat.broulik.de>
Date: Tue, 21 Jan 2020 13:27:50 +0100
Subject: [PATCH] Implement inline-reply

On supported notification servers (currently only KDE Plasma 5.18+) this
action will create a reply text field inside the notification.
---
 .../linux/notifications_manager_linux.cpp     | 26 ++++++++++++++++---
 .../linux/notifications_manager_linux.h       |  1 +
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp
index b5569a315..8c854012d 100644
--- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp
+++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp
@@ -107,13 +107,22 @@ NotificationData::NotificationData(
 	if (capabilities.contains(qsl("actions"))) {
 		_actions << qsl("default") << QString();
 
-		// icon name according to https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
-		_actions << qsl("mail-reply-sender")
-			<< tr::lng_notification_reply(tr::now);
-
 		connect(_notificationInterface.get(),
 			SIGNAL(ActionInvoked(uint, QString)),
 			this, SLOT(notificationClicked(uint)));
+
+		if (capabilities.contains(qsl("inline-reply"))) {
+			_actions << qsl("inline-reply")
+				<< tr::lng_notification_reply(tr::now);
+
+			connect(_notificationInterface.get(),
+				SIGNAL(NotificationReplied(uint,QString)),
+				this, SLOT(notificationReplied(uint,QString)));
+		} else {
+			// icon name according to https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
+			_actions << qsl("mail-reply-sender")
+				<< tr::lng_notification_reply(tr::now);
+		}
 	}
 
 	if (capabilities.contains(qsl("action-icons"))) {
@@ -236,6 +245,15 @@ void NotificationData::notificationClicked(uint id) {
 	}
 }
 
+void NotificationData::notificationReplied(uint id, const QString &text) {
+	if (id == _notificationId) {
+		const auto manager = _manager;
+		crl::on_main(manager, [=] {
+			manager->notificationReplied(_peerId, _msgId, { text, {} });
+		});
+	}
+}
+
 QDBusArgument &operator<<(QDBusArgument &argument,
 		const NotificationData::ImageData &imageData) {
 	argument.beginStructure();
diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h
index b5bcc726d..00f1bce85 100644
--- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h
+++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h
@@ -70,6 +70,7 @@ private:
 private slots:
 	void notificationClosed(uint id);
 	void notificationClicked(uint id);
+	void notificationReplied(uint id, const QString &text);
 };
 
 using Notification = std::shared_ptr<NotificationData>;