|
11 | 11 | [status-im.utils.datetime :as datetime]
|
12 | 12 | [clojure.string :as string]
|
13 | 13 | [status-im.utils.config :as config]
|
| 14 | + [status-im.ui.components.react :as react] |
14 | 15 | ["react-native-mail" :default react-native-mail]))
|
15 | 16 |
|
16 | 17 | ( def report-email "[email protected]")
|
|
54 | 55 | {:db (assoc-in db [:multiaccount :log-level] log-level)
|
55 | 56 | :logs/set-level log-level}))
|
56 | 57 |
|
57 |
| -(fx/defn send-logs |
58 |
| - {:events [:logging.ui/send-logs-pressed]} |
59 |
| - [{:keys [db]}] |
60 |
| - ;; TODO: Add message explaining db export |
61 |
| - (let [db-json (types/clj->json (select-keys db [:app-state |
62 |
| - :current-chat-id |
63 |
| - :network |
64 |
| - :network-status |
65 |
| - :peers-count |
66 |
| - :peers-summary |
67 |
| - :sync-state |
68 |
| - :view-id |
69 |
| - :chat/cooldown-enabled? |
70 |
| - :chat/cooldowns |
71 |
| - :chat/last-outgoing-message-sent-at |
72 |
| - :chat/spam-messages-frequency |
73 |
| - :chats/loading? |
74 |
| - :dimensions/window]))] |
75 |
| - {:logs/archive-logs [db-json ::send-email]})) |
76 |
| - |
77 |
| -(fx/defn show-client-error |
78 |
| - {:events [:show-client-error]} |
79 |
| - [_] |
80 |
| - {:utils/show-popup {:title (i18n/label :t/cant-report-bug) |
81 |
| - :content (i18n/label :t/mail-should-be-configured)}}) |
82 |
| - |
83 |
| -(fx/defn show-logs-dialog |
84 |
| - {:events [:shake-event]} |
85 |
| - [{:keys [db]}] |
86 |
| - (when-not (:logging/dialog-shown? db) |
87 |
| - {:db |
88 |
| - (assoc db :logging/dialog-shown? true) |
89 |
| - :utils/show-confirmation |
90 |
| - {:title (i18n/label :t/send-logs) |
91 |
| - :content (i18n/label :t/send-logs-to |
92 |
| - {:email report-email}) |
93 |
| - :confirm-button-text (i18n/label :t/send-logs) |
94 |
| - :on-accept #(re-frame/dispatch |
95 |
| - [:logging.ui/send-logs-pressed]) |
96 |
| - :on-cancel #(re-frame/dispatch |
97 |
| - [:logging/dialog-canceled])}})) |
98 |
| - |
99 |
| -(fx/defn dialog-closed |
100 |
| - {:events [:logging/dialog-canceled]} |
101 |
| - [{:keys [db]}] |
102 |
| - {:db (dissoc db :logging/dialog-shown?)}) |
103 |
| - |
104 | 58 | (defn email-body
|
105 | 59 | "logs attached"
|
106 | 60 | [{:keys [:web3-node-version :mailserver/current-id
|
|
139 | 93 | (datetime/timestamp->long-date
|
140 | 94 | (datetime/now))]))))
|
141 | 95 |
|
142 |
| -(re-frame/reg-fx |
143 |
| - :email/send |
144 |
| - ;; https://github.com/chirag04/react-native-mail#example |
145 |
| - (fn [[opts callback]] |
146 |
| - (.mail react-native-mail |
147 |
| - (clj->js opts) |
148 |
| - callback))) |
| 96 | +(fx/defn dialog-closed |
| 97 | + {:events [:logging/dialog-canceled]} |
| 98 | + [{:keys [db]}] |
| 99 | + {:db (dissoc db :logging/dialog-shown?)}) |
149 | 100 |
|
150 | 101 | (fx/defn send-email
|
151 | 102 | [_ opts callback]
|
|
158 | 109 | cofx
|
159 | 110 | (dialog-closed)
|
160 | 111 | (send-email
|
161 |
| - {:subject "Error report" |
162 |
| - :recipients [report-email] |
163 |
| - :body (email-body db) |
164 |
| - :attachments [{:uri archive-uri |
165 |
| - :type "zip" |
166 |
| - :name "status_logs.zip"}]} |
| 112 | + (cond-> {:subject "Error report" |
| 113 | + :recipients [report-email] |
| 114 | + :body (email-body db)} |
| 115 | + |
| 116 | + (not (nil? archive-uri)) |
| 117 | + (assoc :attachments [{:uri archive-uri |
| 118 | + :type "zip" |
| 119 | + :name "status_logs.zip"}])) |
167 | 120 | (fn [event]
|
168 | 121 | (when (= event "not_available")
|
169 | 122 | (re-frame/dispatch [:show-client-error]))))))
|
| 123 | + |
| 124 | +(defn logs-enabled? [db] |
| 125 | + (not (string/blank? (get-in db [:multiaccount :log-level])))) |
| 126 | + |
| 127 | +(fx/defn send-logs |
| 128 | + {:events [:logging.ui/send-logs-pressed]} |
| 129 | + [{:keys [db] :as cofx} transport] |
| 130 | + (if (logs-enabled? db) |
| 131 | + ;; TODO: Add message explaining db export |
| 132 | + (let [db-json (types/clj->json (select-keys db [:app-state |
| 133 | + :current-chat-id |
| 134 | + :network |
| 135 | + :network-status |
| 136 | + :peers-count |
| 137 | + :peers-summary |
| 138 | + :sync-state |
| 139 | + :view-id |
| 140 | + :chat/cooldown-enabled? |
| 141 | + :chat/cooldowns |
| 142 | + :chat/last-outgoing-message-sent-at |
| 143 | + :chat/spam-messages-frequency |
| 144 | + :chats/loading? |
| 145 | + :dimensions/window]))] |
| 146 | + {:logs/archive-logs [db-json (if (= transport :email) |
| 147 | + ::send-email |
| 148 | + ::share-logs-file)]}) |
| 149 | + (send-email-event cofx nil))) |
| 150 | + |
| 151 | +(fx/defn show-client-error |
| 152 | + {:events [:show-client-error]} |
| 153 | + [_] |
| 154 | + {:utils/show-popup {:title (i18n/label :t/cant-report-bug) |
| 155 | + :content (i18n/label :t/mail-should-be-configured)}}) |
| 156 | + |
| 157 | +(fx/defn show-logs-dialog |
| 158 | + {:events [:shake-event]} |
| 159 | + [{:keys [db]}] |
| 160 | + (when-not (:logging/dialog-shown? db) |
| 161 | + {:db |
| 162 | + (assoc db :logging/dialog-shown? true) |
| 163 | + :utils/show-confirmation |
| 164 | + (cond-> {:title (i18n/label :t/send-logs) |
| 165 | + :content (i18n/label :t/send-logs-to |
| 166 | + {:email report-email}) |
| 167 | + :confirm-button-text (i18n/label :t/send-logs) |
| 168 | + :on-accept #(re-frame/dispatch |
| 169 | + [:logging.ui/send-logs-pressed :email]) |
| 170 | + :on-cancel #(re-frame/dispatch |
| 171 | + [:logging/dialog-canceled])} |
| 172 | + |
| 173 | + (and #_platform/ios? (logs-enabled? db)) |
| 174 | + (assoc :extra-options [{:text (i18n/label :t/share-logs) |
| 175 | + :onPress #(re-frame/dispatch |
| 176 | + [:logging.ui/send-logs-pressed :sharing]) |
| 177 | + :style "default"}]))})) |
| 178 | + |
| 179 | +(re-frame/reg-fx |
| 180 | + :email/send |
| 181 | + ;; https://github.com/chirag04/react-native-mail#example |
| 182 | + (fn [[opts callback]] |
| 183 | + (.mail react-native-mail (clj->js opts) callback))) |
| 184 | + |
| 185 | +(re-frame/reg-fx |
| 186 | + ::share-archive |
| 187 | + (fn [opts] |
| 188 | + (.share ^js react/sharing (clj->js opts)))) |
| 189 | + |
| 190 | +(fx/defn share-archive |
| 191 | + [_ opts] |
| 192 | + {::share-archive opts}) |
| 193 | + |
| 194 | +(fx/defn share-logs-file |
| 195 | + {:events [::share-logs-file]} |
| 196 | + [{:keys [db] :as cofx} archive-uri] |
| 197 | + (fx/merge |
| 198 | + cofx |
| 199 | + (dialog-closed) |
| 200 | + (share-archive |
| 201 | + {:title "Archived logs" |
| 202 | + :url archive-uri |
| 203 | + :message archive-uri}))) |
| 204 | + |
0 commit comments