Render chat by chat ID
- Upon logout, the chat-list-item component is reprocessed and the subscription returns a nil chat because the app-db state has been cleaned up. We fix the timestamp formatter to handle nil values and return a default string.
This commit is contained in:
parent
d5fa11a918
commit
edd50dfe18
|
@ -280,18 +280,31 @@
|
||||||
{:style (merge style/container {:margin-horizontal 0})}
|
{:style (merge style/container {:margin-horizontal 0})}
|
||||||
[chat-item item]])
|
[chat-item item]])
|
||||||
|
|
||||||
|
(defn- bottom-sheet-options
|
||||||
|
[chat-id chat-type]
|
||||||
|
(cond-> {:content (fn []
|
||||||
|
(let [chat (rf/sub [:chats/chat-by-id chat-id])]
|
||||||
|
[actions/chat-actions chat false]))}
|
||||||
|
(= chat-type constants/one-to-one-chat-type)
|
||||||
|
(assoc :selected-item
|
||||||
|
(fn []
|
||||||
|
(let [chat (rf/sub [:chats/chat-by-id chat-id])]
|
||||||
|
[chat-user chat])))))
|
||||||
|
|
||||||
(defn chat-list-item
|
(defn chat-list-item
|
||||||
[{:keys [chat-id chat-type]
|
[{:keys [chat-id]}]
|
||||||
:as item}]
|
(let [{:keys [chat-type]
|
||||||
(let [customization-color (rf/sub [:profile/customization-color])
|
:as chat} (rf/sub [:chats/chat-by-id chat-id])
|
||||||
theme (quo.theme/use-theme)]
|
customization-color (rf/sub [:profile/customization-color])
|
||||||
|
theme (quo.theme/use-theme)
|
||||||
|
on-long-press (rn/use-callback
|
||||||
|
(fn []
|
||||||
|
(rf/dispatch [:show-bottom-sheet
|
||||||
|
(bottom-sheet-options chat-id chat-type)]))
|
||||||
|
[chat-id chat-type])]
|
||||||
[rn/touchable-highlight
|
[rn/touchable-highlight
|
||||||
{:style style/container
|
{:style style/container
|
||||||
:on-press (open-chat chat-id)
|
:on-press (open-chat chat-id)
|
||||||
:underlay-color (colors/resolve-color customization-color theme 5)
|
:underlay-color (colors/resolve-color customization-color theme 5)
|
||||||
:on-long-press #(rf/dispatch [:show-bottom-sheet
|
:on-long-press on-long-press}
|
||||||
(cond-> {:content (fn [] [actions/chat-actions item false])}
|
[chat-item chat]]))
|
||||||
(= chat-type constants/one-to-one-chat-type)
|
|
||||||
(assoc :selected-item
|
|
||||||
(fn [] [chat-user item])))])}
|
|
||||||
[chat-item item]]))
|
|
||||||
|
|
|
@ -23,12 +23,10 @@
|
||||||
[_ index]
|
[_ index]
|
||||||
#js {:length 56 :offset (* 56 index) :index index})
|
#js {:length 56 :offset (* 56 index) :index index})
|
||||||
|
|
||||||
(defn filter-and-sort-items-by-tab
|
(defn filter-by-tab
|
||||||
[tab items]
|
[tab items]
|
||||||
(let [k (if (= tab :tab/groups) :group-chat :chat-id)]
|
(let [k (if (= tab :tab/groups) :group-chat :chat-id)]
|
||||||
(->> items
|
(filter k items)))
|
||||||
(filter k)
|
|
||||||
(sort-by :timestamp >))))
|
|
||||||
|
|
||||||
(defn empty-state-content
|
(defn empty-state-content
|
||||||
[theme]
|
[theme]
|
||||||
|
@ -56,7 +54,7 @@
|
||||||
(defn chats
|
(defn chats
|
||||||
[{:keys [theme selected-tab set-scroll-ref scroll-shared-value]}]
|
[{:keys [theme selected-tab set-scroll-ref scroll-shared-value]}]
|
||||||
(let [unfiltered-items (rf/sub [:chats/chats-stack-items])
|
(let [unfiltered-items (rf/sub [:chats/chats-stack-items])
|
||||||
items (filter-and-sort-items-by-tab selected-tab unfiltered-items)
|
items (filter-by-tab selected-tab unfiltered-items)
|
||||||
on-scroll (rn/use-callback
|
on-scroll (rn/use-callback
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(common.banner/set-scroll-shared-value
|
(common.banner/set-scroll-shared-value
|
||||||
|
|
|
@ -53,22 +53,18 @@
|
||||||
(fn [[{:keys [chats]}] [_ community-id chat-id]]
|
(fn [[{:keys [chats]}] [_ community-id chat-id]]
|
||||||
(get chats (string/replace chat-id community-id ""))))
|
(get chats (string/replace chat-id community-id ""))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub :chats/home-list-chats
|
||||||
:chats/home-list-chats
|
|
||||||
:<- [:chats/chats]
|
:<- [:chats/chats]
|
||||||
:<- [:chats-home-list]
|
:<- [:chats-home-list]
|
||||||
:<- [:multiaccount/public-key]
|
(fn [[chats active-chats-ids]]
|
||||||
(fn [[chats active-chats my-public-key]]
|
(->> active-chats-ids
|
||||||
(reduce #(if-let [item (get chats %2)]
|
(keep #(get chats %))
|
||||||
(let [group-chat-member? (and (chat.events/group-chat? item)
|
(sort-by :timestamp >)
|
||||||
(group-chats.db/member? my-public-key item))]
|
(map (fn [{:keys [chat-id id public-key group-chat]}]
|
||||||
(conj %1
|
{:chat-id chat-id
|
||||||
(assoc item
|
:group-chat group-chat
|
||||||
:group-chat-member?
|
:id id
|
||||||
group-chat-member?)))
|
:public-key public-key})))))
|
||||||
%1)
|
|
||||||
[]
|
|
||||||
active-chats)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:chats/chat-by-id
|
:chats/chat-by-id
|
||||||
|
|
|
@ -160,15 +160,16 @@
|
||||||
;;;; Timestamp formatters
|
;;;; Timestamp formatters
|
||||||
(defn- to-str
|
(defn- to-str
|
||||||
[ms old-fmt-fn yesterday-fmt-fn today-fmt-fn]
|
[ms old-fmt-fn yesterday-fmt-fn today-fmt-fn]
|
||||||
(let [date (t.coerce/from-long ms)
|
(if-let [date (t.coerce/from-long ms)]
|
||||||
;; NOTE(edge-case): this is wrong, it uses the current timezone offset, regardless of DST.
|
(let [;; NOTE(edge-case): this is wrong, it uses the current timezone offset, regardless of DST.
|
||||||
local (t/plus date time-zone-offset)
|
local (t/plus date time-zone-offset)
|
||||||
today (t/minus (t/today-at-midnight) time-zone-offset)
|
today (t/minus (t/today-at-midnight) time-zone-offset)
|
||||||
yesterday (t/plus today (t/days -1))]
|
yesterday (t/plus today (t/days -1))]
|
||||||
(cond
|
(cond
|
||||||
(t/before? date yesterday) (old-fmt-fn local)
|
(t/before? date yesterday) (old-fmt-fn local)
|
||||||
(t/before? date today) (yesterday-fmt-fn local)
|
(t/before? date today) (yesterday-fmt-fn local)
|
||||||
:else (today-fmt-fn local))))
|
:else (today-fmt-fn local)))
|
||||||
|
""))
|
||||||
|
|
||||||
(defn to-short-str
|
(defn to-short-str
|
||||||
[ms]
|
[ms]
|
||||||
|
|
Loading…
Reference in New Issue