From 798aab0f729669ec7a81df492db43da93901f883 Mon Sep 17 00:00:00 2001 From: virvar Date: Thu, 12 May 2016 12:13:09 +0300 Subject: [PATCH 01/13] Read/save group chat settings Former-commit-id: 14be588ca234fefcfd7813dc2b9ef67584ae3339 --- src/syng_im/android/core.cljs | 2 + src/syng_im/components/chat.cljs | 18 ++-- src/syng_im/components/group_settings.cljs | 96 ++++++++++++++++++++++ src/syng_im/db.cljs | 3 + src/syng_im/handlers.cljs | 31 +++++-- src/syng_im/models/chat.cljs | 10 +++ src/syng_im/models/chats.cljs | 17 +++- src/syng_im/subs.cljs | 12 +++ 8 files changed, 171 insertions(+), 18 deletions(-) create mode 100644 src/syng_im/components/group_settings.cljs diff --git a/src/syng_im/android/core.cljs b/src/syng_im/android/core.cljs index 8cdc69d449..73f2fcfcc7 100644 --- a/src/syng_im/android/core.cljs +++ b/src/syng_im/android/core.cljs @@ -15,6 +15,7 @@ [syng-im.components.chats.new-group :refer [new-group]] [syng-im.components.chat.new-participants :refer [new-participants]] [syng-im.components.chat.remove-participants :refer [remove-participants]] + [syng-im.components.group-settings :refer [group-settings]] [syng-im.components.profile :refer [profile my-profile]] [syng-im.utils.logging :as log] [syng-im.utils.utils :refer [toast]] @@ -46,6 +47,7 @@ :remove-participants [remove-participants] :chat-list [chats-list] :new-group [new-group] + :group-settings [group-settings] :contact-list [contact-list] :chat [chat] :profile [profile] diff --git a/src/syng_im/components/chat.cljs b/src/syng_im/components/chat.cljs index e11d48e727..8411cb580f 100644 --- a/src/syng_im/components/chat.cljs +++ b/src/syng_im/components/chat.cljs @@ -122,27 +122,23 @@ :icon :menu_group :icon-style {:width 25 :height 19} - :handler nil #_#(dispatch [:show-add-participants - navigator])} + :handler #(dispatch [:show-add-participants])} {:title "Remove Contact from chat" :subtitle "Alex, John" :icon :search_gray_copy :icon-style {:width 17 :height 17} - :handler nil #_#(dispatch - [:show-remove-participants navigator])} + :handler #(dispatch [:show-remove-participants])} {:title "Leave Chat" :icon :muted :icon-style {:width 18 :height 21} - :handler nil #_#(dispatch [:leave-group-chat - navigator])} + :handler #(dispatch [:leave-group-chat])} {:title "Settings" - :subtitle "Not implemented" :icon :settings :icon-style {:width 20 :height 13} - :handler (fn [])}] + :handler #(dispatch [:show-group-settings])}] [{:title "Profile" :custom-icon [menu-item-icon-profile] :icon :menu_group @@ -154,15 +150,13 @@ :icon :search_gray_copy :icon-style {:width 17 :height 17} - :handler nil #_#(dispatch - [:show-remove-participants navigator])} + :handler nil} {:title "Notifications and sounds" :subtitle "!not implemented" :icon :muted :icon-style {:width 18 :height 21} - :handler nil #_#(dispatch [:leave-group-chat - navigator])} + :handler nil} {:title "Settings" :subtitle "!not implemented" :icon :settings diff --git a/src/syng_im/components/group_settings.cljs b/src/syng_im/components/group_settings.cljs new file mode 100644 index 0000000000..8c5a30eaf7 --- /dev/null +++ b/src/syng_im/components/group_settings.cljs @@ -0,0 +1,96 @@ +(ns syng-im.components.group-settings + (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [syng-im.resources :as res] + [syng-im.components.react :refer [view + text-input + text + image + touchable-highlight]] + [syng-im.components.styles :refer [font + title-font + color-white + color-purple + text1-color + text2-color + toolbar-background1]] + [syng-im.components.toolbar :refer [toolbar]] + [syng-im.components.realm :refer [list-view]] + [syng-im.utils.listview :refer [to-realm-datasource]] + [syng-im.components.contact-list.contact-inner :refer [contact-inner-view]] + [syng-im.components.chats.new-group-contact :refer [new-group-contact]] + [reagent.core :as r])) + +(defn set-group-settings-name [chat-name] + (dispatch [:set-group-settings-name chat-name])) + +(defn chat-members [members] + [view {:style {:marginBottom 10}} + (for [member members] + ^{:key member} [contact-inner-view member] + ;; [new-group-contact member nil] + )]) + +(defn new-group-toolbar [chat-name] + [toolbar {:title "Chat settings" + :action {:image {:source res/v ;; {:uri "icon_search"} + :style {:width 20 + :height 18}} + :handler (fn [] + (dispatch [:save-group-chat chat-name]))}}]) + +(defn group-settings [] + (let [chat-name (subscribe [:group-settings-name]) + members (subscribe [:group-settings-members])] + (fn [] + [view {:style {:flex 1 + :flexDirection "column" + :backgroundColor color-white}} + [new-group-toolbar @chat-name] + [view {:style {:marginHorizontal 16}} + [text {:style {:marginTop 24 + :marginBottom 16 + :color text2-color + :fontFamily font + :fontSize 14 + :lineHeight 20}} + "Chat name"] + [text-input {:underlineColorAndroid color-purple + :style {:marginLeft -4 + :fontSize 14 + :fontFamily font + :color text1-color} + :autoFocus true + :placeholderTextColor text2-color + :onChangeText set-group-settings-name} + @chat-name] + [text {:style {:marginTop 24 + :marginBottom 16 + :color text2-color + :fontFamily font + :fontSize 14 + :lineHeight 20}} + "Members"] + [touchable-highlight {:on-press (fn []) + :underlay-color :transparent} + [view {:style {:flexDirection "row" + :marginBottom 16}} + [image {:source {:uri "icon_add_gray"} + :style {:marginVertical 19 + :marginHorizontal 3 + :width 17 + :height 17}}] + [text {:style {:marginTop 18 + :marginLeft 32 + :color text2-color + :fontFamily font + :fontSize 14 + :lineHeight 20}} + "Add members"]]] + [chat-members (vals (js->clj @members :keywordize-keys true))] + [text {:style {:marginTop 24 + :marginBottom 16 + :color text2-color + :fontFamily font + :fontSize 14 + :lineHeight 20}} + "Settings"]]]))) diff --git a/src/syng_im/db.cljs b/src/syng_im/db.cljs index 27a48ce65d..f795817c7a 100644 --- a/src/syng_im/db.cljs +++ b/src/syng_im/db.cljs @@ -50,6 +50,9 @@ (defn chat-command-request-path [chat-id msg-id] [:chats chat-id :command-requests msg-id]) (def show-actions-path [:show-actions]) +(def group-settings-path [:group-settings]) +(def group-settings-name-path [:group-settings :name]) +(def group-settings-members-path [:group-settings :contacts]) (def new-group-path [:new-group]) (def new-participants-path [:new-participants]) (def updated-discoveries-signal-path [:discovery-updated-signal]) diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index c776b061b6..128dbca520 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -35,6 +35,7 @@ [syng-im.components.discovery.handlers :as discovery] [syng-im.models.chats :refer [chat-exists? create-chat + save-chat chat-add-participants chat-remove-participants set-chat-active @@ -43,6 +44,7 @@ [syng-im.models.chat :refer [signal-chat-updated set-current-chat-id current-chat-id + set-group-settings update-new-group-selection update-new-participants-selection clear-new-group @@ -393,7 +395,7 @@ ((after handle-commands)))) (register-handler :leave-group-chat - (fn [db [action navigator]] + (fn [db [action]] (log/debug action) (let [chat-id (current-chat-id db)] (api/leave-group-chat chat-id) @@ -542,9 +544,9 @@ (update-new-participants-selection db identity add?))) (register-handler :show-remove-participants - (fn [db [action navigator]] + (fn [db [action]] (log/debug action) - (nav-push navigator {:view-id :remove-participants}) + (dispatch [:navigate-to :remove-participants]) (clear-new-participants db))) (register-handler :remove-selected-participants @@ -560,9 +562,9 @@ (signal-chat-updated db chat-id)))) (register-handler :show-add-participants - (fn [db [action navigator]] + (fn [db [action]] (log/debug action) - (nav-push navigator {:view-id :add-participants}) + (dispatch [:navigate-to :add-participants]) (clear-new-participants db))) (register-handler :add-new-participants @@ -596,6 +598,25 @@ (dispatch [:show-chat group-id navigator :replace]) db))) +(register-handler :show-group-settings + (fn [db [action]] + (log/debug action) + (let [db (set-group-settings db)] + (dispatch [:navigate-to :group-settings]) + db))) + +(register-handler :set-group-settings-name + (fn [db [action chat-name]] + (log/debug action) + (assoc-in db db/group-settings-name-path chat-name))) + +(register-handler :save-group-chat + (fn [db [action]] + (log/debug action) + (let [db (save-chat db)] + (dispatch [:navigate-back]) + db))) + (register-handler :group-chat-invite-received (fn [db [action from group-id identities group-name]] (log/debug action from group-id identities) diff --git a/src/syng_im/models/chat.cljs b/src/syng_im/models/chat.cljs index 763be721db..1fa736cafd 100644 --- a/src/syng_im/models/chat.cljs +++ b/src/syng_im/models/chat.cljs @@ -7,6 +7,9 @@ (defn current-chat-id [db] (get-in db db/current-chat-id-path)) +(defn current-chat [db] + (get-in db [:chats (current-chat-id db)])) + (defn signal-chat-updated [db chat-id] (update-in db (db/updated-chat-signal-path chat-id) (fn [current] (if current @@ -16,6 +19,13 @@ (defn chat-updated? [db chat-id] (get-in db (db/updated-chat-signal-path chat-id))) +(defn get-group-settings [db] + (get-in db db/group-settings-path)) + +(defn set-group-settings [db] + (let [group-chat (current-chat db)] + (assoc-in db db/group-settings-path group-chat))) + (defn update-new-group-selection [db identity add?] (update-in db db/new-group-path (fn [new-group] (if add? diff --git a/src/syng_im/models/chats.cljs b/src/syng_im/models/chats.cljs index ade0679521..faa2820fdf 100644 --- a/src/syng_im/models/chats.cljs +++ b/src/syng_im/models/chats.cljs @@ -1,5 +1,6 @@ (ns syng-im.models.chats (:require [clojure.set :refer [difference]] + [re-frame.core :refer [dispatch]] [syng-im.persistence.realm :as r] [syng-im.utils.random :as random :refer [timestamp]] [clojure.string :refer [join blank?]] @@ -8,7 +9,8 @@ [syng-im.constants :refer [content-type-status]] [syng-im.models.messages :refer [save-message]] [syng-im.persistence.realm-queries :refer [include-query]] - [syng-im.models.chat :refer [signal-chat-updated]])) + [syng-im.models.chat :refer [signal-chat-updated + get-group-settings]])) (defn signal-chats-updated [db] (update-in db db/updated-chats-signal-path (fn [current] @@ -75,6 +77,19 @@ (add-status-message chat-id) (signal-chats-updated db))))) +(defn save-chat [db] + (let [chat-settings (get-group-settings db) + chat-id (:chat-id chat-settings)] + (r/write + (fn [] + ;; TODO UNDONE contacts + (r/create :chats (select-keys chat-settings [:chat-id :name]) true))) + ;; TODO update chat in db atom + (dispatch [:initialize-chats]) + (-> db + (signal-chats-updated) + (signal-chat-updated chat-id)))) + (defn chat-contacts [chat-id] (-> (r/get-by-field :chats :chat-id chat-id) (r/single) diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index f09e537391..b3cab18d6d 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -4,6 +4,7 @@ [syng-im.db :as db] [syng-im.components.discovery.subs :as discovery] [syng-im.models.chat :refer [current-chat-id + get-group-settings chat-updated?]] [syng-im.models.chats :refer [chats-list chats-updated? @@ -177,6 +178,17 @@ (map :identity))] (contacts-list-include current-participants))))))) +(register-sub :group-settings-name + (fn [db [_]] + (reaction (get-in @db db/group-settings-name-path)))) + +(register-sub :group-settings-members + (fn [db [_]] + (let [members (reaction (get-in @db db/group-settings-members-path))] + (reaction + (let [current-participants (map :identity @members)] + (contacts-list-include current-participants)))))) + (register-sub :view-id (fn [db _] (reaction (@db :view-id)))) From 84bb1b80b58eab4d3eb4e95b3eff5d3664072014 Mon Sep 17 00:00:00 2001 From: virvar Date: Thu, 12 May 2016 14:15:09 +0300 Subject: [PATCH 02/13] Group settings styles Former-commit-id: 240569434c31ae5ff73d24307523d7f5331d846f --- src/syng_im/components/group_settings.cljs | 87 +++++++------------ .../components/group_settings_styles.cljs | 86 ++++++++++++++++++ src/syng_im/models/chat.cljs | 3 +- src/syng_im/models/chats.cljs | 3 +- 4 files changed, 120 insertions(+), 59 deletions(-) create mode 100644 src/syng_im/components/group_settings_styles.cljs diff --git a/src/syng_im/components/group_settings.cljs b/src/syng_im/components/group_settings.cljs index 8c5a30eaf7..b1777e659a 100644 --- a/src/syng_im/components/group_settings.cljs +++ b/src/syng_im/components/group_settings.cljs @@ -5,16 +5,13 @@ text-input text image + icon touchable-highlight]] - [syng-im.components.styles :refer [font - title-font - color-white - color-purple - text1-color - text2-color - toolbar-background1]] [syng-im.components.toolbar :refer [toolbar]] [syng-im.components.realm :refer [list-view]] + [syng-im.components.styles :refer [color-purple + text2-color]] + [syng-im.components.group-settings-styles :as st] [syng-im.utils.listview :refer [to-realm-datasource]] [syng-im.components.contact-list.contact-inner :refer [contact-inner-view]] [syng-im.components.chats.new-group-contact :refer [new-group-contact]] @@ -23,74 +20,50 @@ (defn set-group-settings-name [chat-name] (dispatch [:set-group-settings-name chat-name])) +(defn save-group-chat [] + (dispatch [:save-group-chat])) + (defn chat-members [members] - [view {:style {:marginBottom 10}} + [view st/chat-members-container (for [member members] ^{:key member} [contact-inner-view member] ;; [new-group-contact member nil] )]) -(defn new-group-toolbar [chat-name] +(defn action-save [] + [touchable-highlight + {:on-press save-group-chat} + [view st/save-btn + [text {:style st/save-btn-text} "S"]]]) + +(defn new-group-toolbar [] [toolbar {:title "Chat settings" - :action {:image {:source res/v ;; {:uri "icon_search"} - :style {:width 20 - :height 18}} - :handler (fn [] - (dispatch [:save-group-chat chat-name]))}}]) + :custom-action [action-save]}]) (defn group-settings [] (let [chat-name (subscribe [:group-settings-name]) members (subscribe [:group-settings-members])] (fn [] - [view {:style {:flex 1 - :flexDirection "column" - :backgroundColor color-white}} - [new-group-toolbar @chat-name] - [view {:style {:marginHorizontal 16}} - [text {:style {:marginTop 24 - :marginBottom 16 - :color text2-color - :fontFamily font - :fontSize 14 - :lineHeight 20}} + [view st/group-settings + [new-group-toolbar] + [view st/properties-container + [text {:style st/chat-name-text} "Chat name"] - [text-input {:underlineColorAndroid color-purple - :style {:marginLeft -4 - :fontSize 14 - :fontFamily font - :color text1-color} + [text-input {:style st/chat-name-input + :underlineColorAndroid color-purple :autoFocus true :placeholderTextColor text2-color :onChangeText set-group-settings-name} @chat-name] - [text {:style {:marginTop 24 - :marginBottom 16 - :color text2-color - :fontFamily font - :fontSize 14 - :lineHeight 20}} + [text {:style st/members-text} "Members"] - [touchable-highlight {:on-press (fn []) - :underlay-color :transparent} - [view {:style {:flexDirection "row" - :marginBottom 16}} - [image {:source {:uri "icon_add_gray"} - :style {:marginVertical 19 - :marginHorizontal 3 - :width 17 - :height 17}}] - [text {:style {:marginTop 18 - :marginLeft 32 - :color text2-color - :fontFamily font - :fontSize 14 - :lineHeight 20}} + [touchable-highlight {:on-press (fn [] + ;; TODO not implemented + )} + [view st/add-members-container + [icon :add-gray st/add-members-icon] + [text {:style st/add-members-text} "Add members"]]] [chat-members (vals (js->clj @members :keywordize-keys true))] - [text {:style {:marginTop 24 - :marginBottom 16 - :color text2-color - :fontFamily font - :fontSize 14 - :lineHeight 20}} + [text {:style st/settings-text} "Settings"]]]))) diff --git a/src/syng_im/components/group_settings_styles.cljs b/src/syng_im/components/group_settings_styles.cljs new file mode 100644 index 0000000000..111a166fe7 --- /dev/null +++ b/src/syng_im/components/group_settings_styles.cljs @@ -0,0 +1,86 @@ +(ns syng-im.components.group-settings-styles + (:require [syng-im.components.styles :refer [font + title-font + color-white + color-purple + chat-background + online-color + selected-message-color + separator-color + text1-color + text2-color + toolbar-background1]])) + +(def chat-members-container + {:marginBottom 10}) + +(def save-btn + {:margin 10 + :width 36 + :height 36 + :borderRadius 50 + :backgroundColor color-purple}) + +(def save-btn-text + {:marginTop 7 + :marginLeft 13 + :color color-white + :fontFamily font + :fontSize 16 + :lineHeight 20}) + +(def group-settings + {:flex 1 + :flexDirection :column + :backgroundColor color-white}) + +(def properties-container + {:marginHorizontal 16}) + +(def chat-name-text + {:marginTop 24 + :marginBottom 16 + :color text2-color + :fontFamily font + :fontSize 14 + :lineHeight 20}) + +(def chat-name-input + {:marginLeft -4 + :fontSize 14 + :fontFamily font + :color text1-color}) + +(def members-text + {:marginTop 24 + :marginBottom 16 + :color text2-color + :fontFamily font + :fontSize 14 + :lineHeight 20}) + +(def add-members-icon + {:marginVertical 19 + :marginHorizontal 3 + :width 17 + :height 17}) + +(def add-members-container + {:flexDirection :row + :marginBottom 16}) + +(def add-members-text + {:marginTop 18 + :marginLeft 32 + :color text2-color + :fontFamily font + :fontSize 14 + :lineHeight 20}) + +(def settings-text + {:marginTop 24 + :marginBottom 16 + :color text2-color + :fontFamily font + :fontSize 14 + :lineHeight 20}) diff --git a/src/syng_im/models/chat.cljs b/src/syng_im/models/chat.cljs index 1fa736cafd..5fda433919 100644 --- a/src/syng_im/models/chat.cljs +++ b/src/syng_im/models/chat.cljs @@ -24,7 +24,8 @@ (defn set-group-settings [db] (let [group-chat (current-chat db)] - (assoc-in db db/group-settings-path group-chat))) + (assoc-in db db/group-settings-path + (select-keys group-chat [:chat-id :name :contacts])))) (defn update-new-group-selection [db identity add?] (update-in db db/new-group-path (fn [new-group] diff --git a/src/syng_im/models/chats.cljs b/src/syng_im/models/chats.cljs index faa2820fdf..f98c830fde 100644 --- a/src/syng_im/models/chats.cljs +++ b/src/syng_im/models/chats.cljs @@ -83,7 +83,8 @@ (r/write (fn [] ;; TODO UNDONE contacts - (r/create :chats (select-keys chat-settings [:chat-id :name]) true))) + (r/create :chats + (select-keys chat-settings [:chat-id :name :contacts]) true))) ;; TODO update chat in db atom (dispatch [:initialize-chats]) (-> db From 70e9e2155b67bfdfd1464fe916bd933d2695757e Mon Sep 17 00:00:00 2001 From: virvar Date: Thu, 12 May 2016 15:32:40 +0300 Subject: [PATCH 03/13] Group settings members Former-commit-id: 344f64b9f236a372c69a8b4a180480a35ffcd901 --- src/syng_im/components/group_settings.cljs | 50 +++++------ .../components/group_settings_member.cljs | 39 ++++++++ .../group_settings_member_styles.cljs | 89 +++++++++++++++++++ .../components/group_settings_styles.cljs | 9 +- 4 files changed, 156 insertions(+), 31 deletions(-) create mode 100644 src/syng_im/components/group_settings_member.cljs create mode 100644 src/syng_im/components/group_settings_member_styles.cljs diff --git a/src/syng_im/components/group_settings.cljs b/src/syng_im/components/group_settings.cljs index b1777e659a..2181daa471 100644 --- a/src/syng_im/components/group_settings.cljs +++ b/src/syng_im/components/group_settings.cljs @@ -13,8 +13,7 @@ text2-color]] [syng-im.components.group-settings-styles :as st] [syng-im.utils.listview :refer [to-realm-datasource]] - [syng-im.components.contact-list.contact-inner :refer [contact-inner-view]] - [syng-im.components.chats.new-group-contact :refer [new-group-contact]] + [syng-im.components.group-settings-member :refer [contact-inner-view]] [reagent.core :as r])) (defn set-group-settings-name [chat-name] @@ -26,9 +25,7 @@ (defn chat-members [members] [view st/chat-members-container (for [member members] - ^{:key member} [contact-inner-view member] - ;; [new-group-contact member nil] - )]) + ^{:key member} [contact-inner-view member])]) (defn action-save [] [touchable-highlight @@ -37,7 +34,7 @@ [text {:style st/save-btn-text} "S"]]]) (defn new-group-toolbar [] - [toolbar {:title "Chat settings" + [toolbar {:title "Chat settings" :custom-action [action-save]}]) (defn group-settings [] @@ -46,24 +43,23 @@ (fn [] [view st/group-settings [new-group-toolbar] - [view st/properties-container - [text {:style st/chat-name-text} - "Chat name"] - [text-input {:style st/chat-name-input - :underlineColorAndroid color-purple - :autoFocus true - :placeholderTextColor text2-color - :onChangeText set-group-settings-name} - @chat-name] - [text {:style st/members-text} - "Members"] - [touchable-highlight {:on-press (fn [] - ;; TODO not implemented - )} - [view st/add-members-container - [icon :add-gray st/add-members-icon] - [text {:style st/add-members-text} - "Add members"]]] - [chat-members (vals (js->clj @members :keywordize-keys true))] - [text {:style st/settings-text} - "Settings"]]]))) + [text {:style st/chat-name-text} + "Chat name"] + [text-input {:style st/chat-name-input + :underlineColorAndroid color-purple + :autoFocus true + :placeholderTextColor text2-color + :onChangeText set-group-settings-name} + @chat-name] + [text {:style st/members-text} + "Members"] + [touchable-highlight {:on-press (fn [] + ;; TODO not implemented + )} + [view st/add-members-container + [icon :add-gray st/add-members-icon] + [text {:style st/add-members-text} + "Add members"]]] + [chat-members (vals (js->clj @members :keywordize-keys true))] + [text {:style st/settings-text} + "Settings"]]))) diff --git a/src/syng_im/components/group_settings_member.cljs b/src/syng_im/components/group_settings_member.cljs new file mode 100644 index 0000000000..892de6c485 --- /dev/null +++ b/src/syng_im/components/group_settings_member.cljs @@ -0,0 +1,39 @@ +(ns syng-im.components.group-settings-member + (:require [clojure.string :as s] + [syng-im.components.react :refer [view image text icon touchable-highlight]] + [syng-im.resources :as res] + [syng-im.components.group-settings-member-styles :as st])) + +(defn contact-photo [{:keys [photo-path]}] + [view st/contact-photo-container + [image {:source (if (s/blank? photo-path) + res/user-no-photo + {:uri photo-path}) + :style st/photo-image}]]) + +(defn contact-online [{:keys [online]}] + (when online + [view st/online-container + [view st/online-dot-left] + [view st/online-dot-right]])) + +(defn contact-inner-view [{:keys [name photo-path online role]}] + [view st/contact-container + [view st/photo-container + [contact-photo {:photo-path photo-path}] + [contact-online {:online online}]] + [view st/info-container + [text {:style st/name-text} + (if (pos? (count name)) + name + ;; todo is this correct behaviour? + "Noname")] + ;; TODO implement :role property for group chat contact + (when role + [text {:style st/role-text} + role])] + [touchable-highlight {:on-press (fn [] + ;; TODO not implemented + )} + [view st/more-btn + [icon :more-vertical st/more-btn-icon]]]]) diff --git a/src/syng_im/components/group_settings_member_styles.cljs b/src/syng_im/components/group_settings_member_styles.cljs new file mode 100644 index 0000000000..122802f4f3 --- /dev/null +++ b/src/syng_im/components/group_settings_member_styles.cljs @@ -0,0 +1,89 @@ +(ns syng-im.components.group-settings-member-styles + (:require [syng-im.components.styles :refer [font + title-font + text1-color + text2-color + color-white + online-color]])) + +(def search-icon + {:width 17 + :height 17}) + +(def contacts-list-container + {:flex 1 + :backgroundColor :white}) + +(def contacts-list + {:backgroundColor :white}) + +(def contact-photo-container + {:borderRadius 50}) + +(def 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 contact-container + {:flexDirection :row + :height 56}) + +(def photo-container + {:marginTop 8 + :marginLeft 16 + :width 44 + :height 44}) + +(def info-container + {:flex 1 + :flexDirection :column + :marginLeft 16 + :justifyContent :center}) + +(def name-text + {:marginTop -2 + :fontSize 16 + :fontFamily font + :color text1-color}) + +(def role-text + {:marginTop 1 + :fontSize 12 + :fontFamily font + :color text2-color}) + +(def more-btn + {:width 56 + :height 56 + :alignItems :center + :justifyContent :center }) + +(def more-btn-icon + {:width 4 + :height 16}) diff --git a/src/syng_im/components/group_settings_styles.cljs b/src/syng_im/components/group_settings_styles.cljs index 111a166fe7..498c212ed8 100644 --- a/src/syng_im/components/group_settings_styles.cljs +++ b/src/syng_im/components/group_settings_styles.cljs @@ -34,11 +34,9 @@ :flexDirection :column :backgroundColor color-white}) -(def properties-container - {:marginHorizontal 16}) - (def chat-name-text {:marginTop 24 + :marginLeft 16 :marginBottom 16 :color text2-color :fontFamily font @@ -46,13 +44,14 @@ :lineHeight 20}) (def chat-name-input - {:marginLeft -4 + {:marginLeft 12 :fontSize 14 :fontFamily font :color text1-color}) (def members-text {:marginTop 24 + :marginLeft 16 :marginBottom 16 :color text2-color :fontFamily font @@ -61,6 +60,7 @@ (def add-members-icon {:marginVertical 19 + :marginLeft 19 :marginHorizontal 3 :width 17 :height 17}) @@ -79,6 +79,7 @@ (def settings-text {:marginTop 24 + :marginLeft 16 :marginBottom 16 :color text2-color :fontFamily font From b62b758c60a49693ccd48f9c7433606ea4ceb249 Mon Sep 17 00:00:00 2001 From: virvar Date: Thu, 12 May 2016 16:31:27 +0300 Subject: [PATCH 04/13] Group settings to new structure Former-commit-id: 5283256804c731dae28bd0de1041f93191c6980b --- src/syng_im/android/core.cljs | 2 +- .../group_settings.cljs | 6 +++--- .../styles/group_settings.cljs} | 2 +- .../styles/member.cljs} | 13 +------------ .../views/member.cljs} | 4 ++-- 5 files changed, 8 insertions(+), 19 deletions(-) rename src/syng_im/{components => group_settings}/group_settings.cljs (92%) rename src/syng_im/{components/group_settings_styles.cljs => group_settings/styles/group_settings.cljs} (97%) rename src/syng_im/{components/group_settings_member_styles.cljs => group_settings/styles/member.cljs} (87%) rename src/syng_im/{components/group_settings_member.cljs => group_settings/views/member.cljs} (91%) diff --git a/src/syng_im/android/core.cljs b/src/syng_im/android/core.cljs index 73f2fcfcc7..38b031cf7d 100644 --- a/src/syng_im/android/core.cljs +++ b/src/syng_im/android/core.cljs @@ -15,7 +15,7 @@ [syng-im.components.chats.new-group :refer [new-group]] [syng-im.components.chat.new-participants :refer [new-participants]] [syng-im.components.chat.remove-participants :refer [remove-participants]] - [syng-im.components.group-settings :refer [group-settings]] + [syng-im.group-settings.group-settings :refer [group-settings]] [syng-im.components.profile :refer [profile my-profile]] [syng-im.utils.logging :as log] [syng-im.utils.utils :refer [toast]] diff --git a/src/syng_im/components/group_settings.cljs b/src/syng_im/group_settings/group_settings.cljs similarity index 92% rename from src/syng_im/components/group_settings.cljs rename to src/syng_im/group_settings/group_settings.cljs index 2181daa471..18f0d0f166 100644 --- a/src/syng_im/components/group_settings.cljs +++ b/src/syng_im/group_settings/group_settings.cljs @@ -1,4 +1,4 @@ -(ns syng-im.components.group-settings +(ns syng-im.group-settings.group-settings (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [syng-im.resources :as res] [syng-im.components.react :refer [view @@ -11,9 +11,9 @@ [syng-im.components.realm :refer [list-view]] [syng-im.components.styles :refer [color-purple text2-color]] - [syng-im.components.group-settings-styles :as st] + [syng-im.group-settings.styles.group-settings :as st] [syng-im.utils.listview :refer [to-realm-datasource]] - [syng-im.components.group-settings-member :refer [contact-inner-view]] + [syng-im.group-settings.views.member :refer [contact-inner-view]] [reagent.core :as r])) (defn set-group-settings-name [chat-name] diff --git a/src/syng_im/components/group_settings_styles.cljs b/src/syng_im/group_settings/styles/group_settings.cljs similarity index 97% rename from src/syng_im/components/group_settings_styles.cljs rename to src/syng_im/group_settings/styles/group_settings.cljs index 498c212ed8..855c5ca92d 100644 --- a/src/syng_im/components/group_settings_styles.cljs +++ b/src/syng_im/group_settings/styles/group_settings.cljs @@ -1,4 +1,4 @@ -(ns syng-im.components.group-settings-styles +(ns syng-im.group-settings.styles.group-settings (:require [syng-im.components.styles :refer [font title-font color-white diff --git a/src/syng_im/components/group_settings_member_styles.cljs b/src/syng_im/group_settings/styles/member.cljs similarity index 87% rename from src/syng_im/components/group_settings_member_styles.cljs rename to src/syng_im/group_settings/styles/member.cljs index 122802f4f3..a25ea0cd5a 100644 --- a/src/syng_im/components/group_settings_member_styles.cljs +++ b/src/syng_im/group_settings/styles/member.cljs @@ -1,4 +1,4 @@ -(ns syng-im.components.group-settings-member-styles +(ns syng-im.group-settings.styles.member (:require [syng-im.components.styles :refer [font title-font text1-color @@ -6,17 +6,6 @@ color-white online-color]])) -(def search-icon - {:width 17 - :height 17}) - -(def contacts-list-container - {:flex 1 - :backgroundColor :white}) - -(def contacts-list - {:backgroundColor :white}) - (def contact-photo-container {:borderRadius 50}) diff --git a/src/syng_im/components/group_settings_member.cljs b/src/syng_im/group_settings/views/member.cljs similarity index 91% rename from src/syng_im/components/group_settings_member.cljs rename to src/syng_im/group_settings/views/member.cljs index 892de6c485..ab1ff9825c 100644 --- a/src/syng_im/components/group_settings_member.cljs +++ b/src/syng_im/group_settings/views/member.cljs @@ -1,8 +1,8 @@ -(ns syng-im.components.group-settings-member +(ns syng-im.group-settings.views.member (:require [clojure.string :as s] [syng-im.components.react :refer [view image text icon touchable-highlight]] [syng-im.resources :as res] - [syng-im.components.group-settings-member-styles :as st])) + [syng-im.group-settings.styles.member :as st])) (defn contact-photo [{:keys [photo-path]}] [view st/contact-photo-container From 470191d9b3552b6fbebdfd88a80a64a1523b3836 Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 13 May 2016 14:17:03 +0300 Subject: [PATCH 05/13] Add/remove group chat members Former-commit-id: b2737d42f7451d8a41f38ae1b37876951c838ef9 --- src/syng_im/components/react.cljs | 1 + src/syng_im/db.cljs | 2 +- .../group_settings/group_settings.cljs | 32 ++++++++++++++++--- .../group_settings/styles/group_settings.cljs | 24 ++++++++++++++ src/syng_im/group_settings/views/member.cljs | 14 +++++--- src/syng_im/handlers.cljs | 21 ++++++++++-- src/syng_im/models/chats.cljs | 25 ++++++++++++--- src/syng_im/models/contacts.cljs | 20 +++++++----- src/syng_im/subs.cljs | 15 ++++----- 9 files changed, 121 insertions(+), 33 deletions(-) diff --git a/src/syng_im/components/react.cljs b/src/syng_im/components/react.cljs index 1ce9a93718..4b926e7b51 100644 --- a/src/syng_im/components/react.cljs +++ b/src/syng_im/components/react.cljs @@ -28,6 +28,7 @@ text]) (def drawer-layout-android (r/adapt-react-class (.-DrawerLayoutAndroid js/React))) (def touchable-opacity (r/adapt-react-class (.-TouchableOpacity js/React))) +(def modal (r/adapt-react-class (.-Modal js/React))) (defn icon [n style] diff --git a/src/syng_im/db.cljs b/src/syng_im/db.cljs index f795817c7a..f7f437c5a0 100644 --- a/src/syng_im/db.cljs +++ b/src/syng_im/db.cljs @@ -52,7 +52,7 @@ (def show-actions-path [:show-actions]) (def group-settings-path [:group-settings]) (def group-settings-name-path [:group-settings :name]) -(def group-settings-members-path [:group-settings :contacts]) +(def group-settings-selected-member-path [:selected-member]) (def new-group-path [:new-group]) (def new-participants-path [:new-participants]) (def updated-discoveries-signal-path [:discovery-updated-signal]) diff --git a/src/syng_im/group_settings/group_settings.cljs b/src/syng_im/group_settings/group_settings.cljs index 18f0d0f166..c87edfb6ce 100644 --- a/src/syng_im/group_settings/group_settings.cljs +++ b/src/syng_im/group_settings/group_settings.cljs @@ -6,6 +6,7 @@ text image icon + modal touchable-highlight]] [syng-im.components.toolbar :refer [toolbar]] [syng-im.components.realm :refer [list-view]] @@ -16,6 +17,25 @@ [syng-im.group-settings.views.member :refer [contact-inner-view]] [reagent.core :as r])) +(defn remove-member [{:keys [whisper-identity]}] + (dispatch [:chat-remove-member whisper-identity])) + +(defn close-member-menu [] + (dispatch [:select-group-chat-member nil])) + +(defn member-menu [member] + [modal {:animated false + :transparent false + :onRequestClose close-member-menu} + [touchable-highlight {:style st/modal-container + :on-press close-member-menu} + [view st/modal-inner-container + [text {:style st/modal-member-name} + (:name member)] + [touchable-highlight {:on-press #(remove-member member)} + [text {:style st/modal-remove-text} + "Remove"]]]]]) + (defn set-group-settings-name [chat-name] (dispatch [:set-group-settings-name chat-name])) @@ -38,8 +58,9 @@ :custom-action [action-save]}]) (defn group-settings [] - (let [chat-name (subscribe [:group-settings-name]) - members (subscribe [:group-settings-members])] + (let [chat-name (subscribe [:group-settings-name]) + members (subscribe [:current-chat-contacts]) + selected-member (subscribe [:selected-group-chat-member])] (fn [] [view st/group-settings [new-group-toolbar] @@ -54,12 +75,13 @@ [text {:style st/members-text} "Members"] [touchable-highlight {:on-press (fn [] - ;; TODO not implemented - )} + (dispatch [:show-add-participants]))} [view st/add-members-container [icon :add-gray st/add-members-icon] [text {:style st/add-members-text} "Add members"]]] [chat-members (vals (js->clj @members :keywordize-keys true))] [text {:style st/settings-text} - "Settings"]]))) + "Settings"] + (when @selected-member + [member-menu @selected-member])]))) diff --git a/src/syng_im/group_settings/styles/group_settings.cljs b/src/syng_im/group_settings/styles/group_settings.cljs index 855c5ca92d..1ccf4ad77b 100644 --- a/src/syng_im/group_settings/styles/group_settings.cljs +++ b/src/syng_im/group_settings/styles/group_settings.cljs @@ -11,6 +11,30 @@ text2-color toolbar-background1]])) +(def modal-container + {:flex 1 + :justifyContent :center + :padding 20}) + +(def modal-inner-container + {:borderRadius 10 + :alignItems :center + :padding 5 + :backgroundColor color-white}) + +(def modal-member-name + {:color text2-color + :fontFamily font + :fontSize 14 + :lineHeight 20}) + +(def modal-remove-text + {:margin 10 + :color text1-color + :fontFamily font + :fontSize 14 + :lineHeight 20}) + (def chat-members-container {:marginBottom 10}) diff --git a/src/syng_im/group_settings/views/member.cljs b/src/syng_im/group_settings/views/member.cljs index ab1ff9825c..6e5349162d 100644 --- a/src/syng_im/group_settings/views/member.cljs +++ b/src/syng_im/group_settings/views/member.cljs @@ -1,6 +1,11 @@ (ns syng-im.group-settings.views.member (:require [clojure.string :as s] - [syng-im.components.react :refer [view image text icon touchable-highlight]] + [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [syng-im.components.react :refer [view + image + text + icon + touchable-highlight]] [syng-im.resources :as res] [syng-im.group-settings.styles.member :as st])) @@ -17,7 +22,7 @@ [view st/online-dot-left] [view st/online-dot-right]])) -(defn contact-inner-view [{:keys [name photo-path online role]}] +(defn contact-inner-view [{:keys [whisper-identity name photo-path online role]}] [view st/contact-container [view st/photo-container [contact-photo {:photo-path photo-path}] @@ -32,8 +37,7 @@ (when role [text {:style st/role-text} role])] - [touchable-highlight {:on-press (fn [] - ;; TODO not implemented - )} + [touchable-highlight + {:on-press #(dispatch [:select-group-chat-member whisper-identity])} [view st/more-btn [icon :more-vertical st/more-btn-icon]]]]) diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 128dbca520..43ca64b021 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -36,6 +36,7 @@ [syng-im.models.chats :refer [chat-exists? create-chat save-chat + chat-remove-member chat-add-participants chat-remove-participants set-chat-active @@ -555,7 +556,7 @@ (let [identities (vec (new-participants-selection db)) chat-id (current-chat-id db)] (chat-remove-participants chat-id identities) - (nav-pop navigator) + (dispatch [:navigate-back]) (doseq [ident identities] (api/group-remove-participant chat-id ident) (removed-participant-msg chat-id ident)) @@ -573,7 +574,7 @@ (let [identities (vec (new-participants-selection db)) chat-id (current-chat-id db)] (chat-add-participants chat-id identities) - (nav-pop navigator) + (dispatch [:navigate-back]) (doseq [ident identities] (api/group-add-participant chat-id ident)) db))) @@ -610,6 +611,22 @@ (log/debug action) (assoc-in db db/group-settings-name-path chat-name))) +(register-handler :select-group-chat-member + (fn [db [action identity]] + (log/debug action) + (assoc-in db db/group-settings-selected-member-path identity))) + +(register-handler :chat-remove-member + (fn [db [action identity]] + (log/debug action) + (let [chat-id (current-chat-id db) + db (chat-remove-member db identity)] + (dispatch [:select-group-chat-member nil]) + ;; TODO uncomment + ;; (api/group-remove-participant chat-id identity) + ;; (removed-participant-msg chat-id identity) + (signal-chat-updated db chat-id)))) + (register-handler :save-group-chat (fn [db [action]] (log/debug action) diff --git a/src/syng_im/models/chats.cljs b/src/syng_im/models/chats.cljs index f98c830fde..6578fc37b8 100644 --- a/src/syng_im/models/chats.cljs +++ b/src/syng_im/models/chats.cljs @@ -9,7 +9,8 @@ [syng-im.constants :refer [content-type-status]] [syng-im.models.messages :refer [save-message]] [syng-im.persistence.realm-queries :refer [include-query]] - [syng-im.models.chat :refer [signal-chat-updated + [syng-im.models.chat :refer [current-chat + signal-chat-updated get-group-settings]])) (defn signal-chats-updated [db] @@ -79,12 +80,12 @@ (defn save-chat [db] (let [chat-settings (get-group-settings db) - chat-id (:chat-id chat-settings)] + chat-id (:chat-id chat-settings)] (r/write (fn [] ;; TODO UNDONE contacts (r/create :chats - (select-keys chat-settings [:chat-id :name :contacts]) true))) + (select-keys chat-settings [:chat-id :name]) true))) ;; TODO update chat in db atom (dispatch [:initialize-chats]) (-> db @@ -143,8 +144,11 @@ (if-let [contact-exists (.find contacts (fn [object index collection] (= contact-identity (aget object "identity"))))] (aset contact-exists "is-in-chat" true) - (.push contacts (clj->js {:identity contact-identity})))))))) + (.push contacts (clj->js {:identity contact-identity}))))))) + ;; TODO temp. Update chat in db atom + (dispatch [:initialize-chats])) +;; TODO deprecated? (is there need to remove multiple member at once?) (defn chat-remove-participants [chat-id identities] (r/write (fn [] @@ -155,6 +159,19 @@ (.forEach (fn [object index collection] (aset object "is-in-chat" false)))))))) +(defn chat-remove-member [db identity] + (let [chat (current-chat db)] + (r/write + (fn [] + (r/create :chats + (update chat :contacts + (fn [members] + (filter #(not= (:identity %) identity) members))) + true))) + ;; TODO temp. Update chat in db atom + (dispatch [:initialize-chats]) + db)) + (defn active-group-chats [] (let [results (r/filtered (r/get-all :chats) "group-chat = true && is-active = true")] diff --git a/src/syng_im/models/contacts.cljs b/src/syng_im/models/contacts.cljs index 3468cd7eab..30fe492d9b 100644 --- a/src/syng_im/models/contacts.cljs +++ b/src/syng_im/models/contacts.cljs @@ -95,16 +95,20 @@ (r/sorted (r/get-all :contacts) :name :asc)) (defn contacts-list-exclude [exclude-idents] - (let [query (exclude-query :whisper-identity exclude-idents)] - (-> (r/get-all :contacts) - (r/filtered query) - (r/sorted :name :asc)))) + (if (empty? exclude-idents) + (contacts-list) + (let [query (exclude-query :whisper-identity exclude-idents)] + (-> (r/get-all :contacts) + (r/filtered query) + (r/sorted :name :asc))))) (defn contacts-list-include [include-indents] - (let [query (include-query :whisper-identity include-indents)] - (-> (r/get-all :contacts) - (r/filtered query) - (r/sorted :name :asc)))) + (if (empty? include-indents) + () + (let [query (include-query :whisper-identity include-indents)] + (-> (r/get-all :contacts) + (r/filtered query) + (r/sorted :name :asc))))) (defn contact-by-identity [identity] (if (= identity "console") diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index b3cab18d6d..688df20988 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -4,6 +4,7 @@ [syng-im.db :as db] [syng-im.components.discovery.subs :as discovery] [syng-im.models.chat :refer [current-chat-id + current-chat get-group-settings chat-updated?]] [syng-im.models.chats :refer [chats-list @@ -168,9 +169,7 @@ (register-sub :current-chat-contacts (fn [db _] - (let [current-chat-id (reaction (current-chat-id @db)) - chat (reaction (when-let [chat-id @current-chat-id] - (chat-by-id chat-id)))] + (let [chat (reaction (current-chat @db))] (reaction (when @chat (let [current-participants (->> @chat @@ -178,16 +177,16 @@ (map :identity))] (contacts-list-include current-participants))))))) +;; TODO for new group only? (register-sub :group-settings-name (fn [db [_]] (reaction (get-in @db db/group-settings-name-path)))) -(register-sub :group-settings-members +(register-sub :selected-group-chat-member (fn [db [_]] - (let [members (reaction (get-in @db db/group-settings-members-path))] - (reaction - (let [current-participants (map :identity @members)] - (contacts-list-include current-participants)))))) + (reaction + (let [identity (get-in @db db/group-settings-selected-member-path)] + (contact-by-identity identity))))) (register-sub :view-id (fn [db _] From 8ab611f5c550b0ba0c0a7b82629e9234a4b53fea Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 13 May 2016 15:15:40 +0300 Subject: [PATCH 06/13] Group settings refactoring Former-commit-id: 6b54767b98beea962db844df39caf74d63e8849e --- src/syng_im/db.cljs | 4 +-- .../group_settings/group_settings.cljs | 23 +++++++-------- .../group_settings/styles/group_settings.cljs | 4 +-- src/syng_im/handlers.cljs | 21 ++++---------- src/syng_im/models/chat.cljs | 8 ------ src/syng_im/models/chats.cljs | 28 ++++++++----------- src/syng_im/subs.cljs | 12 ++++---- 7 files changed, 36 insertions(+), 64 deletions(-) diff --git a/src/syng_im/db.cljs b/src/syng_im/db.cljs index f7f437c5a0..c80a77c8bf 100644 --- a/src/syng_im/db.cljs +++ b/src/syng_im/db.cljs @@ -35,6 +35,8 @@ (def updated-chats-signal-path [:chats-updated-signal]) (defn updated-chat-signal-path [chat-id] [:chats chat-id :chat-updated-signal]) +(defn chat-name-path [chat-id] + [:chats chat-id :name]) (defn chat-input-text-path [chat-id] [:chats chat-id :input-text]) (defn chat-staged-commands-path [chat-id] @@ -50,8 +52,6 @@ (defn chat-command-request-path [chat-id msg-id] [:chats chat-id :command-requests msg-id]) (def show-actions-path [:show-actions]) -(def group-settings-path [:group-settings]) -(def group-settings-name-path [:group-settings :name]) (def group-settings-selected-member-path [:selected-member]) (def new-group-path [:new-group]) (def new-participants-path [:new-participants]) diff --git a/src/syng_im/group_settings/group_settings.cljs b/src/syng_im/group_settings/group_settings.cljs index c87edfb6ce..2c50beb9a9 100644 --- a/src/syng_im/group_settings/group_settings.cljs +++ b/src/syng_im/group_settings/group_settings.cljs @@ -36,29 +36,26 @@ [text {:style st/modal-remove-text} "Remove"]]]]]) -(defn set-group-settings-name [chat-name] - (dispatch [:set-group-settings-name chat-name])) - -(defn save-group-chat [] - (dispatch [:save-group-chat])) +(defn set-group-chat-name [chat-name] + (dispatch [:set-group-chat-name chat-name])) (defn chat-members [members] [view st/chat-members-container (for [member members] ^{:key member} [contact-inner-view member])]) -(defn action-save [] - [touchable-highlight - {:on-press save-group-chat} - [view st/save-btn - [text {:style st/save-btn-text} "S"]]]) +(defn chat-icon [] + (let [chat-name (subscribe [:get-current-chat-name])] + (fn [] + [view st/chat-icon + [text {:style st/chat-icon-text} (nth @chat-name 0)]]))) (defn new-group-toolbar [] [toolbar {:title "Chat settings" - :custom-action [action-save]}]) + :custom-action [chat-icon]}]) (defn group-settings [] - (let [chat-name (subscribe [:group-settings-name]) + (let [chat-name (subscribe [:get-current-chat-name]) members (subscribe [:current-chat-contacts]) selected-member (subscribe [:selected-group-chat-member])] (fn [] @@ -70,7 +67,7 @@ :underlineColorAndroid color-purple :autoFocus true :placeholderTextColor text2-color - :onChangeText set-group-settings-name} + :onChangeText set-group-chat-name} @chat-name] [text {:style st/members-text} "Members"] diff --git a/src/syng_im/group_settings/styles/group_settings.cljs b/src/syng_im/group_settings/styles/group_settings.cljs index 1ccf4ad77b..490e0e5c1f 100644 --- a/src/syng_im/group_settings/styles/group_settings.cljs +++ b/src/syng_im/group_settings/styles/group_settings.cljs @@ -38,14 +38,14 @@ (def chat-members-container {:marginBottom 10}) -(def save-btn +(def chat-icon {:margin 10 :width 36 :height 36 :borderRadius 50 :backgroundColor color-purple}) -(def save-btn-text +(def chat-icon-text {:marginTop 7 :marginLeft 13 :color color-white diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 43ca64b021..536227289b 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -35,7 +35,7 @@ [syng-im.components.discovery.handlers :as discovery] [syng-im.models.chats :refer [chat-exists? create-chat - save-chat + set-group-chat-name chat-remove-member chat-add-participants chat-remove-participants @@ -45,7 +45,6 @@ [syng-im.models.chat :refer [signal-chat-updated set-current-chat-id current-chat-id - set-group-settings update-new-group-selection update-new-participants-selection clear-new-group @@ -602,14 +601,13 @@ (register-handler :show-group-settings (fn [db [action]] (log/debug action) - (let [db (set-group-settings db)] - (dispatch [:navigate-to :group-settings]) - db))) + (dispatch [:navigate-to :group-settings]) + db)) -(register-handler :set-group-settings-name +(register-handler :set-group-chat-name (fn [db [action chat-name]] (log/debug action) - (assoc-in db db/group-settings-name-path chat-name))) + (set-group-chat-name db chat-name))) (register-handler :select-group-chat-member (fn [db [action identity]] @@ -622,18 +620,11 @@ (let [chat-id (current-chat-id db) db (chat-remove-member db identity)] (dispatch [:select-group-chat-member nil]) - ;; TODO uncomment + ;; TODO fix and uncomment ;; (api/group-remove-participant chat-id identity) ;; (removed-participant-msg chat-id identity) (signal-chat-updated db chat-id)))) -(register-handler :save-group-chat - (fn [db [action]] - (log/debug action) - (let [db (save-chat db)] - (dispatch [:navigate-back]) - db))) - (register-handler :group-chat-invite-received (fn [db [action from group-id identities group-name]] (log/debug action from group-id identities) diff --git a/src/syng_im/models/chat.cljs b/src/syng_im/models/chat.cljs index 5fda433919..09bf425768 100644 --- a/src/syng_im/models/chat.cljs +++ b/src/syng_im/models/chat.cljs @@ -19,14 +19,6 @@ (defn chat-updated? [db chat-id] (get-in db (db/updated-chat-signal-path chat-id))) -(defn get-group-settings [db] - (get-in db db/group-settings-path)) - -(defn set-group-settings [db] - (let [group-chat (current-chat db)] - (assoc-in db db/group-settings-path - (select-keys group-chat [:chat-id :name :contacts])))) - (defn update-new-group-selection [db identity add?] (update-in db db/new-group-path (fn [new-group] (if add? diff --git a/src/syng_im/models/chats.cljs b/src/syng_im/models/chats.cljs index 6578fc37b8..56af4b1c96 100644 --- a/src/syng_im/models/chats.cljs +++ b/src/syng_im/models/chats.cljs @@ -9,9 +9,9 @@ [syng-im.constants :refer [content-type-status]] [syng-im.models.messages :refer [save-message]] [syng-im.persistence.realm-queries :refer [include-query]] - [syng-im.models.chat :refer [current-chat - signal-chat-updated - get-group-settings]])) + [syng-im.models.chat :refer [current-chat-id + current-chat + signal-chat-updated]])) (defn signal-chats-updated [db] (update-in db db/updated-chats-signal-path (fn [current] @@ -78,19 +78,13 @@ (add-status-message chat-id) (signal-chats-updated db))))) -(defn save-chat [db] - (let [chat-settings (get-group-settings db) - chat-id (:chat-id chat-settings)] - (r/write - (fn [] - ;; TODO UNDONE contacts - (r/create :chats - (select-keys chat-settings [:chat-id :name]) true))) - ;; TODO update chat in db atom - (dispatch [:initialize-chats]) - (-> db - (signal-chats-updated) - (signal-chat-updated chat-id)))) +(defn set-group-chat-name [db name] + (let [chat-id (current-chat-id db)] + (r/write (fn [] + (-> (r/get-by-field :chats :chat-id chat-id) + (r/single) + (aset "name" name)))) + (assoc-in db (db/chat-name-path chat-id) name))) (defn chat-contacts [chat-id] (-> (r/get-by-field :chats :chat-id chat-id) @@ -160,7 +154,7 @@ (aset object "is-in-chat" false)))))))) (defn chat-remove-member [db identity] - (let [chat (current-chat db)] + (let [chat (current-chat db)] (r/write (fn [] (r/create :chats diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index 688df20988..c06ddfd17f 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -5,7 +5,6 @@ [syng-im.components.discovery.subs :as discovery] [syng-im.models.chat :refer [current-chat-id current-chat - get-group-settings chat-updated?]] [syng-im.models.chats :refer [chats-list chats-updated? @@ -92,6 +91,10 @@ (let [current-chat-id (current-chat-id @db)] (reaction (get-in @db [:chats current-chat-id]))))) +(register-sub :get-current-chat-name + (fn [db _] + (let [current-chat-id (current-chat-id @db)] + (reaction (get-in @db (db/chat-name-path current-chat-id :name)))))) ;; -- User data -------------------------------------------------------------- @@ -177,13 +180,8 @@ (map :identity))] (contacts-list-include current-participants))))))) -;; TODO for new group only? -(register-sub :group-settings-name - (fn [db [_]] - (reaction (get-in @db db/group-settings-name-path)))) - (register-sub :selected-group-chat-member - (fn [db [_]] + (fn [db [_]] (reaction (let [identity (get-in @db db/group-settings-selected-member-path)] (contact-by-identity identity))))) From b4e8adc951d87369f7b62377f31f8fc35d9605e5 Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 13 May 2016 18:03:45 +0300 Subject: [PATCH 07/13] Chat name edit form. Fix styles. Former-commit-id: bf6c419c5d3c5bef7f4a56daaf325fded95d6c2d --- src/syng_im/android/core.cljs | 2 + src/syng_im/components/styles.cljs | 3 +- .../group_settings/group_settings.cljs | 23 +++++------ .../group_settings/styles/chat_name_edit.cljs | 19 ++++++++++ .../group_settings/styles/group_settings.cljs | 38 ++++++++++++++----- .../group_settings/views/chat_name_edit.cljs | 33 ++++++++++++++++ src/syng_im/group_settings/views/member.cljs | 2 +- src/syng_im/subs.cljs | 2 +- 8 files changed, 99 insertions(+), 23 deletions(-) create mode 100644 src/syng_im/group_settings/styles/chat_name_edit.cljs create mode 100644 src/syng_im/group_settings/views/chat_name_edit.cljs diff --git a/src/syng_im/android/core.cljs b/src/syng_im/android/core.cljs index 38b031cf7d..8bee230a48 100644 --- a/src/syng_im/android/core.cljs +++ b/src/syng_im/android/core.cljs @@ -16,6 +16,7 @@ [syng-im.components.chat.new-participants :refer [new-participants]] [syng-im.components.chat.remove-participants :refer [remove-participants]] [syng-im.group-settings.group-settings :refer [group-settings]] + [syng-im.group-settings.views.chat-name-edit :refer [chat-name-edit]] [syng-im.components.profile :refer [profile my-profile]] [syng-im.utils.logging :as log] [syng-im.utils.utils :refer [toast]] @@ -48,6 +49,7 @@ :chat-list [chats-list] :new-group [new-group] :group-settings [group-settings] + :chat-name-edit [chat-name-edit] :contact-list [contact-list] :chat [chat] :profile [profile] diff --git a/src/syng_im/components/styles.cljs b/src/syng_im/components/styles.cljs index 1f02586a7f..326f223cda 100644 --- a/src/syng_im/components/styles.cljs +++ b/src/syng_im/components/styles.cljs @@ -2,7 +2,8 @@ (def font "sans-serif") ;; (def font "Avenir-Roman") -(def title-font "sans-serif-medium") +(def font-medium "sans-serif-medium") +(def title-font font-medium) (def color-blue "#7099e6") (def color-blue-transparent "#7099e632") diff --git a/src/syng_im/group_settings/group_settings.cljs b/src/syng_im/group_settings/group_settings.cljs index 2c50beb9a9..13b5346f73 100644 --- a/src/syng_im/group_settings/group_settings.cljs +++ b/src/syng_im/group_settings/group_settings.cljs @@ -14,7 +14,7 @@ text2-color]] [syng-im.group-settings.styles.group-settings :as st] [syng-im.utils.listview :refer [to-realm-datasource]] - [syng-im.group-settings.views.member :refer [contact-inner-view]] + [syng-im.group-settings.views.member :refer [member-view]] [reagent.core :as r])) (defn remove-member [{:keys [whisper-identity]}] @@ -36,13 +36,13 @@ [text {:style st/modal-remove-text} "Remove"]]]]]) -(defn set-group-chat-name [chat-name] - (dispatch [:set-group-chat-name chat-name])) - (defn chat-members [members] [view st/chat-members-container (for [member members] - ^{:key member} [contact-inner-view member])]) + ^{:key member} [member-view member])]) + +(defn show-chat-name-edit [] + (dispatch [:navigate-to :chat-name-edit])) (defn chat-icon [] (let [chat-name (subscribe [:get-current-chat-name])] @@ -63,12 +63,13 @@ [new-group-toolbar] [text {:style st/chat-name-text} "Chat name"] - [text-input {:style st/chat-name-input - :underlineColorAndroid color-purple - :autoFocus true - :placeholderTextColor text2-color - :onChangeText set-group-chat-name} - @chat-name] + [view st/chat-name-value-container + [text {:style st/chat-name-value} + @chat-name] + [touchable-highlight {:style st/chat-name-btn-edit-container + :on-press show-chat-name-edit} + [text {:style st/chat-name-btn-edit-text} + "Edit"]]] [text {:style st/members-text} "Members"] [touchable-highlight {:on-press (fn [] diff --git a/src/syng_im/group_settings/styles/chat_name_edit.cljs b/src/syng_im/group_settings/styles/chat_name_edit.cljs new file mode 100644 index 0000000000..0a5afb59d3 --- /dev/null +++ b/src/syng_im/group_settings/styles/chat_name_edit.cljs @@ -0,0 +1,19 @@ +(ns syng-im.group-settings.styles.chat-name-edit + (:require [syng-im.components.styles :refer [font + color-white + text1-color]])) + +(def save-action-icon + {:width 18 + :height 14}) + +(def chat-name-container + {:flex 1 + :flexDirection :column + :backgroundColor color-white}) + +(def chat-name-input + {:marginLeft 12 + :fontSize 14 + :fontFamily font + :color text1-color}) diff --git a/src/syng_im/group_settings/styles/group_settings.cljs b/src/syng_im/group_settings/styles/group_settings.cljs index 490e0e5c1f..53b975b3c6 100644 --- a/src/syng_im/group_settings/styles/group_settings.cljs +++ b/src/syng_im/group_settings/styles/group_settings.cljs @@ -1,5 +1,6 @@ (ns syng-im.group-settings.styles.group-settings (:require [syng-im.components.styles :refer [font + font-medium title-font color-white color-purple @@ -63,22 +64,42 @@ :marginLeft 16 :marginBottom 16 :color text2-color - :fontFamily font + :fontFamily font-medium :fontSize 14 :lineHeight 20}) -(def chat-name-input - {:marginLeft 12 - :fontSize 14 +(def chat-name-value-container + {:flexDirection :row + :marginLeft 16 + :height 56 + :alignItems :center + :justifyContent :center + :borderBottomWidth 1 + :borderBottomColor separator-color}) + +(def chat-name-value + {:flex 1 + :fontSize 16 :fontFamily font :color text1-color}) +(def chat-name-btn-edit-container + {:padding 16 + :justifyContent :center}) + +(def chat-name-btn-edit-text + {:marginTop -1 + :color text2-color + :fontFamily font + :fontSize 16 + :lineHeight 20}) + (def members-text {:marginTop 24 :marginLeft 16 :marginBottom 16 :color text2-color - :fontFamily font + :fontFamily font-medium :fontSize 14 :lineHeight 20}) @@ -90,15 +111,14 @@ :height 17}) (def add-members-container - {:flexDirection :row - :marginBottom 16}) + {:flexDirection :row}) (def add-members-text {:marginTop 18 :marginLeft 32 :color text2-color :fontFamily font - :fontSize 14 + :fontSize 16 :lineHeight 20}) (def settings-text @@ -106,6 +126,6 @@ :marginLeft 16 :marginBottom 16 :color text2-color - :fontFamily font + :fontFamily font-medium :fontSize 14 :lineHeight 20}) diff --git a/src/syng_im/group_settings/views/chat_name_edit.cljs b/src/syng_im/group_settings/views/chat_name_edit.cljs new file mode 100644 index 0000000000..d283177af1 --- /dev/null +++ b/src/syng_im/group_settings/views/chat_name_edit.cljs @@ -0,0 +1,33 @@ +(ns syng-im.group-settings.views.chat-name-edit + (:require [reagent.core :as r] + [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [syng-im.components.react :refer [view text-input]] + [syng-im.components.toolbar :refer [toolbar]] + [syng-im.group-settings.styles.chat-name-edit :as st] + [syng-im.components.styles :refer [toolbar-background2 + text2-color]])) + +(defn save-group-chat-name [chat-name] + (dispatch [:set-group-chat-name chat-name]) + (dispatch [:navigate-back])) + +(defn chat-name-edit-toolbar [chat-name] + [toolbar {:background-color toolbar-background2 + :title "Edit chat name" + ;; TODO change to dark 'ok' icon + :action {:image {:source {:uri :icon_ok} + :style st/save-action-icon} + :handler #(save-group-chat-name chat-name)}}]) + +(defn chat-name-edit [] + (let [current-chat-name (subscribe [:get-current-chat-name]) + chat-name (r/atom @current-chat-name)] + (fn [] + [view st/chat-name-container + [chat-name-edit-toolbar @chat-name] + [text-input {:style st/chat-name-input + :autoFocus true + :placeholderTextColor text2-color + :onChangeText (fn [text] + (reset! chat-name text))} + @chat-name]]))) diff --git a/src/syng_im/group_settings/views/member.cljs b/src/syng_im/group_settings/views/member.cljs index 6e5349162d..6584724755 100644 --- a/src/syng_im/group_settings/views/member.cljs +++ b/src/syng_im/group_settings/views/member.cljs @@ -22,7 +22,7 @@ [view st/online-dot-left] [view st/online-dot-right]])) -(defn contact-inner-view [{:keys [whisper-identity name photo-path online role]}] +(defn member-view [{:keys [whisper-identity name photo-path online role]}] [view st/contact-container [view st/photo-container [contact-photo {:photo-path photo-path}] diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index c06ddfd17f..254a883466 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -94,7 +94,7 @@ (register-sub :get-current-chat-name (fn [db _] (let [current-chat-id (current-chat-id @db)] - (reaction (get-in @db (db/chat-name-path current-chat-id :name)))))) + (reaction (get-in @db (db/chat-name-path current-chat-id)))))) ;; -- User data -------------------------------------------------------------- From 8919410735a1a5a3cb557b545d5b6ca084c33719 Mon Sep 17 00:00:00 2001 From: virvar Date: Mon, 16 May 2016 13:47:34 +0300 Subject: [PATCH 08/13] Chat color Former-commit-id: 14e69f9369148f334e77072d8e9a2431bd53bdfa --- .../src/main/res/drawable-hdpi/icon_bin.png | Bin 0 -> 358 bytes .../drawable-hdpi/icon_notifications_on.png | Bin 0 -> 823 bytes .../src/main/res/drawable-mdpi/icon_bin.png | Bin 0 -> 217 bytes .../drawable-mdpi/icon_notifications_on.png | Bin 0 -> 585 bytes .../src/main/res/drawable-xhdpi/icon_bin.png | Bin 0 -> 412 bytes .../drawable-xhdpi/icon_notifications_on.png | Bin 0 -> 1034 bytes .../src/main/res/drawable-xxhdpi/icon_bin.png | Bin 0 -> 616 bytes .../drawable-xxhdpi/icon_notifications_on.png | Bin 0 -> 1488 bytes .../main/res/drawable-xxxhdpi/icon_bin.png | Bin 0 -> 889 bytes .../icon_notifications_on.png | Bin 0 -> 1779 bytes src/syng_im/components/react.cljs | 2 + src/syng_im/db.cljs | 5 +- .../group_settings/group_settings.cljs | 139 ++++++++++++++---- .../group_settings/styles/group_settings.cljs | 58 +++++++- src/syng_im/handlers.cljs | 11 ++ src/syng_im/models/chats.cljs | 8 + src/syng_im/persistence/realm.cljs | 2 + src/syng_im/subs.cljs | 10 +- 18 files changed, 205 insertions(+), 30 deletions(-) create mode 100644 android/app/src/main/res/drawable-hdpi/icon_bin.png create mode 100644 android/app/src/main/res/drawable-hdpi/icon_notifications_on.png create mode 100644 android/app/src/main/res/drawable-mdpi/icon_bin.png create mode 100644 android/app/src/main/res/drawable-mdpi/icon_notifications_on.png create mode 100644 android/app/src/main/res/drawable-xhdpi/icon_bin.png create mode 100644 android/app/src/main/res/drawable-xhdpi/icon_notifications_on.png create mode 100644 android/app/src/main/res/drawable-xxhdpi/icon_bin.png create mode 100644 android/app/src/main/res/drawable-xxhdpi/icon_notifications_on.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi/icon_bin.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi/icon_notifications_on.png diff --git a/android/app/src/main/res/drawable-hdpi/icon_bin.png b/android/app/src/main/res/drawable-hdpi/icon_bin.png new file mode 100644 index 0000000000000000000000000000000000000000..a9686273842f9424ddff4d8b5d247a56d0382183 GIT binary patch literal 358 zcmV-s0h#`ZP)Px$AW1|)R5%f1WWWL1dS+_;WB5JuKf`|;uo6awqijq}>E(sl*Rg3~Y@Reznd$fM zuzw8y*^w16GBAYy|IeU-BF4yY<39t#N@Ou62F9QNSXo!GF#i6%tw5 zr~^d-<1oM4_*{qSUCTs{{LgBxb@^E0~5q0Sk#ap1TupK**mo* zxxnN@JZSEj3{55frKlGDqXrRPx%@kvBMR7efARZU1#Q4~Js`bOPESb!7QsSIF z^O)oj1xorZrLUEN3A)p{djRsnS|Hs#5J57Ny-Mjw=)k<}6%%yz4W0lA!!8Koq^tWV z6%q9I4;{b)KBruVR#KKXX&w6%)qOVd;Sc`j<4i-A` z*p2UqB+amE4yvrGqC_O}wHzR^31Eezts>>HS^3`yR;7qu%4=m2J3`{;J7((?or7PI zm2LT3r3!>4Wp<=9TJ}9zhQj;qOzsVLFXa5QgH z?ey~1*?g-gVMh3k8d96Nn-R$sHTRKrY0dT}V5j}N>!U>SN`X-k4EJP)j;pz+L`(zX z0)1&W=bnxwWADhwmi+9}Tl#}WHqlYd($jsYAmtaeuk%)$C)T=uzyR&d&A&p`HK(bh zfAXA&>KrNmT~A&ip)Q63n<&i1B1y5SuW; zr#LX{)&^(&`=7poh11x`Xv=kxr&|=X6LVh9-1F3)x!HV^f}WW&^Wm^%|9c#YGdLw? z|6W#Q@bAC<>;M1%Z~CFbWc9@Gf@!AC5e+s;79)Wd-y(GkCTDvWef+g_XSz|q%lb&Q znsW!#%vUi+uUOE1(Qb-Fbk%a3rlV%NzP_jlsA5umZz8}PD>RqiyM`gh#Z-Nv!nPuy P^B6o`{an^LB{Ts5OMy>U literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-mdpi/icon_notifications_on.png b/android/app/src/main/res/drawable-mdpi/icon_notifications_on.png new file mode 100644 index 0000000000000000000000000000000000000000..89a9ca8f15d80fb52529e73b28d9bfe3b9d9d65d GIT binary patch literal 585 zcmV-P0=E5$P)Px%14%?dR5%fhR8L5hK@@*)_RA6vL5D6vcoVyJ@Ty>!gu1Lzw-!2>y9&DrqOGUZ zN?KP)WxI69;~oMd7mA`zdiA6zfr55u3GvX@;_f%k_dcAMoo_#DV7~Y7_j@z*-pq&a zALHrESJ(ZM##=<%%sw8yXH%4Iw9;P`i&u5Mu?9fhL@?xH&P`A#l-g@m{~Zx^oe@L$ zki)FNB&_Pn3a{LY0DH#o%E$yWh2>{VjswE+g_s(2iN^MfV$0e5(nC!&frxcpJwB06 zZs+ogHUx6>OI#NKuT(0vefwUy;R9V1htjG`lP-!*h>xeDt`t1O(Zkv&MWEUbC zPT+4Batn)n5Px$R!KxbR7ef&SFujRKn(S}gpCbY3VZ{<(2>tzB4S`E2rwN^Y)Cd>T+bFXx}tM zuElLliehM_a*?wc1HeYNA@rlVQwaG71IoSRX7#`54>p;LE-|&GC0o_@gq%PRKy-4} zIT%C9X;Qq(L0YRu>_&s|O(xojZRItSYbsl?sAB$QakJO963OMNa5X&_zKauL52`=pwH~NP9Qq+3&J9sx$z((IKfceo>%s z8=b)HkhEy92d|vUZFIcT35#ItY! literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xhdpi/icon_notifications_on.png b/android/app/src/main/res/drawable-xhdpi/icon_notifications_on.png new file mode 100644 index 0000000000000000000000000000000000000000..9322a10becbefde66c3013796f0ff05adc2eee44 GIT binary patch literal 1034 zcmV+l1oiugP)PxRU!R9Fe^SY1dIQ53#+#x*Je=@%<|5`*d`1D~YuH3`hXha{t{mRt*6gIHaE za@UH;HByN!75bsThw`PMw}gbCqNg5|eqa-#v_G=Hot)b_tJB_@oteEeBlOb1a?j5_ z=X^W&oO{n5N*3^m$K$@~8Ks92R!Inb&3wL^*5m${b|G@?lumV1UzI@!zHiQs<&&gx z3+NI%Ka!o&iLR@=zdapXvt(N}%4%E?0MYaP)hbgvOoC*6!=3>^@KQq6L6hJ@B2NI$ z#QF;fVIz!@MMBX`Cbiw!KFW$Z4j`wGo3rIcy3=;#W-@bGZ%clGBT##oUq5G8Fo zUVw20U?TB;0RH)Q-ajSuYB*RQUB5;fe0;uS-DY4e#w$tk!`OxVu8d>1)rC%PrZSzo_Ic)Rd%VAtu-1T4@j#s z%8k(j&5cLL%;r0hnv@AB^&dMHNGEy-z5&a8m#e8qZG-Q)e%Lmpoxllw5OD zZdU#w2iP_%B`?Qaj!NWgY4Mg?Uhb8~9LVLJNL1?Jd8AdUCS)p&h8pW$8FgOyj52I# z3K;6#YY2OLp)$00;Z6G=z(0Qj8A%xF?(HzHszhi)_4!7fZo5W5W;_DGQ!HJIjIF zIXV?KBiNMagdP|v)DUBY!pnN z$i?^#q9~7G307(opcNm2CM6L*5qPM{+>AnHh}jQE(Qa%)v>s7buvrzt)=;C#fZj3w=G_(G_y3hy5Y0{X_dr#ksU5um&1hr6n!`}KqZ*$Y z0T5i#TXix4#uWg(11zPBE1^6m_!w|S@8o$A+7$qF91I@%2y0jlx1tXsfvo1Z27nGj z!2oPfw1O{Bt3XzAPXN%VS$SFoGn0D;fKIVIsYEkQQBY+)H5UW`f`Ge1C*;F*q|*<5 zmZr_A)LCGzaxPu9%vU=#ll%gfd+Px%B1uF+R9Fe^SWPbjK^T7Dp;W|?CX(KS1OGuBNc;geB=pt_T0uga(27V9i8?e& zllDJ2aPl9xNSwr1g#+p{_BHRu9x8Nfv)ek%Ty}TfnP;AT_L)xeAe7NEnT+@1t}t!@ z3?o1r5qTH}5#Ism6aljh*s>804?Nq2mw5IXlR3XD>`4+mC1)ZWHlnZJE-6tG^oQd4 z?bC#k49_FzelqftKR}f1!c;2d$v?g?NPuC9(pqw~Yel>Ogj|QeC02V=cw3ZYW?ftB zPryy##0(Nob_sWWPzb`6(Kvodp(k_5= z+}v0fa}HA@RY-xN9k#TV95Dz2va^eTn%v|d&$|aeIwln9XgIiItz{Bg+SvBd z$7@a=3B6XKl2>^sAJlnqXgV0YGS9MVlHnI;A>Ljn%l8;x-x>wONb^J0n-BqkWCW^C zx2* zId>EsJUR_rHlE}nI0Y>mz~PC^#SEnqYsvj;C9u{zaS}Tp3H6z~j3Zg@u!@zw^4eHa zKgjDA#de&?njxsn`rI};8(3y~M*<-|7YXfJB76exou`HdnU}5r00001uy!EP)Px)ib+I4RA>e5T3u`uMI4{myX#l9!4ROvfWD}StuIwcltj}QH4%tk4G#*54d{{H zwdmayXnTFSYn6t(B6lYegD*6goF5bmK}k&2h`v}J)S93#NHtX-(A0?F-R}7RUwd#I zGkdeUv&&02Y47&`G4uP)?EH52zemXpI+FXc4-=gXGeX({!q1e^L_8LH*D4%pH9bm ze11DgR&!2I&*T_kk6F!=iFbVlhSS+T0ROTK7&|ep5*QiFJqy?M9y`Efb6g|v+P>Ta zhGC3@T)KL%afJZNrLG&3B2}S;ek(h|wc?Z$K)EEB*m03uQcC6sr5kDill3bluppOz zz6bjo{tb!Ji$3Pt7>|Z#WdYWTQ!1kia!DQ+bZWrpKi?nio)-9RnUxVprZO>DutK@i zG%Yq52_3VA(j-X<0hCL_V55Y<#ltx?N)G_|F^)^xl+Wkuew_V10SQ|clMdgtdex9) z0w|ZDI3SmVE0>hgkMCT)vPT-JAn@$@Ka$|;t8niGLeBO=ufK6{O|i&?yGu};?*hvj zH^HG-bZqM@>{K^%61Uh^A(YEv;lC4b*|cyP2JB=G^nU%Wty}-*`K{VuhHtITL7OcC zH$pC}!I#gktbviS?1P3uI>B)-ti}3r0Ppk5Gc(H}Mzl3Hd`x?xKc-eLc{tEkB9KVs zlCTi_;aqM;_+nG)0~T%HK(u?JbmGB34Ii)xGX|x>n}9;Oj7P(1lMv-D%^=1O6|Jh0 zORHEkMj6&+937xIr|MTUcdC#}t3dp)7@MsoU5%$_K`+M!Bi(Pq3>a7K-hI2GLe*VT zKYgUyRzBC5PlvtD?Cu@G^Jp82hRQC_KZOM1uY|ww9F2_*bfL~b=&TTEdUe~IORV^ zgm+>n)-K{=FaCPrpL4^h?6$#Z_*1vR^4iBW@DtA=YXkCk0G*S`boMFP9F=hzloA|| z9FPdW^XZXfI&;5Da58OajkF)iiXjls~aT3>q zvkq7bRw_ybUS|zSXO~oHSMN)|K*p1M4jsB#pZ~XwFs;t41%t5`Sjg|dJFlkdI2eI8 zcpsLB%Eg9`jt*2SSC4CCbg_o>wM>ujEPYug`Uenu-OUiz#1mhgnaP50yG&b7Vy^34 zwy}X&_XIrD>=ebrECq+txv0pm%5Iwg0)T>TiW2QD5g2&IGz#+ijL5IT?uY;aSa;t& zJ+Syc5rEM^UdL6)D^DrW=9mC3)aJmlO`u}mb4jR^*TdEA!vZ3&2!k8$m-aR`spq)O7-gvX;C$Vd4pa1rp}+iZON`s5~Qp0BgxBZ2aah z&dT8_0R(0yuTWu_v;rPuJtu(jdP@WC#AonIu=p!3T2Jt8sinix#>rC462VXqdlY^m q(hhs1b1QDDn+OJj1&Oq4LjDJ-JlQ0;IEEYm0000h=h=GLhVaF8b_V)X2~A;^;OFYnH8^)=+rko_FYWo;pY3J7JNIto=d<6>R_{I_ z64LEvHTT^K-L-MfM;KX3qZH*<&XRi29kgSCsLeis7nMRhZ04)inO89J{tDfB^zq7d zU*GnMvwWzz+PZ%Z!+{!gtG^EmIwoc1y?AzKYSOd%2glyj9W1s9()=L&N%C8+S>0vM zC)2{#2`?xvWp*qz+rGmnVEcW&_9RYUHKDt$Ha?206h2b{)-MB&RfRKweNEB z_r**nETn>xx3`OxJzA+U;cQy%`sepuUp_L}8*BD=)^1~u)qR=YZ!X%I)+bkVXkoyL z1E0l&J=7+jdlmK1a&NED>wEH3PI!Ag(ozrnQ=5=lYkW)Z!OXZ-6SP-nw@S!6uY7jD zYHNNH|Pwf_22~4?_8&p;EAy^|!}nmB{tBJIkMn`1#q~hVNJ7iCupCfO(0*)78&qol`;+03MT~ A>i_@% literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxxhdpi/icon_notifications_on.png b/android/app/src/main/res/drawable-xxxhdpi/icon_notifications_on.png new file mode 100644 index 0000000000000000000000000000000000000000..cc4a37280a9f7ba22cbdc8deba684d71cf9cec7d GIT binary patch literal 1779 zcmVPx*tw}^dRCodHTy0DoMHrsh10)n;Fo9T8el{jGT2lPiM8!m7TWO7n#Hi7v)t+!v z=s~IS@r#eNg*&vzhs2^0t5SdX5hUmj6KniqYGc&a*grP0KiZT;EfTaGx8w63y@np# z?kqdAw_ezU?A^{g@4nA7@659^I|pYzKl;YUH(b9u+b9@&o^e)za4#C1zq5H$S**6U zcEN4<+^qwh_4`If%CFBSri2jpr{9M&KDoW>o+qoTs~6MDoP0N&7<*}(Z29@b^lIQK z4#7mtw?F*yg4>vUNdQ0_Nc#_Q-ev`m3-d**a+$I`86&T4x(9}%XyY2&`wD)yt&NR= z?=qk(G8kf}*=Q4YvKZZc^l&8-Q>PNCliRD-ng z=L-Uk#$tEHMf`InM6p${I?A$60Lfi^flmV5CLI9nd}fsZlDmIrW+N@iQKsbX;nWf1UQg8SI_xYz*A+O6VUVe@O`FW6H;==jfPa9y3U>w zKyqg;Vs^(wi5(!$jsDK&(5RiA+j7qca3Xh{^H18t^@rVpld10s0nX%(pD8QOe-0#= zG63A#crqL8i4H~ZlxHt@oc(@VA>SPg2It)ZldZ2k1G=L_^~iuG+kiNmHS+RywT41h zY;6@9Xw870f#Ds(G>=QfyJ!ej+um4rPQuo)Nq1zZ0*!EtbMYWm7J{Ef7i;Zk4qehl z0Lh(LG*4l~x1ZfX?%JC}Uphu6QGvh%@sEIADzLJ;bcm-B*P|$_)Ivbd!01MEabXHK zvz0r>cto$$a^Xa;?C8;(=~L7jY8G1=KcrWB`ZSWa0(Ej_@T3M!^cXB5a%}Sd*!T1(k zy`I1u`9(W}!M&c%?p8vyzG7h1SN<{rz!T8W;nG50-S*1f8S4HGkH?{HK7g_I9JpKS@~Xl_vYwCFc7avGcr+3N(zu$0R->lu*Ctt*3V zJp*J|%4M7N49MlymBF^20WvJ*vW@LrpsPP7H5tN0=o*N+h^5r&fXE+jYYG1Pe;`g- z7r<=rcKlUhdi|QoB7l_!FSeTz49UU!Ne%()>DFepz1|+Ix=Hj#&QdxIX8L!b1u0MfQpRZIp zP4@-xd+?&AKmEENzT@{tT;M$&?a9$f0>B=`=EyoffLqkeTvF)#h z5BzLp>s6VufvF=L8U%^>t&jDAXN8hQ!Kdhbq_w3trOF7PaM6tp;m3`i+J%lxs4x@p zNk7P=QUZ_xW_fYJvlvIt+L3^_QB_yx7T(XcJSruCK+~=dBamMMGA`MYAlMVxmPh3T z5a{-U!OMAE?2=Ryt@6k@yPUZp_!TV#&<$yn7Y46ICg8_l)`w`&ogE>b4 z0dgXbIY~g01W9?!Spo3Ok|aPLaUPHX zwlt-cvCM4aI|3+FY|m|xkw>gGxPAriO9Eu&(ctVv=C+k9@g)HiI>}?8plAoC&}UYI zLK(8TqWs;}%A8#DEdd0Aertfmk%#aCvkgRCz{0{j{>}q@Gu9WL!ar2BU2n7_<3Gf@ VV-clj @members :keywordize-keys true))] - [text {:style st/settings-text} - "Settings"] + [scroll-view st/body + [text {:style st/chat-name-text} + "Chat name"] + [view st/chat-name-value-container + [text {:style st/chat-name-value} + @chat-name] + [touchable-highlight {:style st/chat-name-btn-edit-container + :on-press show-chat-name-edit} + [text {:style st/chat-name-btn-edit-text} + "Edit"]]] + [text {:style st/members-text} + "Members"] + [touchable-highlight {:on-press (fn [] + (dispatch [:show-add-participants]))} + [view st/add-members-container + [icon :add-gray st/add-members-icon] + [text {:style st/add-members-text} + "Add members"]]] + [chat-members (vals (js->clj @members :keywordize-keys true))] + [text {:style st/settings-text} + "Settings"] + [settings-view]] + (when @show-color-picker + [chat-color-picker]) (when @selected-member [member-menu @selected-member])]))) diff --git a/src/syng_im/group_settings/styles/group_settings.cljs b/src/syng_im/group_settings/styles/group_settings.cljs index 53b975b3c6..092ab7387e 100644 --- a/src/syng_im/group_settings/styles/group_settings.cljs +++ b/src/syng_im/group_settings/styles/group_settings.cljs @@ -36,15 +36,28 @@ :fontSize 14 :lineHeight 20}) +(def modal-color-picker-inner-container + {:borderRadius 10 + :padding 5 + :backgroundColor color-white}) + +(def modal-color-picker-save-btn-text + {:margin 10 + :alignSelf :center + :color text1-color + :fontFamily font + :fontSize 14 + :lineHeight 20}) + (def chat-members-container {:marginBottom 10}) -(def chat-icon +(defn chat-icon [color] {:margin 10 :width 36 :height 36 :borderRadius 50 - :backgroundColor color-purple}) + :backgroundColor color}) (def chat-icon-text {:marginTop 7 @@ -59,6 +72,10 @@ :flexDirection :column :backgroundColor color-white}) +(def body + {:flex 1 + :flexDirection :column}) + (def chat-name-text {:marginTop 24 :marginLeft 16 @@ -129,3 +146,40 @@ :fontFamily font-medium :fontSize 14 :lineHeight 20}) + +(def settings-container + {:flexDirection :column}) + +(def setting-row + {:flexDirection :row + :height 56}) + +(def setting-icon-view + {:width 56 + :height 56 + :alignItems :center + :justifyContent :center}) + +(def setting-view + {:flex 1 + :marginLeft 16 + :alignItems :flex-start + :justifyContent :center}) + +(def setting-title + {:marginTop -2.5 + :color text1-color + :fontSize 16 + :fontFamily font}) + +(def setting-subtitle + {:marginTop 1 + :color text2-color + :fontSize 12 + :fontFamily font}) + +(defn chat-color-icon [color] + {:borderRadius 50 + :width 24 + :height 24 + :backgroundColor color}) diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 536227289b..f73a56a23c 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -36,6 +36,7 @@ [syng-im.models.chats :refer [chat-exists? create-chat set-group-chat-name + set-chat-color chat-remove-member chat-add-participants chat-remove-participants @@ -609,11 +610,21 @@ (log/debug action) (set-group-chat-name db chat-name))) +(register-handler :set-chat-color + (fn [db [action color]] + (log/debug action) + (set-chat-color db color))) + (register-handler :select-group-chat-member (fn [db [action identity]] (log/debug action) (assoc-in db db/group-settings-selected-member-path identity))) +(register-handler :show-group-settings-color-picker + (fn [db [action show?]] + (log/debug action) + (assoc-in db db/group-settings-show-color-picker show?))) + (register-handler :chat-remove-member (fn [db [action identity]] (log/debug action) diff --git a/src/syng_im/models/chats.cljs b/src/syng_im/models/chats.cljs index 56af4b1c96..861d4635da 100644 --- a/src/syng_im/models/chats.cljs +++ b/src/syng_im/models/chats.cljs @@ -86,6 +86,14 @@ (aset "name" name)))) (assoc-in db (db/chat-name-path chat-id) name))) +(defn set-chat-color [db color] + (let [chat-id (current-chat-id db)] + (r/write (fn [] + (-> (r/get-by-field :chats :chat-id chat-id) + (r/single) + (aset "color" color)))) + (assoc-in db (db/chat-color-path chat-id) color))) + (defn chat-contacts [chat-id] (-> (r/get-by-field :chats :chat-id chat-id) (r/single) diff --git a/src/syng_im/persistence/realm.cljs b/src/syng_im/persistence/realm.cljs index 83faef94a4..dcc7cd7043 100644 --- a/src/syng_im/persistence/realm.cljs +++ b/src/syng_im/persistence/realm.cljs @@ -43,6 +43,8 @@ :primaryKey :chat-id :properties {:chat-id "string" :name "string" + :color {:type "string" + :default "#a187d5"} :group-chat {:type "bool" :indexed true} :is-active "bool" diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index 254a883466..3f8cf88a12 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -96,6 +96,10 @@ (let [current-chat-id (current-chat-id @db)] (reaction (get-in @db (db/chat-name-path current-chat-id)))))) +(register-sub :get-current-chat-color + (fn [db _] + (let [current-chat-id (current-chat-id @db)] + (reaction (get-in @db (db/chat-color-path current-chat-id)))))) ;; -- User data -------------------------------------------------------------- @@ -181,11 +185,15 @@ (contacts-list-include current-participants))))))) (register-sub :selected-group-chat-member - (fn [db [_]] + (fn [db [_]] (reaction (let [identity (get-in @db db/group-settings-selected-member-path)] (contact-by-identity identity))))) +(register-sub :group-settings-show-color-picker + (fn [db [_]] + (reaction (get-in @db db/group-settings-show-color-picker)))) + (register-sub :view-id (fn [db _] (reaction (@db :view-id)))) From 435d11eb2a04dc75c91136d456ff1224a594286c Mon Sep 17 00:00:00 2001 From: virvar Date: Mon, 16 May 2016 15:19:13 +0300 Subject: [PATCH 09/13] 'Clear history', 'Leave chat' handlers Former-commit-id: 1fe23fe57c25275fbd0bfc51808da9a651e86855 --- src/syng_im/group_settings/group_settings.cljs | 6 ++---- src/syng_im/handlers.cljs | 13 ++++++++++++- src/syng_im/models/chats.cljs | 9 +++++++++ src/syng_im/models/messages.cljs | 13 +++++++++++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/syng_im/group_settings/group_settings.cljs b/src/syng_im/group_settings/group_settings.cljs index 7153ce6207..baba9bc9b1 100644 --- a/src/syng_im/group_settings/group_settings.cljs +++ b/src/syng_im/group_settings/group_settings.cljs @@ -113,14 +113,12 @@ :icon-style {:width 12 :height 12} :title "Clear history" - :subtitle "!not implemented" - :handler nil} + :handler #(dispatch [:clear-history])} {:icon :bin :icon-style {:width 12 :height 18} :title "Delete and leave" - :subtitle "!not implemented" - :handler nil}]] + :handler #(dispatch [:leave-group-chat])}]] [view st/settings-container (for [setting settings] ^{:key setting} [setting-view setting])])) diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index f73a56a23c..396cf9839c 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -14,7 +14,8 @@ [syng-im.models.messages :refer [save-message update-message! message-by-id - get-messages]] + get-messages + clear-history]] [syng-im.models.commands :as commands :refer [set-chat-command set-response-chat-command set-chat-command-content @@ -41,6 +42,7 @@ chat-add-participants chat-remove-participants set-chat-active + delete-chat re-join-group-chat chat-by-id2] :as chats] [syng-im.models.chat :refer [signal-chat-updated @@ -395,6 +397,13 @@ ((after save-commands-to-realm!)) ((after handle-commands)))) +(register-handler :clear-history + (fn [db [action]] + (log/debug action) + (let [chat-id (current-chat-id db)] + (clear-history chat-id) + (signal-chat-updated db chat-id)))) + (register-handler :leave-group-chat (fn [db [action]] (log/debug action) @@ -402,6 +411,8 @@ (api/leave-group-chat chat-id) (set-chat-active chat-id false) (left-chat-msg chat-id) + (delete-chat chat-id) + (dispatch [:navigate-back]) (signal-chat-updated db chat-id)))) (register-handler :send-group-chat-msg diff --git a/src/syng_im/models/chats.cljs b/src/syng_im/models/chats.cljs index 861d4635da..481322ba55 100644 --- a/src/syng_im/models/chats.cljs +++ b/src/syng_im/models/chats.cljs @@ -186,3 +186,12 @@ (-> (r/get-by-field :chats :chat-id chat-id) (r/single) (aset "is-active" active?))))) + +(defn delete-chat [chat-id] + (r/write + (fn [] + (-> (r/get-by-field :chats :chat-id chat-id) + (r/single) + (r/delete)))) + ;; TODO temp. Update chat in db atom + (dispatch [:initialize-chats])) diff --git a/src/syng_im/models/messages.cljs b/src/syng_im/models/messages.cljs index b8fc9cff57..87517068c6 100644 --- a/src/syng_im/models/messages.cljs +++ b/src/syng_im/models/messages.cljs @@ -1,5 +1,6 @@ (ns syng-im.models.messages (:require [syng-im.persistence.realm :as r] + [re-frame.core :refer [dispatch]] [cljs.reader :refer [read-string]] [syng-im.utils.random :refer [timestamp]] [syng-im.db :as db] @@ -41,8 +42,9 @@ :outgoing outgoing :timestamp (timestamp) :delivery-status nil - :same-author same-author - :same-direction same-direction} true)))))) + ;; TODO 'some?' is temp + :same-author (some? same-author) + :same-direction (some? same-direction)} true)))))) (defn get-messages [chat-id] (->> (-> (r/get-by-field :msgs :chat-id chat-id) @@ -64,3 +66,10 @@ (fn [] (when (r/exists? :msgs :msg-id msg-id) (r/create :msgs msg true))))) + +(defn clear-history [chat-id] + (r/write + (fn [] + (r/delete (r/get-by-field :msgs :chat-id chat-id)))) + ;; TODO temp. Update chat in db atom + (dispatch [:initialize-chats])) From 2d32a5c507ae9d086c131e30ef70b686640b1740 Mon Sep 17 00:00:00 2001 From: virvar Date: Mon, 16 May 2016 19:38:35 +0300 Subject: [PATCH 10/13] Group settings handler/sub Former-commit-id: 1059c47826df191e5fd6a6c39540d7df7c80e778 --- .../group_settings/group_settings.cljs | 2 - src/syng_im/group_settings/handlers.cljs | 77 +++++++++++++++++++ src/syng_im/group_settings/subs.cljs | 28 +++++++ src/syng_im/handlers.cljs | 51 +----------- src/syng_im/models/chats.cljs | 44 +---------- src/syng_im/subs.cljs | 25 +----- 6 files changed, 108 insertions(+), 119 deletions(-) create mode 100644 src/syng_im/group_settings/handlers.cljs create mode 100644 src/syng_im/group_settings/subs.cljs diff --git a/src/syng_im/group_settings/group_settings.cljs b/src/syng_im/group_settings/group_settings.cljs index baba9bc9b1..5d23a3ea40 100644 --- a/src/syng_im/group_settings/group_settings.cljs +++ b/src/syng_im/group_settings/group_settings.cljs @@ -16,9 +16,7 @@ [syng-im.components.styles :refer [color-purple text2-color]] [syng-im.group-settings.styles.group-settings :as st] - [syng-im.utils.listview :refer [to-realm-datasource]] [syng-im.group-settings.views.member :refer [member-view]] - [syng-im.utils.logging :as log] [reagent.core :as r])) (defn remove-member [{:keys [whisper-identity]}] diff --git a/src/syng_im/group_settings/handlers.cljs b/src/syng_im/group_settings/handlers.cljs new file mode 100644 index 0000000000..218ab1c61c --- /dev/null +++ b/src/syng_im/group_settings/handlers.cljs @@ -0,0 +1,77 @@ +(ns syng-im.group-settings.handlers + (:require [re-frame.core :refer [register-handler debug dispatch]] + [syng-im.db :as db] + [syng-im.persistence.realm :as r])) + +(defn set-group-chat-name [db name] + (let [chat-id (:current-chat-id db)] + (r/write (fn [] + (-> (r/get-by-field :chats :chat-id chat-id) + (r/single) + (aset "name" name)))) + (assoc-in db (db/chat-name-path chat-id) name))) + +(defn set-chat-color [db color] + (let [chat-id (:current-chat-id db)] + (r/write (fn [] + (-> (r/get-by-field :chats :chat-id chat-id) + (r/single) + (aset "color" color)))) + (assoc-in db (db/chat-color-path chat-id) color))) + +(defn chat-remove-member [db identity] + (let [chat (get-in db [:chats (:current-chat-id db)])] + (r/write + (fn [] + (r/create :chats + (update chat :contacts + (fn [members] + (filter #(not= (:identity %) identity) members))) + true))) + ;; TODO temp. Update chat in db atom + (dispatch [:initialize-chats]) + db)) + +(defn delete-chat [chat-id] + (r/write + (fn [] + (-> (r/get-by-field :chats :chat-id chat-id) + (r/single) + (r/delete)))) + ;; TODO temp. Update chat in db atom + (dispatch [:initialize-chats])) + +(register-handler :show-group-settings + (fn [db [action]] + (dispatch [:navigate-to :group-settings]) + db)) + +(register-handler :set-group-chat-name + (fn [db [action chat-name]] + (set-group-chat-name db chat-name))) + +(register-handler :set-chat-color + (fn [db [action color]] + (set-chat-color db color))) + +(register-handler :select-group-chat-member + (fn [db [action identity]] + (assoc-in db db/group-settings-selected-member-path identity))) + +(register-handler :show-group-settings-color-picker + (fn [db [action show?]] + (assoc-in db db/group-settings-show-color-picker show?))) + +(register-handler :chat-remove-member + (fn [db [action identity]] + (let [chat-id (:current-chat-id db) + db (chat-remove-member db identity)] + (dispatch [:select-group-chat-member nil]) + ;; TODO fix and uncomment + ;; (api/group-remove-participant chat-id identity) + ;; (removed-participant-msg chat-id identity) + ))) + +(register-handler :clear-history + (fn [db [action]] + (clear-history (:current-chat-id db)))) diff --git a/src/syng_im/group_settings/subs.cljs b/src/syng_im/group_settings/subs.cljs new file mode 100644 index 0000000000..f544cc3294 --- /dev/null +++ b/src/syng_im/group_settings/subs.cljs @@ -0,0 +1,28 @@ +(ns syng-im.group-settings.subs + (:require-macros [reagent.ratom :refer [reaction]]) + (:require [re-frame.core :refer [register-sub]] + [syng-im.db :as db] + [syng-im.models.chats :refer [chats-list chat-by-id]] + [syng-im.models.contacts :refer [get-contacts + contacts-list-exclude + contacts-list-include + contact-by-identity]] + [syng-im.handlers.content-suggestions :refer [get-content-suggestions]])) + +(register-sub :get-current-chat-name + (fn [db _] + (reaction (get-in @db (db/chat-name-path (:current-chat-id @db)))))) + +(register-sub :get-current-chat-color + (fn [db _] + (reaction (get-in @db (db/chat-color-path (:current-chat-id @db)))))) + +(register-sub :selected-group-chat-member + (fn [db [_]] + (reaction + (let [identity (get-in @db db/group-settings-selected-member-path)] + (contact-by-identity identity))))) + +(register-sub :group-settings-show-color-picker + (fn [db [_]] + (reaction (get-in @db db/group-settings-show-color-picker)))) diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 2da34d7660..16a0cf4855 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -13,8 +13,6 @@ [syng-im.models.contacts :as contacts] [syng-im.models.messages :refer [save-message update-message! - message-by-id - get-messages clear-history]] [syng-im.models.commands :refer [set-commands]] [syng-im.handlers.server :as server] @@ -22,13 +20,9 @@ [syng-im.handlers.sign-up :as sign-up-service] [syng-im.models.chats :refer [chat-exists? create-chat - set-group-chat-name - set-chat-color - chat-remove-member chat-add-participants chat-remove-participants set-chat-active - delete-chat re-join-group-chat chat-by-id2]] [syng-im.utils.logging :as log] @@ -41,6 +35,7 @@ [syng-im.utils.crypt :refer [gen-random-bytes]] [syng-im.utils.random :as random] syng-im.chat.handlers + [syng-im.group-settings.handlers :refer [delete-chat]] [syng-im.navigation.handlers :as nav] syng-im.discovery.handlers syng-im.contacts.handlers)) @@ -219,13 +214,6 @@ (update-message! {:msg-id msg-id :delivery-status :failed}))) -(register-handler :clear-history - (fn [db [action]] - (log/debug action) - (let [chat-id (current-chat-id db)] - (clear-history chat-id) - (signal-chat-updated db chat-id)))) - (register-handler :leave-group-chat (fn [db [action]] (log/debug action) @@ -295,43 +283,6 @@ (dispatch [:show-chat group-id :replace]) db))) -(register-handler :show-group-settings - (fn [db [action]] - (log/debug action) - (dispatch [:navigate-to :group-settings]) - db)) - -(register-handler :set-group-chat-name - (fn [db [action chat-name]] - (log/debug action) - (set-group-chat-name db chat-name))) - -(register-handler :set-chat-color - (fn [db [action color]] - (log/debug action) - (set-chat-color db color))) - -(register-handler :select-group-chat-member - (fn [db [action identity]] - (log/debug action) - (assoc-in db db/group-settings-selected-member-path identity))) - -(register-handler :show-group-settings-color-picker - (fn [db [action show?]] - (log/debug action) - (assoc-in db db/group-settings-show-color-picker show?))) - -(register-handler :chat-remove-member - (fn [db [action identity]] - (log/debug action) - (let [chat-id (current-chat-id db) - db (chat-remove-member db identity)] - (dispatch [:select-group-chat-member nil]) - ;; TODO fix and uncomment - ;; (api/group-remove-participant chat-id identity) - ;; (removed-participant-msg chat-id identity) - (signal-chat-updated db chat-id)))) - (register-handler :group-chat-invite-received (fn [db [action from group-id identities group-name]] (log/debug action from group-id identities) diff --git a/src/syng_im/models/chats.cljs b/src/syng_im/models/chats.cljs index c7cc356e2e..de9ea76963 100644 --- a/src/syng_im/models/chats.cljs +++ b/src/syng_im/models/chats.cljs @@ -7,10 +7,7 @@ [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]] - [syng-im.models.chat :refer [current-chat-id - current-chat - signal-chat-updated]])) + [syng-im.persistence.realm-queries :refer [include-query]])) (defn chat-name-from-contacts [identities] (let [chat-name (->> identities @@ -66,22 +63,6 @@ (add-status-message chat-id) db)))) -(defn set-group-chat-name [db name] - (let [chat-id (current-chat-id db)] - (r/write (fn [] - (-> (r/get-by-field :chats :chat-id chat-id) - (r/single) - (aset "name" name)))) - (assoc-in db (db/chat-name-path chat-id) name))) - -(defn set-chat-color [db color] - (let [chat-id (current-chat-id db)] - (r/write (fn [] - (-> (r/get-by-field :chats :chat-id chat-id) - (r/single) - (aset "color" color)))) - (assoc-in db (db/chat-color-path chat-id) color))) - (defn chat-contacts [chat-id] (-> (r/get-by-field :chats :chat-id chat-id) (r/single) @@ -148,37 +129,14 @@ (.forEach (fn [object _ _] (aset object "is-in-chat" false)))))))) -(defn chat-remove-member [db identity] - (let [chat (current-chat db)] - (r/write - (fn [] - (r/create :chats - (update chat :contacts - (fn [members] - (filter #(not= (:identity %) identity) members))) - true))) - ;; TODO temp. Update chat in db atom - (dispatch [:initialize-chats]) - db)) - (defn active-group-chats [] (let [results (r/filtered (r/get-all :chats) "group-chat = true && is-active = true")] (js->clj (.map results (fn [object _ _] (aget object "chat-id")))))) - (defn set-chat-active [chat-id active?] (r/write (fn [] (-> (r/get-by-field :chats :chat-id chat-id) (r/single) (aset "is-active" active?))))) - -(defn delete-chat [chat-id] - (r/write - (fn [] - (-> (r/get-by-field :chats :chat-id chat-id) - (r/single) - (r/delete)))) - ;; TODO temp. Update chat in db atom - (dispatch [:initialize-chats])) diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index 17adff37ec..6e4c360999 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -1,13 +1,8 @@ (ns syng-im.subs (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub]] - [syng-im.models.chats :refer [chats-list chat-by-id]] - [syng-im.models.contacts :refer [get-contacts - current-chat - contacts-list-exclude - contacts-list-include - contact-by-identity]] syng-im.chat.subs + syng-im.group-settings.subs syng-im.navigation.subs syng-im.discovery.subs syng-im.contacts.subs)) @@ -17,14 +12,6 @@ (register-sub :get (fn [db [_ k]] (reaction (k @db)))) -(register-sub :get-current-chat-name - (fn [db _] - (let [current-chat-id (current-chat-id @db)] - (reaction (get-in @db (db/chat-name-path current-chat-id)))))) -(register-sub :get-current-chat-color - (fn [db _] - (let [current-chat-id (current-chat-id @db)] - (reaction (get-in @db (db/chat-color-path current-chat-id)))))) ;; -- User data -------------------------------------------------------------- (register-sub @@ -32,15 +19,5 @@ (fn [db _] (reaction (:signed-up @db)))) -(register-sub :selected-group-chat-member - (fn [db [_]] - (reaction - (let [identity (get-in @db db/group-settings-selected-member-path)] - (contact-by-identity identity))))) - -(register-sub :group-settings-show-color-picker - (fn [db [_]] - (reaction (get-in @db db/group-settings-show-color-picker)))) - (register-sub :db (fn [db _] (reaction @db))) From 4eba7c0cd9164fbdefae9fc0ff9f80dfd4eae12b Mon Sep 17 00:00:00 2001 From: virvar Date: Tue, 17 May 2016 13:26:20 +0300 Subject: [PATCH 11/13] Fix group chat Former-commit-id: 69b0dbdb8d7a813c3811054e918bdc6621552d65 --- src/syng_im/chat/screen.cljs | 5 +- .../group_settings/group_settings.cljs | 87 +++++++++---------- src/syng_im/navigation/handlers.cljs | 2 +- 3 files changed, 45 insertions(+), 49 deletions(-) diff --git a/src/syng_im/chat/screen.cljs b/src/syng_im/chat/screen.cljs index 1121e99dab..dd355b4223 100644 --- a/src/syng_im/chat/screen.cljs +++ b/src/syng_im/chat/screen.cljs @@ -224,12 +224,11 @@ :dataSource (to-datasource messages)}])) (defview chat [] - [is-active [:chat :is-active] - group-chat [:chat :group-chat] + [group-chat [:chat :group-chat] show-actions-atom [:show-actions]] [view st/chat-view [chat-toolbar] [messages-view group-chat] (when group-chat [typing-all]) - (when is-active [chat-message-new]) + [chat-message-new] (when show-actions-atom [actions-view])]) diff --git a/src/syng_im/group_settings/group_settings.cljs b/src/syng_im/group_settings/group_settings.cljs index 5d23a3ea40..b8f3886788 100644 --- a/src/syng_im/group_settings/group_settings.cljs +++ b/src/syng_im/group_settings/group_settings.cljs @@ -1,4 +1,5 @@ (ns syng-im.group-settings.group-settings + (: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 @@ -38,7 +39,8 @@ [text {:style st/modal-remove-text} "Remove"]]]]]) -(defn chat-members [members] +(defview chat-members [] + [members [:current-chat-contacts]] [view st/chat-members-container (for [member members] ^{:key member} [member-view member])]) @@ -87,10 +89,9 @@ [text {:style st/modal-color-picker-save-btn-text} "Save"]]]]]))) -(defn chat-color-icon [] - (let [chat-color (subscribe [:get-current-chat-color])] - (fn [] - [view {:style (st/chat-color-icon @chat-color)}]))) +(defview chat-color-icon [] + [chat-color [:get-current-chat-color]] + [view {:style (st/chat-color-icon chat-color)}]) (defn settings-view [] ;; TODO implement settings handlers @@ -121,48 +122,44 @@ (for [setting settings] ^{:key setting} [setting-view setting])])) -(defn chat-icon [] - (let [chat-name (subscribe [:get-current-chat-name]) - chat-color (subscribe [:get-current-chat-color])] - (fn [] - [view (st/chat-icon @chat-color) - [text {:style st/chat-icon-text} (nth @chat-name 0)]]))) +(defview chat-icon [] + [chat-name [:get-current-chat-name] + chat-color [:get-current-chat-color]] + [view (st/chat-icon chat-color) + [text {:style st/chat-icon-text} (nth chat-name 0)]]) (defn new-group-toolbar [] [toolbar {:title "Chat settings" :custom-action [chat-icon]}]) -(defn group-settings [] - (let [chat-name (subscribe [:get-current-chat-name]) - members (subscribe [:current-chat-contacts]) - selected-member (subscribe [:selected-group-chat-member]) - show-color-picker (subscribe [:group-settings-show-color-picker])] - (fn [] - [view st/group-settings - [new-group-toolbar] - [scroll-view st/body - [text {:style st/chat-name-text} - "Chat name"] - [view st/chat-name-value-container - [text {:style st/chat-name-value} - @chat-name] - [touchable-highlight {:style st/chat-name-btn-edit-container - :on-press show-chat-name-edit} - [text {:style st/chat-name-btn-edit-text} - "Edit"]]] - [text {:style st/members-text} - "Members"] - [touchable-highlight {:on-press (fn [] - (dispatch [:show-add-participants]))} - [view st/add-members-container - [icon :add-gray st/add-members-icon] - [text {:style st/add-members-text} - "Add members"]]] - [chat-members (vals (js->clj @members :keywordize-keys true))] - [text {:style st/settings-text} - "Settings"] - [settings-view]] - (when @show-color-picker - [chat-color-picker]) - (when @selected-member - [member-menu @selected-member])]))) +(defview group-settings [] + [chat-name [:get-current-chat-name] + selected-member [:selected-group-chat-member] + show-color-picker [:group-settings-show-color-picker]] + [view st/group-settings + [new-group-toolbar] + [scroll-view st/body + [text {:style st/chat-name-text} + "Chat name"] + [view st/chat-name-value-container + [text {:style st/chat-name-value} + chat-name] + [touchable-highlight {:style st/chat-name-btn-edit-container + :on-press show-chat-name-edit} + [text {:style st/chat-name-btn-edit-text} + "Edit"]]] + [text {:style st/members-text} + "Members"] + [touchable-highlight {:on-press #(dispatch [:show-add-participants])} + [view st/add-members-container + [icon :add-gray st/add-members-icon] + [text {:style st/add-members-text} + "Add members"]]] + [chat-members] + [text {:style st/settings-text} + "Settings"] + [settings-view]] + (when show-color-picker + [chat-color-picker]) + (when selected-member + [member-menu selected-member])]) diff --git a/src/syng_im/navigation/handlers.cljs b/src/syng_im/navigation/handlers.cljs index 217bd88136..35c4750bf5 100644 --- a/src/syng_im/navigation/handlers.cljs +++ b/src/syng_im/navigation/handlers.cljs @@ -57,7 +57,7 @@ (push-view db :contact-list))) (defn clear-new-participants [db] - (assoc-in db :new-participants #{})) + (assoc db :new-participants #{})) (register-handler :show-remove-participants (fn [db _] From 1dd00819db1dd0a5071bcc9742c2d185f9fba143 Mon Sep 17 00:00:00 2001 From: virvar Date: Tue, 17 May 2016 14:26:45 +0300 Subject: [PATCH 12/13] Rename group-settings to screen Former-commit-id: 9ad014a5098f999f30c714dc162bb2be37e35574 --- src/syng_im/android/core.cljs | 2 +- src/syng_im/group_settings/{group_settings.cljs => screen.cljs} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/syng_im/group_settings/{group_settings.cljs => screen.cljs} (99%) diff --git a/src/syng_im/android/core.cljs b/src/syng_im/android/core.cljs index b26063092b..b4312b2de3 100644 --- a/src/syng_im/android/core.cljs +++ b/src/syng_im/android/core.cljs @@ -14,7 +14,7 @@ [syng-im.new-group.screen :refer [new-group]] [syng-im.participants.views.create :refer [new-participants]] [syng-im.participants.views.remove :refer [remove-participants]] - [syng-im.group-settings.group-settings :refer [group-settings]] + [syng-im.group-settings.screen :refer [group-settings]] [syng-im.group-settings.views.chat-name-edit :refer [chat-name-edit]] [syng-im.profile.screen :refer [profile my-profile]] [syng-im.utils.utils :refer [toast]] diff --git a/src/syng_im/group_settings/group_settings.cljs b/src/syng_im/group_settings/screen.cljs similarity index 99% rename from src/syng_im/group_settings/group_settings.cljs rename to src/syng_im/group_settings/screen.cljs index b8f3886788..2a1f04d8fb 100644 --- a/src/syng_im/group_settings/group_settings.cljs +++ b/src/syng_im/group_settings/screen.cljs @@ -1,4 +1,4 @@ -(ns syng-im.group-settings.group-settings +(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] From 9f61a21a982d0ce6d7215347a89004477d616f5e Mon Sep 17 00:00:00 2001 From: virvar Date: Tue, 17 May 2016 16:57:45 +0300 Subject: [PATCH 13/13] Update with new structure Former-commit-id: 1512b6de9d67a519397a84639e8aff38f8028453 --- src/syng_im/db.cljs | 6 -- src/syng_im/group_settings/handlers.cljs | 75 +++++++++---------- src/syng_im/group_settings/screen.cljs | 70 ++++++++--------- src/syng_im/group_settings/subs.cljs | 22 +----- .../group_settings/views/chat_name_edit.cljs | 28 ++++--- src/syng_im/handlers.cljs | 26 +++++++ 6 files changed, 114 insertions(+), 113 deletions(-) diff --git a/src/syng_im/db.cljs b/src/syng_im/db.cljs index 4720ad0c62..f031922451 100644 --- a/src/syng_im/db.cljs +++ b/src/syng_im/db.cljs @@ -30,10 +30,6 @@ :current-tag nil}) (def protocol-initialized-path [:protocol-initialized]) -(defn chat-name-path [chat-id] - [:chats chat-id :name]) -(defn chat-color-path [chat-id] - [:chats chat-id :color]) (defn chat-input-text-path [chat-id] [:chats chat-id :input-text]) (defn chat-staged-commands-path [chat-id] @@ -48,5 +44,3 @@ [:chats chat-id :command-requests]) (defn chat-command-request-path [chat-id msg-id] [:chats chat-id :command-requests msg-id]) -(def group-settings-selected-member-path [:group-settings-selected-member]) -(def group-settings-show-color-picker [:group-settings-show-color-picker]) diff --git a/src/syng_im/group_settings/handlers.cljs b/src/syng_im/group_settings/handlers.cljs index 218ab1c61c..d38e52ab06 100644 --- a/src/syng_im/group_settings/handlers.cljs +++ b/src/syng_im/group_settings/handlers.cljs @@ -1,36 +1,25 @@ (ns syng-im.group-settings.handlers (:require [re-frame.core :refer [register-handler debug dispatch]] - [syng-im.db :as db] - [syng-im.persistence.realm :as r])) + [syng-im.persistence.realm :as r] + [syng-im.models.messages :refer [clear-history]])) -(defn set-group-chat-name [db name] - (let [chat-id (:current-chat-id db)] +(defn set-chat-name [db] + (let [chat-id (:current-chat-id db) + name (:new-chat-name db)] (r/write (fn [] (-> (r/get-by-field :chats :chat-id chat-id) (r/single) (aset "name" name)))) - (assoc-in db (db/chat-name-path chat-id) name))) + (assoc-in db [:chats chat-id :name] name))) -(defn set-chat-color [db color] - (let [chat-id (:current-chat-id db)] +(defn set-chat-color [db] + (let [chat-id (:current-chat-id db) + color (:new-chat-color db)] (r/write (fn [] (-> (r/get-by-field :chats :chat-id chat-id) (r/single) (aset "color" color)))) - (assoc-in db (db/chat-color-path chat-id) color))) - -(defn chat-remove-member [db identity] - (let [chat (get-in db [:chats (:current-chat-id db)])] - (r/write - (fn [] - (r/create :chats - (update chat :contacts - (fn [members] - (filter #(not= (:identity %) identity) members))) - true))) - ;; TODO temp. Update chat in db atom - (dispatch [:initialize-chats]) - db)) + (assoc-in db [:chats chat-id :color] color))) (defn delete-chat [chat-id] (r/write @@ -43,34 +32,40 @@ (register-handler :show-group-settings (fn [db [action]] - (dispatch [:navigate-to :group-settings]) - db)) + (let [chat-id (:current-chat-id db) + chat-name (get-in db [:chats chat-id :name]) + chat-color (get-in db [:chats chat-id :color]) + db (assoc db + :new-chat-name chat-name + :new-chat-color chat-color + :group-settings-show-color-picker false + :group-settings-selected-member nil)] + (dispatch [:navigate-to :group-settings]) + db))) -(register-handler :set-group-chat-name - (fn [db [action chat-name]] - (set-group-chat-name db chat-name))) +(register-handler :set-chat-name + (fn [db [action]] + (set-chat-name db))) (register-handler :set-chat-color + (fn [db [action]] + (set-chat-color db))) + +(register-handler :set-new-chat-name + (fn [db [action name]] + (assoc db :new-chat-name name))) + +(register-handler :set-new-chat-color (fn [db [action color]] - (set-chat-color db color))) + (assoc db :new-chat-color color))) (register-handler :select-group-chat-member (fn [db [action identity]] - (assoc-in db db/group-settings-selected-member-path identity))) + (assoc db :group-settings-selected-member identity))) -(register-handler :show-group-settings-color-picker +(register-handler :set-group-settings-show-color-picker (fn [db [action show?]] - (assoc-in db db/group-settings-show-color-picker show?))) - -(register-handler :chat-remove-member - (fn [db [action identity]] - (let [chat-id (:current-chat-id db) - db (chat-remove-member db identity)] - (dispatch [:select-group-chat-member nil]) - ;; TODO fix and uncomment - ;; (api/group-remove-participant chat-id identity) - ;; (removed-participant-msg chat-id identity) - ))) + (assoc db :group-settings-show-color-picker show?))) (register-handler :clear-history (fn [db [action]] diff --git a/src/syng_im/group_settings/screen.cljs b/src/syng_im/group_settings/screen.cljs index 2a1f04d8fb..9d3011b5fb 100644 --- a/src/syng_im/group_settings/screen.cljs +++ b/src/syng_im/group_settings/screen.cljs @@ -26,7 +26,8 @@ (defn close-member-menu [] (dispatch [:select-group-chat-member nil])) -(defn member-menu [member] +(defview member-menu [] + [member [:group-settings-selected-member]] [modal {:animated false :transparent false :onRequestClose close-member-menu} @@ -62,42 +63,43 @@ subtitle])]]]) (defn close-chat-color-picker [] - (dispatch [:show-group-settings-color-picker false])) + (dispatch [:set-group-settings-show-color-picker false])) -(defn set-chat-color [color] +(defn set-chat-color [] (close-chat-color-picker) - (dispatch [:set-chat-color color])) + (dispatch [:set-chat-color])) -(defn chat-color-picker [] - (let [show-color-picker (subscribe [:group-settings-show-color-picker]) - chat-color (subscribe [:get-current-chat-color]) - selected-color (r/atom @chat-color)] - (fn [] - [modal {:animated false - :transparent false - :onRequestClose close-chat-color-picker} - [touchable-highlight {:style st/modal-container - :on-press close-chat-color-picker} - [view st/modal-color-picker-inner-container - [picker {:selectedValue @selected-color - :onValueChange #(reset! selected-color %)} - [picker-item {:label "Blue" :value "#7099e6"}] - [picker-item {:label "Purple" :value "#a187d5"}] - [picker-item {:label "Green" :value "green"}] - [picker-item {:label "Red" :value "red"}]] - [touchable-highlight {:on-press #(set-chat-color @selected-color)} - [text {:style st/modal-color-picker-save-btn-text} - "Save"]]]]]))) +(defview chat-color-picker [] + [show-color-picker [:group-settings-show-color-picker] + new-color [:get :new-chat-color]] + [modal {:animated false + :transparent false + :onRequestClose close-chat-color-picker} + [touchable-highlight {:style st/modal-container + :on-press close-chat-color-picker} + [view st/modal-color-picker-inner-container + [picker {:selectedValue new-color + :onValueChange #(dispatch [:set-new-chat-color %])} + [picker-item {:label "Blue" :value "#7099e6"}] + [picker-item {:label "Purple" :value "#a187d5"}] + [picker-item {:label "Green" :value "green"}] + [picker-item {:label "Red" :value "red"}]] + [touchable-highlight {:on-press set-chat-color} + [text {:style st/modal-color-picker-save-btn-text} + "Save"]]]]]) (defview chat-color-icon [] - [chat-color [:get-current-chat-color]] + [chat-color [:chat :color]] [view {:style (st/chat-color-icon chat-color)}]) +(defn show-chat-color-picker [] + (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 #(dispatch [:show-group-settings-color-picker true])} + :handler show-chat-color-picker} (merge {:title "Notifications and sounds" :subtitle "!not implemented" :handler nil} @@ -123,19 +125,19 @@ ^{:key setting} [setting-view setting])])) (defview chat-icon [] - [chat-name [:get-current-chat-name] - chat-color [:get-current-chat-color]] - [view (st/chat-icon chat-color) - [text {:style st/chat-icon-text} (nth chat-name 0)]]) + [name [:chat :name] + color [:chat :color]] + [view (st/chat-icon color) + [text {:style st/chat-icon-text} (nth name 0)]]) (defn new-group-toolbar [] [toolbar {:title "Chat settings" :custom-action [chat-icon]}]) (defview group-settings [] - [chat-name [:get-current-chat-name] - selected-member [:selected-group-chat-member] - show-color-picker [:group-settings-show-color-picker]] + [chat-name [:chat :name] + selected-member [:group-settings-selected-member] + show-color-picker [:get :group-settings-show-color-picker]] [view st/group-settings [new-group-toolbar] [scroll-view st/body @@ -162,4 +164,4 @@ (when show-color-picker [chat-color-picker]) (when selected-member - [member-menu selected-member])]) + [member-menu])]) diff --git a/src/syng_im/group_settings/subs.cljs b/src/syng_im/group_settings/subs.cljs index f544cc3294..8ef774b5f6 100644 --- a/src/syng_im/group_settings/subs.cljs +++ b/src/syng_im/group_settings/subs.cljs @@ -1,28 +1,14 @@ (ns syng-im.group-settings.subs (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub]] - [syng-im.db :as db] - [syng-im.models.chats :refer [chats-list chat-by-id]] - [syng-im.models.contacts :refer [get-contacts - contacts-list-exclude - contacts-list-include - contact-by-identity]] - [syng-im.handlers.content-suggestions :refer [get-content-suggestions]])) + [syng-im.models.contacts :refer [contact-by-identity]])) -(register-sub :get-current-chat-name - (fn [db _] - (reaction (get-in @db (db/chat-name-path (:current-chat-id @db)))))) - -(register-sub :get-current-chat-color - (fn [db _] - (reaction (get-in @db (db/chat-color-path (:current-chat-id @db)))))) - -(register-sub :selected-group-chat-member +(register-sub :group-settings-selected-member (fn [db [_]] (reaction - (let [identity (get-in @db db/group-settings-selected-member-path)] + (let [identity (get @db :group-settings-selected-member)] (contact-by-identity identity))))) (register-sub :group-settings-show-color-picker (fn [db [_]] - (reaction (get-in @db db/group-settings-show-color-picker)))) + (reaction (get @db :group-settings-show-color-picker)))) diff --git a/src/syng_im/group_settings/views/chat_name_edit.cljs b/src/syng_im/group_settings/views/chat_name_edit.cljs index d283177af1..7ba34e6dd7 100644 --- a/src/syng_im/group_settings/views/chat_name_edit.cljs +++ b/src/syng_im/group_settings/views/chat_name_edit.cljs @@ -1,4 +1,5 @@ (ns syng-im.group-settings.views.chat-name-edit + (:require-macros [syng-im.utils.views :refer [defview]]) (:require [reagent.core :as r] [re-frame.core :refer [subscribe dispatch dispatch-sync]] [syng-im.components.react :refer [view text-input]] @@ -7,8 +8,8 @@ [syng-im.components.styles :refer [toolbar-background2 text2-color]])) -(defn save-group-chat-name [chat-name] - (dispatch [:set-group-chat-name chat-name]) +(defn save-group-chat-name [] + (dispatch [:set-chat-name]) (dispatch [:navigate-back])) (defn chat-name-edit-toolbar [chat-name] @@ -17,17 +18,14 @@ ;; TODO change to dark 'ok' icon :action {:image {:source {:uri :icon_ok} :style st/save-action-icon} - :handler #(save-group-chat-name chat-name)}}]) + :handler save-group-chat-name}}]) -(defn chat-name-edit [] - (let [current-chat-name (subscribe [:get-current-chat-name]) - chat-name (r/atom @current-chat-name)] - (fn [] - [view st/chat-name-container - [chat-name-edit-toolbar @chat-name] - [text-input {:style st/chat-name-input - :autoFocus true - :placeholderTextColor text2-color - :onChangeText (fn [text] - (reset! chat-name text))} - @chat-name]]))) +(defview chat-name-edit [] + [new-chat-name [:get :new-chat-name]] + [view st/chat-name-container + [chat-name-edit-toolbar] + [text-input {:style st/chat-name-input + :autoFocus true + :placeholderTextColor text2-color + :onChangeText #(dispatch [:set-new-chat-name %])} + new-chat-name]]) diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 976f0858e8..37f1e23311 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -2,6 +2,7 @@ (:require [re-frame.core :refer [register-handler after dispatch debug enrich]] [schema.core :as s :include-macros true] + [syng-im.persistence.realm :as r] [syng-im.db :refer [app-db schema]] [syng-im.persistence.simple-kv-store :as kv] [syng-im.protocol.state.storage :as storage] @@ -263,6 +264,31 @@ (api/group-add-participant chat-id ident)) db))) +(defn chat-remove-member [db] + (let [chat (get-in db [:chats (:current-chat-id db)]) + identity (:group-settings-selected-member db)] + (r/write + (fn [] + (r/create :chats + (update chat :contacts + (fn [members] + (filter #(not= (:identity %) identity) members))) + true))) + ;; TODO temp. Update chat in db atom + (dispatch [:initialize-chats]) + db)) + +(register-handler :chat-remove-member + (fn [db [action]] + (let [chat-id (:current-chat-id db) + identity (:group-settings-selected-member db) + db (chat-remove-member db)] + (dispatch [:select-group-chat-member nil]) + ;; TODO fix and uncomment + (api/group-remove-participant chat-id identity) + (removed-participant-msg chat-id identity) + db))) + (defn update-new-group-selection [db identity add?] (update-in db :new-group (fn [new-group] (if add?