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,23 +113,23 @@
: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?]
status-bar-height (get-in platform-specific [:component-styles :status-bar :default :height])] members [:current-chat-contacts]
(fn [] status-bar-height (get-in platform-specific [:component-styles :status-bar :default :height])]
(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)
(get-in platform-specific [:component-styles :actions-list-view])) (get-in platform-specific [:component-styles :actions-list-view]))
[view st/actions-separator] [view st/actions-separator]
[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,32 +52,35 @@
(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]
(let [{:keys [status]} (if group-chat name [:chat :name]
{:photo-path nil color [:chat :color]
:status nil members [:current-chat-contacts]]
:last-online 0} (let [{:keys [status]} (if group-chat
(first @members))] {:photo-path nil
[view st/status-container :status nil
[chat-icon-message-status chat-id group-chat name color false] :last-online 0}
[text {:style st/status-from (first members))]
:font :default [view st/status-container
:number-of-lines 1} [chat-icon-message-status chat-id group-chat name color false]
(if (str/blank? name) [text {:style st/status-from
(generate-gfy) :font :default
(or (get-contact-translated chat-id :name name) :number-of-lines 1}
(label :t/chat-name)))] (if (str/blank? name)
(when (or status content) (generate-gfy)
[text {:style st/status-text (or (get-contact-translated chat-id :name name)
:font :default} (label :t/chat-name)))]
(or status content)]) (when (or status content)
(if (> messages-count 1) [text {:style st/status-text
[view st/message-datemark :font :default}
[chat-datemark datemark]] (or status content)])
[view st/message-empty-spacing])])))) (if (> messages-count 1)
[view st/message-datemark
[chat-datemark datemark]]
[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,35 +61,33 @@
(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? (let [chat-name (if (str/blank? name)
@creating?)) (generate-gfy)
(let [chat-name (if (str/blank? name) (or (get-contact-translated chat-id :name name)
(generate-gfy) (label :t/chat-name)))]
(or (get-contact-translated chat-id :name name) [text {:style st/chat-name-text
(label :t/chat-name)))] :number-of-lines 1
[text {:style st/chat-name-text :font :toolbar-title}
:number-of-lines 1 (if public?
:font :toolbar-title} (str "#" chat-name)
(if public? chat-name)])
(str "#" chat-name) (if group-chat
chat-name)]) [group-last-activity {:contacts contacts
(if group-chat :public? public?
[group-last-activity {:contacts contacts :sync-state sync-state}]
:public? public? [last-activity {:online-text (online-text contact chat-id)
:sync-state @sync-state}] :sync-state sync-state}])]))
[last-activity {:online-text (online-text @contact chat-id)
:sync-state @sync-state}])])))

View File

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