diff --git a/src/status_im/data_store/activities.cljs b/src/status_im/data_store/activities.cljs index 20396f6704..bd5d4c7080 100644 --- a/src/status_im/data_store/activities.cljs +++ b/src/status_im/data_store/activities.cljs @@ -13,6 +13,16 @@ (and (= type notification-types/contact-request) (= contact-id author))) +(defn parse-notification-counts-response + [response] + (reduce-kv (fn [acc k count-number] + (let [maybe-type (js/parseInt (name k) 10)] + (if (notification-types/all-supported maybe-type) + (assoc acc maybe-type count-number) + acc))) + {} + response)) + (defn- rpc->type [{:keys [type name] :as chat}] (case type diff --git a/src/status_im/data_store/activities_test.cljs b/src/status_im/data_store/activities_test.cljs index c80d154b67..02eb87b456 100644 --- a/src/status_im/data_store/activities_test.cljs +++ b/src/status_im/data_store/activities_test.cljs @@ -107,3 +107,23 @@ "contact-id" {:type notification-types/contact-request :author "contactzzzz"})))) + +(deftest parse-notification-counts-response-test + (is + (= {notification-types/one-to-one-chat 15 + notification-types/private-group-chat 16 + notification-types/mention 17 + notification-types/reply 18 + notification-types/contact-request 19 + notification-types/admin 20 + notification-types/contact-verification 21} + (store/parse-notification-counts-response + {(keyword (str notification-types/one-to-one-chat)) 15 + (keyword (str notification-types/private-group-chat)) 16 + (keyword (str notification-types/mention)) 17 + (keyword (str notification-types/reply)) 18 + (keyword (str notification-types/contact-request)) 19 + (keyword (str notification-types/admin)) 20 + (keyword (str notification-types/contact-verification)) 21 + ;; Unsupported type in the response is ignored + :999 100})))) diff --git a/src/status_im2/contexts/activity_center/events.cljs b/src/status_im2/contexts/activity_center/events.cljs index 6560621aa8..4c9ee9baa0 100644 --- a/src/status_im2/contexts/activity_center/events.cljs +++ b/src/status_im2/contexts/activity_center/events.cljs @@ -327,6 +327,9 @@ (def ^:const status-unread 2) (def ^:const status-all 3) +(def ^:const read-type-read 1) +(def ^:const read-type-unread 2) +(def ^:const read-type-all 3) (defn status [filter-status] @@ -335,6 +338,15 @@ :all status-all 99)) +(defn ->rpc-read-type + [read-type] + (case read-type + :read read-type-read + :unread read-type-unread + :all read-type-all + ;; Send invalid type, so the backend fails fast. + -1)) + (defn filter-type->rpc-param [filter-type] (cond @@ -353,15 +365,13 @@ (rf/defn notifications-fetch [{:keys [db]} {:keys [cursor per-page filter-type filter-status reset-data?]}] (when-not (get-in db [:activity-center :loading?]) - (let [per-page (or per-page (defaults :notifications-per-page)) - accepted? true] + (let [per-page (or per-page (defaults :notifications-per-page))] {:db (assoc-in db [:activity-center :loading?] true) - :json-rpc/call [{:method "wakuext_activityCenterNotificationsBy" - :params [cursor - per-page - (filter-type->rpc-param filter-type) - (status filter-status) - accepted?] + :json-rpc/call [{:method "wakuext_activityCenterNotifications" + :params [{:cursor cursor + :limit per-page + :activityTypes (filter-type->rpc-param filter-type) + :readType (->rpc-read-type filter-status)}] :on-success #(rf/dispatch [:activity-center.notifications/fetch-success reset-data? %]) :on-error #(rf/dispatch [:activity-center.notifications/fetch-error @@ -421,19 +431,16 @@ to explicitly support fetching notifications for 'pending' contact requests." {:events [:activity-center.notifications/fetch-pending-contact-requests]} [{:keys [db]}] - (let [accepted? true] - {:db (assoc-in db [:activity-center :loading?] true) - :json-rpc/call - [{:method "wakuext_activityCenterNotificationsBy" - :params [start-or-end-cursor - 20 - [types/contact-request] - (status :unread) - accepted?] - :on-success #(rf/dispatch [:activity-center.notifications/fetch-pending-contact-requests-success - %]) - :on-error #(rf/dispatch [:activity-center.notifications/fetch-error - types/contact-request :unread %])}]})) + {:db (assoc-in db [:activity-center :loading?] true) + :json-rpc/call + [{:method "wakuext_activityCenterNotifications" + :params [{:cursor start-or-end-cursor + :limit 20 + :activityTypes [types/contact-request] + :readType (->rpc-read-type :unread)}] + :on-success #(rf/dispatch [:activity-center.notifications/fetch-pending-contact-requests-success %]) + :on-error #(rf/dispatch [:activity-center.notifications/fetch-error types/contact-request :unread + %])}]}) (rf/defn notifications-fetch-pending-contact-requests-success {:events [:activity-center.notifications/fetch-pending-contact-requests-success]} @@ -458,24 +465,19 @@ (rf/defn notifications-fetch-unread-count {:events [:activity-center.notifications/fetch-unread-count]} [_] - {:dispatch-n (mapv (fn [notification-type] - [:activity-center.notifications/fetch-unread-count-for-type notification-type]) - types/all-supported)}) - -(rf/defn notifications-fetch-unread-count-for-type - {:events [:activity-center.notifications/fetch-unread-count-for-type]} - [_ notification-type] - {:json-rpc/call [{:method "wakuext_unreadAndAcceptedActivityCenterNotificationsCount" - :params [[notification-type]] - :on-success #(rf/dispatch [:activity-center.notifications/fetch-unread-count-success - notification-type %]) - :on-error #(rf/dispatch [:activity-center.notifications/fetch-unread-count-error - %])}]}) + {:json-rpc/call + [{:method "wakuext_activityCenterNotificationsCount" + :params [{:activityTypes types/all-supported + :readType (->rpc-read-type :unread)}] + :on-success #(rf/dispatch [:activity-center.notifications/fetch-unread-count-success %]) + :on-error #(rf/dispatch [:activity-center.notifications/fetch-unread-count-error %])}]}) (rf/defn notifications-fetch-unread-count-success {:events [:activity-center.notifications/fetch-unread-count-success]} - [{:keys [db]} notification-type result] - {:db (assoc-in db [:activity-center :unread-counts-by-type notification-type] result)}) + [{:keys [db]} response] + {:db (assoc-in db + [:activity-center :unread-counts-by-type] + (activities/parse-notification-counts-response response))}) (rf/defn notifications-fetch-unread-count-error {:events [:activity-center.notifications/fetch-unread-count-error]} diff --git a/src/status_im2/contexts/activity_center/events_test.cljs b/src/status_im2/contexts/activity_center/events_test.cljs index 16bf10be29..ba690b376e 100644 --- a/src/status_im2/contexts/activity_center/events_test.cljs +++ b/src/status_im2/contexts/activity_center/events_test.cljs @@ -461,7 +461,7 @@ {:filter-type types/one-to-one-chat}]) (is (= :unread (get-in (h/db) [:activity-center :filter :status]))) - (is (= "" (get-in @spy-queue [0 :args 0 :params 0])) + (is (= "" (get-in @spy-queue [0 :args 0 :params 0 :cursor])) "Should be called with empty cursor when fetching first page") (is (= "10" (get-in (h/db) [:activity-center :cursor]))) (is (= [{:chat-id "0x9" @@ -506,8 +506,7 @@ (rf/dispatch [:activity-center.notifications/fetch-next-page]) - (is (= "wakuext_activityCenterNotificationsBy" (get-in @spy-queue [0 :args 0 :method]))) - (is (= "10" (get-in @spy-queue [0 :args 0 :params 0])) + (is (= "10" (get-in @spy-queue [0 :args 0 :params 0 :cursor])) "Should be called with current cursor") (is (= "" (get-in (h/db) [:activity-center :cursor]))) (is (= [{:chat-id "0x9" @@ -540,32 +539,3 @@ :unread :fake-error] (:args (last @spy-queue)))))))) - -(deftest notifications-fetch-unread-count-test - (testing "fetches total notification count and store in db" - (h/run-test-sync - (setup) - (let [spy-queue (atom [])] - (h/stub-fx-with-callbacks :json-rpc/call - :on-success - (fn [{:keys [params]}] - (if (= types/mention (ffirst params)) - 9 - 0))) - (h/spy-fx spy-queue :json-rpc/call) - - (rf/dispatch [:activity-center.notifications/fetch-unread-count]) - - (is (= "wakuext_unreadAndAcceptedActivityCenterNotificationsCount" - (get-in @spy-queue [0 :args 0 :method]))) - - (let [actual (get-in (h/db) [:activity-center :unread-counts-by-type])] - (is (= {types/one-to-one-chat 0 - types/private-group-chat 0 - types/contact-verification 0 - types/contact-request 0 - types/mention 9 - types/reply 0 - types/admin 0} - actual)) - (is (= types/all-supported (set (keys actual))))))))) diff --git a/status-go-version.json b/status-go-version.json index c395e3bc4a..acedde89e8 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.135.2", - "commit-sha1": "6cdc0ed5a191f486b748b7f501ec78280ac61dfc", - "src-sha256": "1szxms3q5v0p5xnmvi96z5s8pxdnxgqzmq23jildchcrl16kqvc2" + "version": "v0.136.0", + "commit-sha1": "ebc1fc337c07b10c9c4a5caab8dae2c540ef54a1", + "src-sha256": "1fcv61k24zpp1cx6d9m7hn2zi5vbzqmfqz6r8l1dn5b09h3323a0" } diff --git a/yarn.lock b/yarn.lock index e7c1e22a13..6774628520 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2222,27 +2222,6 @@ dependencies: "@types/yargs-parser" "*" -"@walletconnect/browser-utils@^1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@walletconnect/browser-utils/-/browser-utils-1.7.1.tgz#2a28846cd4d73166debbbf7d470e78ba25616f5e" - integrity sha512-y6KvxPhi52sWzS0/HtA3EhdgmtG8mXcxdc26YURDOVC/BJh3MxV8E16JFrT4InylOqYJs6dcSLWVfcnJaiPtZw== - dependencies: - "@walletconnect/safe-json" "1.0.0" - "@walletconnect/types" "^1.7.1" - "@walletconnect/window-getters" "1.0.0" - "@walletconnect/window-metadata" "1.0.0" - detect-browser "5.2.0" - -"@walletconnect/client-legacy@npm:@walletconnect/client@^1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@walletconnect/client/-/client-1.7.1.tgz#aaa74199bdc0605db9ac2ecdf8a463b271586d3b" - integrity sha512-xD8B8s1hL7Z5vJwb3L0u1bCVAk6cRQfIY9ycymf7KkmIhkAONQJNf2Y0C0xIpbPp2fdn9VwnSfLm5Ed/Ht/1IA== - dependencies: - "@walletconnect/core" "^1.7.1" - "@walletconnect/iso-crypto" "^1.7.1" - "@walletconnect/types" "^1.7.1" - "@walletconnect/utils" "^1.7.1" - "@walletconnect/client@^2.0.0-beta.23": version "2.0.0-beta.23" resolved "https://registry.yarnpkg.com/@walletconnect/client/-/client-2.0.0-beta.23.tgz#934f91beb66ec7bb1a79afc1973fcd48481ccbc5" @@ -2259,15 +2238,6 @@ "@walletconnect/utils" "^2.0.0-beta.23" ws "^8.3.0" -"@walletconnect/core@^1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-1.7.1.tgz#321c14d63af81241658b028022e0e5fa6dc7f374" - integrity sha512-qO+4wykyRNiq3HEuaAA2pW2PDnMM4y7pyPAgiCwfHiqF4PpWvtcdB301hI0K5am9ghuqKZMy1HlE9LWNOEBvcw== - dependencies: - "@walletconnect/socket-transport" "^1.7.1" - "@walletconnect/types" "^1.7.1" - "@walletconnect/utils" "^1.7.1" - "@walletconnect/crypto@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@walletconnect/crypto/-/crypto-1.0.1.tgz#d4c1b1cd5dd1be88fe9a82dfc54cadbbb3f9d325" @@ -2301,15 +2271,6 @@ resolved "https://registry.yarnpkg.com/@walletconnect/environment/-/environment-1.0.0.tgz#c4545869fa9c389ec88c364e1a5f8178e8ab5034" integrity sha512-4BwqyWy6KpSvkocSaV7WR3BlZfrxLbJSLkg+j7Gl6pTDE+U55lLhJvQaMuDVazXYxcjBsG09k7UlH7cGiUI5vQ== -"@walletconnect/iso-crypto@^1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@walletconnect/iso-crypto/-/iso-crypto-1.7.1.tgz#c463bb5874686c2f21344e2c7f3cf4d71c34ca70" - integrity sha512-qMiW0kLN6KCjnLMD50ijIj1lQqjNjGszGUwrSVUiS2/Dp4Ecx+4QEtHbmVwGEkfx4kelYPFpDJV3ZJpQ4Kqg/g== - dependencies: - "@walletconnect/crypto" "^1.0.1" - "@walletconnect/types" "^1.7.1" - "@walletconnect/utils" "^1.7.1" - "@walletconnect/jsonrpc-provider@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@walletconnect/jsonrpc-provider/-/jsonrpc-provider-1.0.0.tgz#066ee5a8a8554c55ea68f9ebf6fe8f96cdb66e7e" @@ -2365,25 +2326,11 @@ dependencies: "@walletconnect/jsonrpc-types" "^1.0.0" -"@walletconnect/safe-json@1.0.0", "@walletconnect/safe-json@^1.0.0": +"@walletconnect/safe-json@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@walletconnect/safe-json/-/safe-json-1.0.0.tgz#12eeb11d43795199c045fafde97e3c91646683b2" integrity sha512-QJzp/S/86sUAgWY6eh5MKYmSfZaRpIlmCJdi5uG4DJlKkZrHEF7ye7gA+VtbVzvTtpM/gRwO2plQuiooIeXjfg== -"@walletconnect/socket-transport@^1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@walletconnect/socket-transport/-/socket-transport-1.7.1.tgz#cc4c8dcf21c40b805812ecb066b2abb156fdb146" - integrity sha512-Gu1RPro0eLe+HHtLhq/1T5TNFfO/HW2z3BnWuUYuJ/F8w1U9iK7+4LMHe+LTgwgWy9Ybcb2k0tiO5e3LgjHBHQ== - dependencies: - "@walletconnect/types" "^1.7.1" - "@walletconnect/utils" "^1.7.1" - ws "7.5.3" - -"@walletconnect/types@^1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-1.7.1.tgz#86cc3832e02415dc9f518f3dcb5366722afbfc03" - integrity sha512-X0NunEUgq46ExDcKo7BnnFpFhuZ89bZ04/1FtohNziBWcP2Mblp2yf+FN7iwmZiuZ3bRTb8J1O4oJH2JGP9I7A== - "@walletconnect/types@^2.0.0-beta.23": version "2.0.0-beta.23" resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.0.0-beta.23.tgz#3adf5c8329b7807d8c8d4aa1419e470eab72445c" @@ -2394,19 +2341,6 @@ pino "^6.7.0" pino-pretty "^4.3.0" -"@walletconnect/utils@^1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-1.7.1.tgz#f858d5f22425a4c2da2a28ae493bde7f2eecf815" - integrity sha512-7Lig9rruqTMaFuwEhBrArq1QgzIf2NuzO6J3sCUYCZh60EQ7uIZjekaDonQjiQJAbfYcgWUBm8qa0PG1TzYN3Q== - dependencies: - "@walletconnect/browser-utils" "^1.7.1" - "@walletconnect/encoding" "^1.0.0" - "@walletconnect/jsonrpc-utils" "^1.0.0" - "@walletconnect/types" "^1.7.1" - bn.js "4.11.8" - js-sha3 "0.8.0" - query-string "6.13.5" - "@walletconnect/utils@^2.0.0-beta.23": version "2.0.0-beta.23" resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.0.0-beta.23.tgz#005e4409a7014a66dda30389e4b1f31d186ebd0e" @@ -2424,12 +2358,12 @@ lodash.union "^4.6.0" query-string "^6.13.5" -"@walletconnect/window-getters@1.0.0", "@walletconnect/window-getters@^1.0.0": +"@walletconnect/window-getters@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@walletconnect/window-getters/-/window-getters-1.0.0.tgz#1053224f77e725dfd611c83931b5f6c98c32bfc8" integrity sha512-xB0SQsLaleIYIkSsl43vm8EwETpBzJ2gnzk7e0wMF3ktqiTGS6TFHxcprMl5R44KKh4tCcHCJwolMCaDSwtAaA== -"@walletconnect/window-metadata@1.0.0", "@walletconnect/window-metadata@^1.0.0": +"@walletconnect/window-metadata@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@walletconnect/window-metadata/-/window-metadata-1.0.0.tgz#93b1cc685e6b9b202f29c26be550fde97800c4e5" integrity sha512-9eFvmJxIKCC3YWOL97SgRkKhlyGXkrHwamfechmqszbypFspaSk+t2jQXAEU7YClHF6Qjw5eYOmy1//zFi9/GA== @@ -3157,11 +3091,6 @@ bluebird@^3.5.4: resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== -bn.js@4.11.8: - version "4.11.8" - resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" - integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA== - bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.4.0: version "4.11.9" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828" @@ -4320,11 +4249,6 @@ destroy@~1.0.4: resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA= -detect-browser@5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/detect-browser/-/detect-browser-5.2.0.tgz#c9cd5afa96a6a19fda0bbe9e9be48a6b6e1e9c97" - integrity sha512-tr7XntDAu50BVENgQfajMLzacmSe34D+qZc4zjnniz0ZVuw/TZcLcyxHQjYpJTM36sGEkZZlYLnIM1hH7alTMA== - detect-libc@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" @@ -7138,11 +7062,6 @@ js-levenshtein@^1.1.3: resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.6.tgz#c6cee58eb3550372df8deb85fad5ce66ce01d59d" integrity sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g== -js-sha3@0.8.0: - version "0.8.0" - resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840" - integrity sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q== - "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" @@ -9308,15 +9227,6 @@ qs@~6.5.2: resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== -query-string@6.13.5: - version "6.13.5" - resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.13.5.tgz#99e95e2fb7021db90a6f373f990c0c814b3812d8" - integrity sha512-svk3xg9qHR39P3JlHuD7g3nRnyay5mHbrPctEBDUxUkHRifPHXJDhBUycdCC0NBjXoDf44Gb+IsOZL1Uwn8M/Q== - dependencies: - decode-uri-component "^0.2.0" - split-on-first "^1.0.0" - strict-uri-encode "^2.0.0" - query-string@^6.13.5: version "6.14.1" resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.14.1.tgz#7ac2dca46da7f309449ba0f86b1fd28255b0c86a" @@ -9632,7 +9542,7 @@ react-native-share@^7.0.1: integrity sha512-hq7nOirgih/zIF9UU9FuYKZ3NGvasu2c/eJesvyPKYiykTtgQZM+mvDwFk/ogEsGwRtTPJBtj8/6IyIFcGa7lw== "react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.5.39": - version "2.5.38" + version "2.5.39" resolved "git+https://github.com/status-im/react-native-status-keycard.git#93dd64754e676172310e6ea7187cc49f2dc013c6" react-native-svg@^9.8.4: @@ -11771,11 +11681,6 @@ write-file-atomic@^3.0.0: signal-exit "^3.0.2" typedarray-to-buffer "^3.1.5" -ws@7.5.3: - version "7.5.3" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.3.tgz#160835b63c7d97bfab418fc1b8a9fced2ac01a74" - integrity sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg== - ws@^1.1.0, ws@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/ws/-/ws-1.1.5.tgz#cbd9e6e75e09fc5d2c90015f21f0c40875e0dd51"