Skip to content

Commit

Permalink
move transport (#18062)
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer authored Dec 5, 2023
1 parent 5c30fd8 commit fe20fa4
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 320 deletions.
1 change: 0 additions & 1 deletion .carve_ignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ react-native.fs/unlink
react-native.fs/file-exists?
status-im.ui.components.colors/white
status-im.ui.components.colors/black
status-im.transport.core-test/messages
status-im.ui.components.core/animated-header
status-im.ui.components.core/safe-area-provider
status-im.ui.components.core/safe-area-consumer
Expand Down
35 changes: 18 additions & 17 deletions src/status_im/chat/models/input.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
[goog.object :as object]
[re-frame.core :as re-frame]
[status-im.chat.models.mentions :as mentions]
[status-im.chat.models.message :as chat.message]
[status-im.chat.models.message-content :as message-content]
[status-im.data-store.messages :as data-store-messages]
[status-im2.constants :as constants]
[status-im2.contexts.chat.composer.link-preview.events :as link-preview]
[status-im2.contexts.chat.messages.transport.events :as messages.transport]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
Expand Down Expand Up @@ -205,7 +205,7 @@
(rf/merge cofx
(clean-input (:current-chat-id db))
(link-preview/reset-unfurled)
(chat.message/send-messages messages)))))
(messages.transport/send-chat-messages messages)))))

(rf/defn send-audio-message
[{:keys [db] :as cofx} audio-path duration current-chat-id]
Expand All @@ -214,25 +214,26 @@
(when-not (string/blank? audio-path)
(rf/merge
{:db (assoc-in db [:chat/inputs current-chat-id :metadata :responding-to-message] nil)}
(chat.message/send-message
(merge
{:chat-id current-chat-id
:content-type constants/content-type-audio
:audio-path audio-path
:audio-duration-ms duration
:text (i18n/label :t/update-to-listen-audio {"locale" "en"})}
(when message-id
{:response-to message-id})))))))
(messages.transport/send-chat-messages
[(merge
{:chat-id current-chat-id
:content-type constants/content-type-audio
:audio-path audio-path
:audio-duration-ms duration
:text (i18n/label :t/update-to-listen-audio {"locale" "en"})}
(when message-id
{:response-to message-id}))])))))

(rf/defn send-sticker-message
[cofx {:keys [hash packID pack]} current-chat-id]
(when-not (or (string/blank? hash) (and (string/blank? packID) (string/blank? pack)))
(chat.message/send-message cofx
{:chat-id current-chat-id
:content-type constants/content-type-sticker
:sticker {:hash hash
:pack (int (if (string/blank? packID) pack packID))}
:text (i18n/label :t/update-to-see-sticker {"locale" "en"})})))
(messages.transport/send-chat-messages
cofx
[{:chat-id current-chat-id
:content-type constants/content-type-sticker
:sticker {:hash hash
:pack (int (if (string/blank? packID) pack packID))}
:text (i18n/label :t/update-to-see-sticker {"locale" "en"})}])))

