This commit is contained in:
Alexander Pantyuhov 2017-10-13 13:13:36 +02:00 committed by Roman Volosovskyi
parent cb72190a18
commit fef984d0b6
8 changed files with 57 additions and 72 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "StatusIm", "name": "StatusIm",
"interface": "reagent", "interface": "reagent",
"androidHost": "localhost", "androidHost": "10.0.3.2",
"modules": [ "modules": [
"react-native-contacts", "react-native-contacts",
"react-native-invertible-scroll-view", "react-native-invertible-scroll-view",

View File

@ -15,7 +15,7 @@
(re-frame.core/dispatch [:load-commands!])) (re-frame.core/dispatch [:load-commands!]))
(figwheel/watch-and-reload (figwheel/watch-and-reload
:websocket-url "ws://localhost:3449/figwheel-ws" :websocket-url "ws://10.0.3.2:3449/figwheel-ws"
:heads-up-display false :heads-up-display false
:jsload-callback callback) :jsload-callback callback)

View File

@ -12,8 +12,8 @@
(def root-el (r/as-element [reloader])) (def root-el (r/as-element [reloader]))
(figwheel/watch-and-reload (figwheel/watch-and-reload
:websocket-url "ws://localhost:3449/figwheel-ws" :websocket-url "ws://10.0.1.15:3449/figwheel-ws"
:heads-up-display false :heads-up-display false
:jsload-callback #(swap! cnt inc)) :jsload-callback #(swap! cnt inc))
(rr/enable-re-frisk-remote! {:host "10.0.1.15:4567" :on-init core/init :pre-send (fn [db] (update db :chats #(into {} %)))}) (rr/enable-re-frisk-remote! {:host "localhost:4567" :on-init core/init :pre-send (fn [db] (update db :chats #(into {} %)))})

View File

@ -79,43 +79,36 @@
account (get accounts current-account-id) account (get accounts current-account-id)
commands (-> (into [] global-commands) commands (-> (into [] global-commands)
(into commands)) (into commands))
{chat-contacts :contacts} (get chats chat-id)] {chat-contacts :contacts
group-chat :group-chat} (get chats chat-id)]
(remove (fn [{:keys [scope]}] (remove (fn [{:keys [scope]}]
(or (or
(and (:registered-only? scope) (and (:registered-only? scope)
(not (:address account))) (not (:address account)))
(and (not (:personal-chats? scope)) (and (not (:personal-chats? scope))
(= (count chat-contacts) 1)) (not group-chat))
(and (not (:group-chats? scope)) (and (not (:group-chats? scope))
(> (count chat-contacts) 1)) group-chat)
(and (not (:can-use-for-dapps? scope)) (and (not (:can-use-for-dapps? scope))
(every? (fn [{:keys [identity]}] (every? (fn [{:keys [identity]}]
(get-in contacts [identity :dapp?])) (get-in contacts [identity :dapp?]))
chat-contacts)))) chat-contacts))))
commands))) commands)))
(defn set-command-for-content (defn- commands-list->map [commands]
"Sets the information about command for a specified message content. (->> commands
We need to use this command because `command` field in persistent storage (db) doesn't (map #(vector (:name %) %))
contain all information about command — we save only the name of it." (into {})))
[commands global-commands content]
(if (map? content)
(let [{:keys [command bot]} content]
(if (and bot (not (bots-constants/mailman-bot? bot)))
(update content :command #((keyword bot) global-commands))
(update content :command #((keyword command) commands))))
content))
(defn set-command-for-request (defn replace-name-with-request
"Sets the information about command for a specified request." "Sets the information about command for a specified request."
[{:keys [message-id content] :as message} possible-requests possible-commands] ([{:keys [content] :as message} commands requests]
(let [requests (->> possible-requests (if (map? content)
(map (fn [{:keys [request] :as message}] (let [{:keys [command content-command]} content
[(:message-id request) message])) commands (commands-list->map commands)
(into {})) requests (commands-list->map requests)]
commands (->> possible-commands (assoc content :command (or (get requests (or content-command command))
(map (fn [{:keys [name] :as message}] (get commands command))))
[name message])) content))
(into {}))] ([message commands]
(assoc content :command (or (get requests message-id) (replace-name-with-request message commands [])))
(get commands (get content :command))))))

View File

@ -120,7 +120,7 @@
:android {:font-size 13} :android {:font-size 13}
:ios {:font-size 14}}) :ios {:font-size 14}})
(def comand-request-view (def command-request-view
{:paddingRight 16}) {:paddingRight 16})
(def command-request-message-view (def command-request-message-view

View File

@ -3,6 +3,7 @@
[status-im.data-store.chats :as chats] [status-im.data-store.chats :as chats]
[status-im.chat.constants :as const] [status-im.chat.constants :as const]
[status-im.chat.models.input :as input-model] [status-im.chat.models.input :as input-model]
[status-im.chat.models.commands :as commands-model]
[status-im.chat.utils :as chat-utils] [status-im.chat.utils :as chat-utils]
[status-im.chat.views.input.utils :as input-utils] [status-im.chat.views.input.utils :as input-utils]
[status-im.constants :refer [response-suggesstion-resize-duration [status-im.constants :refer [response-suggesstion-resize-duration
@ -62,15 +63,9 @@
(fn [_ [_ chat-id]] (fn [_ [_ chat-id]]
(chats/get-by-id chat-id))) (chats/get-by-id chat-id)))
(reg-sub :get-commands-and-responses (reg-sub :get-commands-for-chat
(fn [{:keys [chats global-commands] :contacts/keys [contacts]} [_ chat-id]] (fn [db [_ chat-id]]
(->> (get-in chats [chat-id :contacts]) (commands-model/commands-for-chat db chat-id)))
(filter :is-in-chat)
(mapv (fn [{:keys [identity]}]
(let [{:keys [commands responses]} (get contacts identity)]
(merge responses commands))))
(apply merge)
(merge global-commands))))
(reg-sub (reg-sub
:selected-chat-command :selected-chat-command

View File

@ -126,34 +126,31 @@
(defview message-content-command (defview message-content-command
[{:keys [message-id content content-type chat-id to from outgoing] :as message}] [{:keys [message-id content content-type chat-id to from outgoing] :as message}]
[commands [:get-commands-and-responses chat-id] (letsubs [commands [:get-commands-for-chat chat-id]
from-commands [:get-commands-and-responses from] current-chat-id [:get-current-chat-id]
global-commands [:get :global-commands] contact-chat [:get-in [:chats (if outgoing to from)]]
current-chat-id [:get-current-chat-id] preview [:get-message-preview message-id]]
contact-chat [:get-in [:chats (if outgoing to from)]] (let [{:keys [command params]} (commands/replace-name-with-request message commands)
preview [:get-message-preview message-id]] {:keys [name type]
(let [commands (merge commands from-commands) icon-path :icon} command]
{:keys [command params]} (commands/set-command-for-content commands global-commands content) [view st/content-command-view
{:keys [name type] (when (:color command)
icon-path :icon} command] [view st/command-container
[view st/content-command-view [view (pill-st/pill command)
(when (:color command) [text {:style pill-st/pill-text
[view st/command-container :font :default}
[view (pill-st/pill command) (str (if (= :command type) chat-consts/command-char "?") name)]]])
[text {:style pill-st/pill-text (when icon-path
:font :default} [view st/command-image-view
(str (if (= :command type) chat-consts/command-char "?") name)]]]) [icon icon-path st/command-image]])
(when icon-path [command-preview {:command (:name command)
[view st/command-image-view :content-type content-type
[icon icon-path st/command-image]]) :params params
[command-preview {:command (:name command) :outgoing? outgoing
:content-type content-type :preview preview
:params params :contact-chat contact-chat
:outgoing? outgoing :contact-address (if outgoing to from)
:preview preview :current-chat-id current-chat-id}]])))
:contact-chat contact-chat
:contact-address (if outgoing to from)
:current-chat-id current-chat-id}]]))
(defn message-view (defn message-view
[{:keys [same-author index group-chat] :as message} content] [{:keys [same-author index group-chat] :as message} content]

View File

@ -73,15 +73,15 @@
(defview message-content-command-request (defview message-content-command-request
[{:keys [message-id chat-id]}] [{:keys [message-id chat-id]}]
(letsubs [requests [:chat-actions :possible-requests] (letsubs [commands [:get-commands-for-chat chat-id]
commands [:chat-actions :possible-commands] requests [:chat-actions :possible-requests]
answered? [:is-request-answered? message-id] answered? [:is-request-answered? message-id]
status-initialized? [:get :status-module-initialized?] status-initialized? [:get :status-module-initialized?]
markup [:get-message-preview message-id]] markup [:get-message-preview message-id]]
(fn [{:keys [message-id content from incoming-group] :as message}] (fn [{:keys [message-id content from incoming-group] :as message}]
(let [{:keys [prefill prefill-bot-db prefillBotDb params] (let [{:keys [prefill prefill-bot-db prefillBotDb params]
text-content :text} content text-content :text} content
{:keys [command content]} (commands/set-command-for-request message requests commands) {:keys [command content]} (commands/replace-name-with-request message commands requests)
command (if (and params command) command (if (and params command)
(merge command {:prefill prefill (merge command {:prefill prefill
:prefill-bot-db (or prefill-bot-db prefillBotDb)}) :prefill-bot-db (or prefill-bot-db prefillBotDb)})
@ -90,7 +90,7 @@
#(dispatch [:execute-command-immediately command]) #(dispatch [:execute-command-immediately command])
(when (and (not answered?) status-initialized?) (when (and (not answered?) status-initialized?)
#(set-chat-command message-id command)))] #(set-chat-command message-id command)))]
[view st/comand-request-view [view st/command-request-view
[touchable-highlight [touchable-highlight
{:on-press on-press-handler} {:on-press on-press-handler}
[view st/command-request-message-view [view st/command-request-message-view