mirror of
https://github.com/status-im/status-react.git
synced 2025-02-06 08:05:55 +00:00
improved system messages for edge cases
This commit is contained in:
parent
8f04104cc0
commit
a555c57bcc
@ -1,59 +1,59 @@
|
|||||||
(ns syng-im.handlers
|
(ns syng-im.handlers
|
||||||
(:require
|
(:require
|
||||||
[re-frame.core :refer [register-handler after dispatch]]
|
[re-frame.core :refer [register-handler after dispatch]]
|
||||||
[schema.core :as s :include-macros true]
|
[schema.core :as s :include-macros true]
|
||||||
[syng-im.db :as db :refer [app-db schema]]
|
[syng-im.db :as db :refer [app-db schema]]
|
||||||
[syng-im.protocol.api :refer [init-protocol]]
|
[syng-im.protocol.api :refer [init-protocol]]
|
||||||
[syng-im.protocol.protocol-handler :refer [make-handler]]
|
[syng-im.protocol.protocol-handler :refer [make-handler]]
|
||||||
[syng-im.models.protocol :refer [update-identity
|
[syng-im.models.protocol :refer [update-identity
|
||||||
set-initialized]]
|
set-initialized]]
|
||||||
[syng-im.models.user-data :as user-data]
|
[syng-im.models.user-data :as user-data]
|
||||||
[syng-im.models.contacts :as contacts]
|
[syng-im.models.contacts :as contacts]
|
||||||
[syng-im.models.messages :refer [save-message
|
[syng-im.models.messages :refer [save-message
|
||||||
update-message!
|
update-message!
|
||||||
message-by-id]]
|
message-by-id]]
|
||||||
[syng-im.models.commands :as commands :refer [set-chat-command
|
[syng-im.models.commands :as commands :refer [set-chat-command
|
||||||
set-response-chat-command
|
set-response-chat-command
|
||||||
set-chat-command-content
|
set-chat-command-content
|
||||||
set-chat-command-request
|
set-chat-command-request
|
||||||
stage-command
|
stage-command
|
||||||
unstage-command
|
unstage-command
|
||||||
set-commands]]
|
set-commands]]
|
||||||
[syng-im.handlers.server :as server]
|
[syng-im.handlers.server :as server]
|
||||||
[syng-im.handlers.contacts :as contacts-service]
|
[syng-im.handlers.contacts :as contacts-service]
|
||||||
[syng-im.handlers.suggestions :refer [get-command
|
[syng-im.handlers.suggestions :refer [get-command
|
||||||
handle-command
|
handle-command
|
||||||
get-command-handler
|
get-command-handler
|
||||||
load-commands
|
load-commands
|
||||||
apply-staged-commands
|
apply-staged-commands
|
||||||
check-suggestion]]
|
check-suggestion]]
|
||||||
[syng-im.handlers.sign-up :as sign-up-service]
|
[syng-im.handlers.sign-up :as sign-up-service]
|
||||||
|
|
||||||
[syng-im.models.chats :refer [chat-exists?
|
[syng-im.models.chats :refer [chat-exists?
|
||||||
create-chat
|
create-chat
|
||||||
chat-add-participants
|
chat-add-participants
|
||||||
chat-remove-participants
|
chat-remove-participants
|
||||||
set-chat-active
|
set-chat-active
|
||||||
re-join-group-chat]]
|
re-join-group-chat]]
|
||||||
[syng-im.models.chat :refer [signal-chat-updated
|
[syng-im.models.chat :refer [signal-chat-updated
|
||||||
set-current-chat-id
|
set-current-chat-id
|
||||||
current-chat-id
|
current-chat-id
|
||||||
update-new-group-selection
|
update-new-group-selection
|
||||||
update-new-participants-selection
|
update-new-participants-selection
|
||||||
clear-new-group
|
clear-new-group
|
||||||
clear-new-participants
|
clear-new-participants
|
||||||
new-group-selection
|
new-group-selection
|
||||||
set-chat-input-text
|
set-chat-input-text
|
||||||
new-participants-selection]]
|
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
|
||||||
content-type-command]]
|
content-type-command]]
|
||||||
[syng-im.navigation :refer [nav-push
|
[syng-im.navigation :refer [nav-push
|
||||||
nav-replace
|
nav-replace
|
||||||
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]))
|
||||||
|
|
||||||
;; -- Middleware ------------------------------------------------------------
|
;; -- Middleware ------------------------------------------------------------
|
||||||
;;
|
;;
|
||||||
@ -115,9 +115,9 @@
|
|||||||
db))
|
db))
|
||||||
|
|
||||||
(register-handler :set-commands
|
(register-handler :set-commands
|
||||||
(fn [db [action commands]]
|
(fn [db [action commands]]
|
||||||
(log/debug action commands)
|
(log/debug action commands)
|
||||||
(set-commands db commands)))
|
(set-commands db commands)))
|
||||||
|
|
||||||
;; -- Protocol --------------------------------------------------------------
|
;; -- Protocol --------------------------------------------------------------
|
||||||
|
|
||||||
@ -156,7 +156,9 @@
|
|||||||
|
|
||||||
(defn participant-invited-to-group-msg [chat-id identity from msg-id]
|
(defn participant-invited-to-group-msg [chat-id identity from msg-id]
|
||||||
(let [inviter-name (:name (contacts/contact-by-identity from))
|
(let [inviter-name (:name (contacts/contact-by-identity from))
|
||||||
invitee-name (:name (contacts/contact-by-identity identity))]
|
invitee-name (if (= identity (api/my-identity))
|
||||||
|
"You"
|
||||||
|
(:name (contacts/contact-by-identity identity)))]
|
||||||
(save-message chat-id {:from "system"
|
(save-message chat-id {:from "system"
|
||||||
:msg-id msg-id
|
:msg-id msg-id
|
||||||
:content (str (or inviter-name from) " invited " (or invitee-name identity))
|
:content (str (or inviter-name from) " invited " (or invitee-name identity))
|
||||||
@ -220,8 +222,10 @@
|
|||||||
(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)
|
||||||
(participant-left-group-msg group-id from msg-id)
|
(if (= (api/my-identity) from)
|
||||||
(signal-chat-updated db group-id)))
|
db
|
||||||
|
(do (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]]
|
||||||
@ -247,26 +251,26 @@
|
|||||||
(defn send-staged-commands [db chat-id]
|
(defn send-staged-commands [db chat-id]
|
||||||
(let [staged-commands (get-in db (db/chat-staged-commands-path chat-id))]
|
(let [staged-commands (get-in db (db/chat-staged-commands-path chat-id))]
|
||||||
(dorun
|
(dorun
|
||||||
(map
|
(map
|
||||||
(fn [staged-command]
|
(fn [staged-command]
|
||||||
(let [command-key (get-in staged-command [:command :command])
|
(let [command-key (get-in staged-command [:command :command])
|
||||||
content (commands/format-command-msg-content command-key
|
content (commands/format-command-msg-content command-key
|
||||||
(:content staged-command))
|
(:content staged-command))
|
||||||
msg (if (= chat-id "console")
|
msg (if (= chat-id "console")
|
||||||
(sign-up-service/send-console-command db command-key content)
|
(sign-up-service/send-console-command db command-key content)
|
||||||
;; TODO handle command, now sends as plain message
|
;; TODO handle command, now sends as plain message
|
||||||
(let [{msg-id :msg-id
|
(let [{msg-id :msg-id
|
||||||
{from :from
|
{from :from
|
||||||
to :to} :msg} (api/send-user-msg {:to chat-id
|
to :to} :msg} (api/send-user-msg {:to chat-id
|
||||||
:content content})]
|
:content content})]
|
||||||
{:msg-id msg-id
|
{:msg-id msg-id
|
||||||
:from from
|
:from from
|
||||||
:to to
|
:to to
|
||||||
:content content
|
:content content
|
||||||
:content-type content-type-command
|
:content-type content-type-command
|
||||||
:outgoing true}))]
|
:outgoing true}))]
|
||||||
(save-message chat-id msg)))
|
(save-message chat-id msg)))
|
||||||
staged-commands))
|
staged-commands))
|
||||||
db))
|
db))
|
||||||
|
|
||||||
(register-handler :send-chat-msg
|
(register-handler :send-chat-msg
|
||||||
@ -278,7 +282,7 @@
|
|||||||
(let [msg (when (pos? (count text))
|
(let [msg (when (pos? (count text))
|
||||||
(if (= chat-id "console")
|
(if (= chat-id "console")
|
||||||
(sign-up-service/send-console-msg text)
|
(sign-up-service/send-console-msg text)
|
||||||
(let [{msg-id :msg-id
|
(let [{msg-id :msg-id
|
||||||
{from :from
|
{from :from
|
||||||
to :to} :msg} (api/send-user-msg {:to chat-id
|
to :to} :msg} (api/send-user-msg {:to chat-id
|
||||||
:content text})]
|
:content text})]
|
||||||
@ -307,7 +311,7 @@
|
|||||||
(register-handler :send-chat-command
|
(register-handler :send-chat-command
|
||||||
(fn [db [action chat-id command content]]
|
(fn [db [action chat-id command content]]
|
||||||
(log/debug action "chat-id" chat-id "command" command "content" content)
|
(log/debug action "chat-id" chat-id "command" command "content" content)
|
||||||
(let [db (set-chat-input-text db nil)
|
(let [db (set-chat-input-text db nil)
|
||||||
msg (if (= chat-id "console")
|
msg (if (= chat-id "console")
|
||||||
(sign-up-service/send-console-command db command content)
|
(sign-up-service/send-console-command db command content)
|
||||||
;; TODO handle command, now sends as plain message
|
;; TODO handle command, now sends as plain message
|
||||||
@ -407,7 +411,7 @@
|
|||||||
(register-handler :stage-command
|
(register-handler :stage-command
|
||||||
(fn [db [action chat-id command content]]
|
(fn [db [action chat-id command content]]
|
||||||
(log/debug action "chat-id" chat-id "command" command "content" content)
|
(log/debug action "chat-id" chat-id "command" command "content" content)
|
||||||
(let [db (set-chat-input-text db nil)
|
(let [db (set-chat-input-text db nil)
|
||||||
command-info {:command command
|
command-info {:command command
|
||||||
:content content
|
:content content
|
||||||
:handler (get-command-handler db (:command command) content)}]
|
:handler (get-command-handler db (:command command) content)}]
|
||||||
|
@ -140,7 +140,7 @@
|
|||||||
(-> (aget (aget (chats-list) 0) "contacts")
|
(-> (aget (aget (chats-list) 0) "contacts")
|
||||||
(r/cljs-list))
|
(r/cljs-list))
|
||||||
|
|
||||||
(r/delete (chats-list))
|
(r/write (fn [] (r/delete (chats-list))))
|
||||||
|
|
||||||
(swap! re-frame.db/app-db signal-chats-updated)
|
(swap! re-frame.db/app-db signal-chats-updated)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user