From 7366f8973b7b40c458e882103b33fb15cc047f7e Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Wed, 30 Jan 2019 18:34:29 +0100 Subject: [PATCH] Add sender name in PNs (if db is unlocked) Signed-off-by: Pedro Pombeiro --- deps.edn | 2 +- src/status_im/notifications/core.cljs | 20 ++++++++++++++------ translations/en.json | 2 -- translations/es_419.json | 1 - translations/fa.json | 1 - translations/ko.json | 1 - translations/ms.json | 1 - translations/ne.json | 1 - translations/pl.json | 1 - translations/ru.json | 1 - translations/zh_Hans_CN.json | 1 - 11 files changed, 15 insertions(+), 17 deletions(-) diff --git a/deps.edn b/deps.edn index c5e262efa7..b949a097e1 100644 --- a/deps.edn +++ b/deps.edn @@ -1,5 +1,5 @@ {:paths ["components/src" "src" "react-native/src/cljsjs" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.9.0"} + :deps {org.clojure/clojure {:mvn/version "1.9.0"} ;; Keep in sync with .TOOLVERSIONS org.clojure/clojurescript {:mvn/version "1.10.439"} org.clojure/core.async {:mvn/version "0.4.474"} reagent {:mvn/version "0.7.0" diff --git a/src/status_im/notifications/core.cljs b/src/status_im/notifications/core.cljs index 6037ad3314..b403f4dc21 100644 --- a/src/status_im/notifications/core.cljs +++ b/src/status_im/notifications/core.cljs @@ -79,11 +79,14 @@ (def group-id "im.status.ethereum.MESSAGE") (def icon "ic_stat_status_notification") + (defn- hash->contact [hash-or-pubkey accounts] + (let [hash (anonymize-pubkey hash-or-pubkey)] + (->> accounts + (filter #(= (anonymize-pubkey (:public-key %)) hash)) + first))) + (defn- hash->pubkey [hash accounts] - (:public-key - (first - (filter #(= (anonymize-pubkey (:public-key %)) hash) - accounts)))) + (:public-key (hash->contact hash accounts))) (defn lookup-contact-pubkey-from-hash [{:keys [db] :as cofx} contact-pubkey-or-hash] @@ -94,7 +97,7 @@ (= (count contact-pubkey-or-hash) pn-pubkey-hash-length)) (if-let [account-pubkey (hash->pubkey contact-pubkey-or-hash - (vals (:accounts/accounts db)))] + (-> db :accounts/accounts vals))] account-pubkey (if (accounts.db/logged-in? cofx) ;; TODO: for simplicity we're doing a linear lookup of the contacts, @@ -144,6 +147,11 @@ ;; TODO: Rehydrate message id :id id}) + (defn- get-contact-name [{:keys [db] :as cofx} from] + (if (accounts.db/logged-in? cofx) + (:name (hash->contact from (-> db :contacts/contacts vals))) + (anonymize-pubkey from))) + (defn- build-notification [{:keys [title body decoded-payload]}] (let [native-notification (clj->js @@ -226,7 +234,7 @@ (assoc-in db [:push-notifications/stored (:to rehydrated-payload)] (js/JSON.stringify (clj->js rehydrated-payload))) :notifications/display-notification - {:title (i18n/label :notifications-new-message-title) + {:title (get-contact-name cofx from) :body (i18n/label :notifications-new-message-body) :decoded-payload rehydrated-payload}}))) diff --git a/translations/en.json b/translations/en.json index 8f83844b01..4ed1170c51 100644 --- a/translations/en.json +++ b/translations/en.json @@ -450,7 +450,6 @@ "other": "days" }, "request-transaction": "Request transaction", - "notifications-new-message-title": "Status", "wallet-send": "Send", "wallet-deposit": "Deposit", "invalid-key-title": "We detected a problem with the encryption key", @@ -742,7 +741,6 @@ "view-profile": "View profile", "message": "Message", "here-is-your-passphrase": "Here is your passphrase, *write this down and keep this safe!* You will need it to recover your account.", - "add-mailserver": "Add Mailserver", "currency-display-name-ttd": "Trinidad and Tobago Dollar", "wallet-assets": "Assets", "are-you-sure-description": "You will not be able to see the whole recovery phrase again", diff --git a/translations/es_419.json b/translations/es_419.json index a63b710ff4..b13acc888c 100644 --- a/translations/es_419.json +++ b/translations/es_419.json @@ -422,7 +422,6 @@ "not-specified": "No especificado", "notifications": "Notificaciones", "notifications-new-message-body": "Tienes un nuevo mensaje", - "notifications-new-message-title": "Status", "notifications-title": "Notificaciones y sonidos", "off": "Apagado", "offline": "Desconectado", diff --git a/translations/fa.json b/translations/fa.json index d82012d352..0da4da2e8f 100644 --- a/translations/fa.json +++ b/translations/fa.json @@ -423,7 +423,6 @@ "not-specified": "مشخص نشده", "notifications": "اغلان ها", "notifications-new-message-body": "شما یک پیغام جدید دارید", - "notifications-new-message-title": "استتوس", "notifications-title": "اطلاعیه ها و صداها", "off": "خاموش", "offline": "آفلاین", diff --git a/translations/ko.json b/translations/ko.json index b6bd758376..4f40a7ad8b 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -450,7 +450,6 @@ "not-specified": "지정되지 않음", "notifications": "알림", "notifications-new-message-body": "새로운 메세지가 있습니다", - "notifications-new-message-title": "스테이터스", "notifications-title": "알림 및 소리", "off": "끄기", "offline": "오프라인", diff --git a/translations/ms.json b/translations/ms.json index 27140786da..18c052c34f 100644 --- a/translations/ms.json +++ b/translations/ms.json @@ -450,7 +450,6 @@ "not-specified": "Tidak diberikan", "notifications": "Pemberitahuan", "notifications-new-message-body": "Anda mempunyai mesej baru", - "notifications-new-message-title": "Status", "notifications-title": "Pemberitahuan dan bunyi", "off": "Tidak aktif", "offline": "Luar talian", diff --git a/translations/ne.json b/translations/ne.json index 8afa0a6888..cc95affa8b 100644 --- a/translations/ne.json +++ b/translations/ne.json @@ -433,7 +433,6 @@ "not-specified": "नतोकिएको", "notifications": "Pemberitahuan", "notifications-new-message-body": "Anda mempunyai mesej baru", - "notifications-new-message-title": "Status", "notifications-title": "सूचना र ध्वनि", "off": "Tidak aktif", "offline": "अफलाइन", diff --git a/translations/pl.json b/translations/pl.json index 3349ba4efb..76963cb1c0 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -415,7 +415,6 @@ "not-specified": "Nie określono", "notifications": "Powiadomienia", "notifications-new-message-body": "Masz nową wiadomość", - "notifications-new-message-title": "Status", "notifications-title": "Powiadomienia i dźwięki", "off": "Wył.", "offline": "Offline", diff --git a/translations/ru.json b/translations/ru.json index d7234eefa9..d8d4de2b75 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -432,7 +432,6 @@ "not-specified": "Не указано", "notifications": "Уведомления", "notifications-new-message-body": "Вы получили новое сообщение", - "notifications-new-message-title": "Status", "notifications-title": "Уведомления и звуки", "off": "Выкл", "offline": "Оффлайн", diff --git a/translations/zh_Hans_CN.json b/translations/zh_Hans_CN.json index 7f44c3f0ff..0787c61785 100644 --- a/translations/zh_Hans_CN.json +++ b/translations/zh_Hans_CN.json @@ -450,7 +450,6 @@ "not-specified": "未指定", "notifications": "通知", "notifications-new-message-body": "你有新信息", - "notifications-new-message-title": "Status", "notifications-title": "通知和声音", "off": "关闭", "offline": "离线",