Add link to message
This commit is contained in:
parent
ff2590a40f
commit
8e7ab43557
|
@ -228,6 +228,11 @@
|
|||
[cofx chat-id]
|
||||
(loading/load-messages cofx chat-id))
|
||||
|
||||
(fx/defn preload-chat-message-data
|
||||
"Takes chat-id and coeffects map, returns effects necessary when navigating to chat"
|
||||
[cofx chat-id message-id]
|
||||
(loading/load-message-context cofx chat-id message-id))
|
||||
|
||||
(fx/defn navigate-to-chat
|
||||
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"
|
||||
{:events [:chat.ui/navigate-to-chat]}
|
||||
|
@ -245,6 +250,22 @@
|
|||
(navigation/pop-to-root-tab % :chat-stack))
|
||||
(navigation/navigate-to-cofx :chat nil)))
|
||||
|
||||
(fx/defn navigate-to-chat-message
|
||||
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"
|
||||
[{db :db :as cofx} chat-id message-id dont-reset?]
|
||||
(fx/merge cofx
|
||||
(close-chat (:current-chat-id db))
|
||||
(fn [{:keys [db]}]
|
||||
{:db (assoc db :current-chat-id chat-id :ignore-close-chat true)})
|
||||
(preload-chat-message-data chat-id message-id)
|
||||
#(when (group-chat? cofx chat-id)
|
||||
(loading/load-chat % chat-id))
|
||||
#(when-not dont-reset?
|
||||
(navigation/change-tab % :chat))
|
||||
#(when-not dont-reset?
|
||||
(navigation/pop-to-root-tab % :chat-stack))
|
||||
(navigation/navigate-to-cofx :chat nil)))
|
||||
|
||||
(fx/defn handle-clear-history-response
|
||||
{:events [::history-cleared]}
|
||||
[{:keys [db]} chat-id response]
|
||||
|
|
|
@ -146,7 +146,9 @@
|
|||
(let [cursor (get-in db [:pagination-info chat-id :cursor])]
|
||||
(when (or first-request cursor)
|
||||
(merge
|
||||
{:db (assoc-in db [:pagination-info chat-id :loading-messages?] true)}
|
||||
{:db (-> db
|
||||
(assoc-in [:pagination-info chat-id :loading-messages?] true)
|
||||
(dissoc :chats/initial-message-id))}
|
||||
{:utils/dispatch-later [{:ms 100 :dispatch [:load-more-reactions cursor chat-id]}
|
||||
{:ms 100 :dispatch [::models.pin-message/load-pin-messages chat-id]}]}
|
||||
(data-store.messages/messages-by-chat-id-rpc
|
||||
|
@ -168,3 +170,32 @@
|
|||
{:db (assoc-in db [:pagination-info chat-id :messages-initialized?] now)
|
||||
:utils/dispatch-later [{:ms 500 :dispatch [:chat.ui/mark-all-read-pressed chat-id]}]}
|
||||
(load-more-messages chat-id true))))
|
||||
|
||||
(fx/defn load-message-context-2
|
||||
[{:keys [db]} chat-id message-id first-request]
|
||||
(when-let [session-id (get-in db [:pagination-info chat-id :messages-initialized?])]
|
||||
(when (and
|
||||
(not (get-in db [:pagination-info chat-id :all-loaded?]))
|
||||
(not (get-in db [:pagination-info chat-id :loading-messages?])))
|
||||
(let [cursor (get-in db [:pagination-info chat-id :cursor])]
|
||||
(when (or first-request cursor)
|
||||
(merge
|
||||
{:db
|
||||
(-> db
|
||||
(assoc :chats/initial-message-id message-id)
|
||||
(assoc-in [:pagination-info chat-id :loading-messages?] true))}
|
||||
(data-store.messages/message-context
|
||||
chat-id
|
||||
message-id
|
||||
constants/default-number-of-messages
|
||||
#(re-frame/dispatch [::messages-loaded chat-id session-id %])
|
||||
#(re-frame/dispatch [::failed-loading-messages chat-id session-id %]))))))))
|
||||
|
||||
(fx/defn load-message-context
|
||||
[{:keys [db now] :as cofx} chat-id message-id]
|
||||
(log/info "loading message context" chat-id message-id)
|
||||
(when-not (get-in db [:pagination-info chat-id :messages-initialized?])
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:pagination-info chat-id :messages-initialized?] now)
|
||||
:utils/dispatch-later [{:ms 500 :dispatch [:chat.ui/mark-all-read-pressed chat-id]}]}
|
||||
(load-message-context-2 chat-id message-id true))))
|
||||
|
|
|
@ -106,3 +106,14 @@
|
|||
|
||||
(fx/defn delete-messages-by-chat-id [cofx chat-id]
|
||||
(delete-messages-by-chat-id-rpc chat-id))
|
||||
|
||||
(defn message-context [chat-id
|
||||
message-id
|
||||
limit
|
||||
on-success
|
||||
on-failure]
|
||||
{::json-rpc/call [{:method (json-rpc/call-ext-method "messageContext")
|
||||
:params [{:chatId chat-id :limit limit :messageId message-id}]
|
||||
:on-success (fn [result]
|
||||
(on-success (update result :messages #(map <-rpc %))))
|
||||
:on-failure on-failure}]})
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
"waku_getSymKey" {}
|
||||
"waku_markTrustedPeer" {}
|
||||
"wakuext_post" {}
|
||||
"wakuext_messageContext" {}
|
||||
"wakuext_requestAllHistoricMessages" {}
|
||||
"wakuext_editMessage" {}
|
||||
"wakuext_deleteMessageAndSend" {}
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
"chat" {["/public/" :chat-id] :public-chat}
|
||||
"b/" browser-extractor
|
||||
"browser/" browser-extractor
|
||||
["m/" :chat-id "/" :message-id] :message
|
||||
["p/" :chat-id] :private-chat
|
||||
["cr/" :community-id] :community-requests
|
||||
["c/" :community-id] :community
|
||||
|
@ -217,6 +218,9 @@
|
|||
(= handler :community)
|
||||
(cb {:type handler :community-id (:community-id route-params)})
|
||||
|
||||
(= handler :message)
|
||||
(cb {:type handler :chat-id (:chat-id route-params) :message-id (:message-id route-params)})
|
||||
|
||||
(= handler :community-chat)
|
||||
(cb {:type handler :chat-id (:chat-id route-params)})
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
(reg-root-key-sub :bottom-sheet/show? :bottom-sheet/show?)
|
||||
(reg-root-key-sub :bottom-sheet/view :bottom-sheet/view)
|
||||
(reg-root-key-sub :bottom-sheet/options :bottom-sheet/options)
|
||||
(reg-root-key-sub :chats/initial-message-id :chats/initial-message-id)
|
||||
|
||||
;;general
|
||||
(reg-root-key-sub :sync-state :sync-state)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
[reagent.core :as reagent]
|
||||
[status-im.i18n.i18n :as i18n]
|
||||
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]
|
||||
[taoensso.timbre :as log]
|
||||
[quo.design-system.colors :as colors]
|
||||
[status-im.ui.components.connectivity.view :as connectivity]
|
||||
[status-im.ui.components.icons.icons :as icons]
|
||||
|
@ -295,6 +296,8 @@
|
|||
|
||||
|
||||
;; TODO: memoize
|
||||
|
||||
|
||||
(defn on-scroll-to-index-failed [^js e]
|
||||
(let [wait (js/Promise. (fn [resolve] (js/setTimeout resolve 50)))]
|
||||
(.then wait (fn []
|
||||
|
@ -302,11 +305,20 @@
|
|||
(.scrollToIndex @messages-list-ref
|
||||
#js {:index (.-index e)}))))))
|
||||
|
||||
|
||||
(defn get-index [messages initial-message-id]
|
||||
(let [i (->> messages
|
||||
(map-indexed vector)
|
||||
(filter (fn [[idx {:keys [message-id]}]]
|
||||
(when (= message-id initial-message-id)
|
||||
idx)))
|
||||
first)]
|
||||
(log/info "Scrolling to I" i)
|
||||
i))
|
||||
|
||||
(defn messages-view [{:keys [chat bottom-space pan-responder space-keeper show-input?]}]
|
||||
(let [{:keys [group-chat chat-id public? community-id admins]} chat
|
||||
messages @(re-frame/subscribe [:chats/chat-messages-stream chat-id])]
|
||||
messages @(re-frame/subscribe [:chats/chat-messages-stream chat-id])
|
||||
initial-message-id @(re-frame/subscribe [:chats/initial-message-id])]
|
||||
;;do not use anonymous functions for handlers
|
||||
(when (seq messages)
|
||||
[list/bidi-flat-list
|
||||
|
@ -330,7 +342,8 @@
|
|||
:on-viewable-items-changed on-viewable-items-changed
|
||||
:on-end-reached list-on-end-reached
|
||||
;; just to simulate initial position on the list
|
||||
:initial-scroll-index (quot (count messages) 2)
|
||||
:initial-scroll-index (when initial-message-id
|
||||
(get-index messages initial-message-id))
|
||||
:on-scroll-to-index-failed on-scroll-to-index-failed
|
||||
:content-container-style {:padding-top (+ bottom-space 16)
|
||||
:padding-bottom 16}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
(def links {:public-chat "%s/%s"
|
||||
:private-chat "%s/p/%s"
|
||||
:message "%s/m/%s/%s"
|
||||
:community-requests "%s/cr/%s"
|
||||
:community "%s/c/%s"
|
||||
:group-chat "%s/g/%s"
|
||||
|
@ -53,6 +54,12 @@
|
|||
(log/info "universal-links: handling group" params)
|
||||
(group-chats/create-from-link cofx params))
|
||||
|
||||
(fx/defn handle-message [{:keys [db] :as cofx} {:keys [chat-id message-id]}]
|
||||
(let [chat (get-in db [:chats chat-id])]
|
||||
(when chat
|
||||
(log/info "universal-links: handling message" chat-id message-id)
|
||||
(chat/navigate-to-chat-message cofx chat-id message-id false))))
|
||||
|
||||
(fx/defn handle-private-chat [{:keys [db] :as cofx} {:keys [chat-id]}]
|
||||
(log/info "universal-links: handling private chat" chat-id)
|
||||
(when chat-id
|
||||
|
@ -130,6 +137,7 @@
|
|||
:group-chat (handle-group-chat cofx data)
|
||||
:public-chat (handle-public-chat cofx data)
|
||||
:private-chat (handle-private-chat cofx data)
|
||||
:message (handle-message cofx data)
|
||||
:community-requests (handle-community-requests cofx data)
|
||||
:community (handle-community cofx data)
|
||||
:community-chat (handle-community-chat cofx data)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
||||
"owner": "status-im",
|
||||
"repo": "status-go",
|
||||
"version": "v0.89.11",
|
||||
"commit-sha1": "23308d7e8c4b7f5c85bffe870ba92010a3784dcb",
|
||||
"src-sha256": "0zlbzys7g1v3sr67l7fq85mhsk58gkplx8ci7lr5imk9cbciarlx"
|
||||
"version": "feature/pagination-both-sides",
|
||||
"commit-sha1": "0fa312e5b11b98c46c719fc175f3d7117105b826",
|
||||
"src-sha256": "1ccl6slayf1gjmlc4x1z32m5i5521vnaa1ngbdkjvxdkpl41n450"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue