Read/save group chat settings
This commit is contained in:
parent
13205348ed
commit
14be588ca2
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"]]])))
|
|
@ -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])
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))))
|
||||
|
|
Loading…
Reference in New Issue