remove :chat-properties sub

This commit is contained in:
Roman Volosovskyi 2017-07-13 13:42:45 +03:00
parent 1a056d0256
commit 29ccf9546f
5 changed files with 88 additions and 90 deletions

View File

@ -13,15 +13,6 @@
[taoensso.timbre :as log] [taoensso.timbre :as log]
[clojure.string :as str])) [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 (reg-sub
:chat-ui-props :chat-ui-props
(fn [db [_ ui-element chat-id]] (fn [db [_ ui-element chat-id]]
@ -34,10 +25,17 @@
(fn [kb-height] (fn [kb-height]
(if ios? kb-height 0))) (if ios? kb-height 0)))
(reg-sub
:chats
(fn [db ]
(:chats db)))
(reg-sub (reg-sub
:chat :chat
(fn [db [_ k chat-id]] :<- [:chats]
(get-in db [:chats (or chat-id (:current-chat-id db)) k]))) :<- [:get-current-chat-id]
(fn [[chats id] [_ k chat-id]]
(get-in chats [(or chat-id id) k])))
(reg-sub (reg-sub
:get-current-chat-id :get-current-chat-id

View File

@ -1,5 +1,5 @@
(ns status-im.chat.views.actions (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]] (:require [re-frame.core :refer [subscribe dispatch]]
[clojure.string :as s] [clojure.string :as s]
[status-im.components.react :refer [view [status-im.components.react :refer [view
@ -113,14 +113,14 @@
:font :default} :font :default}
subtitle])]]]) subtitle])]]])
(defn actions-list-view [] (defview actions-list-view []
(let [{:keys [group-chat chat-id public?]} (letsubs [group-chat [:chat :group-chat]
@(subscribe [:chat-properties [:group-chat :chat-id :public?]]) chat-id [:chat :chat-id]
members (subscribe [:current-chat-contacts]) public? [:chat :public?]
members [:current-chat-contacts]
status-bar-height (get-in platform-specific [:component-styles :status-bar :default :height])] status-bar-height (get-in platform-specific [:component-styles :status-bar :default :height])]
(fn []
(when-let [actions (if group-chat (when-let [actions (if group-chat
(group-chat-items @members public?) (group-chat-items members public?)
(user-chat-items chat-id))] (user-chat-items chat-id))]
[view (merge [view (merge
(st/actions-wrapper status-bar-height) (st/actions-wrapper status-bar-height)
@ -129,7 +129,7 @@
[view st/actions-view [view st/actions-view
(for [action actions] (for [action actions]
(if action (if action
^{:key action} [action-view action]))]])))) ^{:key action} [action-view action]))]])))
(defn actions-view [] (defn actions-view []
[overlay {:on-click-outside #(dispatch [:set-chat-ui-props {:show-actions? false}])} [overlay {:on-click-outside #(dispatch [:set-chat-ui-props {:show-actions? false}])}

View File

@ -1,5 +1,5 @@
(ns status-im.chat.views.message.message (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]] (:require [re-frame.core :refer [subscribe dispatch]]
[clojure.walk :as walk] [clojure.walk :as walk]
[reagent.core :as r] [reagent.core :as r]
@ -52,15 +52,18 @@
(or incoming-name "Unknown contact"))] (or incoming-name "Unknown contact"))]
[text {:style st/author} name])) [text {:style st/author} name]))
(defn message-content-status [_] (defview message-content-status
(let [{:keys [chat-id group-chat name color]} @(subscribe [:chat-properties [:chat-id :group-chat :name :color]]) [{:keys [messages-count content datemark]}]
members (subscribe [:current-chat-contacts])] (letsubs [chat-id [:chat :chat-id]
(fn [{:keys [messages-count content datemark]}] group-chat [:chat :group-id]
name [:chat :name]
color [:chat :color]
members [:current-chat-contacts]]
(let [{:keys [status]} (if group-chat (let [{:keys [status]} (if group-chat
{:photo-path nil {:photo-path nil
:status nil :status nil
:last-online 0} :last-online 0}
(first @members))] (first members))]
[view st/status-container [view st/status-container
[chat-icon-message-status chat-id group-chat name color false] [chat-icon-message-status chat-id group-chat name color false]
[text {:style st/status-from [text {:style st/status-from
@ -77,7 +80,7 @@
(if (> messages-count 1) (if (> messages-count 1)
[view st/message-datemark [view st/message-datemark
[chat-datemark datemark]] [chat-datemark datemark]]
[view st/message-empty-spacing])])))) [view st/message-empty-spacing])])))
(defn message-content-audio [_] (defn message-content-audio [_]
[view st/audio-container [view st/audio-container

View File

@ -1,5 +1,5 @@
(ns status-im.chat.views.toolbar-content (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]] (:require [re-frame.core :refer [subscribe dispatch]]
[clojure.string :as str] [clojure.string :as str]
[cljs-time.core :as t] [cljs-time.core :as t]
@ -61,22 +61,20 @@
(let [cnt (inc (count contacts))] (let [cnt (inc (count contacts))]
(label-pluralize cnt :t/members-active)))]]))) (label-pluralize cnt :t/members-active)))]])))
(defn toolbar-content-view [] (defview toolbar-content-view []
(let [{:keys [group-chat (letsubs [group-chat [:chat :group-chat]
name name [:chat :name]
contacts chat-id [:chat :chat-id]
chat-id contacts [:chat :contacts]
public?]} public? [:chat :public?]
@(subscribe [:chat-properties [:group-chat :name :contacts :chat-id :public?]]) show-actions? [:chat-ui-props :show-actions?]
show-actions? (subscribe [:chat-ui-props :show-actions?]) accounts [:get :accounts]
accounts (subscribe [:get :accounts]) contact [:get-in [:contacts @chat-id]]
contact (subscribe [:get-in [:contacts chat-id]]) sync-state [:get :sync-state]
sync-state (subscribe [:get :sync-state]) creating? [:get :creating-account?]]
creating? (subscribe [:get :creating-account?])] [view (st/chat-name-view (or (empty? accounts)
(fn [] show-actions?
[view (st/chat-name-view (or (empty? @accounts) creating?))
@show-actions?
@creating?))
(let [chat-name (if (str/blank? name) (let [chat-name (if (str/blank? name)
(generate-gfy) (generate-gfy)
(or (get-contact-translated chat-id :name name) (or (get-contact-translated chat-id :name name)
@ -90,6 +88,6 @@
(if group-chat (if group-chat
[group-last-activity {:contacts contacts [group-last-activity {:contacts contacts
:public? public? :public? public?
:sync-state @sync-state}] :sync-state sync-state}]
[last-activity {:online-text (online-text @contact chat-id) [last-activity {:online-text (online-text contact chat-id)
:sync-state @sync-state}])]))) :sync-state sync-state}])]))

View File

@ -62,4 +62,3 @@
(fn ~params (fn ~params
(let [~@vars-bindings] (let [~@vars-bindings]
~body))})))))) ~body))}))))))