From 733f2b193f2d7648f0ff31594a9424208d81f741 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Thu, 3 May 2018 20:20:56 +0200 Subject: [PATCH] dont send seen for public messages and remove checkmark --- src/status_im/chat/events.cljs | 17 ++++----- src/status_im/chat/models/message.cljs | 4 ++- .../ui/screens/home/views/inner_item.cljs | 16 ++------- .../status_im/test/chat/models/message.cljs | 35 +++++++++++++++++++ 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/status_im/chat/events.cljs b/src/status_im/chat/events.cljs index 98d2603ec1..96c4e31e82 100644 --- a/src/status_im/chat/events.cljs +++ b/src/status_im/chat/events.cljs @@ -212,7 +212,8 @@ unseen-messages-ids)}) (defn- send-messages-seen [chat-id message-ids {:keys [db] :as cofx}] - (when (and (seq message-ids) + (when (and (not (get-in db [:chats chat-id :public?])) + (seq message-ids) (not (models/bot-only-chat? db chat-id))) (transport.message/send (protocol/map->MessagesSeen {:message-ids message-ids}) chat-id cofx))) @@ -237,13 +238,13 @@ (when (or (seq unseen-messages-ids) (seq unseen-system-messages-ids)) (handlers-macro/merge-fx cofx - {:db (-> (reduce (fn [new-db message-id] - (assoc-in new-db (into messages-path [message-id :user-statuses me]) :seen)) - db - (into unseen-messages-ids unseen-system-messages-ids)) - (update-in [:chats chat-id :unviewed-messages] set/difference unseen-messages-ids unseen-system-messages-ids))} - (persist-seen-messages chat-id (into unseen-messages-ids unseen-system-messages-ids)) - (send-messages-seen chat-id unseen-messages-ids))))) + {:db (-> (reduce (fn [new-db message-id] + (assoc-in new-db (into messages-path [message-id :user-statuses me]) :seen)) + db + (into unseen-messages-ids unseen-system-messages-ids)) + (update-in [:chats chat-id :unviewed-messages] set/difference unseen-messages-ids unseen-system-messages-ids))} + (persist-seen-messages chat-id (into unseen-messages-ids unseen-system-messages-ids)) + (send-messages-seen chat-id unseen-messages-ids))))) (defn- fire-off-chat-loaded-event [chat-id {:keys [db]}] diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index cb0e4bd600..a9c493f43c 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -65,7 +65,8 @@ :contacts/keys [contacts]} db {:keys [public-key] :as current-account} (:account/account db) current-chat? (and (= :chat view-id) (= current-chat-id chat-id)) - {:keys [last-clock-value] :as chat} (get-in db [:chats chat-id]) + {:keys [last-clock-value + public?] :as chat} (get-in db [:chats chat-id]) request-command (:request-command content) command-request? (and (= content-type constants/content-type-command-request) request-command) @@ -86,6 +87,7 @@ current-account chat contacts request-command))) current-chat?) (send-message-seen chat-id message-id (and public-key + (not public?) current-chat? (not (chat-model/bot-only-chat? db chat-id)) (not (= constants/system from))))))) diff --git a/src/status_im/ui/screens/home/views/inner_item.cljs b/src/status_im/ui/screens/home/views/inner_item.cljs index 5c32a43808..ee1952943e 100644 --- a/src/status_im/ui/screens/home/views/inner_item.cljs +++ b/src/status_im/ui/screens/home/views/inner_item.cljs @@ -44,17 +44,6 @@ :accessibility-label :chat-message-text} content])]) -(defview message-status [{:keys [chat-id contacts]} - {:keys [message-id user-statuses outgoing] :as msg}] - (letsubs [current-public-key [:get-current-public-key]] - (let [delivery-statuses (dissoc user-statuses current-public-key) - seen-by-everyone (and (= (count delivery-statuses) (count contacts) - (every? (comp (partial = :seen) second) - delivery-statuses)))] - (when (and outgoing (or (= chat-id const/console-chat-id) - seen-by-everyone)) - [vector-icons/icon :icons/ok {:style styles/status-image}])))) - (defn message-timestamp [{:keys [timestamp]}] (when timestamp [react/text {:style styles/datetime-text @@ -90,8 +79,8 @@ chat-name)]]])) (defview home-list-chat-item-inner-view [{:keys [chat-id name color online - group-chat contacts public? - public-key unremovable? :as chat]}] + group-chat public? + public-key]}] (letsubs [last-message [:get-last-message chat-id]] (let [name (or (i18n/get-contact-translated chat-id :name name) (gfycat/generate-gfy public-key)) @@ -105,7 +94,6 @@ [chat-list-item-name name group-chat public? public-key] (when last-message [react/view styles/message-status-container - [message-status chat last-message] [message-timestamp last-message]])] [react/view styles/item-lower-container [message-content-text last-message] diff --git a/test/cljs/status_im/test/chat/models/message.cljs b/test/cljs/status_im/test/chat/models/message.cljs index 4c64331348..fe927925e3 100644 --- a/test/cljs/status_im/test/chat/models/message.cljs +++ b/test/cljs/status_im/test/chat/models/message.cljs @@ -1,5 +1,6 @@ (ns status-im.test.chat.models.message (:require [cljs.test :refer-macros [deftest is testing]] + [status-im.transport.message.v1.protocol :as protocol] [status-im.chat.models.message :as message])) (deftest add-to-chat? @@ -24,3 +25,37 @@ {:message-id "message-id" :from "a" :chat-id "a"}))))) + +(deftest receive-send-seen + (let [db {:db {:chats {"chat-id" {}} + :account/account {:public-key "a"} + :current-chat-id "chat-id" + :view-id :chat}} + message {:chat-id "chat-id" + :from "a" + :message-id "1"} + extract-seen (comp :payload :message :shh/post)] + (testing "it send a seen message when the chat is 1-to-1 and is open" + (is (instance? protocol/MessagesSeen + (extract-seen (message/receive message db)))) + (is (= #{"1"} (:message-ids (extract-seen (message/receive message db)))))) + (testing "it does not send any when the chat is public" + (is (nil? (extract-seen + (message/receive + message + (assoc-in db [:db :chats "chat-id" :public?] true)))))) + (testing "it does not send any when we are in a different chat" + (is (nil? (extract-seen + (message/receive + message + (assoc-in db [:db :current-chat-id] :different)))))) + (testing "it does not send any when we are not in a chat view" + (is (nil? (extract-seen + (message/receive + message + (assoc-in db [:db :view-id] :home)))))) + (testing "it does not send any when no public key is in account" + (is (nil? (extract-seen + (message/receive + message + (assoc-in db [:db :account/account :public-key] nil))))))))