parent
470191d9b3
commit
8ab611f5c5
|
@ -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])
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)))))
|
||||
|
|
Loading…
Reference in New Issue