parent
b62b758c60
commit
470191d9b3
|
@ -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]
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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])])))
|
||||
|
|
|
@ -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})
|
||||
|
||||
|
|
|
@ -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]]]])
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 _]
|
||||
|
|
Loading…
Reference in New Issue