parent
8d2532eb46
commit
9f61a21a98
|
@ -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])
|
||||
|
|
|
@ -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]]
|
||||
(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))
|
||||
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]]
|
||||
|
|
|
@ -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 []
|
||||
(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 @selected-color
|
||||
:onValueChange #(reset! selected-color %)}
|
||||
[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 @selected-color)}
|
||||
[touchable-highlight {:on-press set-chat-color}
|
||||
[text {:style st/modal-color-picker-save-btn-text}
|
||||
"Save"]]]]])))
|
||||
"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])])
|
||||
|
|
|
@ -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))))
|
||||
|
|
|
@ -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 []
|
||||
(defview chat-name-edit []
|
||||
[new-chat-name [:get :new-chat-name]]
|
||||
[view st/chat-name-container
|
||||
[chat-name-edit-toolbar @chat-name]
|
||||
[chat-name-edit-toolbar]
|
||||
[text-input {:style st/chat-name-input
|
||||
:autoFocus true
|
||||
:placeholderTextColor text2-color
|
||||
:onChangeText (fn [text]
|
||||
(reset! chat-name text))}
|
||||
@chat-name]])))
|
||||
:onChangeText #(dispatch [:set-new-chat-name %])}
|
||||
new-chat-name]])
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in New Issue