remove chat model
This commit is contained in:
parent
bc494dcacd
commit
544571e3a7
|
@ -1,9 +1,7 @@
|
|||
(ns syng-im.chat.handlers
|
||||
(:require [syng-im.db :as db]
|
||||
[re-frame.core :refer [register-handler enrich after debug]]
|
||||
(:require [re-frame.core :refer [register-handler enrich after debug]]
|
||||
[syng-im.models.commands :as commands]
|
||||
[clojure.string :as str]
|
||||
[syng-im.models.chat :as chat]
|
||||
[syng-im.handlers.suggestions :as suggestions]
|
||||
[syng-im.protocol.api :as api]
|
||||
[syng-im.models.messages :as messages]
|
||||
|
@ -16,7 +14,7 @@
|
|||
|
||||
(register-handler :set-show-actions
|
||||
(fn [db [_ show-actions]]
|
||||
(assoc-in db db/show-actions-path show-actions)))
|
||||
(assoc db :show-actions show-actions)))
|
||||
|
||||
(register-handler :load-more-messages
|
||||
(fn [db _]
|
||||
|
@ -41,9 +39,13 @@
|
|||
(fn [db [_ content]]
|
||||
(commands/set-chat-command-content db content)))
|
||||
|
||||
(defn update-input-text
|
||||
[{:keys [current-chat-id] :as db} text]
|
||||
(assoc-in db [:chats current-chat-id :input-text] text))
|
||||
|
||||
(register-handler :stage-command
|
||||
(fn [{:keys [current-chat-id] :as db} _]
|
||||
(let [db (chat/set-chat-input-text db nil)
|
||||
(let [db (update-input-text db nil)
|
||||
{:keys [command content]}
|
||||
(get-in db [:chats current-chat-id :command-input])
|
||||
command-info {:command command
|
||||
|
@ -55,8 +57,9 @@
|
|||
(fn [db [_ to-msg-id command-key]]
|
||||
(commands/set-response-chat-command db to-msg-id command-key)))
|
||||
|
||||
(defn update-text [db [_ text]]
|
||||
(chat/set-chat-input-text db text))
|
||||
(defn update-text
|
||||
[db [_ text]]
|
||||
(update-input-text db text))
|
||||
|
||||
(defn update-command [db [_ text]]
|
||||
(let [{:keys [command]} (suggestions/check-suggestion db text)]
|
||||
|
@ -76,8 +79,7 @@
|
|||
:content text
|
||||
:content-type text-content-type
|
||||
:outgoing true}]
|
||||
(messages/save-message chat-id msg)
|
||||
(chat/signal-chat-updated db chat-id))))
|
||||
(messages/save-message chat-id msg))))
|
||||
|
||||
(defn console? [s]
|
||||
(= "console" s))
|
||||
|
@ -225,7 +227,7 @@
|
|||
(register-handler :sign-up-confirm
|
||||
(fn [db [_ confirmation-code]]
|
||||
(sign-up-service/on-send-code-response confirmation-code)
|
||||
db))
|
||||
(sign-up-service/set-signed-up db true)))
|
||||
|
||||
(register-handler :set-signed-up
|
||||
(fn [db [_ signed-up]]
|
||||
|
@ -284,4 +286,4 @@
|
|||
(register-handler :group-received-msg
|
||||
(fn [db [_ {chat-id :group-id :as msg}]]
|
||||
(messages/save-message chat-id msg)
|
||||
(chat/signal-chat-updated db chat-id)))
|
||||
db))
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
(register-sub
|
||||
:show-actions
|
||||
(fn [db _]
|
||||
(reaction (get-in @db db/show-actions-path))))
|
||||
(reaction (:show-actions @db))))
|
||||
|
||||
(register-sub :chat
|
||||
(fn [db [_ k]]
|
||||
|
@ -50,13 +50,13 @@
|
|||
|
||||
(register-sub :get-chat-input-text
|
||||
(fn [db _]
|
||||
(->> (db/chat-input-text-path (:current-chat-id @db))
|
||||
(->> [:chats (:current-chat-id @db) :input-text]
|
||||
(get-in @db)
|
||||
(reaction))))
|
||||
|
||||
(register-sub :get-chat-staged-commands
|
||||
(fn [db _]
|
||||
(->> (db/chat-staged-commands-path (:current-chat-id @db))
|
||||
(->> [:chats (:current-chat-id @db) :staged-commands]
|
||||
(get-in @db)
|
||||
(reaction))))
|
||||
|
||||
|
|
|
@ -23,11 +23,10 @@
|
|||
(defn new-group-toolbar [navigator group-name]
|
||||
[toolbar {:navigator navigator
|
||||
:title "New group chat"
|
||||
:action {:image {:source res/v ;; {:uri "icon_search"}
|
||||
:style {:width 20
|
||||
:height 18}}
|
||||
:handler (fn []
|
||||
(dispatch [:create-new-group group-name navigator]))}}])
|
||||
:action {:image {:source res/v ;; {:uri "icon_search"}
|
||||
:style {:width 20
|
||||
:height 18}}
|
||||
:handler #(dispatch [:create-new-group group-name])}}])
|
||||
|
||||
(defn new-group [{:keys [navigator]}]
|
||||
(let [contacts (subscribe [:all-contacts])
|
||||
|
|
|
@ -13,36 +13,36 @@
|
|||
|
||||
|
||||
(register-sub :get-discoveries
|
||||
(fn [db _]
|
||||
(let [discoveries-updated (-> (discoveries-updated? @db)
|
||||
(reaction))]
|
||||
(reaction
|
||||
(let [_ @discoveries-updated]
|
||||
(discovery-list))))))
|
||||
(fn [db _]
|
||||
(let [discoveries-updated (-> (discoveries-updated? @db)
|
||||
(reaction))]
|
||||
(reaction
|
||||
(let [_ @discoveries-updated]
|
||||
(discovery-list))))))
|
||||
|
||||
(register-sub :get-discoveries-by-tag
|
||||
(fn [db [_ tag limit]]
|
||||
(let [discoveries-updated (-> (discoveries-updated? @db)
|
||||
(reaction))]
|
||||
(log/debug "Getting discoveries for: " tag)
|
||||
(reaction
|
||||
(let [_ @discoveries-updated]
|
||||
(discoveries-by-tag tag limit))))))
|
||||
(fn [db [_ tag limit]]
|
||||
(let [discoveries-updated (-> (discoveries-updated? @db)
|
||||
(reaction))]
|
||||
(log/debug "Getting discoveries for: " tag)
|
||||
(reaction
|
||||
(let [_ @discoveries-updated]
|
||||
(discoveries-by-tag tag limit))))))
|
||||
|
||||
(register-sub :get-popular-tags
|
||||
(fn [db [_ limit]]
|
||||
(let [discoveries-updated (-> (discoveries-updated? @db)
|
||||
(reaction))]
|
||||
(log/debug "Getting tags limited: " limit)
|
||||
(reaction
|
||||
(let [_ @discoveries-updated]
|
||||
(get-tag-popular limit))))))
|
||||
(fn [db [_ limit]]
|
||||
(let [discoveries-updated (-> (discoveries-updated? @db)
|
||||
(reaction))]
|
||||
(log/debug "Getting tags limited: " limit)
|
||||
(reaction
|
||||
(let [_ @discoveries-updated]
|
||||
(get-tag-popular limit))))))
|
||||
|
||||
(register-sub :get-current-tag
|
||||
(fn [db _]
|
||||
(let [current-tag-updated (-> (current-tag-updated? @db)
|
||||
(reaction))]
|
||||
(reaction
|
||||
(let [_ @current-tag-updated]
|
||||
(current-tag @db))))))
|
||||
(fn [db _]
|
||||
(let [current-tag-updated (-> (current-tag-updated? @db)
|
||||
(reaction))]
|
||||
(reaction
|
||||
(let [_ @current-tag-updated]
|
||||
(current-tag @db))))))
|
||||
|
||||
|
|
|
@ -27,10 +27,7 @@
|
|||
|
||||
(def protocol-initialized-path [:protocol-initialized])
|
||||
(def identity-password-path [:identity-password])
|
||||
(def current-chat-id-path [:current-chat-id])
|
||||
(def updated-chats-signal-path [:chats-updated-signal])
|
||||
(defn updated-chat-signal-path [chat-id]
|
||||
[:chats chat-id :chat-updated-signal])
|
||||
(defn chat-input-text-path [chat-id]
|
||||
[:chats chat-id :input-text])
|
||||
(defn chat-staged-commands-path [chat-id]
|
||||
|
@ -45,11 +42,6 @@
|
|||
[:chats chat-id :command-requests])
|
||||
(defn chat-command-request-path [chat-id msg-id]
|
||||
[:chats chat-id :command-requests msg-id])
|
||||
(def show-actions-path [:show-actions])
|
||||
(def new-group-path [:new-group])
|
||||
(def new-participants-path [:new-participants])
|
||||
(def updated-discoveries-signal-path [:discovery-updated-signal])
|
||||
(defn updated-discovery-signal-path [whisper-id]
|
||||
[:discoveries whisper-id :discovery-updated-signal])
|
||||
(def current-tag-path [:current-tag])
|
||||
(def updated-current-tag-signal-path [:current-tag-updated-signal])
|
||||
|
|
|
@ -28,15 +28,6 @@
|
|||
set-chat-active
|
||||
re-join-group-chat
|
||||
chat-by-id2]]
|
||||
[syng-im.models.chat :refer [signal-chat-updated
|
||||
set-current-chat-id
|
||||
current-chat-id
|
||||
update-new-group-selection
|
||||
update-new-participants-selection
|
||||
clear-new-participants
|
||||
new-group-selection
|
||||
set-chat-input-text
|
||||
new-participants-selection]]
|
||||
[syng-im.utils.logging :as log]
|
||||
[syng-im.protocol.api :as api]
|
||||
[syng-im.constants :refer [text-content-type
|
||||
|
@ -46,7 +37,9 @@
|
|||
nav-pop]]
|
||||
[syng-im.utils.crypt :refer [gen-random-bytes]]
|
||||
[syng-im.utils.random :as random]
|
||||
syng-im.chat.handlers))
|
||||
syng-im.chat.handlers
|
||||
syng-im.navigation.handlers
|
||||
syng-im.components.discovery.handlers))
|
||||
|
||||
;; -- Middleware ------------------------------------------------------------
|
||||
;;
|
||||
|
@ -173,60 +166,51 @@
|
|||
(register-handler :group-chat-invite-acked
|
||||
(fn [db [action from group-id ack-msg-id]]
|
||||
(log/debug action from group-id ack-msg-id)
|
||||
(joined-chat-msg group-id from ack-msg-id)
|
||||
(signal-chat-updated db group-id)))
|
||||
(joined-chat-msg group-id from ack-msg-id)))
|
||||
|
||||
(register-handler :participant-removed-from-group
|
||||
(fn [db [action from group-id identity msg-id]]
|
||||
(log/debug action msg-id from group-id identity)
|
||||
(chat-remove-participants group-id [identity])
|
||||
(participant-removed-from-group-msg group-id identity from msg-id)
|
||||
(signal-chat-updated db group-id)))
|
||||
(participant-removed-from-group-msg group-id identity from msg-id)))
|
||||
|
||||
(register-handler :you-removed-from-group
|
||||
(fn [db [action from group-id msg-id]]
|
||||
(log/debug action msg-id from group-id)
|
||||
(you-removed-from-group-msg group-id from msg-id)
|
||||
(set-chat-active group-id false)
|
||||
(signal-chat-updated db group-id)))
|
||||
(set-chat-active group-id false)))
|
||||
|
||||
(register-handler :participant-left-group
|
||||
(fn [db [action from group-id msg-id]]
|
||||
(log/debug action msg-id from group-id)
|
||||
(if (= (api/my-identity) from)
|
||||
db
|
||||
(do (participant-left-group-msg group-id from msg-id)
|
||||
(signal-chat-updated db group-id)))))
|
||||
(participant-left-group-msg group-id from msg-id))))
|
||||
|
||||
(register-handler :participant-invited-to-group
|
||||
(fn [db [action from group-id identity msg-id]]
|
||||
(log/debug action msg-id from group-id identity)
|
||||
(participant-invited-to-group-msg group-id identity from msg-id)
|
||||
(signal-chat-updated db group-id)))
|
||||
(participant-invited-to-group-msg group-id identity from msg-id)))
|
||||
|
||||
(register-handler :acked-msg
|
||||
(fn [db [action from msg-id]]
|
||||
(log/debug action from msg-id)
|
||||
(update-message! {:msg-id msg-id
|
||||
:delivery-status :delivered})
|
||||
(signal-chat-updated db from)))
|
||||
:delivery-status :delivered})))
|
||||
|
||||
(register-handler :msg-delivery-failed
|
||||
(fn [db [action msg-id]]
|
||||
(log/debug action msg-id)
|
||||
(update-message! {:msg-id msg-id
|
||||
:delivery-status :failed})
|
||||
(let [{:keys [chat-id]} (message-by-id msg-id)]
|
||||
(signal-chat-updated db chat-id))))
|
||||
:delivery-status :failed})))
|
||||
|
||||
(register-handler :leave-group-chat
|
||||
(fn [db [action navigator]]
|
||||
(log/debug action)
|
||||
(let [chat-id (current-chat-id db)]
|
||||
(let [chat-id (:current-chat-id db)]
|
||||
(api/leave-group-chat chat-id)
|
||||
(set-chat-active chat-id false)
|
||||
(left-chat-msg chat-id)
|
||||
(signal-chat-updated db chat-id))))
|
||||
(left-chat-msg chat-id))))
|
||||
|
||||
;; -- User data --------------------------------------------------------------
|
||||
|
||||
|
@ -253,6 +237,11 @@
|
|||
(contacts/load-syng-contacts db)))
|
||||
|
||||
;; -- Chats --------------------------------------------------------------
|
||||
(defn update-new-participants-selection [db identity add?]
|
||||
(update db :new-participants (fn [new-participants]
|
||||
(if add?
|
||||
(conj new-participants identity)
|
||||
(disj new-participants identity)))))
|
||||
|
||||
(register-handler :select-new-participant
|
||||
(fn [db [action identity add?]]
|
||||
|
@ -262,35 +251,39 @@
|
|||
(register-handler :remove-selected-participants
|
||||
(fn [db [action navigator]]
|
||||
(log/debug action)
|
||||
(let [identities (vec (new-participants-selection db))
|
||||
chat-id (current-chat-id db)]
|
||||
(let [identities (vec (:new-participants db))
|
||||
chat-id (:current-chat-id db)]
|
||||
(chat-remove-participants chat-id identities)
|
||||
(nav-pop navigator)
|
||||
(doseq [ident identities]
|
||||
(api/group-remove-participant chat-id ident)
|
||||
(removed-participant-msg chat-id ident))
|
||||
(signal-chat-updated db chat-id))))
|
||||
(removed-participant-msg chat-id ident)))))
|
||||
|
||||
(register-handler :add-new-participants
|
||||
(fn [db [action navigator]]
|
||||
(log/debug action)
|
||||
(let [identities (vec (new-participants-selection db))
|
||||
chat-id (current-chat-id db)]
|
||||
(let [identities (vec (:new-participants db))
|
||||
chat-id (:current-chat-id db)]
|
||||
(chat-add-participants chat-id identities)
|
||||
(nav-pop navigator)
|
||||
(doseq [ident identities]
|
||||
(api/group-add-participant chat-id ident))
|
||||
db)))
|
||||
|
||||
(defn update-new-group-selection [db identity add?]
|
||||
(update-in db :new-group (fn [new-group]
|
||||
(if add?
|
||||
(conj new-group identity)
|
||||
(disj new-group identity)))))
|
||||
|
||||
(register-handler :select-for-new-group
|
||||
(fn [db [action identity add?]]
|
||||
(log/debug action identity add?)
|
||||
(fn [db [_ identity add?]]
|
||||
(update-new-group-selection db identity add?)))
|
||||
|
||||
(register-handler :create-new-group
|
||||
(fn [db [action group-name navigator]]
|
||||
(fn [db [action group-name]]
|
||||
(log/debug action)
|
||||
(let [identities (vec (new-group-selection db))
|
||||
(let [identities (vec (:new-group db))
|
||||
group-id (api/start-group-chat identities group-name)
|
||||
db (create-chat db group-id identities true group-name)]
|
||||
(dispatch [:show-chat group-id :replace])
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||
[syng-im.persistence.simple-kv-store :as kv]
|
||||
[syng-im.protocol.state.storage :as s]
|
||||
[syng-im.models.chat :refer [set-current-chat-id]]
|
||||
[syng-im.models.chats :as c]
|
||||
[syng-im.utils.utils :refer [log on-error http-post toast]]
|
||||
[syng-im.utils.random :as random]
|
||||
|
@ -196,5 +195,5 @@
|
|||
(-> db
|
||||
(assoc-in [:chats "console"] console-chat)
|
||||
(assoc :new-chat console-chat)
|
||||
(set-current-chat-id "console")
|
||||
(assoc :current-chat-id "console")
|
||||
(intro))))))
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
(ns syng-im.handlers.suggestions
|
||||
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||
[syng-im.db :as db]
|
||||
[syng-im.models.chat :refer [current-chat-id]]
|
||||
[syng-im.models.commands :refer [commands
|
||||
suggestions
|
||||
get-commands
|
||||
|
@ -39,7 +38,8 @@
|
|||
(command-handler to-msg-id command-key content)))))
|
||||
|
||||
(defn apply-staged-commands [db]
|
||||
(let [staged-commands (get-in db (db/chat-staged-commands-path (current-chat-id db)))]
|
||||
(let [staged-commands (get-in db (db/chat-staged-commands-path
|
||||
(:current-chat-id db)))]
|
||||
(dorun (map (fn [staged-command]
|
||||
(when-let [handler (:handler staged-command)]
|
||||
(handler)))
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
(ns syng-im.models.chat
|
||||
(:require [syng-im.db :as db]))
|
||||
|
||||
(defn set-current-chat-id [db chat-id]
|
||||
(assoc-in db db/current-chat-id-path chat-id))
|
||||
|
||||
(defn current-chat-id [db]
|
||||
(get-in db db/current-chat-id-path))
|
||||
|
||||
(defn signal-chat-updated [db chat-id]
|
||||
(update-in db (db/updated-chat-signal-path chat-id) (fn [current]
|
||||
(if current
|
||||
(inc current)
|
||||
0))))
|
||||
|
||||
(defn chat-updated? [db chat-id]
|
||||
(get-in db (db/updated-chat-signal-path chat-id)))
|
||||
|
||||
(defn update-new-group-selection [db identity add?]
|
||||
(update-in db db/new-group-path (fn [new-group]
|
||||
(if add?
|
||||
(conj new-group identity)
|
||||
(disj new-group identity)))))
|
||||
|
||||
(defn update-new-participants-selection [db identity add?]
|
||||
(update-in db db/new-participants-path (fn [new-participants]
|
||||
(if add?
|
||||
(conj new-participants identity)
|
||||
(disj new-participants identity)))))
|
||||
|
||||
(defn new-group-selection [db]
|
||||
(get-in db db/new-group-path))
|
||||
|
||||
(defn clear-new-group [db]
|
||||
(assoc-in db db/new-group-path #{}))
|
||||
|
||||
(defn new-participants-selection [db]
|
||||
(get-in db db/new-participants-path))
|
||||
|
||||
(defn clear-new-participants [db]
|
||||
(assoc-in db db/new-participants-path #{}))
|
||||
|
||||
(defn set-chat-input-text [db text]
|
||||
(assoc-in db (db/chat-input-text-path (current-chat-id db)) text))
|
||||
|
||||
(comment
|
||||
|
||||
(swap! re-frame.db/app-db (fn [db]
|
||||
(signal-chat-updated db "0x0479a5ed1f38cadfad1db6cd56c4b659b0ebe052bbe9efa950f6660058519fa4ca6be2dda66afa80de96ab00eb97a2605d5267a1e8f4c2a166ab551f6826608cdd")))
|
||||
|
||||
(current-chat-id @re-frame.db/app-db)
|
||||
)
|
|
@ -7,8 +7,7 @@
|
|||
[syng-im.utils.logging :as log]
|
||||
[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.persistence.realm-queries :refer [include-query]]))
|
||||
|
||||
(defn signal-chats-updated [db]
|
||||
(update-in db db/updated-chats-signal-path (fn [current]
|
||||
|
@ -96,8 +95,7 @@
|
|||
:is-active true
|
||||
:name group-name
|
||||
:contacts contacts} true))))
|
||||
(-> (signal-chats-updated db)
|
||||
(signal-chat-updated group-id)))
|
||||
(signal-chats-updated db))
|
||||
|
||||
(defn normalize-contacts
|
||||
[chats]
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
[cljs.core.async :as async :refer [chan put! <! >!]]
|
||||
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||
[syng-im.db :as db]
|
||||
[syng-im.models.chat :refer [current-chat-id]]
|
||||
[syng-im.components.styles :refer [color-blue
|
||||
color-dark-mint]]
|
||||
[syng-im.utils.utils :refer [log toast]]))
|
||||
|
@ -80,18 +79,18 @@
|
|||
(first (filter #(= command-key (:command %)) commands)))
|
||||
|
||||
(defn get-chat-command-content [db]
|
||||
(get-in db (db/chat-command-content-path (current-chat-id db))))
|
||||
(get-in db (db/chat-command-content-path (:current-chat-id db))))
|
||||
|
||||
(defn set-chat-command-content [db content]
|
||||
(assoc-in db
|
||||
[:chats (get-in db db/current-chat-id-path) :command-input :content]
|
||||
[:chats (:current-chat-id db) :command-input :content]
|
||||
content))
|
||||
|
||||
(defn get-chat-command [db]
|
||||
(get-in db (db/chat-command-path (current-chat-id db))))
|
||||
(get-in db (db/chat-command-path (:current-chat-id db))))
|
||||
|
||||
(defn set-response-chat-command [db msg-id command-key]
|
||||
(let [chat-id (current-chat-id db)]
|
||||
(let [chat-id (:current-chat-id db)]
|
||||
(-> db
|
||||
(assoc-in [:chats chat-id :command-input :content] nil)
|
||||
(assoc-in [:chats chat-id :command-input :command]
|
||||
|
@ -102,29 +101,29 @@
|
|||
(set-response-chat-command db nil command-key))
|
||||
|
||||
(defn get-chat-command-to-msg-id [db]
|
||||
(get-in db (db/chat-command-to-msg-id-path (current-chat-id db))))
|
||||
(get-in db (db/chat-command-to-msg-id-path (:current-chat-id db))))
|
||||
|
||||
(defn stage-command [db command-info]
|
||||
(update-in db (db/chat-staged-commands-path (current-chat-id db))
|
||||
(update-in db (db/chat-staged-commands-path (:current-chat-id db))
|
||||
(fn [staged-commands]
|
||||
(if staged-commands
|
||||
(conj staged-commands command-info)
|
||||
[command-info]))))
|
||||
|
||||
(defn unstage-command [db staged-command]
|
||||
(update-in db (db/chat-staged-commands-path (current-chat-id db))
|
||||
(update-in db (db/chat-staged-commands-path (:current-chat-id db))
|
||||
(fn [staged-commands]
|
||||
(filterv #(not= % staged-command) staged-commands))))
|
||||
|
||||
(defn clear-staged-commands [db]
|
||||
(assoc-in db (db/chat-staged-commands-path (current-chat-id db)) []))
|
||||
(assoc-in db (db/chat-staged-commands-path (:current-chat-id db)) []))
|
||||
|
||||
(defn get-chat-command-request [db]
|
||||
(get-in db (db/chat-command-request-path (current-chat-id db)
|
||||
(get-in db (db/chat-command-request-path (:current-chat-id db)
|
||||
(get-chat-command-to-msg-id db))))
|
||||
|
||||
(defn set-chat-command-request [db msg-id handler]
|
||||
(update-in db (db/chat-command-requests-path (current-chat-id db))
|
||||
(update-in db (db/chat-command-requests-path (:current-chat-id db))
|
||||
#(assoc % msg-id handler)))
|
||||
|
||||
(defn parse-command-msg-content [commands content]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns syng-im.navigation.handlers
|
||||
(:require [re-frame.core :refer [register-handler dispatch]]
|
||||
[syng-im.models.chat :as chat]))
|
||||
(:require [re-frame.core :refer [register-handler dispatch]]))
|
||||
|
||||
(defn push-view [db view-id]
|
||||
(-> db
|
||||
|
@ -39,27 +38,30 @@
|
|||
(fn [db _]
|
||||
(-> db
|
||||
(push-view :new-group)
|
||||
chat/clear-new-group)))
|
||||
(assoc-in :new-group #{}))))
|
||||
|
||||
(register-handler :show-chat
|
||||
(fn [db [_ chat-id nav-type]]
|
||||
(let [update-view-id-fn (if (= :replace nav-type) replace-view push-view)]
|
||||
(-> db
|
||||
(update-view-id-fn :chat)
|
||||
(chat/set-current-chat-id chat-id)))))
|
||||
(assoc :current-chat-id chat-id)))))
|
||||
|
||||
(register-handler :show-contacts
|
||||
(fn [db _]
|
||||
(push-view db :contact-list)))
|
||||
|
||||
(defn clear-new-participants [db]
|
||||
(assoc-in db :new-participants #{}))
|
||||
|
||||
(register-handler :show-remove-participants
|
||||
(fn [db _]
|
||||
(-> db
|
||||
(push-view :remove-participants)
|
||||
chat/clear-new-participants)))
|
||||
clear-new-participants)))
|
||||
|
||||
(register-handler :show-add-participants
|
||||
(fn [db _]
|
||||
(-> db
|
||||
(push-view :add-participants)
|
||||
chat/clear-new-participants)))
|
||||
clear-new-participants)))
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
(ns syng-im.subs
|
||||
(:require-macros [reagent.ratom :refer [reaction]])
|
||||
(:require [re-frame.core :refer [register-sub]]
|
||||
[syng-im.models.chat :refer [current-chat-id chat-updated?]]
|
||||
[syng-im.models.chats :refer [chats-list chats-updated? chat-by-id]]
|
||||
[syng-im.models.contacts :refer [contacts-list
|
||||
contacts-list-exclude
|
||||
contacts-list-include]]
|
||||
syng-im.chat.subs))
|
||||
syng-im.chat.subs
|
||||
syng-im.navigation.subs
|
||||
syng-im.components.discovery.subs))
|
||||
|
||||
;; -- Chats list --------------------------------------------------------------
|
||||
|
||||
|
@ -56,7 +57,7 @@
|
|||
|
||||
(register-sub :all-new-contacts
|
||||
(fn [db _]
|
||||
(let [current-chat-id (reaction (current-chat-id @db))
|
||||
(let [current-chat-id (reaction (:current-chat-id @db))
|
||||
chat (reaction (when-let [chat-id @current-chat-id]
|
||||
(chat-by-id chat-id)))]
|
||||
(reaction
|
||||
|
@ -68,7 +69,7 @@
|
|||
|
||||
(register-sub :current-chat-contacts
|
||||
(fn [db _]
|
||||
(let [current-chat-id (reaction (current-chat-id @db))
|
||||
(let [current-chat-id (reaction (:current-chat-id @db))
|
||||
chat (reaction (when-let [chat-id @current-chat-id]
|
||||
(chat-by-id chat-id)))]
|
||||
(reaction
|
||||
|
|
Loading…
Reference in New Issue