(rf/defn send-edited-message
[{:keys [db]
Expand Down
15 changes: 0 additions & 15 deletions src/status_im/chat/models/message.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[react-native.platform :as platform]
[status-im.chat.models.loading :as chat.loading]
[status-im.data-store.messages :as data-store.messages]
[status-im.transport.message.protocol :as protocol]
[status-im.utils.deprecated-types :as types]
[status-im2.contexts.chat.messages.delete-message.events :as delete-message]
[status-im2.contexts.chat.messages.list.events :as message-list]
Expand All @@ -21,12 +20,6 @@
[db chat-id clock-value]
(>= (get-in db [:chats chat-id :deleted-at-clock-value]) clock-value))

(defn add-timeline-message
[acc chat-id message-id message]
(-> acc
(update-in [:db :messages chat-id] assoc message-id message)
(update-in [:db :message-lists chat-id] message-list/add message)))

(defn hide-message
"Hide chat message, rebuild message-list"
[{:keys [db]} chat-id message-id]
Expand Down Expand Up @@ -145,14 +138,6 @@
:on-error #(log/error "failed to re-send message" %)}]}
(update-message-status chat-id message-id :sending)))

(rf/defn send-message
[cofx message]
(protocol/send-chat-messages cofx [message]))

(rf/defn send-messages
[cofx messages]
(protocol/send-chat-messages cofx messages))

(rf/defn handle-removed-messages
{:events [::handle-removed-messages]}
[{:keys [db] :as cofx} removed-messages]
Expand Down
18 changes: 0 additions & 18 deletions src/status_im/chat/models/reactions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require
[re-frame.core :as re-frame]
[status-im.data-store.reactions :as data-store.reactions]
[status-im.transport.message.protocol :as message.protocol]
[status-im2.constants :as constants]
[taoensso.timbre :as log]
[utils.re-frame :as rf]
Expand Down Expand Up @@ -63,23 +62,6 @@
(let [reactions-w-chat-id (map #(assoc % :chat-id chat-id) reactions)]
{:db (update db :reactions (process-reactions (:chats db)) reactions-w-chat-id)})))


;; Send reactions


(rf/defn send-emoji-reaction
{:events [:models.reactions/send-emoji-reaction]}
[{{:keys [current-chat-id]} :db :as cofx} reaction]
(message.protocol/send-reaction cofx
(update reaction :chat-id #(or % current-chat-id))))

(rf/defn send-retract-emoji-reaction
{:events [:models.reactions/send-emoji-reaction-retraction]}
[{{:keys [current-chat-id]} :db :as cofx} reaction]
(message.protocol/send-retract-reaction cofx
(update reaction :chat-id #(or % current-chat-id))))


(defn message-reactions
[current-public-key reactions]
(reduce
Expand Down
2 changes: 0 additions & 2 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
status-im.pairing.core
status-im.profile.core
status-im.search.core
status-im.signals.core
status-im.stickers.core
status-im.transport.core
status-im.ui.components.invite.events
[status-im.ui.components.react :as react]
status-im.ui.screens.notifications-settings.events
Expand Down
14 changes: 14 additions & 0 deletions src/status_im/mailserver/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,17 @@
(rf/merge cofx
{:db (dissoc db :mailserver.edit/mailserver)}
(navigation/navigate-to :edit-mailserver nil)))

(defn add-mailservers
[db mailservers]
(reduce (fn [db {:keys [fleet id name] :as mailserver}]
(let [updated-mailserver
(-> mailserver
(update :id keyword)
(assoc :name (if (seq name) name id))
(dissoc :fleet))]
(assoc-in db
[:mailserver/mailservers (keyword fleet) (keyword id)]
updated-mailserver)))
db
mailservers))
58 changes: 0 additions & 58 deletions src/status_im/transport/core.cljs
Original file line number Diff line number Diff line change
@@ -1,58 +0,0 @@
(ns ^{:doc "API to init and stop whisper messaging"} status-im.transport.core
(:require
[re-frame.core :as re-frame]
[status-im.pairing.core :as pairing]
[status-im.stickers.core :as stickers]
status-im.transport.shh
[status-im2.common.universal-links :as universal-links]
[taoensso.timbre :as log]
[utils.re-frame :as rf]))

(rf/defn set-node-info
{:events [:transport.callback/node-info-fetched]}
[{:keys [db]} node-info]
{:db (assoc db :node-info node-info)})

(rf/defn fetch-node-info-fx
[_]
{:json-rpc/call [{:method "admin_nodeInfo"
:on-success #(re-frame/dispatch [:transport.callback/node-info-fetched %])
:on-error #(log/error "node-info: failed error" %)}]})

(defn add-mailservers
[db mailservers]
(reduce (fn [db {:keys [fleet id name] :as mailserver}]
(let [updated-mailserver
(-> mailserver
(update :id keyword)
(assoc :name (if (seq name) name id))
(dissoc :fleet))]
(assoc-in db
[:mailserver/mailservers (keyword fleet) (keyword id)]
updated-mailserver)))
db
mailservers))

(rf/defn start-messenger
"We should only start receiving messages/processing topics once all the
initializiation is completed, otherwise we might receive messages/topics
when the state has not been properly initialized."
[_]
{:json-rpc/call [{:method "wakuext_startMessenger"
:on-success #(re-frame/dispatch [::messenger-started %])
:on-error #(log/error "failed to start messenger")}]})

(rf/defn messenger-started
{:events [::messenger-started]}
[{:keys [db] :as cofx} {:keys [mailservers] :as response}]
(log/info "Messenger started")
(let [new-account? (get db :onboarding/new-account?)]
(rf/merge cofx
{:db (-> db
(assoc :messenger/started? true)
(add-mailservers mailservers))}
(fetch-node-info-fx)
(pairing/init)
(stickers/load-packs)
(when-not new-account?
(universal-links/process-stored-event)))))
59 changes: 0 additions & 59 deletions src/status_im/transport/message/protocol.cljs

This file was deleted.

35 changes: 0 additions & 35 deletions src/status_im/transport/shh.cljs

This file was deleted.

18 changes: 0 additions & 18 deletions src/status_im/transport/utils.cljs

This file was deleted.

10 changes: 7 additions & 3 deletions src/status_im/utils/logging/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
[react-native.mail :as react-native-mail]
[react-native.platform :as platform]
[status-im.bottom-sheet.events :as bottom-sheet]
[status-im.transport.utils :as transport.utils]
[status-im.ui.components.react :as react]
[status-im.utils.build :as build]
[status-im.utils.deprecated-types :as types]
Expand Down Expand Up @@ -38,6 +37,11 @@
{:json-rpc/call [{:method "web3_clientVersion"
:on-success #(re-frame/dispatch [:logging/store-web3-client-version %])}]})

(defn extract-url-components
[address]
(when address
(rest (re-matches #"enode://(.*?)@(.*):(.*)" address))))

(defn email-body
"logs attached"
[{:keys [:web3-node-version :mailserver/current-id
Expand All @@ -46,7 +50,7 @@
build-version (str build/version " (" build-number ")")
separator (string/join (take 40 (repeat "-")))
[enode-id ip-address port]
(transport.utils/extract-url-components (:enode node-info))]
(extract-url-components (:enode node-info))]
(string/join
"\n"
(concat [(i18n/label :t/report-bug-email-template
Expand All @@ -68,7 +72,7 @@
(mapcat
(fn [{:keys [enode]}]
(let [[enode-id ip-address port]
(transport.utils/extract-url-components enode)]
(extract-url-components enode)]
[(str "id: " enode-id)
(str "ip: " ip-address)
(str "port: " port)
Expand Down
Loading

0 comments on commit fe20fa4

Please sign in to comment.