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