Update with new structure
This commit is contained in:
parent
e93e7724e2
commit
1512b6de9d
|
@ -30,10 +30,6 @@
|
||||||
:current-tag nil})
|
:current-tag nil})
|
||||||
|
|
||||||
(def protocol-initialized-path [:protocol-initialized])
|
(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]
|
(defn chat-input-text-path [chat-id]
|
||||||
[:chats chat-id :input-text])
|
[:chats chat-id :input-text])
|
||||||
(defn chat-staged-commands-path [chat-id]
|
(defn chat-staged-commands-path [chat-id]
|
||||||
|
@ -48,5 +44,3 @@
|
||||||
[:chats chat-id :command-requests])
|
[:chats chat-id :command-requests])
|
||||||
(defn chat-command-request-path [chat-id msg-id]
|
(defn chat-command-request-path [chat-id msg-id]
|
||||||
[:chats chat-id :command-requests 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])
|
|
||||||
|
|
|
@ -1,36 +1,25 @@
|
||||||
(ns syng-im.group-settings.handlers
|
(ns syng-im.group-settings.handlers
|
||||||
(:require [re-frame.core :refer [register-handler debug dispatch]]
|
(: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]
|
(defn set-chat-name [db]
|
||||||
(let [chat-id (:current-chat-id db)]
|
(let [chat-id (:current-chat-id db)
|
||||||
|
name (:new-chat-name db)]
|
||||||
(r/write (fn []
|
(r/write (fn []
|
||||||
(-> (r/get-by-field :chats :chat-id chat-id)
|
(-> (r/get-by-field :chats :chat-id chat-id)
|
||||||
(r/single)
|
(r/single)
|
||||||
(aset "name" name))))
|
(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]
|
(defn set-chat-color [db]
|
||||||
(let [chat-id (:current-chat-id db)]
|
(let [chat-id (:current-chat-id db)
|
||||||
|
color (:new-chat-color db)]
|
||||||
(r/write (fn []
|
(r/write (fn []
|
||||||
(-> (r/get-by-field :chats :chat-id chat-id)
|
(-> (r/get-by-field :chats :chat-id chat-id)
|
||||||
(r/single)
|
(r/single)
|
||||||
(aset "color" color))))
|
(aset "color" color))))
|
||||||
(assoc-in db (db/chat-color-path chat-id) color)))
|
(assoc-in db [:chats chat-id :color] 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]
|
(defn delete-chat [chat-id]
|
||||||
(r/write
|
(r/write
|
||||||
|
@ -43,34 +32,40 @@
|
||||||
|
|
||||||
(register-handler :show-group-settings
|
(register-handler :show-group-settings
|
||||||
(fn [db [action]]
|
(fn [db [action]]
|
||||||
(dispatch [:navigate-to :group-settings])
|
(let [chat-id (:current-chat-id db)
|
||||||
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
|
(register-handler :set-chat-name
|
||||||
(fn [db [action chat-name]]
|
(fn [db [action]]
|
||||||
(set-group-chat-name db chat-name)))
|
(set-chat-name db)))
|
||||||
|
|
||||||
(register-handler :set-chat-color
|
(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]]
|
(fn [db [action color]]
|
||||||
(set-chat-color db color)))
|
(assoc db :new-chat-color color)))
|
||||||
|
|
||||||
(register-handler :select-group-chat-member
|
(register-handler :select-group-chat-member
|
||||||
(fn [db [action identity]]
|
(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?]]
|
(fn [db [action show?]]
|
||||||
(assoc-in db db/group-settings-show-color-picker show?)))
|
(assoc 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
|
(register-handler :clear-history
|
||||||
(fn [db [action]]
|
(fn [db [action]]
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
(defn close-member-menu []
|
(defn close-member-menu []
|
||||||
(dispatch [:select-group-chat-member nil]))
|
(dispatch [:select-group-chat-member nil]))
|
||||||
|
|
||||||
(defn member-menu [member]
|
(defview member-menu []
|
||||||
|
[member [:group-settings-selected-member]]
|
||||||
[modal {:animated false
|
[modal {:animated false
|
||||||
:transparent false
|
:transparent false
|
||||||
:onRequestClose close-member-menu}
|
:onRequestClose close-member-menu}
|
||||||
|
@ -62,42 +63,43 @@
|
||||||
subtitle])]]])
|
subtitle])]]])
|
||||||
|
|
||||||
(defn close-chat-color-picker []
|
(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)
|
(close-chat-color-picker)
|
||||||
(dispatch [:set-chat-color color]))
|
(dispatch [:set-chat-color]))
|
||||||
|
|
||||||
(defn chat-color-picker []
|
(defview chat-color-picker []
|
||||||
(let [show-color-picker (subscribe [:group-settings-show-color-picker])
|
[show-color-picker [:group-settings-show-color-picker]
|
||||||
chat-color (subscribe [:get-current-chat-color])
|
new-color [:get :new-chat-color]]
|
||||||
selected-color (r/atom @chat-color)]
|
[modal {:animated false
|
||||||
(fn []
|
:transparent false
|
||||||
[modal {:animated false
|
:onRequestClose close-chat-color-picker}
|
||||||
:transparent false
|
[touchable-highlight {:style st/modal-container
|
||||||
:onRequestClose close-chat-color-picker}
|
:on-press close-chat-color-picker}
|
||||||
[touchable-highlight {:style st/modal-container
|
[view st/modal-color-picker-inner-container
|
||||||
:on-press close-chat-color-picker}
|
[picker {:selectedValue new-color
|
||||||
[view st/modal-color-picker-inner-container
|
:onValueChange #(dispatch [:set-new-chat-color %])}
|
||||||
[picker {:selectedValue @selected-color
|
[picker-item {:label "Blue" :value "#7099e6"}]
|
||||||
:onValueChange #(reset! selected-color %)}
|
[picker-item {:label "Purple" :value "#a187d5"}]
|
||||||
[picker-item {:label "Blue" :value "#7099e6"}]
|
[picker-item {:label "Green" :value "green"}]
|
||||||
[picker-item {:label "Purple" :value "#a187d5"}]
|
[picker-item {:label "Red" :value "red"}]]
|
||||||
[picker-item {:label "Green" :value "green"}]
|
[touchable-highlight {:on-press set-chat-color}
|
||||||
[picker-item {:label "Red" :value "red"}]]
|
[text {:style st/modal-color-picker-save-btn-text}
|
||||||
[touchable-highlight {:on-press #(set-chat-color @selected-color)}
|
"Save"]]]]])
|
||||||
[text {:style st/modal-color-picker-save-btn-text}
|
|
||||||
"Save"]]]]])))
|
|
||||||
|
|
||||||
(defview chat-color-icon []
|
(defview chat-color-icon []
|
||||||
[chat-color [:get-current-chat-color]]
|
[chat-color [:chat :color]]
|
||||||
[view {:style (st/chat-color-icon 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 []
|
(defn settings-view []
|
||||||
;; TODO implement settings handlers
|
;; TODO implement settings handlers
|
||||||
(let [settings [{:custom-icon [chat-color-icon]
|
(let [settings [{:custom-icon [chat-color-icon]
|
||||||
:title "Change color"
|
:title "Change color"
|
||||||
:handler #(dispatch [:show-group-settings-color-picker true])}
|
:handler show-chat-color-picker}
|
||||||
(merge {:title "Notifications and sounds"
|
(merge {:title "Notifications and sounds"
|
||||||
:subtitle "!not implemented"
|
:subtitle "!not implemented"
|
||||||
:handler nil}
|
:handler nil}
|
||||||
|
@ -123,19 +125,19 @@
|
||||||
^{:key setting} [setting-view setting])]))
|
^{:key setting} [setting-view setting])]))
|
||||||
|
|
||||||
(defview chat-icon []
|
(defview chat-icon []
|
||||||
[chat-name [:get-current-chat-name]
|
[name [:chat :name]
|
||||||
chat-color [:get-current-chat-color]]
|
color [:chat :color]]
|
||||||
[view (st/chat-icon chat-color)
|
[view (st/chat-icon color)
|
||||||
[text {:style st/chat-icon-text} (nth chat-name 0)]])
|
[text {:style st/chat-icon-text} (nth name 0)]])
|
||||||
|
|
||||||
(defn new-group-toolbar []
|
(defn new-group-toolbar []
|
||||||
[toolbar {:title "Chat settings"
|
[toolbar {:title "Chat settings"
|
||||||
:custom-action [chat-icon]}])
|
:custom-action [chat-icon]}])
|
||||||
|
|
||||||
(defview group-settings []
|
(defview group-settings []
|
||||||
[chat-name [:get-current-chat-name]
|
[chat-name [:chat :name]
|
||||||
selected-member [:selected-group-chat-member]
|
selected-member [:group-settings-selected-member]
|
||||||
show-color-picker [:group-settings-show-color-picker]]
|
show-color-picker [:get :group-settings-show-color-picker]]
|
||||||
[view st/group-settings
|
[view st/group-settings
|
||||||
[new-group-toolbar]
|
[new-group-toolbar]
|
||||||
[scroll-view st/body
|
[scroll-view st/body
|
||||||
|
@ -162,4 +164,4 @@
|
||||||
(when show-color-picker
|
(when show-color-picker
|
||||||
[chat-color-picker])
|
[chat-color-picker])
|
||||||
(when selected-member
|
(when selected-member
|
||||||
[member-menu selected-member])])
|
[member-menu])])
|
||||||
|
|
|
@ -1,28 +1,14 @@
|
||||||
(ns syng-im.group-settings.subs
|
(ns syng-im.group-settings.subs
|
||||||
(:require-macros [reagent.ratom :refer [reaction]])
|
(:require-macros [reagent.ratom :refer [reaction]])
|
||||||
(:require [re-frame.core :refer [register-sub]]
|
(:require [re-frame.core :refer [register-sub]]
|
||||||
[syng-im.db :as db]
|
[syng-im.models.contacts :refer [contact-by-identity]]))
|
||||||
[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
|
(register-sub :group-settings-selected-member
|
||||||
(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 [_]]
|
(fn [db [_]]
|
||||||
(reaction
|
(reaction
|
||||||
(let [identity (get-in @db db/group-settings-selected-member-path)]
|
(let [identity (get @db :group-settings-selected-member)]
|
||||||
(contact-by-identity identity)))))
|
(contact-by-identity identity)))))
|
||||||
|
|
||||||
(register-sub :group-settings-show-color-picker
|
(register-sub :group-settings-show-color-picker
|
||||||
(fn [db [_]]
|
(fn [db [_]]
|
||||||
(reaction (get-in @db db/group-settings-show-color-picker))))
|
(reaction (get @db :group-settings-show-color-picker))))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
(ns syng-im.group-settings.views.chat-name-edit
|
(ns syng-im.group-settings.views.chat-name-edit
|
||||||
|
(:require-macros [syng-im.utils.views :refer [defview]])
|
||||||
(:require [reagent.core :as r]
|
(:require [reagent.core :as r]
|
||||||
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||||
[syng-im.components.react :refer [view text-input]]
|
[syng-im.components.react :refer [view text-input]]
|
||||||
|
@ -7,8 +8,8 @@
|
||||||
[syng-im.components.styles :refer [toolbar-background2
|
[syng-im.components.styles :refer [toolbar-background2
|
||||||
text2-color]]))
|
text2-color]]))
|
||||||
|
|
||||||
(defn save-group-chat-name [chat-name]
|
(defn save-group-chat-name []
|
||||||
(dispatch [:set-group-chat-name chat-name])
|
(dispatch [:set-chat-name])
|
||||||
(dispatch [:navigate-back]))
|
(dispatch [:navigate-back]))
|
||||||
|
|
||||||
(defn chat-name-edit-toolbar [chat-name]
|
(defn chat-name-edit-toolbar [chat-name]
|
||||||
|
@ -17,17 +18,14 @@
|
||||||
;; TODO change to dark 'ok' icon
|
;; TODO change to dark 'ok' icon
|
||||||
:action {:image {:source {:uri :icon_ok}
|
:action {:image {:source {:uri :icon_ok}
|
||||||
:style st/save-action-icon}
|
:style st/save-action-icon}
|
||||||
:handler #(save-group-chat-name chat-name)}}])
|
:handler save-group-chat-name}}])
|
||||||
|
|
||||||
(defn chat-name-edit []
|
(defview chat-name-edit []
|
||||||
(let [current-chat-name (subscribe [:get-current-chat-name])
|
[new-chat-name [:get :new-chat-name]]
|
||||||
chat-name (r/atom @current-chat-name)]
|
[view st/chat-name-container
|
||||||
(fn []
|
[chat-name-edit-toolbar]
|
||||||
[view st/chat-name-container
|
[text-input {:style st/chat-name-input
|
||||||
[chat-name-edit-toolbar @chat-name]
|
:autoFocus true
|
||||||
[text-input {:style st/chat-name-input
|
:placeholderTextColor text2-color
|
||||||
:autoFocus true
|
:onChangeText #(dispatch [:set-new-chat-name %])}
|
||||||
:placeholderTextColor text2-color
|
new-chat-name]])
|
||||||
:onChangeText (fn [text]
|
|
||||||
(reset! chat-name text))}
|
|
||||||
@chat-name]])))
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
(:require
|
(:require
|
||||||
[re-frame.core :refer [register-handler after dispatch debug enrich]]
|
[re-frame.core :refer [register-handler after dispatch debug enrich]]
|
||||||
[schema.core :as s :include-macros true]
|
[schema.core :as s :include-macros true]
|
||||||
|
[syng-im.persistence.realm :as r]
|
||||||
[syng-im.db :refer [app-db schema]]
|
[syng-im.db :refer [app-db schema]]
|
||||||
[syng-im.persistence.simple-kv-store :as kv]
|
[syng-im.persistence.simple-kv-store :as kv]
|
||||||
[syng-im.protocol.state.storage :as storage]
|
[syng-im.protocol.state.storage :as storage]
|
||||||
|
@ -263,6 +264,31 @@
|
||||||
(api/group-add-participant chat-id ident))
|
(api/group-add-participant chat-id ident))
|
||||||
db)))
|
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?]
|
(defn update-new-group-selection [db identity add?]
|
||||||
(update-in db :new-group (fn [new-group]
|
(update-in db :new-group (fn [new-group]
|
||||||
(if add?
|
(if add?
|
||||||
|
|
Loading…
Reference in New Issue