|
121 | 121 | (get-in db [:account/account :desktop-notifications?])
|
122 | 122 | (< (time/seconds-ago (time/to-date timestamp)) constants/one-earth-day))
|
123 | 123 | (let [{:keys [title body prioritary?]} (build-desktop-notification cofx message)]
|
124 |
| - (.sendNotification react/desktop-notification title body prioritary?))) |
| 124 | + (.displayNotification react/desktop-notification title body prioritary?))) |
125 | 125 | (fx/merge cofx
|
126 | 126 | {:db (cond->
|
127 | 127 | (-> db
|
|
159 | 159 | message
|
160 | 160 | (assoc message :clock-value (utils.clocks/send last-clock-value))))
|
161 | 161 |
|
162 |
| -(fx/defn display-notification |
163 |
| - [cofx chat-id] |
164 |
| - (when config/in-app-notifications-enabled? |
165 |
| - (let [view-id (get-in cofx [:db :view-id]) |
166 |
| - from (accounts.db/current-public-key cofx) |
167 |
| - current-chat-id (get-in cofx [:db :current-chat-id])] |
168 |
| - (when-not (and (= :chat view-id) |
169 |
| - (= current-chat-id chat-id)) |
170 |
| - {:notifications/display-notification {:title (i18n/label :notifications-new-message-title) |
171 |
| - :body (i18n/label :notifications-new-message-body) |
172 |
| - :to chat-id |
173 |
| - :from from}})))) |
174 |
| - |
175 | 162 | (defn check-response-to
|
176 | 163 | [{{:keys [response-to response-to-v2]} :content :as message}
|
177 | 164 | old-id->message]
|
|
210 | 197 | current-chat? :seen
|
211 | 198 | :else :received))
|
212 | 199 | (commands-receiving/receive message)
|
213 |
| - (display-notification chat-id) |
214 | 200 | (send-message-seen chat-id message-id (and (not group-chat)
|
215 | 201 | current-chat?
|
216 | 202 | (not (= constants/system from))
|
|
391 | 377 | (add-own-status chat-id message-id :sending)
|
392 | 378 | (send chat-id message-id wrapped-record))))
|
393 | 379 |
|
394 |
| -(fx/defn send-push-notification [cofx fcm-token status] |
| 380 | +(fx/defn send-push-notification [cofx message-id fcm-token status] |
| 381 | + (log/debug "#6772 - send-push-notification" message-id fcm-token) |
395 | 382 | (when (and fcm-token (= status :sent))
|
396 |
| - {:send-notification {:message (js/JSON.stringify #js {:from (accounts.db/current-public-key cofx) |
397 |
| - :to (get-in cofx [:db :current-chat-id])}) |
398 |
| - :payload {:title (i18n/label :notifications-new-message-title) |
399 |
| - :body (i18n/label :notifications-new-message-body) |
400 |
| - :sound notifications/sound-name} |
401 |
| - :tokens [fcm-token]}})) |
| 383 | + (let [payload {:from (accounts.db/current-public-key cofx) |
| 384 | + :to (get-in cofx [:db :current-chat-id]) |
| 385 | + :id message-id}] |
| 386 | + {:send-notification {:data-payload (notifications/encode-notification-payload payload) |
| 387 | + :tokens [fcm-token]}}))) |
402 | 388 |
|
403 | 389 | (fx/defn update-message-status [{:keys [db]} chat-id message-id status]
|
404 | 390 | (let [from (get-in db [:chats chat-id :messages message-id :from])
|
|
484 | 470 |
|
485 | 471 | (re-frame/reg-fx
|
486 | 472 | :send-notification
|
487 |
| - (fn [{:keys [message payload tokens]}] |
488 |
| - (let [payload-json (types/clj->json payload) |
489 |
| - tokens-json (types/clj->json tokens)] |
490 |
| - (log/debug "send-notification message: " message " payload-json: " payload-json " tokens-json: " tokens-json) |
491 |
| - (status/notify-users {:message message :payload payload-json :tokens tokens-json} #(log/debug "send-notification cb result: " %))))) |
| 473 | + (fn [{:keys [data-payload tokens]}] |
| 474 | + "Sends a notification to another device. data-payload is a Clojure map of strings to strings" |
| 475 | + (let [data-payload-json (types/clj->json data-payload) |
| 476 | + tokens-json (types/clj->json tokens)] |
| 477 | + (log/debug "send-notification data-payload-json:" data-payload-json "tokens-json:" tokens-json) |
| 478 | + ;; NOTE: react-native-firebase doesn't have a good implementation of sendMessage |
| 479 | + ;; (supporting e.g. priority or content_available properties), |
| 480 | + ;; therefore we must use an implementation in status-go. |
| 481 | + (status/notify-users {:data-payload data-payload-json :tokens tokens-json} |
| 482 | + #(log/debug "send-notification cb result: " %))))) |
0 commit comments