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 <goranjovic@gmail.com>
This commit is contained in:
Pedro Pombeiro 2018-11-14 18:10:54 +01:00 committed by Goran Jovic
parent dfe00fab87
commit 9f350765e9
No known key found for this signature in database
GPG Key ID: D429D1A9B2EB8A8E
3 changed files with 27 additions and 10 deletions

View File

@ -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<ModuleMethod *> 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);
}

View File

@ -35,7 +35,7 @@ public:
QList<ModuleMethod*> 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<DesktopNotificationPrivate> d_ptr;

View File

@ -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