[#7179] Fix command message preview in the list of chats
The bug was introduced in #7055. `message-type` was stored and used instead of `content-type` which caused incorrect displaying of the last message preview if the one was a command.
This commit is contained in:
parent
768da1a5f0
commit
15747558fa
|
@ -100,12 +100,12 @@
|
||||||
deleted-at-clock-value
|
deleted-at-clock-value
|
||||||
(utils.clocks/send 0))]
|
(utils.clocks/send 0))]
|
||||||
{:db (update-in db [:chats chat-id] merge
|
{:db (update-in db [:chats chat-id] merge
|
||||||
{:messages empty-message-map
|
{:messages empty-message-map
|
||||||
:message-groups {}
|
:message-groups {}
|
||||||
:last-message-content nil
|
:last-message-content nil
|
||||||
:last-message-type nil
|
:last-message-content-type nil
|
||||||
:unviewed-messages-count 0
|
:unviewed-messages-count 0
|
||||||
:deleted-at-clock-value last-message-clock-value})
|
:deleted-at-clock-value last-message-clock-value})
|
||||||
:data-store/tx [(chats-store/clear-history-tx chat-id last-message-clock-value)
|
:data-store/tx [(chats-store/clear-history-tx chat-id last-message-clock-value)
|
||||||
(messages-store/delete-messages-tx chat-id)]}))
|
(messages-store/delete-messages-tx chat-id)]}))
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,7 @@
|
||||||
(defn- update-last-message [all-chats chat-id]
|
(defn- update-last-message [all-chats chat-id]
|
||||||
(let [{:keys [messages message-groups]}
|
(let [{:keys [messages message-groups]}
|
||||||
(get all-chats chat-id)
|
(get all-chats chat-id)
|
||||||
{:keys [content message-type clock-value]}
|
{:keys [content content-type clock-value]}
|
||||||
(->> (chat.db/sort-message-groups message-groups messages)
|
(->> (chat.db/sort-message-groups message-groups messages)
|
||||||
first
|
first
|
||||||
second
|
second
|
||||||
|
@ -284,10 +284,10 @@
|
||||||
:message-id
|
:message-id
|
||||||
(get messages))]
|
(get messages))]
|
||||||
(chat-model/upsert-chat
|
(chat-model/upsert-chat
|
||||||
{:chat-id chat-id
|
{:chat-id chat-id
|
||||||
:last-message-content content
|
:last-message-content content
|
||||||
:last-message-type message-type
|
:last-message-content-type content-type
|
||||||
:last-clock-value clock-value})))
|
:last-clock-value clock-value})))
|
||||||
|
|
||||||
(fx/defn update-last-messages
|
(fx/defn update-last-messages
|
||||||
[{:keys [db] :as cofx} chat-ids]
|
[{:keys [db] :as cofx} chat-ids]
|
||||||
|
@ -377,11 +377,11 @@
|
||||||
|
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
(chat-model/upsert-chat
|
(chat-model/upsert-chat
|
||||||
{:chat-id chat-id
|
{:chat-id chat-id
|
||||||
:timestamp now
|
:timestamp now
|
||||||
:last-message-content (:content message)
|
:last-message-content (:content message)
|
||||||
:last-message-type (:message-type message)
|
:last-message-content-type (:content-type message)
|
||||||
:last-clock-value (:clock-value message)})
|
:last-clock-value (:clock-value message)})
|
||||||
(add-message {:batch? false
|
(add-message {:batch? false
|
||||||
:message message-with-id
|
:message message-with-id
|
||||||
:current-chat? true
|
:current-chat? true
|
||||||
|
|
|
@ -54,7 +54,6 @@
|
||||||
(update :tags #(into #{} %))
|
(update :tags #(into #{} %))
|
||||||
(update :membership-updates (partial unmarshal-membership-updates chat-id))
|
(update :membership-updates (partial unmarshal-membership-updates chat-id))
|
||||||
(update :last-clock-value utils.clocks/safe-timestamp)
|
(update :last-clock-value utils.clocks/safe-timestamp)
|
||||||
(update :last-message-type keyword)
|
|
||||||
(update :last-message-content utils/safe-read-message-content)))
|
(update :last-message-content utils/safe-read-message-content)))
|
||||||
|
|
||||||
(re-frame/reg-cofx
|
(re-frame/reg-cofx
|
||||||
|
@ -95,7 +94,7 @@
|
||||||
(let [chat (get-chat-by-id chat-id realm)]
|
(let [chat (get-chat-by-id chat-id realm)]
|
||||||
(doto chat
|
(doto chat
|
||||||
(aset "last-message-content" nil)
|
(aset "last-message-content" nil)
|
||||||
(aset "last-message-type" nil)
|
(aset "last-message-content-type" nil)
|
||||||
(aset "deleted-at-clock-value" deleted-at-clock-value)))))
|
(aset "deleted-at-clock-value" deleted-at-clock-value)))))
|
||||||
|
|
||||||
(defn deactivate-chat-tx
|
(defn deactivate-chat-tx
|
||||||
|
|
|
@ -235,3 +235,11 @@
|
||||||
(update v10 :properties merge
|
(update v10 :properties merge
|
||||||
{:last-clock-value {:type :int
|
{:last-clock-value {:type :int
|
||||||
:optional true}}))
|
:optional true}}))
|
||||||
|
|
||||||
|
(def v12
|
||||||
|
(-> v11
|
||||||
|
(update :properties merge
|
||||||
|
{:last-message-content-type
|
||||||
|
{:type :string
|
||||||
|
:optional true}})
|
||||||
|
(update :properties dissoc :last-message-type)))
|
||||||
|
|
|
@ -317,6 +317,19 @@
|
||||||
browser/v8
|
browser/v8
|
||||||
dapp-permissions/v9])
|
dapp-permissions/v9])
|
||||||
|
|
||||||
|
(def v30 [chat/v12
|
||||||
|
transport/v7
|
||||||
|
contact/v3
|
||||||
|
message/v9
|
||||||
|
mailserver/v11
|
||||||
|
mailserver-topic/v1
|
||||||
|
user-status/v2
|
||||||
|
membership-update/v1
|
||||||
|
installation/v2
|
||||||
|
local-storage/v1
|
||||||
|
browser/v8
|
||||||
|
dapp-permissions/v9])
|
||||||
|
|
||||||
;; put schemas ordered by version
|
;; put schemas ordered by version
|
||||||
(def schemas [{:schema v1
|
(def schemas [{:schema v1
|
||||||
:schemaVersion 1
|
:schemaVersion 1
|
||||||
|
@ -404,4 +417,7 @@
|
||||||
:migration migrations/v28}
|
:migration migrations/v28}
|
||||||
{:schema v29
|
{:schema v29
|
||||||
:schemaVersion 29
|
:schemaVersion 29
|
||||||
:migration migrations/v29}])
|
:migration migrations/v29}
|
||||||
|
{:schema v30
|
||||||
|
:schemaVersion 30
|
||||||
|
:migration migrations/v30}])
|
||||||
|
|
|
@ -307,16 +307,7 @@
|
||||||
(.sorted "timestamp" true)
|
(.sorted "timestamp" true)
|
||||||
(aget 0)))
|
(aget 0)))
|
||||||
|
|
||||||
(defn v28 [old-realm new-realm]
|
(defn v28 [old-realm new-realm])
|
||||||
(let [chats (.objects new-realm "chat")]
|
|
||||||
(dotimes [i (.-length chats)]
|
|
||||||
(let [chat (aget chats i)
|
|
||||||
chat-id (aget chat "chat-id")]
|
|
||||||
(when-let [last-message (get-last-message new-realm chat-id)]
|
|
||||||
(let [content (aget last-message "content")
|
|
||||||
message-type (aget last-message "message-type")]
|
|
||||||
(aset chat "last-message-content" content)
|
|
||||||
(aset chat "last-message-type" message-type)))))))
|
|
||||||
|
|
||||||
(defn get-last-clock-value [realm chat-id]
|
(defn get-last-clock-value [realm chat-id]
|
||||||
(if-let [last-message
|
(if-let [last-message
|
||||||
|
@ -337,3 +328,14 @@
|
||||||
chat-id (aget chat "chat-id")]
|
chat-id (aget chat "chat-id")]
|
||||||
(when-let [last-clock-value (get-last-clock-value new-realm chat-id)]
|
(when-let [last-clock-value (get-last-clock-value new-realm chat-id)]
|
||||||
(aset chat "last-clock-value" last-clock-value))))))
|
(aset chat "last-clock-value" last-clock-value))))))
|
||||||
|
|
||||||
|
(defn v30 [old-realm new-realm]
|
||||||
|
(let [chats (.objects new-realm "chat")]
|
||||||
|
(dotimes [i (.-length chats)]
|
||||||
|
(let [chat (aget chats i)
|
||||||
|
chat-id (aget chat "chat-id")]
|
||||||
|
(when-let [last-message (get-last-message new-realm chat-id)]
|
||||||
|
(let [content (aget last-message "content")
|
||||||
|
content-type (aget last-message "content-type")]
|
||||||
|
(aset chat "last-message-content" content)
|
||||||
|
(aset chat "last-message-content-type" content-type)))))))
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
color public? public-key
|
color public? public-key
|
||||||
timestamp
|
timestamp
|
||||||
last-message-content
|
last-message-content
|
||||||
last-message-type]
|
last-message-content-type]
|
||||||
:as chat-item}]
|
:as chat-item}]
|
||||||
(views/letsubs [photo-path [:contacts/chat-photo chat-id]
|
(views/letsubs [photo-path [:contacts/chat-photo chat-id]
|
||||||
unviewed-messages-count [:chats/unviewed-messages-count chat-id]
|
unviewed-messages-count [:chats/unviewed-messages-count chat-id]
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
current-chat-id [:chats/current-chat-id]]
|
current-chat-id [:chats/current-chat-id]]
|
||||||
(let [last-message {:content last-message-content
|
(let [last-message {:content last-message-content
|
||||||
:timestamp timestamp
|
:timestamp timestamp
|
||||||
:message-type last-message-type}
|
:content-type last-message-content-type}
|
||||||
name (or chat-name
|
name (or chat-name
|
||||||
(gfycat/generate-gfy public-key))
|
(gfycat/generate-gfy public-key))
|
||||||
[unviewed-messages-label large?] [(utils/unread-messages-count unviewed-messages-count) true]
|
[unviewed-messages-label large?] [(utils/unread-messages-count unviewed-messages-count) true]
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
public-key
|
public-key
|
||||||
timestamp
|
timestamp
|
||||||
last-message-content
|
last-message-content
|
||||||
last-message-type]}]
|
last-message-content-type]}]
|
||||||
(letsubs [chat-name [:chats/chat-name chat-id]]
|
(letsubs [chat-name [:chats/chat-name chat-id]]
|
||||||
(let [truncated-chat-name (utils/truncate-str chat-name 30)]
|
(let [truncated-chat-name (utils/truncate-str chat-name 30)]
|
||||||
[react/touchable-highlight {:on-press #(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id])}
|
[react/touchable-highlight {:on-press #(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id])}
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
[message-timestamp timestamp]]]
|
[message-timestamp timestamp]]]
|
||||||
[react/view styles/item-lower-container
|
[react/view styles/item-lower-container
|
||||||
[message-content-text {:content last-message-content
|
[message-content-text {:content last-message-content
|
||||||
:content-type last-message-type}]
|
:content-type last-message-content-type}]
|
||||||
[unviewed-indicator chat-id]]]]])))
|
[unviewed-indicator chat-id]]]]])))
|
||||||
|
|
||||||
(defn home-list-browser-item-inner-view [{:keys [dapp url name browser-id] :as browser}]
|
(defn home-list-browser-item-inner-view [{:keys [dapp url name browser-id] :as browser}]
|
||||||
|
|
|
@ -5,17 +5,15 @@
|
||||||
|
|
||||||
(deftest normalize-chat-test
|
(deftest normalize-chat-test
|
||||||
(testing "admins & contacts"
|
(testing "admins & contacts"
|
||||||
(is (= {:admins #{4}
|
(is (= {:admins #{4}
|
||||||
:contacts #{2}
|
:contacts #{2}
|
||||||
:tags #{}
|
:tags #{}
|
||||||
:membership-updates []
|
:membership-updates []
|
||||||
:last-message-type :message-type
|
:last-message-content {:foo "bar"}
|
||||||
:last-message-content {:foo "bar"}
|
:last-clock-value nil}
|
||||||
:last-clock-value nil}
|
|
||||||
(chats/normalize-chat
|
(chats/normalize-chat
|
||||||
{:admins [4]
|
{:admins [4]
|
||||||
:contacts [2]
|
:contacts [2]
|
||||||
:last-message-type "message-type"
|
|
||||||
:last-message-content "{:foo \"bar\"}"}))))
|
:last-message-content "{:foo \"bar\"}"}))))
|
||||||
(testing "membership-updates"
|
(testing "membership-updates"
|
||||||
(let [raw-events {"1" {:id "1" :type "members-added" :clock-value 10 :members [1 2] :signature "a" :from "id-1"}
|
(let [raw-events {"1" {:id "1" :type "members-added" :clock-value 10 :members [1 2] :signature "a" :from "id-1"}
|
||||||
|
|
Loading…
Reference in New Issue