[#4433] update mac os dock badge label on new messages
Signed-off-by: Dmitry Novotochinov <dmitry.novot@gmail.com>
This commit is contained in:
parent
6063134202
commit
737d44931f
|
@ -115,3 +115,7 @@ void DesktopNotification::sendNotification(QString text) {
|
||||||
text, Snore::Icon::defaultIcon());
|
text, Snore::Icon::defaultIcon());
|
||||||
Snore::SnoreCore::instance().broadcastNotification(notification);
|
Snore::SnoreCore::instance().broadcastNotification(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DesktopNotification::setDockBadgeLabel(const QString label) {
|
||||||
|
Snore::SnoreCore::instance().setDockBadgeLabel(label);
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
QVariantMap constantsToExport() override;
|
QVariantMap constantsToExport() override;
|
||||||
|
|
||||||
Q_INVOKABLE void sendNotification(QString text);
|
Q_INVOKABLE void sendNotification(QString text);
|
||||||
|
Q_INVOKABLE void setDockBadgeLabel(const QString label);
|
||||||
private:
|
private:
|
||||||
QScopedPointer<DesktopNotificationPrivate> d_ptr;
|
QScopedPointer<DesktopNotificationPrivate> d_ptr;
|
||||||
bool m_appHasFocus = false;
|
bool m_appHasFocus = false;
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
[status-im.utils.fx :as fx]
|
[status-im.utils.fx :as fx]
|
||||||
[status-im.utils.gfycat.core :as gfycat]
|
[status-im.utils.gfycat.core :as gfycat]
|
||||||
[status-im.utils.utils :as utils]
|
[status-im.utils.utils :as utils]
|
||||||
|
[status-im.ui.components.colors :as colors]
|
||||||
|
[status-im.ui.components.react :as react]
|
||||||
[status-im.utils.platform :as platform]))
|
[status-im.utils.platform :as platform]))
|
||||||
|
|
||||||
(defn multi-user-chat? [cofx chat-id]
|
(defn multi-user-chat? [cofx chat-id]
|
||||||
|
@ -130,6 +132,23 @@
|
||||||
(when (not (get-in db [:chats chat-id :group-chat]))
|
(when (not (get-in db [:chats chat-id :group-chat]))
|
||||||
(protocol/send (protocol/map->MessagesSeen {:message-ids message-ids}) chat-id cofx)))
|
(protocol/send (protocol/map->MessagesSeen {:message-ids message-ids}) chat-id cofx)))
|
||||||
|
|
||||||
|
(defn- unread-messages-number [chats]
|
||||||
|
(apply + (map (comp count :unviewed-messages) chats)))
|
||||||
|
|
||||||
|
(fx/defn update-dock-badge-label
|
||||||
|
[cofx]
|
||||||
|
(let [chats (get-in cofx [:db :chats])
|
||||||
|
active-chats (filter :is-active (vals chats))
|
||||||
|
private-chats (filter (complement :public?) active-chats)
|
||||||
|
public-chats (filter :public? active-chats)
|
||||||
|
private-chats-unread-count (unread-messages-number private-chats)
|
||||||
|
public-chats-unread-count (unread-messages-number public-chats)
|
||||||
|
label (cond
|
||||||
|
(pos? private-chats-unread-count) private-chats-unread-count
|
||||||
|
(pos? public-chats-unread-count) "•"
|
||||||
|
:else nil)]
|
||||||
|
{:set-dock-badge-label label}))
|
||||||
|
|
||||||
;; TODO (janherich) - ressurect `constants/system` messages for group chats in the future
|
;; TODO (janherich) - ressurect `constants/system` messages for group chats in the future
|
||||||
(fx/defn mark-messages-seen
|
(fx/defn mark-messages-seen
|
||||||
"Marks all unviewed loaded messages as seen in particular chat"
|
"Marks all unviewed loaded messages as seen in particular chat"
|
||||||
|
@ -154,7 +173,9 @@
|
||||||
(update-in [:chats chat-id :unviewed-messages]
|
(update-in [:chats chat-id :unviewed-messages]
|
||||||
#(apply disj % loaded-unviewed-ids)))
|
#(apply disj % loaded-unviewed-ids)))
|
||||||
:data-store/tx [(user-statuses-store/save-statuses-tx updated-statuses)]}
|
:data-store/tx [(user-statuses-store/save-statuses-tx updated-statuses)]}
|
||||||
(send-messages-seen chat-id loaded-unviewed-ids))))))
|
(send-messages-seen chat-id loaded-unviewed-ids)
|
||||||
|
(when platform/desktop?
|
||||||
|
(update-dock-badge-label)))))))
|
||||||
|
|
||||||
(fx/defn preload-chat-data
|
(fx/defn preload-chat-data
|
||||||
"Takes chat-id and coeffects map, returns effects necessary when navigating to chat"
|
"Takes chat-id and coeffects map, returns effects necessary when navigating to chat"
|
||||||
|
@ -217,3 +238,12 @@
|
||||||
(utils/show-popup nil
|
(utils/show-popup nil
|
||||||
(i18n/label :cooldown/warning-message)
|
(i18n/label :cooldown/warning-message)
|
||||||
#())))
|
#())))
|
||||||
|
|
||||||
|
(defn set-dock-badge-label [label]
|
||||||
|
"Sets dock badge label (OSX only for now).
|
||||||
|
Label must be a string. Pass nil or empty string to clear the label."
|
||||||
|
(.setDockBadgeLabel react/desktop-notification label))
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
:set-dock-badge-label
|
||||||
|
set-dock-badge-label)
|
||||||
|
|
|
@ -98,7 +98,8 @@
|
||||||
(get-in db [:account/account :desktop-notifications?])
|
(get-in db [:account/account :desktop-notifications?])
|
||||||
(< (time/seconds-ago (time/to-date timestamp)) constants/one-earth-day))
|
(< (time/seconds-ago (time/to-date timestamp)) constants/one-earth-day))
|
||||||
(.sendNotification react/desktop-notification (:text content)))
|
(.sendNotification react/desktop-notification (:text content)))
|
||||||
(let [fx {:db (cond->
|
(fx/merge cofx
|
||||||
|
{:db (cond->
|
||||||
(-> db
|
(-> db
|
||||||
(update-in [:chats chat-id :messages] assoc message-id prepared-message)
|
(update-in [:chats chat-id :messages] assoc message-id prepared-message)
|
||||||
;; this will increase last-clock-value twice when sending our own messages
|
;; this will increase last-clock-value twice when sending our own messages
|
||||||
|
@ -106,13 +107,14 @@
|
||||||
(and (not current-chat?)
|
(and (not current-chat?)
|
||||||
(not= from (:current-public-key db)))
|
(not= from (:current-public-key db)))
|
||||||
(update-in [:chats chat-id :unviewed-messages] (fnil conj #{}) message-id))
|
(update-in [:chats chat-id :unviewed-messages] (fnil conj #{}) message-id))
|
||||||
:data-store/tx [(messages-store/save-message-tx prepared-message)]}]
|
:data-store/tx [(messages-store/save-message-tx prepared-message)]}
|
||||||
(if batch?
|
(when (and platform/desktop?
|
||||||
fx
|
(not batch?))
|
||||||
(fx/merge cofx
|
(chat-model/update-dock-badge-label))
|
||||||
fx
|
(when-not batch?
|
||||||
(re-index-message-groups chat-id)
|
(re-index-message-groups chat-id))
|
||||||
(chat-loading/group-chat-messages chat-id [message]))))))
|
(when-not batch?
|
||||||
|
(chat-loading/group-chat-messages chat-id [message])))))
|
||||||
|
|
||||||
(fx/defn send-message-seen
|
(fx/defn send-message-seen
|
||||||
[cofx chat-id message-id send-seen?]
|
[cofx chat-id message-id send-seen?]
|
||||||
|
@ -217,7 +219,11 @@
|
||||||
chat-ids)
|
chat-ids)
|
||||||
messages-fx-fns (map #(add-received-message true %) deduped-messages)
|
messages-fx-fns (map #(add-received-message true %) deduped-messages)
|
||||||
groups-fx-fns (map #(update-group-messages chat->message %) chat-ids)]
|
groups-fx-fns (map #(update-group-messages chat->message %) chat-ids)]
|
||||||
(apply fx/merge cofx (concat chats-fx-fns messages-fx-fns groups-fx-fns))))
|
(apply fx/merge cofx (concat chats-fx-fns
|
||||||
|
messages-fx-fns
|
||||||
|
groups-fx-fns
|
||||||
|
(when platform/desktop?
|
||||||
|
[(chat-model/update-dock-badge-label)])))))
|
||||||
|
|
||||||
(defn system-message [{:keys [now] :as cofx} {:keys [clock-value chat-id content from]}]
|
(defn system-message [{:keys [now] :as cofx} {:keys [clock-value chat-id content from]}]
|
||||||
(let [{:keys [last-clock-value]} (get-in cofx [:db :chats chat-id])
|
(let [{:keys [last-clock-value]} (get-in cofx [:db :chats chat-id])
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
[status-im.utils.universal-links.core :as universal-links]
|
[status-im.utils.universal-links.core :as universal-links]
|
||||||
[status-im.utils.utils :as utils]
|
[status-im.utils.utils :as utils]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
[status-im.utils.fx :as fx]))
|
[status-im.utils.fx :as fx]
|
||||||
|
[status-im.chat.models :as chat-model]))
|
||||||
|
|
||||||
(defn init-store!
|
(defn init-store!
|
||||||
"Try to decrypt the database, move on if successful otherwise go back to
|
"Try to decrypt the database, move on if successful otherwise go back to
|
||||||
|
@ -188,7 +189,9 @@
|
||||||
{:notifications/request-notifications-permissions nil}
|
{:notifications/request-notifications-permissions nil}
|
||||||
(navigation/navigate-to-cofx :home nil)
|
(navigation/navigate-to-cofx :home nil)
|
||||||
(universal-links/process-stored-event)
|
(universal-links/process-stored-event)
|
||||||
(notifications/process-stored-event address)))
|
(notifications/process-stored-event address)
|
||||||
|
(when platform/desktop?
|
||||||
|
(chat-model/update-dock-badge-label))))
|
||||||
|
|
||||||
(defn dev-mode? [cofx]
|
(defn dev-mode? [cofx]
|
||||||
(get-in cofx [:db :account/account :dev-mode?]))
|
(get-in cofx [:db :account/account :dev-mode?]))
|
||||||
|
|
|
@ -253,3 +253,29 @@
|
||||||
(is (= #{"4" "5" "6"}
|
(is (= #{"4" "5" "6"}
|
||||||
(set (get-in (chat/mark-messages-seen {:db test-db} "1-1")
|
(set (get-in (chat/mark-messages-seen {:db test-db} "1-1")
|
||||||
[:shh/post 0 :message :payload :message-ids]))))))
|
[:shh/post 0 :message :payload :message-ids]))))))
|
||||||
|
|
||||||
|
(deftest update-dock-badge-label
|
||||||
|
(testing "When user has unseen private messages"
|
||||||
|
(is (= {:set-dock-badge-label 3}
|
||||||
|
(chat/update-dock-badge-label {:db {:chats {"0x0" {:is-active true
|
||||||
|
:public? false
|
||||||
|
:unviewed-messages #{1 2 3}}
|
||||||
|
"status" {:is-active true
|
||||||
|
:public? true
|
||||||
|
:unviewed-messages #{1 2}}}}}))))
|
||||||
|
(testing "When user has unseen public messages and no unseen private messages"
|
||||||
|
(is (= {:set-dock-badge-label "•"}
|
||||||
|
(chat/update-dock-badge-label {:db {:chats {"0x0" {:is-active true
|
||||||
|
:public? false
|
||||||
|
:unviewed-messages #{}}
|
||||||
|
"status" {:is-active true
|
||||||
|
:public? true
|
||||||
|
:unviewed-messages #{1 2}}}}}))))
|
||||||
|
(testing "When user has no unseen messages"
|
||||||
|
(is (= {:set-dock-badge-label nil}
|
||||||
|
(chat/update-dock-badge-label {:db {:chats {"0x0" {:is-active true
|
||||||
|
:public? false
|
||||||
|
:unviewed-messages #{}}
|
||||||
|
"status" {:is-active true
|
||||||
|
:public? true
|
||||||
|
:unviewed-messages #{}}}}})))))
|
||||||
|
|
Loading…
Reference in New Issue