[#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:
Roman Volosovskyi 2018-12-25 18:24:50 +02:00
parent 768da1a5f0
commit 15747558fa
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
9 changed files with 66 additions and 43 deletions

View File

@ -103,7 +103,7 @@
{:messages empty-message-map
:message-groups {}
:last-message-content nil
:last-message-type nil
:last-message-content-type nil
:unviewed-messages-count 0
:deleted-at-clock-value last-message-clock-value})
:data-store/tx [(chats-store/clear-history-tx chat-id last-message-clock-value)

View File

@ -276,7 +276,7 @@
(defn- update-last-message [all-chats chat-id]
(let [{:keys [messages message-groups]}
(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)
first
second
@ -286,7 +286,7 @@
(chat-model/upsert-chat
{:chat-id chat-id
:last-message-content content
:last-message-type message-type
:last-message-content-type content-type
:last-clock-value clock-value})))
(fx/defn update-last-messages
@ -380,7 +380,7 @@
{:chat-id chat-id
:timestamp now
:last-message-content (:content message)
:last-message-type (:message-type message)
:last-message-content-type (:content-type message)
:last-clock-value (:clock-value message)})
(add-message {:batch? false
:message message-with-id

View File

@ -54,7 +54,6 @@
(update :tags #(into #{} %))
(update :membership-updates (partial unmarshal-membership-updates chat-id))
(update :last-clock-value utils.clocks/safe-timestamp)
(update :last-message-type keyword)
(update :last-message-content utils/safe-read-message-content)))
(re-frame/reg-cofx
@ -95,7 +94,7 @@
(let [chat (get-chat-by-id chat-id realm)]
(doto chat
(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)))))
(defn deactivate-chat-tx

View File

@ -235,3 +235,11 @@
(update v10 :properties merge
{:last-clock-value {:type :int
:optional true}}))
(def v12
(-> v11
(update :properties merge
{:last-message-content-type
{:type :string
:optional true}})
(update :properties dissoc :last-message-type)))

View File

@ -317,6 +317,19 @@
browser/v8
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
(def schemas [{:schema v1
:schemaVersion 1
@ -404,4 +417,7 @@
:migration migrations/v28}
{:schema v29
:schemaVersion 29
:migration migrations/v29}])
:migration migrations/v29}
{:schema v30
:schemaVersion 30
:migration migrations/v30}])

View File

@ -307,16 +307,7 @@
(.sorted "timestamp" true)
(aget 0)))
(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 v28 [old-realm new-realm])
(defn get-last-clock-value [realm chat-id]
(if-let [last-message
@ -337,3 +328,14 @@
chat-id (aget chat "chat-id")]
(when-let [last-clock-value (get-last-clock-value new-realm chat-id)]
(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)))))))

View File

@ -23,7 +23,7 @@
color public? public-key
timestamp
last-message-content
last-message-type]
last-message-content-type]
:as chat-item}]
(views/letsubs [photo-path [:contacts/chat-photo chat-id]
unviewed-messages-count [:chats/unviewed-messages-count chat-id]
@ -31,7 +31,7 @@
current-chat-id [:chats/current-chat-id]]
(let [last-message {:content last-message-content
:timestamp timestamp
:message-type last-message-type}
:content-type last-message-content-type}
name (or chat-name
(gfycat/generate-gfy public-key))
[unviewed-messages-label large?] [(utils/unread-messages-count unviewed-messages-count) true]

View File

@ -90,7 +90,7 @@
public-key
timestamp
last-message-content
last-message-type]}]
last-message-content-type]}]
(letsubs [chat-name [:chats/chat-name chat-id]]
(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])}
@ -104,7 +104,7 @@
[message-timestamp timestamp]]]
[react/view styles/item-lower-container
[message-content-text {:content last-message-content
:content-type last-message-type}]
:content-type last-message-content-type}]
[unviewed-indicator chat-id]]]]])))
(defn home-list-browser-item-inner-view [{:keys [dapp url name browser-id] :as browser}]

View File

@ -9,13 +9,11 @@
:contacts #{2}
:tags #{}
:membership-updates []
:last-message-type :message-type
:last-message-content {:foo "bar"}
:last-clock-value nil}
(chats/normalize-chat
{:admins [4]
:contacts [2]
:last-message-type "message-type"
:last-message-content "{:foo \"bar\"}"}))))
(testing "membership-updates"
(let [raw-events {"1" {:id "1" :type "members-added" :clock-value 10 :members [1 2] :signature "a" :from "id-1"}