[#12684] Messages disappear from Timeline if join public chat and open Timeline tab while public chat history is loading

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-10-06 13:45:39 +02:00
parent a9333ad52c
commit 8d0bdf7c7f
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
3 changed files with 36 additions and 47 deletions

View File

@ -187,10 +187,12 @@
(fx/defn offload-messages (fx/defn offload-messages
{:events [:offload-messages]} {:events [:offload-messages]}
[{:keys [db]} chat-id] [{:keys [db]} chat-id]
{:db (-> db (merge {:db (-> db
(update :messages dissoc chat-id) (update :messages dissoc chat-id)
(update :message-lists dissoc chat-id) (update :message-lists dissoc chat-id)
(update :pagination-info dissoc chat-id))}) (update :pagination-info dissoc chat-id))}
(when (and (= chat-id constants/timeline-chat-id) (= (:view-id db) :status))
{:dispatch [:init-timeline-chat]})))
(fx/defn close-chat (fx/defn close-chat
{:events [:close-chat]} {:events [:close-chat]}

View File

@ -39,27 +39,37 @@
(fx/defn ensure-contacts (fx/defn ensure-contacts
[{:keys [db]} contacts chats] [{:keys [db]} contacts chats]
{:db (update db :contacts/contacts (let [events
#(reduce (fn [acc {:keys [public-key] :as contact}] (reduce
(-> acc (fn [acc {:keys [public-key] :as contact}]
(update public-key merge contact) (let [added (:added contact)
(assoc-in [public-key :nickname] (:nickname contact)))) was-added (contact.db/added? db public-key)
% blocked (:blocked contact)
contacts)) was-blocked (contact.db/blocked? db public-key)]
:dispatch-n (mapcat (fn [{:keys [public-key] :as contact}] (cond-> acc
(cond-> [] (and added (not was-added))
(:added contact) (conj [:start-profile-chat public-key])
(conj [:start-profile-chat public-key])
(not (:added contact)) (and was-added (not added))
(conj [:offload-messages constants/timeline-chat-id]) (conj nil)
(:blocked contact) (and blocked (not was-blocked))
(conj [::contact.block/contact-blocked contact chats]) (conj [::contact.block/contact-blocked contact chats])
(contact.db/blocked? db public-key) (and was-blocked (not blocked))
(conj [::contact.block/contact-unblocked public-key]))) (conj [::contact.block/contact-unblocked public-key]))))
contacts)}) [[:offload-messages constants/timeline-chat-id]]
contacts)]
(merge
{:db (update db :contacts/contacts
#(reduce (fn [acc {:keys [public-key] :as contact}]
(-> acc
(update public-key merge contact)
(assoc-in [public-key :nickname] (:nickname contact))))
%
contacts))}
(when (> (count events) 1)
{:dispatch-n events}))))
(fx/defn upsert-contact (fx/defn upsert-contact
[{:keys [db] :as cofx} [{:keys [db] :as cofx}

View File

@ -73,8 +73,8 @@
(get-in db [:contacts/contacts public-key])) (get-in db [:contacts/contacts public-key]))
(defn added? (defn added?
([{:keys [system-tags]}] ([contact]
(contains? system-tags :contact/added)) (:added contact))
([db public-key] ([db public-key]
(added? (get-in db [:contacts/contacts public-key])))) (added? (get-in db [:contacts/contacts public-key]))))
@ -84,29 +84,6 @@
([db public-key] ([db public-key]
(blocked? (get-in db [:contacts/contacts public-key])))) (blocked? (get-in db [:contacts/contacts public-key]))))
(defn pending?
"Check if this is a pending? contact, meaning one side sent a contact request
but the other didn't respond to it yet"
([{:keys [system-tags] :as contact}]
(let [request-received? (contains? system-tags :contact/request-received)
added? (added? contact)]
(and (or request-received?
added?)
(not (and request-received? added?)))))
([db public-key]
(pending? (get-in db [:contacts/contacts public-key]))))
(defn legacy-pending?
"Would the :pending? field be true? for contacts sync payload sent to devices
running 0.11.0 or older?"
([{:keys [system-tags] :as contact}]
(let [request-received? (contains? system-tags :contact/request-received)
added? (added? contact)]
(and request-received?
(not added?))))
([db public-key]
(pending? (get-in db [:contacts/contacts public-key]))))
(defn active? (defn active?
"Checks that the user is added to the contact and not blocked" "Checks that the user is added to the contact and not blocked"
([contact] ([contact]