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",
"interface": "reagent",
"androidHost": "localhost",
"androidHost": "10.0.3.2",
"modules": [
"react-native-contacts",
"react-native-invertible-scroll-view",

View File

@ -15,7 +15,7 @@
(re-frame.core/dispatch [:load-commands!]))
(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
:jsload-callback callback)

View File

@ -12,8 +12,8 @@
(def root-el (r/as-element [reloader]))
(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
: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)
commands (-> (into [] global-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]}]
(or
(and (:registered-only? scope)
(not (:address account)))
(and (not (:personal-chats? scope))
(= (count chat-contacts) 1))
(not group-chat))
(and (not (:group-chats? scope))
(> (count chat-contacts) 1))
group-chat)
(and (not (:can-use-for-dapps? scope))
(every? (fn [{:keys [identity]}]
(get-in contacts [identity :dapp?]))
chat-contacts))))
commands)))
(defn set-command-for-content
"Sets the information about command for a specified message content.
We need to use this command because `command` field in persistent storage (db) doesn't
contain all information about command — we save only the name of it."
[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- commands-list->map [commands]
(->> commands
(map #(vector (:name %) %))
(into {})))
(defn set-command-for-request
(defn replace-name-with-request
"Sets the information about command for a specified request."
[{:keys [message-id content] :as message} possible-requests possible-commands]
(let [requests (->> possible-requests
(map (fn [{:keys [request] :as message}]
[(:message-id request) message]))
(into {}))
commands (->> possible-commands
(map (fn [{:keys [name] :as message}]
[name message]))
(into {}))]
(assoc content :command (or (get requests message-id)
(get commands (get content :command))))))
([{:keys [content] :as message} commands requests]
(if (map? content)
(let [{:keys [command content-command]} content
commands (commands-list->map commands)
requests (commands-list->map requests)]
(assoc content :command (or (get requests (or content-command command))
(get commands command))))
content))
([message commands]
(replace-name-with-request message commands [])))

View File

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

View File

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

View File

@ -126,14 +126,11 @@
(defview message-content-command
[{:keys [message-id content content-type chat-id to from outgoing] :as message}]
[commands [:get-commands-and-responses chat-id]
from-commands [:get-commands-and-responses from]
global-commands [:get :global-commands]
(letsubs [commands [:get-commands-for-chat chat-id]
current-chat-id [:get-current-chat-id]
contact-chat [:get-in [:chats (if outgoing to from)]]
preview [:get-message-preview message-id]]
(let [commands (merge commands from-commands)
{:keys [command params]} (commands/set-command-for-content commands global-commands content)
(let [{:keys [command params]} (commands/replace-name-with-request message commands)
{:keys [name type]
icon-path :icon} command]
[view st/content-command-view
@ -153,7 +150,7 @@
:preview preview
:contact-chat contact-chat
:contact-address (if outgoing to from)
:current-chat-id current-chat-id}]]))
:current-chat-id current-chat-id}]])))
(defn message-view
[{:keys [same-author index group-chat] :as message} content]

View File

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