From 29ccf9546fb74561cc3f4d000cdf940aab1b2c04 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 13 Jul 2017 13:42:45 +0300 Subject: [PATCH] remove :chat-properties sub --- src/status_im/chat/subs.cljs | 20 +++--- src/status_im/chat/views/actions.cljs | 36 +++++------ src/status_im/chat/views/message/message.cljs | 57 +++++++++-------- src/status_im/chat/views/toolbar_content.cljs | 64 +++++++++---------- src/status_im/utils/views.clj | 1 - 5 files changed, 88 insertions(+), 90 deletions(-) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 697c409a98..767306e559 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -13,15 +13,6 @@ [taoensso.timbre :as log] [clojure.string :as str])) -(reg-sub - :chat-properties - (fn [db [_ properties]] - (->> properties - (map (fn [k] - [k (get-in db[:chats (:current-chat-id db) k]) - ])) - (into {})))) - (reg-sub :chat-ui-props (fn [db [_ ui-element chat-id]] @@ -34,10 +25,17 @@ (fn [kb-height] (if ios? kb-height 0))) +(reg-sub + :chats + (fn [db ] + (:chats db))) + (reg-sub :chat - (fn [db [_ k chat-id]] - (get-in db [:chats (or chat-id (:current-chat-id db)) k]))) + :<- [:chats] + :<- [:get-current-chat-id] + (fn [[chats id] [_ k chat-id]] + (get-in chats [(or chat-id id) k]))) (reg-sub :get-current-chat-id diff --git a/src/status_im/chat/views/actions.cljs b/src/status_im/chat/views/actions.cljs index cd4e72b0fc..1f47752f93 100644 --- a/src/status_im/chat/views/actions.cljs +++ b/src/status_im/chat/views/actions.cljs @@ -1,5 +1,5 @@ (ns status-im.chat.views.actions - (:require-macros [status-im.utils.views :refer [defview]]) + (:require-macros [status-im.utils.views :refer [defview letsubs]]) (:require [re-frame.core :refer [subscribe dispatch]] [clojure.string :as s] [status-im.components.react :refer [view @@ -113,23 +113,23 @@ :font :default} subtitle])]]]) -(defn actions-list-view [] - (let [{:keys [group-chat chat-id public?]} - @(subscribe [:chat-properties [:group-chat :chat-id :public?]]) - members (subscribe [:current-chat-contacts]) - status-bar-height (get-in platform-specific [:component-styles :status-bar :default :height])] - (fn [] - (when-let [actions (if group-chat - (group-chat-items @members public?) - (user-chat-items chat-id))] - [view (merge - (st/actions-wrapper status-bar-height) - (get-in platform-specific [:component-styles :actions-list-view])) - [view st/actions-separator] - [view st/actions-view - (for [action actions] - (if action - ^{:key action} [action-view action]))]])))) +(defview actions-list-view [] + (letsubs [group-chat [:chat :group-chat] + chat-id [:chat :chat-id] + public? [:chat :public?] + members [:current-chat-contacts] + status-bar-height (get-in platform-specific [:component-styles :status-bar :default :height])] + (when-let [actions (if group-chat + (group-chat-items members public?) + (user-chat-items chat-id))] + [view (merge + (st/actions-wrapper status-bar-height) + (get-in platform-specific [:component-styles :actions-list-view])) + [view st/actions-separator] + [view st/actions-view + (for [action actions] + (if action + ^{:key action} [action-view action]))]]))) (defn actions-view [] [overlay {:on-click-outside #(dispatch [:set-chat-ui-props {:show-actions? false}])} diff --git a/src/status_im/chat/views/message/message.cljs b/src/status_im/chat/views/message/message.cljs index a2dae36e0e..b20bf79dc0 100644 --- a/src/status_im/chat/views/message/message.cljs +++ b/src/status_im/chat/views/message/message.cljs @@ -1,5 +1,5 @@ (ns status-im.chat.views.message.message - (:require-macros [status-im.utils.views :refer [defview]]) + (:require-macros [status-im.utils.views :refer [defview letsubs]]) (:require [re-frame.core :refer [subscribe dispatch]] [clojure.walk :as walk] [reagent.core :as r] @@ -52,32 +52,35 @@ (or incoming-name "Unknown contact"))] [text {:style st/author} name])) -(defn message-content-status [_] - (let [{:keys [chat-id group-chat name color]} @(subscribe [:chat-properties [:chat-id :group-chat :name :color]]) - members (subscribe [:current-chat-contacts])] - (fn [{:keys [messages-count content datemark]}] - (let [{:keys [status]} (if group-chat - {:photo-path nil - :status nil - :last-online 0} - (first @members))] - [view st/status-container - [chat-icon-message-status chat-id group-chat name color false] - [text {:style st/status-from - :font :default - :number-of-lines 1} - (if (str/blank? name) - (generate-gfy) - (or (get-contact-translated chat-id :name name) - (label :t/chat-name)))] - (when (or status content) - [text {:style st/status-text - :font :default} - (or status content)]) - (if (> messages-count 1) - [view st/message-datemark - [chat-datemark datemark]] - [view st/message-empty-spacing])])))) +(defview message-content-status + [{:keys [messages-count content datemark]}] + (letsubs [chat-id [:chat :chat-id] + group-chat [:chat :group-id] + name [:chat :name] + color [:chat :color] + members [:current-chat-contacts]] + (let [{:keys [status]} (if group-chat + {:photo-path nil + :status nil + :last-online 0} + (first members))] + [view st/status-container + [chat-icon-message-status chat-id group-chat name color false] + [text {:style st/status-from + :font :default + :number-of-lines 1} + (if (str/blank? name) + (generate-gfy) + (or (get-contact-translated chat-id :name name) + (label :t/chat-name)))] + (when (or status content) + [text {:style st/status-text + :font :default} + (or status content)]) + (if (> messages-count 1) + [view st/message-datemark + [chat-datemark datemark]] + [view st/message-empty-spacing])]))) (defn message-content-audio [_] [view st/audio-container diff --git a/src/status_im/chat/views/toolbar_content.cljs b/src/status_im/chat/views/toolbar_content.cljs index 022a498d44..cc8b545905 100644 --- a/src/status_im/chat/views/toolbar_content.cljs +++ b/src/status_im/chat/views/toolbar_content.cljs @@ -1,5 +1,5 @@ (ns status-im.chat.views.toolbar-content - (:require-macros [status-im.utils.views :refer [defview]]) + (:require-macros [status-im.utils.views :refer [defview letsubs]]) (:require [re-frame.core :refer [subscribe dispatch]] [clojure.string :as str] [cljs-time.core :as t] @@ -61,35 +61,33 @@ (let [cnt (inc (count contacts))] (label-pluralize cnt :t/members-active)))]]))) -(defn toolbar-content-view [] - (let [{:keys [group-chat - name - contacts - chat-id - public?]} - @(subscribe [:chat-properties [:group-chat :name :contacts :chat-id :public?]]) - show-actions? (subscribe [:chat-ui-props :show-actions?]) - accounts (subscribe [:get :accounts]) - contact (subscribe [:get-in [:contacts chat-id]]) - sync-state (subscribe [:get :sync-state]) - creating? (subscribe [:get :creating-account?])] - (fn [] - [view (st/chat-name-view (or (empty? @accounts) - @show-actions? - @creating?)) - (let [chat-name (if (str/blank? name) - (generate-gfy) - (or (get-contact-translated chat-id :name name) - (label :t/chat-name)))] - [text {:style st/chat-name-text - :number-of-lines 1 - :font :toolbar-title} - (if public? - (str "#" chat-name) - chat-name)]) - (if group-chat - [group-last-activity {:contacts contacts - :public? public? - :sync-state @sync-state}] - [last-activity {:online-text (online-text @contact chat-id) - :sync-state @sync-state}])]))) +(defview toolbar-content-view [] + (letsubs [group-chat [:chat :group-chat] + name [:chat :name] + chat-id [:chat :chat-id] + contacts [:chat :contacts] + public? [:chat :public?] + show-actions? [:chat-ui-props :show-actions?] + accounts [:get :accounts] + contact [:get-in [:contacts @chat-id]] + sync-state [:get :sync-state] + creating? [:get :creating-account?]] + [view (st/chat-name-view (or (empty? accounts) + show-actions? + creating?)) + (let [chat-name (if (str/blank? name) + (generate-gfy) + (or (get-contact-translated chat-id :name name) + (label :t/chat-name)))] + [text {:style st/chat-name-text + :number-of-lines 1 + :font :toolbar-title} + (if public? + (str "#" chat-name) + chat-name)]) + (if group-chat + [group-last-activity {:contacts contacts + :public? public? + :sync-state sync-state}] + [last-activity {:online-text (online-text contact chat-id) + :sync-state sync-state}])])) diff --git a/src/status_im/utils/views.clj b/src/status_im/utils/views.clj index 92b7120e33..bde46c0d3a 100644 --- a/src/status_im/utils/views.clj +++ b/src/status_im/utils/views.clj @@ -62,4 +62,3 @@ (fn ~params (let [~@vars-bindings] ~body))})))))) -