Fix mark as read for hidden messages

If a message is hidden and is not currently loaded, it will not be
marked as read, resulting in the count being always positive. To avoid this
we always mark it as read, and from the backend we return whether it has
been marked as read or was already seen.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2020-04-06 17:56:07 +02:00
parent a914334fed
commit c2d129d04e
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
5 changed files with 21 additions and 17 deletions

View File

@ -228,7 +228,7 @@
true))
db
loaded-unviewed-ids)}
(messages-store/mark-messages-seen chat-id loaded-unviewed-ids)
(messages-store/mark-messages-seen chat-id loaded-unviewed-ids nil)
(update-chats-unviewed-messages-count {:chat-id chat-id})
(when platform/desktop?
(update-dock-badge-label))))))

View File

@ -64,17 +64,19 @@
{:db (assoc-in db [:chats chat-id :message-list]
(message-list/add-many nil (vals (get-in db [:chats chat-id :messages]))))})
(fx/defn hidden-message-marked-as-seen
{:events [::hidden-message-marked-as-seen]}
[{:keys [db] :as cofx} chat-id _ hidden-message-count]
(when (= 1 hidden-message-count)
{:db (update-in db [:chats chat-id]
update
:unviewed-messages-count dec)}))
(fx/defn hide-message
"Hide chat message, rebuild message-list"
[{:keys [db] :as cofx} chat-id {:keys [seen message-id]}]
(fx/merge cofx
{:db (update-in db [:chats chat-id :messages] dissoc message-id)}
#(when (not seen)
(fx/merge %
{:db (update-in db [:chats chat-id]
update
:unviewed-messages-count dec)}
(data-store.messages/mark-messages-seen chat-id [message-id])))
{:db (update-in db [:chats chat-id :messages] dissoc message-id)}
(data-store.messages/mark-messages-seen chat-id [message-id] #(re-frame/dispatch [::hidden-message-marked-as-seen %1 %2 %3]))
(rebuild-message-list chat-id)))
(fx/defn add-message
@ -175,7 +177,7 @@
(and chat-view? (= current-chat-id chat-id))
(fx/merge cofx
(data-store.messages/mark-messages-seen current-chat-id [message-id]))
(data-store.messages/mark-messages-seen current-chat-id [message-id] nil))
:else
{:db (update-in db [:chats chat-id]

View File

@ -65,10 +65,12 @@
(on-success (update result :messages #(map <-rpc %))))
:on-failure on-failure}]})
(defn mark-seen-rpc [waku-enabled? chat-id ids]
(defn mark-seen-rpc [waku-enabled? chat-id ids on-success]
{::json-rpc/call [{:method (json-rpc/call-ext-method waku-enabled? "markMessagesSeen")
:params [chat-id ids]
:on-success #(log/debug "successfully marked as seen")
:on-success #(do
(log/debug "successfully marked as seen" %)
(when on-success (on-success chat-id ids %)))
:on-failure #(log/error "failed to get messages" %)}]})
(defn delete-message-rpc [waku-enabled? id]
@ -95,8 +97,8 @@
(fx/defn delete-messages-from [cofx author]
(delete-messages-from-rpc (waku/enabled? cofx) author))
(fx/defn mark-messages-seen [cofx chat-id ids]
(mark-seen-rpc (waku/enabled? cofx) chat-id ids))
(fx/defn mark-messages-seen [cofx chat-id ids on-success]
(mark-seen-rpc (waku/enabled? cofx) chat-id ids on-success))
(fx/defn update-outgoing-status [cofx message-id status]
(update-outgoing-status-rpc (waku/enabled? cofx) message-id status))

View File

@ -168,4 +168,4 @@
(re-frame/dispatch [:chat.ui/send-current-message])
(set-text ""))]
[send-button/send-button-view {:input-text input-text}
#(re-frame/dispatch [:chat.ui/send-current-message])]))]])))
#(re-frame/dispatch [:chat.ui/send-current-message])]))]])))

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.50.2",
"commit-sha1": "44272944abeb3c32cc0ca6b089e783cb530037d4",
"src-sha256": "1n6fsqnxpbn5srdxg37iqpw57xipfxan3sh35aa3vg8y9dhns1cn"
"version": "v0.51.0",
"commit-sha1": "3c5354280c3e117d75d5d44c41b6f962adf9c829",
"src-sha256": "1f3pfci04z3l6rd8qwcbv2knc1fnpjxmhp2p4wkng6ml6pilg2vi"
}