From 9f350765e96149bd4c156970542cf0c20332844f Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Wed, 14 Nov 2018 18:10:54 +0100 Subject: [PATCH] Show chat name, source contact and time in PN body. Part of #6621 - Add higher priority for 1:1 messages Signed-off-by: Goran Jovic --- .../desktop/desktopnotification.cpp | 16 ++++++++-------- .../desktop/desktopnotification.h | 2 +- src/status_im/chat/models/message.cljs | 19 ++++++++++++++++++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/modules/react-native-desktop-notification/desktop/desktopnotification.cpp b/modules/react-native-desktop-notification/desktop/desktopnotification.cpp index 76c83db460..91ae7eba24 100644 --- a/modules/react-native-desktop-notification/desktop/desktopnotification.cpp +++ b/modules/react-native-desktop-notification/desktop/desktopnotification.cpp @@ -65,11 +65,6 @@ DesktopNotification::DesktopNotification(QObject *parent) m_appHasFocus = (focusWindow != nullptr); }); - d_ptr->snoreApp = Snore::Application(QCoreApplication::applicationName(), - Snore::Icon::defaultIcon()); - d_ptr->snoreApp.addAlert( - Snore::Alert(NewMessageAlert, Snore::Icon::defaultIcon())); - if (Snore::SnoreCore::instance().pluginNames().isEmpty()) { Snore::SnoreCore::instance().loadPlugins(Snore::SnorePlugin::Backend); } @@ -77,6 +72,10 @@ DesktopNotification::DesktopNotification(QObject *parent) qCDebug(NOTIFICATION) << "DesktopNotification::DesktopNotification List of all loaded Snore plugins:" << Snore::SnoreCore::instance().pluginNames(); + Snore::Icon icon(":/icon.png"); + d_ptr->snoreApp = Snore::Application(QCoreApplication::applicationName(), icon); + d_ptr->snoreApp.addAlert(Snore::Alert(NewMessageAlert, icon)); + Snore::SnoreCore::instance().registerApplication(d_ptr->snoreApp); Snore::SnoreCore::instance().setDefaultApplication(d_ptr->snoreApp); @@ -101,7 +100,7 @@ QList DesktopNotification::methodsToExport() { QVariantMap DesktopNotification::constantsToExport() { return QVariantMap(); } -void DesktopNotification::sendNotification(QString text) { +void DesktopNotification::sendNotification(QString title, QString body, bool prioritary) { Q_D(DesktopNotification); qCDebug(NOTIFICATION) << "::sendNotification"; @@ -111,8 +110,9 @@ void DesktopNotification::sendNotification(QString text) { } Snore::Notification notification( - d_ptr->snoreApp, d_ptr->snoreApp.alerts()[NewMessageAlert], "New message", - text, Snore::Icon::defaultIcon()); + d_ptr->snoreApp, d_ptr->snoreApp.alerts()[NewMessageAlert], title, + body, Snore::Icon::defaultIcon(), + prioritary ? Snore::Notification::Prioritys::High : Snore::Notification::Prioritys::Normal); Snore::SnoreCore::instance().broadcastNotification(notification); } diff --git a/modules/react-native-desktop-notification/desktop/desktopnotification.h b/modules/react-native-desktop-notification/desktop/desktopnotification.h index 55fdf34a9f..2087869b8e 100644 --- a/modules/react-native-desktop-notification/desktop/desktopnotification.h +++ b/modules/react-native-desktop-notification/desktop/desktopnotification.h @@ -35,7 +35,7 @@ public: QList methodsToExport() override; QVariantMap constantsToExport() override; - Q_INVOKABLE void sendNotification(QString text); + Q_INVOKABLE void sendNotification(QString title, QString body, bool prioritary); Q_INVOKABLE void setDockBadgeLabel(const QString label); private: QScopedPointer d_ptr; diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index 54f3ab6a73..2016224ff7 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -7,6 +7,7 @@ [status-im.i18n :as i18n] [status-im.utils.core :as utils] [status-im.utils.config :as config] + [status-im.utils.contacts :as utils.contacts] [status-im.utils.ethereum.core :as ethereum] [status-im.utils.datetime :as time] [status-im.transport.message.group-chat :as message.group-chat] @@ -14,6 +15,7 @@ [status-im.chat.models.loading :as chat-loading] [status-im.chat.models.message-content :as message-content] [status-im.chat.commands.receiving :as commands-receiving] + [status-im.chat.subs :as chat-subs] [status-im.utils.clocks :as utils.clocks] [status-im.utils.money :as money] [status-im.utils.types :as types] @@ -90,6 +92,20 @@ (assoc message :outgoing (and (= from current-public-key) (not (system-message? message))))) +(defn build-desktop-notification [{:keys [db] :as cofx} {:keys [chat-id timestamp content from] :as message}] + (let [chat-name' (chat-subs/chat-name (get-in db [:chats chat-id]) from) + contact-name' (if-let [contact-name (get-in db [:contacts/contacts from :name])] + contact-name + (:name (utils.contacts/public-key->new-contact from))) + shown-chat-name (when-not (= chat-name' contact-name') chat-name') ; No point in repeating contact name if the chat name already contains the same name + timestamp' (when-not (< (time/seconds-ago (time/to-date timestamp)) 15) + (str " @ " (time/to-short-str timestamp))) + body-first-line (when (or shown-chat-name timestamp') + (str shown-chat-name timestamp' ":\n"))] + {:title contact-name' + :body (str body-first-line (:text content)) + :prioritary? (not (chat-model/multi-user-chat? cofx chat-id))})) + (fx/defn add-message [{:keys [db] :as cofx} batch? {:keys [chat-id message-id clock-value timestamp content from] :as message} current-chat?] (let [current-public-key (accounts.db/current-public-key cofx) @@ -100,7 +116,8 @@ (not= from current-public-key) (get-in db [:account/account :desktop-notifications?]) (< (time/seconds-ago (time/to-date timestamp)) constants/one-earth-day)) - (.sendNotification react/desktop-notification (:text content))) + (let [{:keys [title body prioritary?]} (build-desktop-notification cofx message)] + (.sendNotification react/desktop-notification title body prioritary?))) (fx/merge cofx {:db (cond-> (-> db