From 6e2809e270e4cae34c3b34ee2aad16e8948a2161 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 10 May 2016 19:06:22 +0300 Subject: [PATCH] contacts screen/views Former-commit-id: f1584b8342af1f35c1b733681fbcbd32576cf655 --- src/syng_im/android/core.cljs | 2 +- .../screen.cljs} | 8 ++--- .../views}/contact.cljs | 4 +-- .../views}/contact_inner.cljs | 2 +- src/syng_im/models/chats.cljs | 15 ++------- src/syng_im/subs.cljs | 31 ++++--------------- 6 files changed, 16 insertions(+), 46 deletions(-) rename src/syng_im/{components/contact_list/contact_list.cljs => contacts/screen.cljs} (90%) rename src/syng_im/{components/contact_list => contacts/views}/contact.cljs (77%) rename src/syng_im/{components/contact_list => contacts/views}/contact_inner.cljs (97%) diff --git a/src/syng_im/android/core.cljs b/src/syng_im/android/core.cljs index 93e8a278ef..56c654bfd2 100644 --- a/src/syng_im/android/core.cljs +++ b/src/syng_im/android/core.cljs @@ -7,7 +7,7 @@ [syng-im.handlers] [syng-im.subs] [syng-im.components.react :refer [navigator app-registry]] - [syng-im.components.contact-list.contact-list :refer [contact-list]] + [syng-im.contacts.screen :refer [contact-list]] [syng-im.components.discovery.discovery :refer [discovery]] [syng-im.components.discovery.discovery-tag :refer [discovery-tag]] [syng-im.chat.screen :refer [chat]] diff --git a/src/syng_im/components/contact_list/contact_list.cljs b/src/syng_im/contacts/screen.cljs similarity index 90% rename from src/syng_im/components/contact_list/contact_list.cljs rename to src/syng_im/contacts/screen.cljs index d4c3ef242c..abdc736d5d 100644 --- a/src/syng_im/components/contact_list/contact_list.cljs +++ b/src/syng_im/contacts/screen.cljs @@ -1,12 +1,12 @@ -(ns syng-im.components.contact-list.contact-list +(ns syng-im.contacts.screen (:require-macros - [natal-shell.data-source :refer [data-source clone-with-rows]] - [natal-shell.core :refer [with-error-view]]) + [natal-shell.data-source :refer [data-source clone-with-rows]] + [natal-shell.core :refer [with-error-view]]) (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [syng-im.components.react :refer [view text image touchable-highlight navigator list-view list-item]] - [syng-im.components.contact-list.contact :refer [contact-view]] + [syng-im.contacts.views.contact :refer [contact-view]] [syng-im.components.styles :refer [font title-font color-white diff --git a/src/syng_im/components/contact_list/contact.cljs b/src/syng_im/contacts/views/contact.cljs similarity index 77% rename from src/syng_im/components/contact_list/contact.cljs rename to src/syng_im/contacts/views/contact.cljs index 7b9d5af1c1..6bbbdc7938 100644 --- a/src/syng_im/components/contact_list/contact.cljs +++ b/src/syng_im/contacts/views/contact.cljs @@ -1,8 +1,8 @@ -(ns syng-im.components.contact-list.contact +(ns syng-im.contacts.views.contact (:require [syng-im.components.react :refer [view text image touchable-highlight]] [syng-im.resources :as res] [syng-im.navigation :as nav] - [syng-im.components.contact-list.contact-inner :refer [contact-inner-view]])) + [syng-im.contacts.views.contact-inner :refer [contact-inner-view]])) (defn show-chat [navigator whisper-identity] (nav/nav-push navigator {:view-id :chat})) diff --git a/src/syng_im/components/contact_list/contact_inner.cljs b/src/syng_im/contacts/views/contact_inner.cljs similarity index 97% rename from src/syng_im/components/contact_list/contact_inner.cljs rename to src/syng_im/contacts/views/contact_inner.cljs index 13e79d983b..3dd46f458f 100644 --- a/src/syng_im/components/contact_list/contact_inner.cljs +++ b/src/syng_im/contacts/views/contact_inner.cljs @@ -1,4 +1,4 @@ -(ns syng-im.components.contact-list.contact-inner +(ns syng-im.contacts.views.contact-inner (:require [clojure.string :as s] [syng-im.components.react :refer [view image text]] [syng-im.components.styles :refer [font diff --git a/src/syng_im/models/chats.cljs b/src/syng_im/models/chats.cljs index 31a6819e06..8d1425b989 100644 --- a/src/syng_im/models/chats.cljs +++ b/src/syng_im/models/chats.cljs @@ -3,20 +3,11 @@ [syng-im.persistence.realm :as r] [syng-im.utils.random :as random :refer [timestamp]] [clojure.string :refer [join blank?]] - [syng-im.db :as db] [syng-im.utils.logging :as log] [syng-im.constants :refer [content-type-status]] [syng-im.models.messages :refer [save-message]] [syng-im.persistence.realm-queries :refer [include-query]])) -(defn signal-chats-updated [db] - (update-in db db/updated-chats-signal-path (fn [current] - (if current - (inc current) - 0)))) - -(defn chats-updated? [db] - (get-in db db/updated-chats-signal-path)) (defn chat-name-from-contacts [identities] (let [chat-name (->> identities @@ -52,8 +43,6 @@ ([{:keys [last-msg-id] :as chat}] (let [chat (assoc chat :last-msg-id (or last-msg-id ""))] (r/write #(r/create :chats chat)))) - ([db chat-id identities group-chat?] - (create-chat db chat-id identities group-chat? nil)) ([db chat-id identities group-chat? chat-name] (if (chat-exists? chat-id) db @@ -72,7 +61,7 @@ :contacts contacts :last-msg-id ""})))) (add-status-message chat-id) - (signal-chats-updated db))))) + db)))) (defn chat-contacts [chat-id] (-> (r/get-by-field :chats :chat-id chat-id) @@ -95,7 +84,7 @@ :is-active true :name group-name :contacts contacts} true)))) - (signal-chats-updated db)) + db) (defn normalize-contacts [chats] diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index bb186a0923..39e1250f42 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -1,7 +1,7 @@ (ns syng-im.subs (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub]] - [syng-im.models.chats :refer [chats-list chats-updated? chat-by-id]] + [syng-im.models.chats :refer [chats-list chat-by-id]] [syng-im.models.contacts :refer [contacts-list contacts-list-exclude contacts-list-include]] @@ -13,10 +13,7 @@ (register-sub :get-chats (fn [db _] - (let [chats-updated (reaction (chats-updated? @db))] - (reaction - (let [_ @chats-updated] - (chats-list)))))) + (reaction (:chats @db)))) ;; -- User data -------------------------------------------------------------- @@ -26,34 +23,19 @@ ;; (reaction ;; (get @db :user-phone-number)))) -(register-sub - :get-user-identity - (fn [db _] - (reaction - (get @db :user-identity)))) - -(register-sub - :get-loading - (fn [db _] - (reaction - (get @db :loading)))) - (register-sub :signed-up (fn [db _] - (reaction - (get @db :signed-up)))) + (reaction (:signed-up @db)))) (register-sub :get-contacts (fn [db _] - (reaction - (get @db :contacts)))) + (reaction (:contacts @db)))) (register-sub :all-contacts - (fn [db _] - (reaction - (contacts-list)))) + (fn [_ _] + (reaction (contacts-list)))) (register-sub :all-new-contacts (fn [db _] @@ -81,4 +63,3 @@ (register-sub :db (fn [db _] (reaction @db))) -