From 8296bda85bd8acebfdbf34d79055069a839a7b16 Mon Sep 17 00:00:00 2001 From: Ibrahem Khalil Date: Tue, 24 Oct 2023 17:23:16 +0300 Subject: [PATCH] Fix recent album not showing count (#17498) --- android/app/src/main/AndroidManifest.xml | 3 +- ios/Podfile.lock | 10 ++--- package.json | 2 +- package.json.gpg | Bin 2195 -> 0 bytes src/mocks/js_dependencies.cljs | 5 ++- src/react_native/cameraroll.cljs | 8 +++- .../photo_selector/album_selector/view.cljs | 21 ++++++--- .../contexts/chat/photo_selector/events.cljs | 40 ++++++++++++++---- .../contexts/chat/photo_selector/view.cljs | 2 +- src/status_im2/subs/chats.cljs | 15 +++++++ yarn.lock | 8 ++-- 11 files changed, 85 insertions(+), 29 deletions(-) delete mode 100644 package.json.gpg diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 58dbd759ed..5efe8eb2f1 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -33,7 +33,8 @@ android:name=".MainApplication" android:largeHeap="true" android:usesCleartextTraffic="true" - android:extractNativeLibs="true"> + android:extractNativeLibs="true" + android:requestLegacyExternalStorage="true"> diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 3ca83c93f1..5b9ddba5b7 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -247,7 +247,7 @@ PODS: - React-Core - react-native-blur (4.3.3): - React-Core - - react-native-cameraroll (4.0.4): + - react-native-cameraroll (5.10.0): - React-Core - react-native-config (1.5.0): - react-native-config/App (= 1.5.0) @@ -468,7 +468,7 @@ DEPENDENCIES: - react-native-background-timer (from `../node_modules/react-native-background-timer`) - react-native-blob-util (from `../node_modules/react-native-blob-util`) - "react-native-blur (from `../node_modules/@react-native-community/blur`)" - - "react-native-cameraroll (from `../node_modules/@react-native-community/cameraroll`)" + - "react-native-cameraroll (from `../node_modules/@react-native-camera-roll/camera-roll`)" - react-native-config (from `../node_modules/react-native-config`) - react-native-image-resizer (from `../node_modules/react-native-image-resizer`) - react-native-lottie-splash-screen (from `../node_modules/react-native-lottie-splash-screen`) @@ -584,7 +584,7 @@ EXTERNAL SOURCES: react-native-blur: :path: "../node_modules/@react-native-community/blur" react-native-cameraroll: - :path: "../node_modules/@react-native-community/cameraroll" + :path: "../node_modules/@react-native-camera-roll/camera-roll" react-native-config: :path: "../node_modules/react-native-config" react-native-image-resizer: @@ -723,7 +723,7 @@ SPEC CHECKSUMS: react-native-background-timer: 1f7d560647b40e6a60b01c452ba29c54bf581fc4 react-native-blob-util: 600972b1782380a5a7d5db61a3817ea32349dae9 react-native-blur: c6d0a1dc2b4b519f7afe3b14d8151998632b6d18 - react-native-cameraroll: 88f4e62d9ecd0e1f253abe4f685474f2ea14bfa2 + react-native-cameraroll: 4701ae7c3dbcd3f5e9e150ca17f250a276154b35 react-native-config: 5330c8258265c1e5fdb8c009d2cabd6badd96727 react-native-image-resizer: 2f1577efa3bc762597681f530c8e8d05ce0ceeb3 react-native-lottie-splash-screen: 068688c15dd478301fda00f8d87d7fb7d5b9a93e @@ -777,6 +777,6 @@ SPEC CHECKSUMS: TouchID: ba4c656d849cceabc2e4eef722dea5e55959ecf4 Yoga: d24d6184b6b85f742536bd93bd07d69d7b9bb4c1 -PODFILE CHECKSUM: 259dd9b0a973943f02a5912c799a4db3ed475b66 +PODFILE CHECKSUM: 6a5f0e6776ce4ef6193032d077947117ace77a87 COCOAPODS: 1.12.0 diff --git a/package.json b/package.json index c5e2b0e392..070c1cd844 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "dependencies": { "@babel/preset-typescript": "^7.17.12", "@react-native-async-storage/async-storage": "^1.17.9", + "@react-native-camera-roll/camera-roll": "git+https://github.com/status-im/react-native-camera-roll.git#refs/tags/v5.1.1.1", "@react-native-community/audio-toolkit": "git+https://github.com/tbenr/react-native-audio-toolkit.git#refs/tags/v2.0.3-status-v6", "@react-native-community/blur": "git+https://github.com/status-im/react-native-blur#refs/tags/v4.3.3-status", - "@react-native-community/cameraroll": "git+https://github.com/status-im/react-native-cameraroll.git#refs/tags/v4.0.4-status.0", "@react-native-community/clipboard": "^1.2.2", "@react-native-community/hooks": "^3.0.0", "@react-native-community/masked-view": "^0.1.6", diff --git a/package.json.gpg b/package.json.gpg deleted file mode 100644 index 036a58bc789c0d140da464ade6c41514cc8e7132..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2195 zcmV;E2yFMG0i9TTj8#V&Uxe1(6$IN_FqOD$HL)pk?mhRhT(G6cLo4apXpOXqT{`ES zx#!N_b7qcb=G@&Y(ol&ul~64ZK-#q>*g7fm#fVR@df2f?WeW0rbnwTrs0yyt-v87 zC zPA$bGO4#CK$aF@BGfN)Ug-*&IS%3RN_JoD7fJdetH~M3+aO1 zcu0eiZ5Xu31RSKKkv!#<&57GIa84@O1wmszm1IC01h%cAV=UqkW)Wsm(%_vn1~!PJ z7zL3?Ry`6qP@O-rLet@sNo22S3Jol(%!B~pKG>gX`V}(kig{&cUVz^X7?sr&4lK%% z}|Qz2-16wp^Dx6a#Yb`H$W#TsboS#@xzXK?IW zvBNT27hl&|N}QL&WF5(>h@Oqy#iC3sRH0-nWP+-r&FTzBBxOY&GUT+}>{7fyln~>R z7O4q)JgOX#O*u`Uja@j@iZZIjs4*xvM4Fs2VoHS;VNqhJ=t?7lNUUYD3AupYgSpAEi)1 zW5XKYCbERQ5)~z=`N$#?K&S;uji?wfQ$da$kYhngKtV*(C!~f$4S%W^7#dBYCtE*5 z6*5)C1#0wAO;+uIZ~7)swmUZDQpT=TB&`M43xQz_3$o6@_EF`HL z2MTD_BEMb~xPbymoh0D1nqKHg8Kp6b3*U&I?WQ5bDl1YuHay>j$fDTcwy5Er>r4d& z+Qx=MP|?BCp+d%amhNIt5eo@HnUwVc$k)42iUgWg-y{?^5i;-zf_Sx@2+0h@Vi#gs zln_x6+`hcLyy?!~l0`a1Uy?*!q?fQKsfmh&SSkQwR9AMvzQh60q{>~Ho;B9?7N)m# z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CS0eLx?acwlK|9NP8T3tKi`d$e!l%unYZL+Lm8>DPK5+{AuVupL*u; zd#CiN*LS}0>U*noeevq+KJ)qaygT0i&-HKq>`x1(#~&T^r=OnOvt#33>z;ebf7SZ) z@$3EL+TEWs(5BoMzOv@Gw>|W1_0!J3C)Q8yF1&Tik%N1GeRg$v=kte7yztT=H<*)a Vk9_~(UkwiD=0890m2Llf^#2WyW~cxF diff --git a/src/mocks/js_dependencies.cljs b/src/mocks/js_dependencies.cljs index d8731a18b0..f062203d4c 100644 --- a/src/mocks/js_dependencies.cljs +++ b/src/mocks/js_dependencies.cljs @@ -346,7 +346,8 @@ (clj->js {:BlurView {}})) (def react-native-camera-roll - (clj->js {:default #js {}})) + (clj->js {:default #js {} + :CameraRoll #js {}})) (def react-native-orientation-locker (clj->js {:default #js {} @@ -410,7 +411,7 @@ "react-native-navigation" react-native-navigation "@react-native-community/push-notification-ios" push-notification-ios "@react-native-community/blur" react-native-blur - "@react-native-community/cameraroll" react-native-camera-roll + "@react-native-camera-roll/camera-roll" react-native-camera-roll "react-native-camera-kit" react-native-camera-kit "react-native-permissions" react-native-permissions "rn-emoji-keyboard" rn-emoji-keyboard diff --git a/src/react_native/cameraroll.cljs b/src/react_native/cameraroll.cljs index 9e7e7b0ab3..2b4f92ae51 100644 --- a/src/react_native/cameraroll.cljs +++ b/src/react_native/cameraroll.cljs @@ -1,6 +1,6 @@ (ns react-native.cameraroll (:require - ["@react-native-community/cameraroll" :as CameraRoll] + ["@react-native-camera-roll/camera-roll" :refer [CameraRoll]] [react-native.fs :as fs] [taoensso.timbre :as log] [utils.transforms :as transforms])) @@ -22,3 +22,9 @@ (-> (.save CameraRoll (clj->js path)) (.then #(fs/unlink path)) (.catch #(fs/unlink path)))) + +(defn get-photos-count-ios + [cb] + (-> (.getPhotosCountiOS CameraRoll) + (.then #(cb %)) + (.catch #(js/console.error %)))) diff --git a/src/status_im2/contexts/chat/photo_selector/album_selector/view.cljs b/src/status_im2/contexts/chat/photo_selector/album_selector/view.cljs index 5da3f25ea4..8d3302ab47 100644 --- a/src/status_im2/contexts/chat/photo_selector/album_selector/view.cljs +++ b/src/status_im2/contexts/chat/photo_selector/album_selector/view.cljs @@ -4,6 +4,7 @@ [quo.foundations.colors :as colors] [react-native.core :as rn] [react-native.gesture :as gesture] + [react-native.platform :as platform] [react-native.reanimated :as reanimated] [status-im2.contexts.chat.photo-selector.album-selector.style :as style] [utils.i18n :as i18n] @@ -61,15 +62,25 @@ (defn- f-album-selector [{:keys [scroll-enabled on-scroll]} album? selected-album top] - (let [albums (rf/sub [:camera-roll/albums]) - albums-sections [{:title no-title :data (:smart-albums albums)} - {:title (i18n/label :t/my-albums) :data (:my-albums albums)}] - window-height (:height (rn/get-window))] + (let [albums (rf/sub [:camera-roll/albums]) + total-photos-count-android (rf/sub [:camera-roll/total-photos-count-android]) + total-photos-count-ios (rf/sub [:camera-roll/total-photos-count-ios]) + albums-sections [{:title no-title + :data [(assoc (:smart-album albums) + :count + (if platform/ios? + total-photos-count-ios + total-photos-count-android))]} + {:title (i18n/label :t/my-albums) + :data (:my-albums albums)}] + window-height (:height (rn/get-window))] [reanimated/view {:style (style/selector-container top)} [gesture/section-list {:data albums-sections :sections albums-sections - :render-data {:album? album? :selected-album selected-album :top top} + :render-data {:album? album? + :selected-album selected-album + :top top} :render-fn render-album :sticky-section-headers-enabled false :render-section-header-fn section-header diff --git a/src/status_im2/contexts/chat/photo_selector/events.cljs b/src/status_im2/contexts/chat/photo_selector/events.cljs index efe9ea60a7..b552cd98a8 100644 --- a/src/status_im2/contexts/chat/photo_selector/events.cljs +++ b/src/status_im2/contexts/chat/photo_selector/events.cljs @@ -6,6 +6,7 @@ [react-native.core :as rn] [react-native.image-resizer :as image-resizer] [react-native.permissions :as permissions] + [react-native.platform :as platform] [status-im2.constants :as constants] [taoensso.timbre :as log] [utils.i18n :as i18n] @@ -56,25 +57,25 @@ (defn get-albums [callback] - (let [albums (atom {:smart-albums [] - :my-albums []})] + (let [albums (atom {:smart-album [] + :my-albums []})] ;; Get the "recent" album first (cameraroll/get-photos - {:first 1 :groupTypes "All"} + {:first 1 :groupTypes "All" :assetType "Photos"} (fn [res-recent] (swap! albums assoc - :smart-albums - [{:title (i18n/label :t/recent) - :uri (get-in (first (:edges res-recent)) [:node :image :uri])}]) + :smart-album + {:title (i18n/label :t/recent) + :uri (get-in (first (:edges res-recent)) [:node :image :uri])}) ;; Get albums, then loop over albums and get each one's cover (first photo) (cameraroll/get-albums - {:assetType :Photos} + {:assetType "Photos"} (fn [res-albums] (let [response-count (count res-albums)] (if (pos? response-count) (doseq [album res-albums] (cameraroll/get-photos - {:first 1 :groupTypes "Albums" :groupName (:title album)} + {:first 1 :groupTypes "Albums" :groupName (:title album) :assetType "Photos"} (fn [res] (let [uri (get-in (first (:edges res)) [:node :image :uri])] (swap! albums update :my-albums conj (merge album {:uri uri})) @@ -83,21 +84,42 @@ (callback @albums)))))) (callback @albums))))))))) +(defn get-photos-count-ios-fx + [cb] + (cameraroll/get-photos-count-ios cb)) + (re-frame/reg-fx :camera-roll-get-albums (fn [] (get-albums #(re-frame/dispatch [:on-camera-roll-get-albums %])))) +(re-frame/reg-fx + :camera-roll-get-photos-count-ios + (fn [] + (when platform/ios? + (get-photos-count-ios-fx #(re-frame/dispatch [:on-camera-roll-get-images-count-ios %]))))) + (rf/defn on-camera-roll-get-albums {:events [:on-camera-roll-get-albums]} [{:keys [db]} albums] - {:db (assoc db :camera-roll/albums albums)}) + {:db (assoc db :camera-roll/albums albums) + :dispatch [:photo-selector/camera-roll-get-ios-photo-count]}) + +(rf/defn get-photos-count-ios + {:events [:on-camera-roll-get-images-count-ios]} + [{:keys [db]} count] + {:db (assoc db :camera-roll/ios-images-count count)}) (rf/defn camera-roll-get-albums {:events [:photo-selector/camera-roll-get-albums]} [_] {:camera-roll-get-albums nil}) +(rf/defn camera-roll-get-ios-photo-count + {:events [:photo-selector/camera-roll-get-ios-photo-count]} + [_] + {:camera-roll-get-photos-count-ios nil}) + (rf/defn camera-roll-select-album {:events [:chat.ui/camera-roll-select-album]} [{:keys [db]} album] diff --git a/src/status_im2/contexts/chat/photo_selector/view.cljs b/src/status_im2/contexts/chat/photo_selector/view.cljs index 5710a5b3ea..7d2d876bed 100644 --- a/src/status_im2/contexts/chat/photo_selector/view.cljs +++ b/src/status_im2/contexts/chat/photo_selector/view.cljs @@ -125,7 +125,7 @@ [album-selector/album-selector sheet album? selected-album top]) [:<> [gesture/flat-list - {:key-fn identity + {:key-fn #(hash (:uri %)) :render-fn render-image :render-data {:window-width window-width :selected selected-images} :data camera-roll-photos diff --git a/src/status_im2/subs/chats.cljs b/src/status_im2/subs/chats.cljs index 4c7c7d1aed..6a8355c577 100644 --- a/src/status_im2/subs/chats.cljs +++ b/src/status_im2/subs/chats.cljs @@ -454,3 +454,18 @@ [(re-frame/subscribe [:chats/chat (str community-id channel-id)])]) (fn [[chat]] (:muted? chat))) + +(re-frame/reg-sub + :camera-roll/total-photos-count-android + (fn [{:keys [camera-roll/albums]}] + (->> albums + :my-albums + (reduce + (fn [total-album-count current-album] + (+ total-album-count (:count current-album))) + 0)))) + +(re-frame/reg-sub + :camera-roll/total-photos-count-ios + (fn [{:keys [camera-roll/ios-images-count]}] + ios-images-count)) diff --git a/yarn.lock b/yarn.lock index c461eba563..499183a425 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2188,6 +2188,10 @@ dependencies: merge-options "^3.0.4" +"@react-native-camera-roll/camera-roll@git+https://github.com/status-im/react-native-camera-roll.git#refs/tags/v5.1.1.1": + version "5.10.0" + resolved "git+https://github.com/status-im/react-native-camera-roll.git#174f8c6ad88e5bad9d9bd207f42173e567ec3138" + "@react-native-community/audio-toolkit@git+https://github.com/tbenr/react-native-audio-toolkit.git#refs/tags/v2.0.3-status-v6": version "2.0.3" resolved "git+https://github.com/tbenr/react-native-audio-toolkit.git#7ae9055cf6169b30f5089bda7bfcfc1c40a715e5" @@ -2200,10 +2204,6 @@ version "4.3.3" resolved "git+https://github.com/status-im/react-native-blur#c140cc8e7d54e3318af0a7c149b5d64b54de3419" -"@react-native-community/cameraroll@git+https://github.com/status-im/react-native-cameraroll.git#refs/tags/v4.0.4-status.0": - version "4.0.4" - resolved "git+https://github.com/status-im/react-native-cameraroll.git#337c5a515e9b0f0728882f73568075553415f523" - "@react-native-community/cli-clean@^8.0.4": version "8.0.4" resolved "https://registry.yarnpkg.com/@react-native-community/cli-clean/-/cli-clean-8.0.4.tgz#97e16a20e207b95de12e29b03816e8f2b2c80cc7"