From 11c08f1e016bc742616e6a3ba4d38e5d246edd1c Mon Sep 17 00:00:00 2001 From: virvar Date: Wed, 18 May 2016 16:45:03 +0300 Subject: [PATCH 01/13] Send international phone number to server. Send confirmation code. Former-commit-id: 9274ba0ebb843d6cc709a70ec15ea2f4793ff2a3 --- src/syng_im/chat/handlers.cljs | 16 ++++++++++------ src/syng_im/chat/sign_up.cljs | 12 +++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/syng_im/chat/handlers.cljs b/src/syng_im/chat/handlers.cljs index 1691319b39..0df1412f06 100644 --- a/src/syng_im/chat/handlers.cljs +++ b/src/syng_im/chat/handlers.cljs @@ -12,6 +12,8 @@ [syng-im.models.chats :as chats] [syng-im.navigation.handlers :as nav] [syng-im.models.chats :as c] + [syng-im.handlers.server :as server] + [syng-im.utils.phone-number :refer [format-phone-number]] [syng-im.utils.handlers :as u])) (register-handler :set-show-actions @@ -222,15 +224,17 @@ (assoc db :password-saved true))) (register-handler :sign-up - (-> (fn [db [_ phone-number]] - ;; todo save phone number to db - (assoc db :user-phone-number phone-number)) - ((after (fn [& _] (sign-up-service/on-sign-up-response)))))) + (fn [db [_ phone-number]] + ;; todo save phone number to db + (let [formatted (format-phone-number phone-number)] + (-> db + (assoc :user-phone-number formatted) + (server/sign-up formatted sign-up-service/on-sign-up-response))))) (register-handler :sign-up-confirm (fn [db [_ confirmation-code]] - (sign-up-service/on-send-code-response confirmation-code) - (sign-up-service/set-signed-up db true))) + (server/sign-up-confirm confirmation-code sign-up-service/on-send-code-response) + db)) (register-handler :set-signed-up (fn [db [_ signed-up]] diff --git a/src/syng_im/chat/sign_up.cljs b/src/syng_im/chat/sign_up.cljs index 8cef60aac0..a00f1d3154 100644 --- a/src/syng_im/chat/sign_up.cljs +++ b/src/syng_im/chat/sign_up.cljs @@ -37,19 +37,21 @@ (dispatch [:set-signed-up true])) (defn sync-contacts [] + ;; TODO 'on-sync-contacts' is never called (dispatch [:sync-contacts on-sync-contacts])) (defn on-send-code-response [body] (dispatch [:received-msg {:msg-id (random/id) - ;; todo replace by real check - :content (if (= "1111" body) - "Confirmed" - "Wrong code") + :content (:message body) :content-type text-content-type :outgoing false :from "console" - :to "me"}])) + :to "me"}]) + (when (:confirmed body) + (sync-contacts) + ;; TODO should be called after sync-contacts? + (dispatch [:set-signed-up true]))) ; todo fn name is not too smart, but... (defn command-content From d1ef5e7e3247166ee82f7f3809dd316e2ff04a66 Mon Sep 17 00:00:00 2001 From: virvar Date: Wed, 18 May 2016 17:40:26 +0300 Subject: [PATCH 02/13] Setup sms-listener Former-commit-id: 1f5dad71e81ec910b3370374544864e554fd6cf1 --- .re-natal | 3 ++- android/app/build.gradle | 1 + .../app/src/main/java/com/syngim/MainActivity.java | 4 +++- android/settings.gradle | 4 +++- package.json | 1 + src/syng_im/chat/sign_up.cljs | 6 ++++++ src/syng_im/utils/sms_listener.cljs | 14 ++++++++++++++ 7 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/syng_im/utils/sms_listener.cljs diff --git a/.re-natal b/.re-natal index 54a57bc450..a5cde841e7 100644 --- a/.re-natal +++ b/.re-natal @@ -14,7 +14,8 @@ "react-native-vector-icons/Ionicons", "react-native-circle-checkbox", "react-native-randombytes", - "dismissKeyboard" + "dismissKeyboard", + "react-native-android-sms-listener" ], "imageDirs": [ "images" diff --git a/android/app/build.gradle b/android/app/build.gradle index c291fec7de..82a4b2fa40 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -128,6 +128,7 @@ dependencies { compile "com.facebook.react:react-native:+" // From node_modules compile project(':react-native-contacts') compile project(':react-native-i18n') + compile project(':ReactNativeAndroidSmsListener') // compile(name:'geth', ext:'aar') compile(group: 'status-im', name: 'android-geth', version: '1.4.0-201604110816-a97a114', ext: 'aar') diff --git a/android/app/src/main/java/com/syngim/MainActivity.java b/android/app/src/main/java/com/syngim/MainActivity.java index b080070f49..9c24036bfd 100644 --- a/android/app/src/main/java/com/syngim/MainActivity.java +++ b/android/app/src/main/java/com/syngim/MainActivity.java @@ -10,6 +10,7 @@ import android.os.Bundle; import android.os.Environment; import com.github.ethereum.go_ethereum.cmd.Geth; import com.bitgo.randombytes.RandomBytesPackage; +import com.centaurwarchief.smslistener.SmsListener; import java.util.Arrays; import java.util.List; @@ -78,7 +79,8 @@ public class MainActivity extends ReactActivity { new VectorIconsPackage(), new ReactNativeContacts(), new ReactNativeI18n(), - new RandomBytesPackage() + new RandomBytesPackage(), + new SmsListener(this) ); } } diff --git a/android/settings.gradle b/android/settings.gradle index 784925e19a..7eb87a3ce1 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -13,4 +13,6 @@ project(':react-native-vector-icons').projectDir = new File(rootProject.projectD include ':realm' project(':realm').projectDir = new File(rootProject.projectDir, '../node_modules/realm/android') include ':randombytes' -project(':randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/app') \ No newline at end of file +project(':randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/app') +include ':ReactNativeAndroidSmsListener' +project(':ReactNativeAndroidSmsListener').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-sms-listener/android') diff --git a/package.json b/package.json index 48ab8e052a..caf351c949 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "react": "^0.14.5", "react-native": "^0.24.1", "react-native-action-button": "^1.1.4", + "react-native-android-sms-listener": "^0.1.3", "react-native-circle-checkbox": "^0.1.3", "react-native-contacts": "^0.2.4", "react-native-i18n": "0.0.8", diff --git a/src/syng_im/chat/sign_up.cljs b/src/syng_im/chat/sign_up.cljs index a00f1d3154..9ff0c3cb34 100644 --- a/src/syng_im/chat/sign_up.cljs +++ b/src/syng_im/chat/sign_up.cljs @@ -6,6 +6,8 @@ [syng-im.models.chats :as c] [syng-im.utils.utils :refer [log on-error http-post toast]] [syng-im.utils.random :as random] + [syng-im.utils.sms-listener :refer [add-sms-listener + remove-sms-listener]] [syng-im.utils.phone-number :refer [format-phone-number]] [syng-im.constants :refer [text-content-type content-type-command @@ -73,6 +75,10 @@ :from "console" :to "me"}]))) +(defn start-listen-confirmation-code-sms [] + ;; TODO UNDONE listen sms + ) + ;; -- Saving password ---------------------------------------- (defn save-password [password] ;; TODO validate and save password diff --git a/src/syng_im/utils/sms_listener.cljs b/src/syng_im/utils/sms_listener.cljs new file mode 100644 index 0000000000..625e1ca8b6 --- /dev/null +++ b/src/syng_im/utils/sms_listener.cljs @@ -0,0 +1,14 @@ +(ns syng-im.utils.sms-listener) + +(def sms-listener (js/require "react-native-android-sms-listener")) + +;; Only android is supported! + +(defn add-sms-listener + "Message format: {originatingAddress: string, body: + string}. Returns cancelable subscription." + [listen-fn] + (.addListener sms-listener listen-fn)) + +(defn remove-sms-listener [subscription] + (.remove subscription)) From a1e47ce00f1072eaf843089057ff72d4c8f6c865 Mon Sep 17 00:00:00 2001 From: virvar Date: Wed, 18 May 2016 18:40:01 +0300 Subject: [PATCH 03/13] Listen and send confirmation code Former-commit-id: 476d36f555124981b1c4809e63312f1ca339096a --- src/syng_im/chat/handlers.cljs | 5 +++++ src/syng_im/chat/sign_up.cljs | 16 +++++++++++++--- src/syng_im/utils/sms_listener.cljs | 17 +++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/syng_im/chat/handlers.cljs b/src/syng_im/chat/handlers.cljs index 0df1412f06..7cf04bd35d 100644 --- a/src/syng_im/chat/handlers.cljs +++ b/src/syng_im/chat/handlers.cljs @@ -229,8 +229,13 @@ (let [formatted (format-phone-number phone-number)] (-> db (assoc :user-phone-number formatted) + sign-up-service/start-listening-confirmation-code-sms (server/sign-up formatted sign-up-service/on-sign-up-response))))) +(register-handler :stop-listening-confirmation-code-sms + (fn [db [_]] + (sign-up-service/stop-listening-confirmation-code-sms db))) + (register-handler :sign-up-confirm (fn [db [_ confirmation-code]] (server/sign-up-confirm confirmation-code sign-up-service/on-send-code-response) diff --git a/src/syng_im/chat/sign_up.cljs b/src/syng_im/chat/sign_up.cljs index 9ff0c3cb34..fe2bdfca78 100644 --- a/src/syng_im/chat/sign_up.cljs +++ b/src/syng_im/chat/sign_up.cljs @@ -51,6 +51,7 @@ :from "console" :to "me"}]) (when (:confirmed body) + (dispatch [:stop-listening-confirmation-code-sms]) (sync-contacts) ;; TODO should be called after sync-contacts? (dispatch [:set-signed-up true]))) @@ -75,9 +76,18 @@ :from "console" :to "me"}]))) -(defn start-listen-confirmation-code-sms [] - ;; TODO UNDONE listen sms - ) +(defn handle-sms [{body :body}] + (when-let [matches (re-matches #"(\d{4})" body)] + (dispatch [:sign-up-confirm (second matches)]))) + +(defn start-listening-confirmation-code-sms [db] + (when (not (:confirmation-code-sms-listener db)) + (assoc db :confirmation-code-sms-listener (add-sms-listener handle-sms)))) + +(defn stop-listening-confirmation-code-sms [db] + (when-let [listener (:confirmation-code-sms-listener db)] + (remove-sms-listener listener) + (dissoc db :confirmation-code-sms-listener))) ;; -- Saving password ---------------------------------------- (defn save-password [password] diff --git a/src/syng_im/utils/sms_listener.cljs b/src/syng_im/utils/sms_listener.cljs index 625e1ca8b6..5083440ad2 100644 --- a/src/syng_im/utils/sms_listener.cljs +++ b/src/syng_im/utils/sms_listener.cljs @@ -1,14 +1,19 @@ -(ns syng-im.utils.sms-listener) +(ns syng-im.utils.sms-listener + (:require [syng-im.components.react :refer [android?]])) -(def sms-listener (js/require "react-native-android-sms-listener")) +(def sms-listener (.-default (js/require "react-native-android-sms-listener"))) ;; Only android is supported! (defn add-sms-listener - "Message format: {originatingAddress: string, body: - string}. Returns cancelable subscription." + "Message format: {:originatingAddress string, :body string}. Returns + cancelable subscription." [listen-fn] - (.addListener sms-listener listen-fn)) + (when android? + (.addListener sms-listener + (fn [message] + (listen-fn (js->clj message :keywordize-keys true)))))) (defn remove-sms-listener [subscription] - (.remove subscription)) + (when android? + (.remove subscription))) From c015d260e86987678230306ad9737c5076d61369 Mon Sep 17 00:00:00 2001 From: virvar Date: Thu, 19 May 2016 11:51:13 +0300 Subject: [PATCH 04/13] Real last message, chat icon Former-commit-id: a5350f9b9ba4496eda8516ef90fcdb3039d40804 --- src/syng_im/chat/screen.cljs | 20 ++++++---- src/syng_im/chat/styles/screen.cljs | 24 +++++++++++- src/syng_im/chats_list/styles.cljs | 15 ++++++++ .../chats_list/views/chat_list_item.cljs | 4 +- src/syng_im/chats_list/views/inner_item.cljs | 32 +++++++++------- src/syng_im/constants.cljs | 11 +----- src/syng_im/contacts/subs.cljs | 37 +++++++++++++------ .../group_settings/styles/group_settings.cljs | 5 ++- 8 files changed, 100 insertions(+), 48 deletions(-) diff --git a/src/syng_im/chat/screen.cljs b/src/syng_im/chat/screen.cljs index dd355b4223..615df4c025 100644 --- a/src/syng_im/chat/screen.cljs +++ b/src/syng_im/chat/screen.cljs @@ -32,13 +32,19 @@ (assoc msg :text-color text-color :background-color background-color)))) -(defn chat-photo [{:keys [photo-path]}] - [view {:margin 10 - :borderRadius 50} - [image {:source (if (s/blank? photo-path) - res/user-no-photo - {:uri photo-path}) - :style st/chat-photo}]]) +(defview default-chat-icon [] + [name [:chat :name] + color [:chat :color]] + [view (st/default-chat-icon color) + [text {:style st/default-chat-icon-text} (nth name 0)]]) + +(defview chat-photo [] + [photo-path [:chat-photo]] + (if photo-path + [view st/contact-photo-container + [image {:source {:uri photo-path} + :style st/chat-photo}]] + [default-chat-icon])) (defn contact-online [{:keys [online]}] (when online diff --git a/src/syng_im/chat/styles/screen.cljs b/src/syng_im/chat/styles/screen.cljs index f3e74ac123..b789b8098c 100644 --- a/src/syng_im/chat/styles/screen.cljs +++ b/src/syng_im/chat/styles/screen.cljs @@ -21,8 +21,10 @@ :elevation 2}) (def icon-view - {:width 56 - :height 56}) + {:width 56 + :height 56 + :paddingTop 10 + :paddingLeft 10}) (def back-icon {:marginTop 21 @@ -153,6 +155,24 @@ :fontFamily font :color text2-color}) +(defn default-chat-icon [color] + {:width 36 + :height 36 + :alignItems :center + :justifyContent :center + :borderRadius 50 + :backgroundColor color}) + +(def default-chat-icon-text + {:marginTop -2 + :color color-white + :fontFamily font + :fontSize 16 + :lineHeight 20}) + +(def contact-photo-container + {:borderRadius 50}) + (def chat-photo {:borderRadius 50 :width 36 diff --git a/src/syng_im/chats_list/styles.cljs b/src/syng_im/chats_list/styles.cljs index 5b37f27122..dee98e3e0b 100644 --- a/src/syng_im/chats_list/styles.cljs +++ b/src/syng_im/chats_list/styles.cljs @@ -8,6 +8,21 @@ text2-color new-messages-count-color]])) +(defn default-chat-icon [color] + {:width 40 + :height 40 + :alignItems :center + :justifyContent :center + :borderRadius 50 + :backgroundColor color}) + +(def default-chat-icon-text + {:marginTop -2 + :color color-white + :fontFamily font + :fontSize 16 + :lineHeight 20}) + (def contact-photo-container {:borderRadius 50}) diff --git a/src/syng_im/chats_list/views/chat_list_item.cljs b/src/syng_im/chats_list/views/chat_list_item.cljs index 3673701ccc..c11e2fcd3f 100644 --- a/src/syng_im/chats_list/views/chat_list_item.cljs +++ b/src/syng_im/chats_list/views/chat_list_item.cljs @@ -13,8 +13,8 @@ {:on-press #(dispatch [:show-chat chat-id :push])} ;; TODO add [photo-path delivery-status new-messages-count online] values to chat-obj [view [chat-list-item-inner-view (merge chat - {:photo-path nil - :delivery-status :seen + ;; TODO stub data + {:delivery-status :seen :new-messages-count 3 :timestamp "13:54" :online true})]]]) diff --git a/src/syng_im/chats_list/views/inner_item.cljs b/src/syng_im/chats_list/views/inner_item.cljs index 0e43c75426..7248e076d8 100644 --- a/src/syng_im/chats_list/views/inner_item.cljs +++ b/src/syng_im/chats_list/views/inner_item.cljs @@ -1,16 +1,19 @@ (ns syng-im.chats-list.views.inner-item - (:require [clojure.string :as s] - [syng-im.components.react :refer [view image icon text]] - [syng-im.chats-list.styles :as st] - [syng-im.resources :as res])) + (:require-macros [syng-im.utils.views :refer [defview]]) + (:require [syng-im.components.react :refer [view image icon text]] + [syng-im.chats-list.styles :as st])) +(defn default-chat-icon [{:keys [name color]}] + [view (st/default-chat-icon color) + [text {:style st/default-chat-icon-text} (nth name 0)]]) -(defn contact-photo [photo-path] - [view st/contact-photo-container - [image {:source (if (s/blank? photo-path) - res/user-no-photo - {:uri photo-path}) - :style st/contact-photo-image}]]) +(defview contact-photo [chat] + [photo-path [:chat-photo (:chat-id chat)]] + (if photo-path + [view st/contact-photo-container + [image {:source {:uri photo-path} + :style st/contact-photo-image}]] + [default-chat-icon chat])) (defn contact-online [online] (when online @@ -19,11 +22,11 @@ [view st/online-dot-right]])) (defn chat-list-item-inner-view - [{:keys [name photo-path delivery-status timestamp new-messages-count online - group-chat contacts]}] + [{:keys [chat-id name photo-path delivery-status timestamp new-messages-count online + group-chat contacts] :as chat}] [view st/chat-container [view st/photo-container - [contact-photo photo-path] + [contact-photo chat] [contact-online online]] [view st/item-container [view st/name-view @@ -37,7 +40,8 @@ "1 member")])] [text {:style st/last-message-text :numberOfLines 2} - (repeatedly 5 #(str "Hi, I'm " name "! "))]] + (when-let [last-message (first (:messages chat))] + (:content last-message))]] [view [view st/status-container (when delivery-status diff --git a/src/syng_im/constants.cljs b/src/syng_im/constants.cljs index 84fbff6b8a..d300f03821 100644 --- a/src/syng_im/constants.cljs +++ b/src/syng_im/constants.cljs @@ -4,18 +4,9 @@ (def server-address "http://rpc0.syng.im:20000/") ;; (def server-address "http://10.0.3.2:3000/") +;; (def server-address "http://localhost:3000/") (def text-content-type "text/plain") (def content-type-command "command") (def content-type-command-request "command-request") (def content-type-status "status") - - -(comment - - (map (fn [c] - {:background c - :foreground c}) group-chat-colors) - (reverse group-chat-colors) - - ) diff --git a/src/syng_im/contacts/subs.cljs b/src/syng_im/contacts/subs.cljs index d889f12b60..7eae232d55 100644 --- a/src/syng_im/contacts/subs.cljs +++ b/src/syng_im/contacts/subs.cljs @@ -12,18 +12,21 @@ (let [contacts (reaction (:contacts @db))] (reaction (sort-by :name (vals @contacts)))))) -(defn contacts-by-current-chat [fn db] - (let [current-chat-id (:current-chat-id @db) - chat (reaction (get-in @db [:chats current-chat-id])) - contacts (reaction (:contacts @db))] +(defn contacts-by-chat [fn db chat-id] + (let [chat (reaction (get-in @db [:chats chat-id])) + contacts (reaction (:contacts @db))] (reaction - (when @chat - (let [current-participants (->> @chat - :contacts - (map :identity) - set)] - (fn #(current-participants (:whisper-identity %)) - (vals @contacts))))))) + (when @chat + (let [current-participants (->> @chat + :contacts + (map :identity) + set)] + (fn #(current-participants (:whisper-identity %)) + (vals @contacts))))))) + +(defn contacts-by-current-chat [fn db] + (let [current-chat-id (:current-chat-id @db)] + (contacts-by-chat fn db current-chat-id))) (register-sub :contact (fn [db _] @@ -37,3 +40,15 @@ (register-sub :current-chat-contacts (fn [db _] (contacts-by-current-chat filter db))) + +(register-sub :chat-photo + (fn [db [_ chat-id]] + (let [chat-id (or chat-id (:current-chat-id @db)) + chat (reaction (get-in @db [:chats chat-id])) + contacts (contacts-by-chat filter db chat-id)] + (reaction + (when @chat + (if (:group-chat @chat) + ;; TODO return group chat icon + nil + (:photo-path (first @contacts)))))))) diff --git a/src/syng_im/group_settings/styles/group_settings.cljs b/src/syng_im/group_settings/styles/group_settings.cljs index 092ab7387e..c891ebb3b3 100644 --- a/src/syng_im/group_settings/styles/group_settings.cljs +++ b/src/syng_im/group_settings/styles/group_settings.cljs @@ -56,12 +56,13 @@ {:margin 10 :width 36 :height 36 + :alignItems :center + :justifyContent :center :borderRadius 50 :backgroundColor color}) (def chat-icon-text - {:marginTop 7 - :marginLeft 13 + {:marginTop -2 :color color-white :fontFamily font :fontSize 16 From ee28404ef606bcf0840d50968b0fa91b3fc76fe5 Mon Sep 17 00:00:00 2001 From: virvar Date: Thu, 19 May 2016 15:45:16 +0300 Subject: [PATCH 05/13] Chat icon component Former-commit-id: 4ce65b37f99a036bc9187eca796e25cc41625357 --- src/syng_im/chat/screen.cljs | 62 ++++------- src/syng_im/chat/styles/screen.cljs | 94 ++-------------- src/syng_im/chats_list/styles.cljs | 57 +--------- src/syng_im/chats_list/views/inner_item.cljs | 28 +---- src/syng_im/components/chat_icon/screen.cljs | 62 +++++++++++ src/syng_im/components/chat_icon/styles.cljs | 103 ++++++++++++++++++ src/syng_im/group_settings/screen.cljs | 12 +- .../group_settings/styles/group_settings.cljs | 20 +--- 8 files changed, 217 insertions(+), 221 deletions(-) create mode 100644 src/syng_im/components/chat_icon/screen.cljs create mode 100644 src/syng_im/components/chat_icon/styles.cljs diff --git a/src/syng_im/chat/screen.cljs b/src/syng_im/chat/screen.cljs index 615df4c025..49c5da0d7d 100644 --- a/src/syng_im/chat/screen.cljs +++ b/src/syng_im/chat/screen.cljs @@ -1,7 +1,6 @@ (ns syng-im.chat.screen (:require-macros [syng-im.utils.views :refer [defview]]) - (:require [clojure.string :as s] - [re-frame.core :refer [subscribe dispatch]] + (:require [re-frame.core :refer [subscribe dispatch]] [syng-im.components.react :refer [view text image @@ -9,8 +8,9 @@ touchable-highlight list-view list-item]] + [syng-im.components.chat-icon.screen :refer [chat-icon-view-action + chat-icon-view-menu-item]] [syng-im.chat.styles.screen :as st] - [syng-im.resources :as res] [syng-im.utils.listview :refer [to-datasource]] [syng-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [syng-im.components.toolbar :refer [toolbar]] @@ -32,25 +32,13 @@ (assoc msg :text-color text-color :background-color background-color)))) -(defview default-chat-icon [] - [name [:chat :name] - color [:chat :color]] - [view (st/default-chat-icon color) - [text {:style st/default-chat-icon-text} (nth name 0)]]) - -(defview chat-photo [] - [photo-path [:chat-photo]] - (if photo-path - [view st/contact-photo-container - [image {:source {:uri photo-path} - :style st/chat-photo}]] - [default-chat-icon])) - -(defn contact-online [{:keys [online]}] - (when online - [view st/online-view - [view st/online-dot-left] - [view st/online-dot-right]])) +(defview chat-icon [] + [chat-id [:chat :chat-id] + group-chat [:chat :group-chat] + name [:chat :name] + color [:chat :color]] + ;; TODO stub data ('online' property) + [chat-icon-view-action chat-id group-chat name color true]) (defn typing [member] [view st/typing-view @@ -100,22 +88,13 @@ [text {:style st/action-subtitle} subtitle])]]]) -(defn menu-item-contact-photo [{:keys [photo-path]}] - [image {:source (if (s/blank? photo-path) - res/user-no-photo - {:uri photo-path}) - :style st/menu-item-profile-contact-photo}]) - -(defn menu-item-contact-online [{:keys [online]}] - (when online - [view st/menu-item-profile-online-view - [view st/menu-item-profile-online-dot-left] - [view st/menu-item-profile-online-dot-right]])) - -(defn menu-item-icon-profile [] - [view st/icon-view - [menu-item-contact-photo {}] - [menu-item-contact-online {:online true}]]) +(defview menu-item-icon-profile [] + [chat-id [:chat :chat-id] + group-chat [:chat :group-chat] + name [:chat :name] + color [:chat :color]] + ;; TODO stub data ('online' property) + [chat-icon-view-menu-item chat-id group-chat name color true]) (defn actions-list-view [] (let [{:keys [group-chat chat-id]} @@ -202,13 +181,12 @@ (if @show-actions [touchable-highlight {:on-press #(dispatch [:set-show-actions false])} - [view st/icon-view + [view st/action [icon :up st/up-icon]]] [touchable-highlight {:on-press #(dispatch [:set-show-actions true])} - [view st/icon-view - [chat-photo {}] - [contact-online {:online true}]]])))) + [view st/action + [chat-icon]]])))) (defn chat-toolbar [] (let [{:keys [group-chat name contacts]} diff --git a/src/syng_im/chat/styles/screen.cljs b/src/syng_im/chat/styles/screen.cljs index b789b8098c..6bcd2af0f7 100644 --- a/src/syng_im/chat/styles/screen.cljs +++ b/src/syng_im/chat/styles/screen.cljs @@ -20,11 +20,15 @@ :backgroundColor toolbar-background1 :elevation 2}) +(def action + {:width 56 + :height 56 + :alignItems :center + :justifyContent :center}) + (def icon-view - {:width 56 - :height 56 - :paddingTop 10 - :paddingLeft 10}) + {:width 56 + :height 56}) (def back-icon {:marginTop 21 @@ -50,10 +54,8 @@ :height 9}) (def up-icon - {:marginTop 23 - :marginLeft 21 - :width 14 - :height 8}) + {:width 14 + :height 8}) (def members {:marginTop -0.5 @@ -110,28 +112,6 @@ :fontSize 12 :fontFamily font}) -(def online-view - {:position :absolute - :top 30 - :left 30 - :width 20 - :height 20 - :borderRadius 50 - :backgroundColor online-color - :borderWidth 2 - :borderColor color-white}) - -(def online-dot - {:position :absolute - :top 6 - :width 4 - :height 4 - :borderRadius 50 - :backgroundColor color-white}) - -(def online-dot-left (merge online-dot {:left 3})) -(def online-dot-right (merge online-dot {:left 9})) - (def typing-all {:marginBottom 20}) @@ -155,29 +135,6 @@ :fontFamily font :color text2-color}) -(defn default-chat-icon [color] - {:width 36 - :height 36 - :alignItems :center - :justifyContent :center - :borderRadius 50 - :backgroundColor color}) - -(def default-chat-icon-text - {:marginTop -2 - :color color-white - :fontFamily font - :fontSize 16 - :lineHeight 20}) - -(def contact-photo-container - {:borderRadius 50}) - -(def chat-photo - {:borderRadius 50 - :width 36 - :height 36}) - (def actions-overlay {:position :absolute :top 0 @@ -187,34 +144,3 @@ (def overlay-highlight {:flex 1}) - -;;----- Menu item Profile ---------------- - -(def menu-item-profile-contact-photo - {:marginTop 13 - :marginLeft 16 - :borderRadius 50 - :width 24 - :height 24}) - -(def menu-item-profile-online-view - {:position :absolute - :top 26 - :left 29 - :width 15 - :height 15 - :borderRadius 50 - :backgroundColor online-color - :borderWidth 2 - :borderColor color-white}) - -(def menu-item-profile-online-dot - {:position :absolute - :top 4 - :width 3 - :height 3 - :borderRadius 50 - :backgroundColor color-white}) - -(def menu-item-profile-online-dot-left (merge menu-item-profile-online-dot {:left 1.7})) -(def menu-item-profile-online-dot-right (merge menu-item-profile-online-dot {:left 6.3})) diff --git a/src/syng_im/chats_list/styles.cljs b/src/syng_im/chats_list/styles.cljs index dee98e3e0b..a67a3292f5 100644 --- a/src/syng_im/chats_list/styles.cljs +++ b/src/syng_im/chats_list/styles.cljs @@ -8,64 +8,17 @@ text2-color new-messages-count-color]])) -(defn default-chat-icon [color] - {:width 40 - :height 40 - :alignItems :center - :justifyContent :center - :borderRadius 50 - :backgroundColor color}) - -(def default-chat-icon-text - {:marginTop -2 - :color color-white - :fontFamily font - :fontSize 16 - :lineHeight 20}) - -(def contact-photo-container - {:borderRadius 50}) - -(def contact-photo-image - {:borderRadius 50 - :width 40 - :height 40}) - -(def online-container - {:position :absolute - :top 24 - :left 24 - :width 20 - :height 20 - :borderRadius 50 - :backgroundColor online-color - :borderWidth 2 - :borderColor color-white}) - -(def online-dot - {:position :absolute - :top 6 - :width 4 - :height 4 - :borderRadius 50 - :backgroundColor color-white}) - -(def online-dot-left - (assoc online-dot :left 3)) - -(def online-dot-right - (assoc online-dot :left 9)) - (def chat-container {:flexDirection :row :paddingVertical 15 :paddingHorizontal 16 :height 90}) -(def photo-container - {:marginTop 2 - :width 44 - :height 44}) +(def chat-icon-container + {:marginTop -2 + :marginLeft -4 + :width 48 + :height 48}) (def item-container {:flexDirection :column diff --git a/src/syng_im/chats_list/views/inner_item.cljs b/src/syng_im/chats_list/views/inner_item.cljs index 7248e076d8..8f2b3b1554 100644 --- a/src/syng_im/chats_list/views/inner_item.cljs +++ b/src/syng_im/chats_list/views/inner_item.cljs @@ -1,33 +1,15 @@ (ns syng-im.chats-list.views.inner-item (:require-macros [syng-im.utils.views :refer [defview]]) (:require [syng-im.components.react :refer [view image icon text]] + [syng-im.components.chat-icon.screen :refer [chat-icon-view-chat-list]] [syng-im.chats-list.styles :as st])) -(defn default-chat-icon [{:keys [name color]}] - [view (st/default-chat-icon color) - [text {:style st/default-chat-icon-text} (nth name 0)]]) - -(defview contact-photo [chat] - [photo-path [:chat-photo (:chat-id chat)]] - (if photo-path - [view st/contact-photo-container - [image {:source {:uri photo-path} - :style st/contact-photo-image}]] - [default-chat-icon chat])) - -(defn contact-online [online] - (when online - [view st/online-container - [view st/online-dot-left] - [view st/online-dot-right]])) - (defn chat-list-item-inner-view - [{:keys [chat-id name photo-path delivery-status timestamp new-messages-count online - group-chat contacts] :as chat}] + [{:keys [chat-id name color photo-path delivery-status timestamp new-messages-count + online group-chat contacts] :as chat}] [view st/chat-container - [view st/photo-container - [contact-photo chat] - [contact-online online]] + [view st/chat-icon-container + [chat-icon-view-chat-list chat-id group-chat name color online]] [view st/item-container [view st/name-view [text {:style st/name-text} name] diff --git a/src/syng_im/components/chat_icon/screen.cljs b/src/syng_im/components/chat_icon/screen.cljs new file mode 100644 index 0000000000..194c23ca63 --- /dev/null +++ b/src/syng_im/components/chat_icon/screen.cljs @@ -0,0 +1,62 @@ +(ns syng-im.components.chat-icon.screen + (:require-macros [syng-im.utils.views :refer [defview]]) + (:require [re-frame.core :refer [subscribe dispatch]] + [syng-im.components.react :refer [view + text + image + icon]] + [syng-im.components.chat-icon.styles :as st])) + +(defn default-chat-icon [name color styles] + [view (:default-chat-icon styles) + [text {:style (:default-chat-icon-text styles)} + (nth name 0)]]) + +(defn chat-icon [photo-path styles] + [image {:source {:uri photo-path} + :style (:chat-icon styles)}]) + +(defn contact-online [online styles] + (when online + [view (:online-view styles) + [view (:online-dot-left styles)] + [view (:online-dot-right styles)]])) + +(defview chat-icon-view [chat-id group-chat name color online styles] + [photo-path [:chat-photo chat-id]] + [view (:container styles) + (if photo-path + [chat-icon photo-path styles] + [default-chat-icon name color styles]) + (when (not group-chat) + [contact-online online styles])]) + +(defn chat-icon-view-chat-list [chat-id group-chat name color online] + [chat-icon-view chat-id group-chat name color online + {:container st/container-chat-list + :online-view st/online-view + :online-dot-left st/online-dot-left + :online-dot-right st/online-dot-right + :chat-icon st/chat-icon-chat-list + :default-chat-icon (st/default-chat-icon-chat-list color) + :default-chat-icon-text st/default-chat-icon-text}]) + +(defn chat-icon-view-action [chat-id group-chat name color online] + [chat-icon-view chat-id group-chat name color online + {:container st/container + :online-view st/online-view + :online-dot-left st/online-dot-left + :online-dot-right st/online-dot-right + :chat-icon st/chat-icon + :default-chat-icon (st/default-chat-icon color) + :default-chat-icon-text st/default-chat-icon-text}]) + +(defn chat-icon-view-menu-item [chat-id group-chat name color online] + [chat-icon-view chat-id group-chat name color online + {:container st/container-menu-item + :online-view st/online-view-menu-item + :online-dot-left st/online-dot-left-menu-item + :online-dot-right st/online-dot-right-menu-item + :chat-icon st/chat-icon-menu-item + :default-chat-icon (st/default-chat-icon-menu-item color) + :default-chat-icon-text st/default-chat-icon-text}]) diff --git a/src/syng_im/components/chat_icon/styles.cljs b/src/syng_im/components/chat_icon/styles.cljs new file mode 100644 index 0000000000..8b0406080c --- /dev/null +++ b/src/syng_im/components/chat_icon/styles.cljs @@ -0,0 +1,103 @@ +(ns syng-im.components.chat-icon.styles + (:require [syng-im.components.styles :refer [font + title-font + color-white + chat-background + online-color + selected-message-color + separator-color + text1-color + text2-color + toolbar-background1]])) + +(defn default-chat-icon [color] + {:margin 4 + :width 36 + :height 36 + :alignItems :center + :justifyContent :center + :borderRadius 50 + :backgroundColor color}) + +(defn default-chat-icon-chat-list [color] + (merge (default-chat-icon color) + {:width 40 + :height 40})) + +(defn default-chat-icon-menu-item [color] + (merge (default-chat-icon color) + {:width 24 + :height 24})) + +(def default-chat-icon-text + {:marginTop -2 + :color color-white + :fontFamily font + :fontSize 16 + :lineHeight 20}) + +(def chat-icon + {:margin 4 + :borderRadius 50 + :width 36 + :height 36}) + +(def chat-icon-chat-list + (merge chat-icon + {:width 40 + :height 40})) + +(def chat-icon-menu-item + (merge chat-icon + {:width 24 + :height 24})) + +(def online-view + {:position :absolute + :bottom 0 + :right 0 + :width 20 + :height 20 + :borderRadius 50 + :backgroundColor online-color + :borderWidth 2 + :borderColor color-white}) + +(def online-view-menu-item + (merge online-view + {:width 15 + :height 15})) + +(def online-dot + {:position :absolute + :top 6 + :width 4 + :height 4 + :borderRadius 50 + :backgroundColor color-white}) + +(def online-dot-left (merge online-dot {:left 3})) +(def online-dot-right (merge online-dot {:left 9})) + +(def online-dot-menu-item + (merge online-dot + {:top 4 + :width 3 + :height 3})) + +(def online-dot-left-menu-item + (merge online-dot-menu-item {:left 1.7})) +(def online-dot-right-menu-item + (merge online-dot-menu-item {:left 6.3})) + +(def container + {:width 44 + :height 44}) + +(def container-chat-list + {:width 48 + :height 48}) + +(def container-menu-item + {:width 32 + :height 32}) diff --git a/src/syng_im/group_settings/screen.cljs b/src/syng_im/group_settings/screen.cljs index 9d3011b5fb..2b60ce8102 100644 --- a/src/syng_im/group_settings/screen.cljs +++ b/src/syng_im/group_settings/screen.cljs @@ -1,7 +1,6 @@ (ns syng-im.group-settings.screen (:require-macros [syng-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] - [syng-im.resources :as res] [syng-im.components.react :refer [view text-input text @@ -13,6 +12,7 @@ scroll-view touchable-highlight]] [syng-im.components.toolbar :refer [toolbar]] + [syng-im.components.chat-icon.screen :refer [chat-icon-view-action]] [syng-im.components.realm :refer [list-view]] [syng-im.components.styles :refer [color-purple text2-color]] @@ -125,10 +125,12 @@ ^{:key setting} [setting-view setting])])) (defview chat-icon [] - [name [:chat :name] - color [:chat :color]] - [view (st/chat-icon color) - [text {:style st/chat-icon-text} (nth name 0)]]) + [chat-id [:chat :chat-id] + group-chat [:chat :group-chat] + name [:chat :name] + color [:chat :color]] + [view st/action + [chat-icon-view-action chat-id group-chat name color false]]) (defn new-group-toolbar [] [toolbar {:title "Chat settings" diff --git a/src/syng_im/group_settings/styles/group_settings.cljs b/src/syng_im/group_settings/styles/group_settings.cljs index c891ebb3b3..3565a996b8 100644 --- a/src/syng_im/group_settings/styles/group_settings.cljs +++ b/src/syng_im/group_settings/styles/group_settings.cljs @@ -52,21 +52,11 @@ (def chat-members-container {:marginBottom 10}) -(defn chat-icon [color] - {:margin 10 - :width 36 - :height 36 - :alignItems :center - :justifyContent :center - :borderRadius 50 - :backgroundColor color}) - -(def chat-icon-text - {:marginTop -2 - :color color-white - :fontFamily font - :fontSize 16 - :lineHeight 20}) +(def action + {:width 56 + :height 56 + :alignItems :center + :justifyContent :center}) (def group-settings {:flex 1 From 06534cfd5dacb069f28a5ba92fb347544a57fb88 Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 20 May 2016 10:22:14 +0300 Subject: [PATCH 06/13] Profile icon Former-commit-id: d9a44d9c0b90b95840afd935a88631509daed8f9 --- src/syng_im/components/chat_icon/screen.cljs | 42 +++++++++++++++++++- src/syng_im/components/chat_icon/styles.cljs | 33 +++++++++++++-- src/syng_im/db.cljs | 1 + src/syng_im/profile/screen.cljs | 31 +++++---------- src/syng_im/profile/styles.cljs | 35 +--------------- 5 files changed, 83 insertions(+), 59 deletions(-) diff --git a/src/syng_im/components/chat_icon/screen.cljs b/src/syng_im/components/chat_icon/screen.cljs index 194c23ca63..028a6cd737 100644 --- a/src/syng_im/components/chat_icon/screen.cljs +++ b/src/syng_im/components/chat_icon/screen.cljs @@ -5,7 +5,8 @@ text image icon]] - [syng-im.components.chat-icon.styles :as st])) + [syng-im.components.chat-icon.styles :as st] + [syng-im.components.styles :refer [color-purple]])) (defn default-chat-icon [name color styles] [view (:default-chat-icon styles) @@ -60,3 +61,42 @@ :chat-icon st/chat-icon-menu-item :default-chat-icon (st/default-chat-icon-menu-item color) :default-chat-icon-text st/default-chat-icon-text}]) + +(defn chat-icon-view-profile [chat-id group-chat name color online] + [chat-icon-view chat-id group-chat name color online + {:container st/container-profile + :online-view st/online-view-profile + :online-dot-left st/online-dot-left-profile + :online-dot-right st/online-dot-right-profile + :chat-icon st/chat-icon-profile + :default-chat-icon (st/default-chat-icon-profile color) + :default-chat-icon-text st/default-chat-icon-text}]) + +(defn profile-icon-view [photo-path name color online] + (let [styles {:container st/container-profile + :online-view st/online-view-profile + :online-dot-left st/online-dot-left-profile + :online-dot-right st/online-dot-right-profile + :chat-icon st/chat-icon-profile + :default-chat-icon (st/default-chat-icon-profile color) + :default-chat-icon-text st/default-chat-icon-text}] + [view (:container styles) + (if photo-path + [chat-icon photo-path styles] + [default-chat-icon name color styles]) + [contact-online online styles]])) + +(defview profile-icon [] + [contact [:contact]] + (let [ ;; TODO stub data + online true + color color-purple] + [profile-icon-view (:photo-path contact) (:name contact) color online])) + +(defview my-profile-icon [] + [name [:get :username] + photo-path [:get :photo-path]] + (let [ ;; TODO stub data + online true + color color-purple] + [profile-icon-view photo-path name color online])) diff --git a/src/syng_im/components/chat_icon/styles.cljs b/src/syng_im/components/chat_icon/styles.cljs index 8b0406080c..3bd91f70b7 100644 --- a/src/syng_im/components/chat_icon/styles.cljs +++ b/src/syng_im/components/chat_icon/styles.cljs @@ -29,6 +29,11 @@ {:width 24 :height 24})) +(defn default-chat-icon-profile [color] + (merge (default-chat-icon color) + {:width 64 + :height 64})) + (def default-chat-icon-text {:marginTop -2 :color color-white @@ -52,6 +57,11 @@ {:width 24 :height 24})) +(def chat-icon-profile + (merge chat-icon + {:width 64 + :height 64})) + (def online-view {:position :absolute :bottom 0 @@ -65,9 +75,14 @@ (def online-view-menu-item (merge online-view - {:width 15 + {:width 15 :height 15})) +(def online-view-profile + (merge online-view + {:width 24 + :height 24})) + (def online-dot {:position :absolute :top 6 @@ -75,7 +90,6 @@ :height 4 :borderRadius 50 :backgroundColor color-white}) - (def online-dot-left (merge online-dot {:left 3})) (def online-dot-right (merge online-dot {:left 9})) @@ -84,12 +98,21 @@ {:top 4 :width 3 :height 3})) - (def online-dot-left-menu-item (merge online-dot-menu-item {:left 1.7})) (def online-dot-right-menu-item (merge online-dot-menu-item {:left 6.3})) +(def online-dot-profile + (merge online-dot + {:top 8 + :width 4 + :height 4})) +(def online-dot-left-profile + (merge online-dot-profile {:left 5})) +(def online-dot-right-profile + (merge online-dot-profile {:left 11})) + (def container {:width 44 :height 44}) @@ -101,3 +124,7 @@ (def container-menu-item {:width 32 :height 32}) + +(def container-profile + {:width 72 + :height 72}) diff --git a/src/syng_im/db.cljs b/src/syng_im/db.cljs index f031922451..436e58a713 100644 --- a/src/syng_im/db.cljs +++ b/src/syng_im/db.cljs @@ -23,6 +23,7 @@ :view-id default-view :navigation-stack (list default-view) ;; TODO fix hardcoded values + :photo-path nil :username "My Name" :phone-number "3147984309" :email "myemail@gmail.com" diff --git a/src/syng_im/profile/screen.cljs b/src/syng_im/profile/screen.cljs index 9d075c4999..946904cb33 100644 --- a/src/syng_im/profile/screen.cljs +++ b/src/syng_im/profile/screen.cljs @@ -1,7 +1,6 @@ (ns syng-im.profile.screen (:require-macros [syng-im.utils.views :refer [defview]]) - (:require [clojure.string :as s] - [re-frame.core :refer [subscribe dispatch]] + (:require [re-frame.core :refer [subscribe dispatch]] [syng-im.components.react :refer [view text image @@ -9,21 +8,10 @@ scroll-view touchable-highlight touchable-opacity]] - [syng-im.resources :as res] + [syng-im.components.chat-icon.screen :refer [profile-icon + my-profile-icon]] [syng-im.profile.styles :as st])) -(defn user-photo [{:keys [photo-path]}] - [image {:source (if (s/blank? photo-path) - res/user-no-photo - {:uri photo-path}) - :style st/user-photo}]) - -(defn user-online [{:keys [online]}] - (when online - [view st/user-online-container - [view st/user-online-dot-left] - [view st/user-online-dot-right]])) - (defn profile-property-view [{:keys [name value]}] [view st/profile-property-view-container [view st/profile-property-view-sub-container @@ -43,8 +31,7 @@ [icon :back st/back-btn-icon]]] [view st/status-block [view st/user-photo-container - [user-photo {}] - [user-online {:online true}]] + [profile-icon]] [text {:style st/user-name} name] [text {:style st/status} "!not implemented"] [view st/btns-container @@ -68,10 +55,11 @@ [text {:style st/report-user-text} "REPORT USER"]]]]]) (defview my-profile [] - [username [:get :username] + [username [:get :username] + photo-path [:get :photo-path] phone-number [:get :phone-number] - email [:get :email] - status [:get :status]] + email [:get :email] + status [:get :status]] [scroll-view {:style st/profile} [touchable-highlight {:style st/back-btn-touchable :on-press #(dispatch [:navigate-back])} @@ -85,8 +73,7 @@ [icon :dots st/actions-btn-icon]]] [view st/status-block [view st/user-photo-container - [user-photo {}] - [user-online {:online true}]] + [my-profile-icon]] [text {:style st/user-name} username] [text {:style st/status} status]] [view st/profile-properties-container diff --git a/src/syng_im/profile/styles.cljs b/src/syng_im/profile/styles.cljs index 545016ca4d..2b8c6aa0c2 100644 --- a/src/syng_im/profile/styles.cljs +++ b/src/syng_im/profile/styles.cljs @@ -11,37 +11,6 @@ text1-color text2-color]])) -(def user-photo - {:borderRadius 50 - :width 64 - :height 64}) - -(def user-online-container - {:position :absolute - :top 44 - :left 44 - :width 24 - :height 24 - :borderRadius 50 - :backgroundColor online-color - :borderWidth 2 - :borderColor color-white}) - -(def user-online-dot - {:position :absolute - :top 8 - :left 5 - :width 4 - :height 4 - :borderRadius 50 - :backgroundColor color-white}) - -(def user-online-dot-left - (assoc user-online-dot :left 5)) - -(def user-online-dot-right - (assoc user-online-dot :left 11)) - (def profile-property-view-container {:height 85 :paddingHorizontal 16}) @@ -101,10 +70,10 @@ :width 249}) (def user-photo-container - {:marginTop 26}) + {:marginTop 22}) (def user-name - {:marginTop 20 + {:marginTop 16 :fontSize 18 :fontFamily font :color text1-color}) From eab6dd79c89f0817bed075e398bb30ff0c7c0f14 Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 20 May 2016 10:55:17 +0300 Subject: [PATCH 07/13] Handle empty photo path Former-commit-id: 62fb91fba64493eef895bc65e19cae622eb4a115 --- src/syng_im/components/chat_icon/screen.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/syng_im/components/chat_icon/screen.cljs b/src/syng_im/components/chat_icon/screen.cljs index 028a6cd737..b0acaa568b 100644 --- a/src/syng_im/components/chat_icon/screen.cljs +++ b/src/syng_im/components/chat_icon/screen.cljs @@ -26,7 +26,7 @@ (defview chat-icon-view [chat-id group-chat name color online styles] [photo-path [:chat-photo chat-id]] [view (:container styles) - (if photo-path + (if (and photo-path (not (empty? photo-path))) [chat-icon photo-path styles] [default-chat-icon name color styles]) (when (not group-chat) @@ -81,7 +81,7 @@ :default-chat-icon (st/default-chat-icon-profile color) :default-chat-icon-text st/default-chat-icon-text}] [view (:container styles) - (if photo-path + (if (and photo-path (not (empty? photo-path))) [chat-icon photo-path styles] [default-chat-icon name color styles]) [contact-online online styles]])) From 98d0afd0343f51fcdeb18ba0b88d3f588b432ee0 Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 20 May 2016 12:41:55 +0300 Subject: [PATCH 08/13] Last message date Former-commit-id: a782cf07262cfee70f150e29b6f98a68be76b4ce --- project.clj | 3 +- src/syng_im/chat/handlers.cljs | 16 +++-- .../chats_list/views/chat_list_item.cljs | 5 +- src/syng_im/chats_list/views/inner_item.cljs | 68 ++++++++++--------- src/syng_im/utils/datetime.cljs | 24 +++++++ 5 files changed, 73 insertions(+), 43 deletions(-) create mode 100644 src/syng_im/utils/datetime.cljs diff --git a/project.clj b/project.clj index 8e27322b77..e1079eb235 100644 --- a/project.clj +++ b/project.clj @@ -11,7 +11,8 @@ ^{:voom {:repo "https://github.com/status-im/status-lib.git" :branch "feature-discover"}} [syng-im/protocol "0.1.1-20160506_171115-ge2c95c1"] - [natal-shell "0.1.6"]] + [natal-shell "0.1.6"] + [com.andrewmcveigh/cljs-time "0.4.0"]] :plugins [[lein-cljsbuild "1.1.1"] [lein-figwheel "0.5.0-2"]] :clean-targets ["target/" "index.ios.js" "index.android.js"] diff --git a/src/syng_im/chat/handlers.cljs b/src/syng_im/chat/handlers.cljs index 7cf04bd35d..f950109b2c 100644 --- a/src/syng_im/chat/handlers.cljs +++ b/src/syng_im/chat/handlers.cljs @@ -14,6 +14,7 @@ [syng-im.models.chats :as c] [syng-im.handlers.server :as server] [syng-im.utils.phone-number :refer [format-phone-number]] + [syng-im.utils.datetime :as time] [syng-im.utils.handlers :as u])) (register-handler :set-show-actions @@ -114,13 +115,14 @@ {:keys [command]} (suggestions/check-suggestion db (str text " ")) message (check-author-direction db current-chat-id - {:msg-id (random/id) - :chat-id current-chat-id - :content text - :to current-chat-id - :from identity - :content-type text-content-type - :outgoing true})] + {:msg-id (random/id) + :chat-id current-chat-id + :content text + :to current-chat-id + :from identity + :content-type text-content-type + :outgoing true + :timestamp (time/now-ms)})] (if command (commands/set-chat-command db command) (assoc db :new-message (when-not (str/blank? text) message))))) diff --git a/src/syng_im/chats_list/views/chat_list_item.cljs b/src/syng_im/chats_list/views/chat_list_item.cljs index c11e2fcd3f..83a12accfe 100644 --- a/src/syng_im/chats_list/views/chat_list_item.cljs +++ b/src/syng_im/chats_list/views/chat_list_item.cljs @@ -11,10 +11,7 @@ (defn chat-list-item [{:keys [chat-id] :as chat}] [touchable-highlight {:on-press #(dispatch [:show-chat chat-id :push])} - ;; TODO add [photo-path delivery-status new-messages-count online] values to chat-obj [view [chat-list-item-inner-view (merge chat ;; TODO stub data - {:delivery-status :seen - :new-messages-count 3 - :timestamp "13:54" + {:new-messages-count 3 :online true})]]]) diff --git a/src/syng_im/chats_list/views/inner_item.cljs b/src/syng_im/chats_list/views/inner_item.cljs index 8f2b3b1554..09984101b0 100644 --- a/src/syng_im/chats_list/views/inner_item.cljs +++ b/src/syng_im/chats_list/views/inner_item.cljs @@ -2,37 +2,43 @@ (:require-macros [syng-im.utils.views :refer [defview]]) (:require [syng-im.components.react :refer [view image icon text]] [syng-im.components.chat-icon.screen :refer [chat-icon-view-chat-list]] - [syng-im.chats-list.styles :as st])) + [syng-im.chats-list.styles :as st] + [syng-im.utils.datetime :as time])) (defn chat-list-item-inner-view - [{:keys [chat-id name color photo-path delivery-status timestamp new-messages-count + [{:keys [chat-id name color photo-path new-messages-count online group-chat contacts] :as chat}] - [view st/chat-container - [view st/chat-icon-container - [chat-icon-view-chat-list chat-id group-chat name color online]] - [view st/item-container - [view st/name-view - [text {:style st/name-text} name] - (when group-chat - [icon :group st/group-icon]) - (when group-chat - [text {:style st/memebers-text} - (if (< 1 (count contacts)) - (str (count contacts) " members") - "1 member")])] - [text {:style st/last-message-text - :numberOfLines 2} - (when-let [last-message (first (:messages chat))] - (:content last-message))]] - [view - [view st/status-container - (when delivery-status - [image {:source (if (= (keyword delivery-status) :seen) - {:uri :icon_ok_small} - ;; todo change icon - {:uri :icon_ok_small}) - :style st/status-image}]) - [text {:style st/datetime-text} timestamp]] - (when (pos? new-messages-count) - [view st/new-messages-container - [text {:style st/new-messages-text} new-messages-count]])]]) + (let [last-message (first (:messages chat))] + [view st/chat-container + [view st/chat-icon-container + [chat-icon-view-chat-list chat-id group-chat name color online]] + [view st/item-container + [view st/name-view + [text {:style st/name-text} name] + (when group-chat + [icon :group st/group-icon]) + (when group-chat + [text {:style st/memebers-text} + (if (< 1 (count contacts)) + (str (count contacts) " members") + "1 member")])] + [text {:style st/last-message-text + :numberOfLines 2} + (when last-message + (:content last-message))]] + [view + (when last-message + [view st/status-container + ;; TODO currently there is not :delivery-status in last-message + (when (:delivery-status last-message) + [image {:source (if (= (keyword (:delivery-status last-message)) :seen) + {:uri :icon_ok_small} + ;; todo change icon + {:uri :icon_ok_small}) + :style st/status-image}]) + (when (:timestamp last-message) + [text {:style st/datetime-text} + (time/to-short-str (:timestamp last-message))])]) + (when (pos? new-messages-count) + [view st/new-messages-container + [text {:style st/new-messages-text} new-messages-count]])]])) diff --git a/src/syng_im/utils/datetime.cljs b/src/syng_im/utils/datetime.cljs new file mode 100644 index 0000000000..7ba3686b4b --- /dev/null +++ b/src/syng_im/utils/datetime.cljs @@ -0,0 +1,24 @@ +(ns syng-im.utils.datetime + (:require [cljs-time.core :as t :refer [date-time now plus days hours before?]] + [cljs-time.coerce :refer [from-long to-long]] + [cljs-time.format :as format :refer [formatters + formatter + unparse]])) + +(def time-zone-offset (hours (- (/ (.getTimezoneOffset (js/Date.)) 60)))) + +(defn to-short-str [ms] + (let [date (from-long ms) + local (plus date time-zone-offset) + today-date (t/today) + today (date-time (t/year today-date) + (t/month today-date) + (t/day today-date)) + yesterday (plus today (days -1))] + (cond + (before? local yesterday) (unparse (formatter "dd MMM") local) + (before? local today) "Yesterday" + :else (unparse (formatters :hour-minute) local)))) + +(defn now-ms [] + (to-long (now))) From 19c11ec37020ab68828ded33549b70fd3702b14d Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 20 May 2016 14:38:20 +0300 Subject: [PATCH 09/13] Fix group members count Former-commit-id: df2d2b02caeeda4c15988abd1b094d94f8f468b0 --- src/status_im/chat/screen.cljs | 3 ++- src/status_im/chats_list/views/inner_item.cljs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 9967778d4a..2b14049c55 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -48,6 +48,7 @@ (defn typing-all [] [view st/typing-all + ;; TODO stub data (for [member ["Geoff" "Justas"]] ^{:key member} [typing member])]) @@ -167,7 +168,7 @@ [view {:flexDirection :row} [icon :group st/group-icon] [text {:style st/members} - (let [cnt (count @contacts)] + (let [cnt (inc (count @contacts))] (str cnt (if (< 1 cnt) " members" diff --git a/src/status_im/chats_list/views/inner_item.cljs b/src/status_im/chats_list/views/inner_item.cljs index dd11cdbab3..a0794d5201 100644 --- a/src/status_im/chats_list/views/inner_item.cljs +++ b/src/status_im/chats_list/views/inner_item.cljs @@ -19,8 +19,8 @@ [icon :group st/group-icon]) (when group-chat [text {:style st/memebers-text} - (if (< 1 (count contacts)) - (str (count contacts) " members") + (if (< 0 (count contacts)) + (str (inc (count contacts)) " members") "1 member")])] [text {:style st/last-message-text :numberOfLines 2} From be0d7e26144576de8741edb019bed8fe7efea77d Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 20 May 2016 15:37:24 +0300 Subject: [PATCH 10/13] Add TODO comments Former-commit-id: 3af6d2f369a105713847b7fa4cb7763dde1d847d --- src/status_im/chat/screen.cljs | 29 ++++++++++++++++------- src/status_im/chat/views/plain_input.cljs | 1 + src/status_im/chats_list/screen.cljs | 1 + src/status_im/group_settings/screen.cljs | 7 +++++- src/status_im/profile/screen.cljs | 6 ++++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 2b14049c55..b1e594f977 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -101,22 +101,29 @@ (let [{:keys [group-chat chat-id]} (subscribe [:chat-properties [:group-chat :chat-id]])] (when-let [actions (if @group-chat - [{:title "Add Contact to chat" + [{:title "Members" + ;; TODO stub data: members + :subtitle "Justas, Geoff, Alex and you" :icon :menu_group :icon-style {:width 25 :height 19} - :handler #(dispatch [:show-add-participants])} - {:title "Remove Contact from chat" - :subtitle "Alex, John" + ;; TODO not implemented: action Members + :handler nil} + {:title "Search chat" + :subtitle "!not implemented" :icon :search_gray_copy :icon-style {:width 17 :height 17} - :handler #(dispatch [:show-remove-participants])} - {:title "Leave Chat" + ;; TODO not implemented: action Search chat + :handler nil} + {:title "Notifications and sounds" + :subtitle "!not implemented" + ;;:subtitle "Chat muted" :icon :muted :icon-style {:width 18 :height 21} - :handler #(dispatch [:leave-group-chat])} + ;; TODO not implemented: action Notifications + :handler nil} {:title "Settings" :icon :settings :icon-style {:width 20 @@ -133,19 +140,23 @@ :icon :search_gray_copy :icon-style {:width 17 :height 17} + ;; TODO not implemented: action Search chat :handler nil} {:title "Notifications and sounds" :subtitle "!not implemented" + ;;:subtitle "Notifications on" :icon :muted :icon-style {:width 18 :height 21} + ;; TODO not implemented: action Notifications :handler nil} {:title "Settings" :subtitle "!not implemented" :icon :settings :icon-style {:width 20 :height 13} - :handler (fn [])}])] + ;; TODO not implemented: action Settings + :handler nil}])] [view st/actions-wrapper [view st/actions-separator] [view st/actions-view @@ -173,7 +184,9 @@ (if (< 1 cnt) " members" " member") + ;; TODO stub data: active members ", " cnt " active"))]] + ;; TODO stub data: last activity [text {:style st/last-activity} "Active a minute ago"])]))) (defn toolbar-action [] diff --git a/src/status_im/chat/views/plain_input.cljs b/src/status_im/chat/views/plain_input.cljs index 9b6bea54c5..eaece17dfb 100644 --- a/src/status_im/chat/views/plain_input.cljs +++ b/src/status_im/chat/views/plain_input.cljs @@ -45,6 +45,7 @@ :onSubmitEditing #(try-send @chat @staged-commands-atom input-message)} input-message] + ;; TODO emoticons: not implemented [icon :smile st/smile-icon] (when (message-valid? @staged-commands-atom input-message) [touchable-highlight {:on-press #(send @chat input-message)} diff --git a/src/status_im/chats_list/screen.cljs b/src/status_im/chats_list/screen.cljs index 4187748604..d1c3d603bc 100644 --- a/src/status_im/chats_list/screen.cljs +++ b/src/status_im/chats_list/screen.cljs @@ -23,6 +23,7 @@ :style st/hamburger-icon} :handler open-drawer} :title "Chats" + ;; TODO implement search :action {:image {:source {:uri :icon_search} :style st/search-icon} :handler (fn [])}}]) diff --git a/src/status_im/group_settings/screen.cljs b/src/status_im/group_settings/screen.cljs index fdc868e311..6fb75a1151 100644 --- a/src/status_im/group_settings/screen.cljs +++ b/src/status_im/group_settings/screen.cljs @@ -22,6 +22,7 @@ (defn close-member-menu [] (dispatch [:select-group-chat-member nil])) +;; TODO not in design (defview member-menu [] [member [:group-settings-selected-member]] [modal {:animated false @@ -65,6 +66,7 @@ (close-chat-color-picker) (dispatch [:set-chat-color])) +;; TODO not in design (defview chat-color-picker [] [show-color-picker [:get :group-settings-show-color-picker] new-color [:get :new-chat-color]] @@ -92,10 +94,10 @@ (dispatch [:set-group-settings-show-color-picker true])) (defn settings-view [] - ;; TODO implement settings handlers (let [settings [{:custom-icon [chat-color-icon] :title "Change color" :handler show-chat-color-picker} + ;; TODO not implemented: Notifications (merge {:title "Notifications and sounds" :subtitle "!not implemented" :handler nil} @@ -110,11 +112,13 @@ :icon-style {:width 12 :height 12} :title "Clear history" + ;; TODO show confirmation dialog? :handler #(dispatch [:clear-history])} {:icon :bin :icon-style {:width 12 :height 18} :title "Delete and leave" + ;; TODO show confirmation dialog? :handler #(dispatch [:leave-group-chat])}]] [view st/settings-container (for [setting settings] @@ -150,6 +154,7 @@ "Edit"]]] [text {:style st/members-text} "Members"] + ;; TODO add participants view is not in design [touchable-highlight {:on-press #(dispatch [:show-add-participants])} [view st/add-members-container [icon :add-gray st/add-members-icon] diff --git a/src/status_im/profile/screen.cljs b/src/status_im/profile/screen.cljs index 41c876222f..f3082555fd 100644 --- a/src/status_im/profile/screen.cljs +++ b/src/status_im/profile/screen.cljs @@ -33,6 +33,7 @@ [view st/user-photo-container [profile-icon]] [text {:style st/user-name} name] + ;; TODO stub data [text {:style st/status} "!not implemented"] [view st/btns-container [touchable-highlight {:onPress #(message-user whisper-identity)} @@ -48,10 +49,13 @@ :value name}] [profile-property-view {:name "Phone number" :value phone-number}] + ;; TODO stub data [profile-property-view {:name "Email" :value "!not implemented"}] [view st/report-user-container - [touchable-opacity {} + [touchable-highlight {:on-press (fn [] + ;; TODO not implemented + )} [text {:style st/report-user-text} "REPORT USER"]]]]]) (defview my-profile [] From 615cc4d73a0d986f06b9b56fadbf3ad28930869c Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 20 May 2016 16:18:12 +0300 Subject: [PATCH 11/13] Chat members names menu item Former-commit-id: 34f5ab31a1da6f553810fff7f2b5793bb85208b1 --- src/status_im/chat/screen.cljs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index b1e594f977..a6020a2fda 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -1,6 +1,7 @@ (ns status-im.chat.screen (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] + [clojure.string :as s] [status-im.components.react :refer [view text image @@ -97,13 +98,20 @@ ;; TODO stub data ('online' property) [chat-icon-view-menu-item chat-id group-chat name color true]) +(defn members-text [members] + (let [max 35 + text (str (s/join ", " (map #(:name %) members)) " and you")] + (if (< max (count text)) + (str (subs text 0 (- max 3)) "...") + text))) + (defn actions-list-view [] (let [{:keys [group-chat chat-id]} - (subscribe [:chat-properties [:group-chat :chat-id]])] + (subscribe [:chat-properties [:group-chat :chat-id]]) + members (subscribe [:current-chat-contacts])] (when-let [actions (if @group-chat [{:title "Members" - ;; TODO stub data: members - :subtitle "Justas, Geoff, Alex and you" + :subtitle (members-text @members) :icon :menu_group :icon-style {:width 25 :height 19} From 585baa9d71e05219bbd5ced5c125fff9e6f1b31a Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 20 May 2016 16:36:00 +0300 Subject: [PATCH 12/13] Truncate chat name Former-commit-id: c3496957ff93f07bcfaf16d3cf78c866b4c7fe05 --- src/status_im/chat/screen.cljs | 9 +++------ src/status_im/chats_list/views/inner_item.cljs | 3 ++- src/status_im/utils/utils.cljs | 5 +++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index a6020a2fda..8289fe7bb9 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -13,6 +13,7 @@ chat-icon-view-menu-item]] [status-im.chat.styles.screen :as st] [status-im.utils.listview :refer [to-datasource]] + [status-im.utils.utils :refer [truncate-str]] [status-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [status-im.components.toolbar :refer [toolbar]] [status-im.chat.views.message :refer [chat-message]] @@ -99,11 +100,7 @@ [chat-icon-view-menu-item chat-id group-chat name color true]) (defn members-text [members] - (let [max 35 - text (str (s/join ", " (map #(:name %) members)) " and you")] - (if (< max (count text)) - (str (subs text 0 (- max 3)) "...") - text))) + (truncate-str (str (s/join ", " (map #(:name %) members)) " and you") 35)) (defn actions-list-view [] (let [{:keys [group-chat chat-id]} @@ -182,7 +179,7 @@ (fn [] [view (st/chat-name-view @show-actions) [text {:style st/chat-name-text} - (or @name "Chat name")] + (truncate-str (or @name "Chat name") 30)] (if @group-chat [view {:flexDirection :row} [icon :group st/group-icon] diff --git a/src/status_im/chats_list/views/inner_item.cljs b/src/status_im/chats_list/views/inner_item.cljs index a0794d5201..e3fc322bb7 100644 --- a/src/status_im/chats_list/views/inner_item.cljs +++ b/src/status_im/chats_list/views/inner_item.cljs @@ -3,6 +3,7 @@ (:require [status-im.components.react :refer [view image icon text]] [status-im.components.chat-icon.screen :refer [chat-icon-view-chat-list]] [status-im.chats-list.styles :as st] + [status-im.utils.utils :refer [truncate-str]] [status-im.utils.datetime :as time])) (defn chat-list-item-inner-view @@ -14,7 +15,7 @@ [chat-icon-view-chat-list chat-id group-chat name color online]] [view st/item-container [view st/name-view - [text {:style st/name-text} name] + [text {:style st/name-text} (truncate-str name 20)] (when group-chat [icon :group st/group-icon]) (when group-chat diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index 8a0be411d7..02d54d3f88 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -47,3 +47,8 @@ (.catch (or on-error (fn [error] (toast (str error)))))))) + +(defn truncate-str [s max] + (if (< max (count s)) + (str (subs s 0 (- max 3)) "...") + s)) From 5142ffc4c3b1723a40fd7a8934df70ce8ae673ea Mon Sep 17 00:00:00 2001 From: virvar Date: Mon, 23 May 2016 13:50:46 +0300 Subject: [PATCH 13/13] Fix new chat icon Former-commit-id: fc5bb416af26496701f4132ef055d463b63ee9d6 --- src/status_im/chat/handlers.cljs | 2 ++ src/status_im/chats_list/screen.cljs | 6 ++-- .../components/chat_icon/screen.cljs | 32 +++++++------------ src/status_im/components/styles.cljs | 1 + src/status_im/new_group/handlers.cljs | 2 ++ src/status_im/persistence/realm.cljs | 3 +- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 45bcc38329..124357de30 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -2,6 +2,7 @@ (:require [re-frame.core :refer [register-handler enrich after debug dispatch]] [status-im.models.commands :as commands] [clojure.string :as str] + [status-im.components.styles :refer [default-chat-color]] [status-im.chat.suggestions :as suggestions] [status-im.protocol.api :as api] [status-im.models.messages :as messages] @@ -304,6 +305,7 @@ (let [name (get-in contacts [contcat-id :name]) chat {:chat-id contcat-id :name name + :color default-chat-color :group-chat false :is-active true :timestamp (.getTime (js/Date.)) diff --git a/src/status_im/chats_list/screen.cljs b/src/status_im/chats_list/screen.cljs index d1c3d603bc..700ee209b2 100644 --- a/src/status_im/chats_list/screen.cljs +++ b/src/status_im/chats_list/screen.cljs @@ -10,9 +10,10 @@ [reagent.core :as r] [status-im.chats-list.views.chat-list-item :refer [chat-list-item]] [status-im.components.action-button :refer [action-button - action-button-item]] + action-button-item]] [status-im.components.drawer.view :refer [drawer-view open-drawer]] - [status-im.components.styles :refer [color-blue]] + [status-im.components.styles :refer [color-blue + toolbar-background2]] [status-im.components.toolbar :refer [toolbar]] [status-im.components.icons.ionicons :refer [icon]] [status-im.chats-list.styles :as st])) @@ -23,6 +24,7 @@ :style st/hamburger-icon} :handler open-drawer} :title "Chats" + :background-color toolbar-background2 ;; TODO implement search :action {:image {:source {:uri :icon_search} :style st/search-icon} diff --git a/src/status_im/components/chat_icon/screen.cljs b/src/status_im/components/chat_icon/screen.cljs index e3aae00a05..e44d334e33 100644 --- a/src/status_im/components/chat_icon/screen.cljs +++ b/src/status_im/components/chat_icon/screen.cljs @@ -8,7 +8,7 @@ [status-im.components.chat-icon.styles :as st] [status-im.components.styles :refer [color-purple]])) -(defn default-chat-icon [name color styles] +(defn default-chat-icon [name styles] [view (:default-chat-icon styles) [text {:style (:default-chat-icon-text styles)} (first name)]]) @@ -23,17 +23,17 @@ [view (:online-dot-left styles)] [view (:online-dot-right styles)]])) -(defview chat-icon-view [chat-id group-chat name color online styles] +(defview chat-icon-view [chat-id group-chat name online styles] [photo-path [:chat-photo chat-id]] [view (:container styles) (if (and photo-path (not (empty? photo-path))) [chat-icon photo-path styles] - [default-chat-icon name color styles]) + [default-chat-icon name styles]) (when (not group-chat) [contact-online online styles])]) (defn chat-icon-view-chat-list [chat-id group-chat name color online] - [chat-icon-view chat-id group-chat name color online + [chat-icon-view chat-id group-chat name online {:container st/container-chat-list :online-view st/online-view :online-dot-left st/online-dot-left @@ -43,7 +43,7 @@ :default-chat-icon-text st/default-chat-icon-text}]) (defn chat-icon-view-action [chat-id group-chat name color online] - [chat-icon-view chat-id group-chat name color online + [chat-icon-view chat-id group-chat name online {:container st/container :online-view st/online-view :online-dot-left st/online-dot-left @@ -53,7 +53,7 @@ :default-chat-icon-text st/default-chat-icon-text}]) (defn chat-icon-view-menu-item [chat-id group-chat name color online] - [chat-icon-view chat-id group-chat name color online + [chat-icon-view chat-id group-chat name online {:container st/container-menu-item :online-view st/online-view-menu-item :online-dot-left st/online-dot-left-menu-item @@ -62,16 +62,6 @@ :default-chat-icon (st/default-chat-icon-menu-item color) :default-chat-icon-text st/default-chat-icon-text}]) -(defn chat-icon-view-profile [chat-id group-chat name color online] - [chat-icon-view chat-id group-chat name color online - {:container st/container-profile - :online-view st/online-view-profile - :online-dot-left st/online-dot-left-profile - :online-dot-right st/online-dot-right-profile - :chat-icon st/chat-icon-profile - :default-chat-icon (st/default-chat-icon-profile color) - :default-chat-icon-text st/default-chat-icon-text}]) - (defn profile-icon-view [photo-path name color online] (let [styles {:container st/container-profile :online-view st/online-view-profile @@ -83,20 +73,20 @@ [view (:container styles) (if (and photo-path (not (empty? photo-path))) [chat-icon photo-path styles] - [default-chat-icon name color styles]) + [default-chat-icon name styles]) [contact-online online styles]])) (defview profile-icon [] [contact [:contact]] - (let [ ;; TODO stub data + (let [;; TODO stub data online true - color color-purple] + color color-purple] [profile-icon-view (:photo-path contact) (:name contact) color online])) (defview my-profile-icon [] [name [:get :username] photo-path [:get :photo-path]] - (let [ ;; TODO stub data + (let [;; TODO stub data online true - color color-purple] + color color-purple] [profile-icon-view photo-path name color online])) diff --git a/src/status_im/components/styles.cljs b/src/status_im/components/styles.cljs index 421224dc92..6ccb836e02 100644 --- a/src/status_im/components/styles.cljs +++ b/src/status_im/components/styles.cljs @@ -26,3 +26,4 @@ (def separator-color "#0000001f") (def toolbar-background1 color-white) (def toolbar-background2 color-light-gray) +(def default-chat-color color-purple) diff --git a/src/status_im/new_group/handlers.cljs b/src/status_im/new_group/handlers.cljs index 7c890399fd..4d934d1e23 100644 --- a/src/status_im/new_group/handlers.cljs +++ b/src/status_im/new_group/handlers.cljs @@ -1,6 +1,7 @@ (ns status-im.new-group.handlers (:require [status-im.protocol.api :as api] [re-frame.core :refer [register-handler after dispatch debug enrich]] + [status-im.components.styles :refer [default-chat-color]] [status-im.models.chats :as chats] [clojure.string :as s])) @@ -37,6 +38,7 @@ (group-name-from-contacts db))] (assoc db :new-chat {:chat-id new-group-id :name chat-name + :color default-chat-color :group-chat true :is-active true :timestamp (.getTime (js/Date.)) diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index 242f98bb9c..a7d564f143 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -1,5 +1,6 @@ (ns status-im.persistence.realm (:require [cljs.reader :refer [read-string]] + [status-im.components.styles :refer [default-chat-color]] [status-im.utils.logging :as log] [status-im.utils.types :refer [to-string]]) (:refer-clojure :exclude [exists?])) @@ -44,7 +45,7 @@ :properties {:chat-id "string" :name "string" :color {:type "string" - :default "#a187d5"} + :default default-chat-color} :group-chat {:type "bool" :indexed true} :is-active "bool"