2016-05-19 18:31:56 +02:00
|
|
|
(ns status-im.chat.screen
|
|
|
|
(:require-macros [status-im.utils.views :refer [defview]])
|
2016-05-19 15:45:16 +03:00
|
|
|
(:require [re-frame.core :refer [subscribe dispatch]]
|
2016-05-20 16:18:12 +03:00
|
|
|
[clojure.string :as s]
|
2016-05-19 18:31:56 +02:00
|
|
|
[status-im.components.react :refer [view
|
2016-06-02 16:23:50 +03:00
|
|
|
animated-view
|
|
|
|
text
|
|
|
|
image
|
|
|
|
icon
|
|
|
|
touchable-highlight
|
|
|
|
list-view
|
|
|
|
list-item]]
|
2016-05-20 14:20:48 +03:00
|
|
|
[status-im.components.chat-icon.screen :refer [chat-icon-view-action
|
|
|
|
chat-icon-view-menu-item]]
|
2016-05-19 18:31:56 +02:00
|
|
|
[status-im.chat.styles.screen :as st]
|
|
|
|
[status-im.utils.listview :refer [to-datasource]]
|
2016-05-20 16:36:00 +03:00
|
|
|
[status-im.utils.utils :refer [truncate-str]]
|
2016-05-19 18:31:56 +02:00
|
|
|
[status-im.components.invertible-scroll-view :refer [invertible-scroll-view]]
|
|
|
|
[status-im.components.toolbar :refer [toolbar]]
|
|
|
|
[status-im.chat.views.message :refer [chat-message]]
|
2016-06-02 15:53:13 +03:00
|
|
|
[status-im.chat.views.content-suggestions :refer [content-suggestions-view]]
|
|
|
|
[status-im.chat.views.suggestions :refer [suggestions-view]]
|
2016-06-03 14:09:34 +03:00
|
|
|
[status-im.chat.views.response :refer [response-view]]
|
2016-05-25 04:27:03 +03:00
|
|
|
[status-im.chat.views.new-message :refer [chat-message-new]]
|
2016-06-03 22:34:24 +03:00
|
|
|
[status-im.i18n :refer [label label-pluralize]]
|
|
|
|
[status-im.components.animation :as anim]
|
|
|
|
[reagent.core :as r]))
|
2016-03-25 13:36:16 +03:00
|
|
|
|
|
|
|
|
2016-04-06 16:13:31 +03:00
|
|
|
(defn contacts-by-identity [contacts]
|
|
|
|
(->> contacts
|
|
|
|
(map (fn [{:keys [identity] :as contact}]
|
|
|
|
[identity contact]))
|
|
|
|
(into {})))
|
|
|
|
|
|
|
|
(defn add-msg-color [{:keys [from] :as msg} contact-by-identity]
|
2016-04-07 14:01:41 +03:00
|
|
|
(if (= "system" from)
|
2016-05-10 13:58:37 +03:00
|
|
|
(assoc msg :text-color :#4A5258
|
|
|
|
:background-color :#D3EEEF)
|
2016-04-07 14:01:41 +03:00
|
|
|
(let [{:keys [text-color background-color]} (get contact-by-identity from)]
|
|
|
|
(assoc msg :text-color text-color
|
|
|
|
:background-color background-color))))
|
2016-04-06 16:13:31 +03:00
|
|
|
|
2016-05-19 15:45:16 +03:00
|
|
|
(defview chat-icon []
|
|
|
|
[chat-id [:chat :chat-id]
|
|
|
|
group-chat [:chat :group-chat]
|
|
|
|
name [:chat :name]
|
|
|
|
color [:chat :color]]
|
|
|
|
;; TODO stub data ('online' property)
|
|
|
|
[chat-icon-view-action chat-id group-chat name color true])
|
2016-04-18 13:38:38 +03:00
|
|
|
|
2016-04-19 15:38:16 +03:00
|
|
|
(defn typing [member]
|
2016-05-07 16:39:03 +03:00
|
|
|
[view st/typing-view
|
|
|
|
[view st/typing-background
|
|
|
|
[text {:style st/typing-text}
|
2016-05-25 18:57:06 +03:00
|
|
|
(str member " " (label :t/is-typing))]]])
|
2016-04-19 15:38:16 +03:00
|
|
|
|
|
|
|
(defn typing-all []
|
2016-05-08 23:13:24 +03:00
|
|
|
[view st/typing-all
|
2016-05-20 14:38:20 +03:00
|
|
|
;; TODO stub data
|
2016-04-19 15:38:16 +03:00
|
|
|
(for [member ["Geoff" "Justas"]]
|
|
|
|
^{:key member} [typing member])])
|
|
|
|
|
2016-05-06 14:06:58 +03:00
|
|
|
(defn message-row [contact-by-identity group-chat]
|
2016-05-08 23:06:38 +03:00
|
|
|
(fn [row _ idx]
|
2016-05-06 14:06:58 +03:00
|
|
|
(let [msg (-> row
|
|
|
|
(add-msg-color contact-by-identity)
|
2016-05-08 23:06:38 +03:00
|
|
|
(assoc :group-chat group-chat)
|
|
|
|
(assoc :last-msg (zero? (js/parseInt idx))))]
|
2016-05-06 14:06:58 +03:00
|
|
|
(list-item [chat-message msg]))))
|
|
|
|
|
|
|
|
(defn on-action-selected [position]
|
|
|
|
(case position
|
2016-05-20 19:58:07 +03:00
|
|
|
0 (dispatch [:navigate-to :add-participants])
|
|
|
|
1 (dispatch [:navigate-to :remove-participants])
|
2016-05-12 12:56:47 +03:00
|
|
|
2 (dispatch [:leave-group-chat])))
|
2016-05-06 14:06:58 +03:00
|
|
|
|
|
|
|
(defn overlay [{:keys [on-click-outside]} items]
|
2016-05-07 16:39:03 +03:00
|
|
|
[view st/actions-overlay
|
|
|
|
[touchable-highlight {:on-press on-click-outside
|
|
|
|
:style st/overlay-highlight}
|
2016-05-06 14:06:58 +03:00
|
|
|
[view nil]]
|
|
|
|
items])
|
|
|
|
|
2016-05-11 14:37:31 +03:00
|
|
|
(defn action-view [{:keys [icon-style custom-icon handler title subtitle]
|
2016-05-07 16:39:03 +03:00
|
|
|
icon-name :icon}]
|
2016-05-03 16:39:08 +03:00
|
|
|
[touchable-highlight {:on-press (fn []
|
|
|
|
(dispatch [:set-show-actions false])
|
2016-05-11 14:37:31 +03:00
|
|
|
(when handler
|
|
|
|
(handler)))}
|
2016-05-07 16:39:03 +03:00
|
|
|
[view st/action-icon-row
|
|
|
|
[view st/action-icon-view
|
2016-05-11 14:37:31 +03:00
|
|
|
(or custom-icon
|
|
|
|
[icon icon-name icon-style])]
|
2016-05-08 23:13:24 +03:00
|
|
|
[view st/action-view
|
2016-05-07 16:39:03 +03:00
|
|
|
[text {:style st/action-title} title]
|
|
|
|
(when-let [subtitle subtitle]
|
|
|
|
[text {:style st/action-subtitle}
|
2016-05-02 16:56:42 +03:00
|
|
|
subtitle])]]])
|
|
|
|
|
2016-05-19 15:45:16 +03:00
|
|
|
(defview menu-item-icon-profile []
|
|
|
|
[chat-id [:chat :chat-id]
|
|
|
|
group-chat [:chat :group-chat]
|
|
|
|
name [:chat :name]
|
|
|
|
color [:chat :color]]
|
|
|
|
;; TODO stub data ('online' property)
|
|
|
|
[chat-icon-view-menu-item chat-id group-chat name color true])
|
2016-05-11 14:37:31 +03:00
|
|
|
|
2016-05-20 16:18:12 +03:00
|
|
|
(defn members-text [members]
|
2016-05-25 18:57:06 +03:00
|
|
|
(truncate-str (str (s/join ", " (map #(:name %) members)) " " (label :t/and-you)) 35))
|
2016-05-20 16:18:12 +03:00
|
|
|
|
2016-05-06 14:06:58 +03:00
|
|
|
(defn actions-list-view []
|
2016-05-09 17:33:41 +03:00
|
|
|
(let [{:keys [group-chat chat-id]}
|
2016-05-20 16:18:12 +03:00
|
|
|
(subscribe [:chat-properties [:group-chat :chat-id]])
|
|
|
|
members (subscribe [:current-chat-contacts])]
|
2016-05-09 17:33:41 +03:00
|
|
|
(when-let [actions (if @group-chat
|
2016-05-25 18:57:06 +03:00
|
|
|
[{:title (label :t/members-title)
|
2016-05-20 16:18:12 +03:00
|
|
|
:subtitle (members-text @members)
|
2016-05-07 16:39:03 +03:00
|
|
|
:icon :menu_group
|
2016-05-06 14:06:58 +03:00
|
|
|
:icon-style {:width 25
|
|
|
|
:height 19}
|
2016-05-20 15:37:24 +03:00
|
|
|
;; TODO not implemented: action Members
|
|
|
|
:handler nil}
|
2016-05-25 18:57:06 +03:00
|
|
|
{:title (label :t/search-chat)
|
|
|
|
:subtitle (label :t/not-implemented)
|
2016-05-07 16:39:03 +03:00
|
|
|
:icon :search_gray_copy
|
2016-05-06 14:06:58 +03:00
|
|
|
:icon-style {:width 17
|
|
|
|
:height 17}
|
2016-05-20 15:37:24 +03:00
|
|
|
;; TODO not implemented: action Search chat
|
|
|
|
:handler nil}
|
2016-05-25 18:57:06 +03:00
|
|
|
{:title (label :t/notifications-title)
|
|
|
|
:subtitle (label :t/not-implemented)
|
2016-05-20 15:37:24 +03:00
|
|
|
;;:subtitle "Chat muted"
|
2016-05-07 16:39:03 +03:00
|
|
|
:icon :muted
|
2016-05-06 14:06:58 +03:00
|
|
|
:icon-style {:width 18
|
|
|
|
:height 21}
|
2016-05-20 15:37:24 +03:00
|
|
|
;; TODO not implemented: action Notifications
|
|
|
|
:handler nil}
|
2016-05-25 18:57:06 +03:00
|
|
|
{:title (label :t/settings)
|
2016-05-07 16:39:03 +03:00
|
|
|
:icon :settings
|
2016-05-06 14:06:58 +03:00
|
|
|
:icon-style {:width 20
|
|
|
|
:height 13}
|
2016-05-12 12:13:09 +03:00
|
|
|
:handler #(dispatch [:show-group-settings])}]
|
2016-05-25 18:57:06 +03:00
|
|
|
[{:title (label :t/profile)
|
2016-05-11 14:37:31 +03:00
|
|
|
:custom-icon [menu-item-icon-profile]
|
2016-05-10 10:59:38 +03:00
|
|
|
:icon :menu_group
|
2016-05-09 17:33:41 +03:00
|
|
|
:icon-style {:width 25
|
|
|
|
:height 19}
|
2016-05-11 14:37:31 +03:00
|
|
|
:handler #(dispatch [:show-profile @chat-id])}
|
2016-05-25 18:57:06 +03:00
|
|
|
{:title (label :t/search-chat)
|
|
|
|
:subtitle (label :t/not-implemented)
|
2016-05-11 14:37:31 +03:00
|
|
|
:icon :search_gray_copy
|
|
|
|
:icon-style {:width 17
|
|
|
|
:height 17}
|
2016-05-20 15:37:24 +03:00
|
|
|
;; TODO not implemented: action Search chat
|
2016-05-12 12:13:09 +03:00
|
|
|
:handler nil}
|
2016-05-25 18:57:06 +03:00
|
|
|
{:title (label :t/notifications-title)
|
|
|
|
:subtitle (label :t/not-implemented)
|
2016-05-20 15:37:24 +03:00
|
|
|
;;:subtitle "Notifications on"
|
2016-05-11 14:37:31 +03:00
|
|
|
:icon :muted
|
|
|
|
:icon-style {:width 18
|
|
|
|
:height 21}
|
2016-05-20 15:37:24 +03:00
|
|
|
;; TODO not implemented: action Notifications
|
2016-05-12 12:13:09 +03:00
|
|
|
:handler nil}
|
2016-05-25 18:57:06 +03:00
|
|
|
{:title (label :t/settings)
|
|
|
|
:subtitle (label :t/not-implemented)
|
2016-05-11 14:37:31 +03:00
|
|
|
:icon :settings
|
|
|
|
:icon-style {:width 20
|
|
|
|
:height 13}
|
2016-05-20 15:37:24 +03:00
|
|
|
;; TODO not implemented: action Settings
|
|
|
|
:handler nil}])]
|
2016-05-07 16:39:03 +03:00
|
|
|
[view st/actions-wrapper
|
|
|
|
[view st/actions-separator]
|
2016-05-08 23:13:24 +03:00
|
|
|
[view st/actions-view
|
2016-05-06 14:06:58 +03:00
|
|
|
(for [action actions]
|
|
|
|
^{:key action} [action-view action])]])))
|
2016-05-02 16:56:42 +03:00
|
|
|
|
2016-05-06 14:06:58 +03:00
|
|
|
(defn actions-view []
|
|
|
|
[overlay {:on-click-outside #(dispatch [:set-show-actions false])}
|
|
|
|
[actions-list-view]])
|
2016-05-03 16:39:08 +03:00
|
|
|
|
2016-05-11 13:53:38 +03:00
|
|
|
(defn toolbar-content []
|
2016-05-06 14:06:58 +03:00
|
|
|
(let [{:keys [group-chat name contacts]}
|
|
|
|
(subscribe [:chat-properties [:group-chat :name :contacts]])
|
|
|
|
show-actions (subscribe [:show-actions])]
|
|
|
|
(fn []
|
2016-05-11 13:53:38 +03:00
|
|
|
[view (st/chat-name-view @show-actions)
|
|
|
|
[text {:style st/chat-name-text}
|
2016-05-25 18:57:06 +03:00
|
|
|
(truncate-str (or @name (label :t/chat-name)) 30)]
|
2016-05-11 13:53:38 +03:00
|
|
|
(if @group-chat
|
|
|
|
[view {:flexDirection :row}
|
|
|
|
[icon :group st/group-icon]
|
|
|
|
[text {:style st/members}
|
2016-05-20 14:38:20 +03:00
|
|
|
(let [cnt (inc (count @contacts))]
|
2016-06-01 14:44:04 +03:00
|
|
|
(label-pluralize cnt :t/members))]]
|
2016-05-20 15:37:24 +03:00
|
|
|
;; TODO stub data: last activity
|
2016-05-25 18:57:06 +03:00
|
|
|
[text {:style st/last-activity} (label :t/last-active)])])))
|
2016-05-11 13:53:38 +03:00
|
|
|
|
|
|
|
(defn toolbar-action []
|
|
|
|
(let [show-actions (subscribe [:show-actions])]
|
|
|
|
(fn []
|
|
|
|
(if @show-actions
|
|
|
|
[touchable-highlight
|
|
|
|
{:on-press #(dispatch [:set-show-actions false])}
|
2016-05-19 15:45:16 +03:00
|
|
|
[view st/action
|
2016-05-11 13:53:38 +03:00
|
|
|
[icon :up st/up-icon]]]
|
|
|
|
[touchable-highlight
|
|
|
|
{:on-press #(dispatch [:set-show-actions true])}
|
2016-05-19 15:45:16 +03:00
|
|
|
[view st/action
|
|
|
|
[chat-icon]]]))))
|
2016-05-11 13:53:38 +03:00
|
|
|
|
|
|
|
(defn chat-toolbar []
|
|
|
|
(let [{:keys [group-chat name contacts]}
|
|
|
|
(subscribe [:chat-properties [:group-chat :name :contacts]])
|
|
|
|
show-actions (subscribe [:show-actions])]
|
|
|
|
(fn []
|
|
|
|
[toolbar {:hide-nav? @show-actions
|
|
|
|
:custom-content [toolbar-content]
|
|
|
|
:custom-action [toolbar-action]}])))
|
2016-05-03 16:39:08 +03:00
|
|
|
|
2016-05-16 10:45:59 +03:00
|
|
|
(defview messages-view [group-chat]
|
2016-06-03 22:34:24 +03:00
|
|
|
[messages [:chat :messages]
|
|
|
|
contacts [:chat :contacts]]
|
|
|
|
(let [contacts' (contacts-by-identity contacts)]
|
|
|
|
[list-view {:renderRow (message-row contacts' group-chat)
|
|
|
|
:renderScrollComponent #(invertible-scroll-view (js->clj %))
|
|
|
|
:onEndReached #(dispatch [:load-more-messages])
|
|
|
|
:enableEmptySections true
|
|
|
|
:keyboardShouldPersistTaps true
|
|
|
|
:dataSource (to-datasource messages)}]))
|
|
|
|
|
|
|
|
(defn messages-container-animation-logic [{:keys [to-value val]}]
|
|
|
|
(fn [_]
|
|
|
|
(let [to-value @to-value]
|
|
|
|
(anim/start (anim/spring val {:toValue to-value})
|
|
|
|
(fn [arg]
|
|
|
|
(when (.-finished arg)
|
|
|
|
(dispatch [:set-in [:animations ::messages-offset-current] to-value])))))))
|
|
|
|
|
|
|
|
(defn messages-container [messages]
|
|
|
|
(let [to-messages-offset (subscribe [:get-in [:animations :messages-offset]])
|
|
|
|
cur-messages-offset (subscribe [:get-in [:animations ::messages-offset-current]])
|
|
|
|
messages-offset (anim/create-value (or @cur-messages-offset 0))
|
|
|
|
context {:to-value to-messages-offset
|
|
|
|
:val messages-offset}
|
|
|
|
on-update (messages-container-animation-logic context)]
|
|
|
|
(r/create-class
|
|
|
|
{:component-did-mount
|
|
|
|
on-update
|
|
|
|
:component-did-update
|
|
|
|
on-update
|
|
|
|
:reagent-render
|
|
|
|
(fn [messages]
|
|
|
|
@to-messages-offset
|
|
|
|
[animated-view {:style (st/messages-container messages-offset)}
|
|
|
|
messages])})))
|
2016-04-19 15:38:16 +03:00
|
|
|
|
2016-05-16 10:45:59 +03:00
|
|
|
(defview chat []
|
2016-05-17 13:26:20 +03:00
|
|
|
[group-chat [:chat :group-chat]
|
2016-06-02 15:53:13 +03:00
|
|
|
show-actions-atom [:show-actions]
|
|
|
|
command [:get-chat-command]
|
|
|
|
to-msg-id [:get-chat-command-to-msg-id]]
|
2016-05-16 10:45:59 +03:00
|
|
|
[view st/chat-view
|
2016-05-16 12:31:08 +03:00
|
|
|
[chat-toolbar]
|
2016-06-03 22:34:24 +03:00
|
|
|
[messages-container
|
|
|
|
[messages-view group-chat]]
|
2016-05-16 10:45:59 +03:00
|
|
|
(when group-chat [typing-all])
|
2016-06-02 15:53:13 +03:00
|
|
|
(cond
|
2016-06-03 14:09:34 +03:00
|
|
|
(and command to-msg-id) [response-view]
|
2016-06-02 15:53:13 +03:00
|
|
|
command [content-suggestions-view]
|
|
|
|
:else [suggestions-view])
|
2016-05-17 13:26:20 +03:00
|
|
|
[chat-message-new]
|
2016-05-16 10:45:59 +03:00
|
|
|
(when show-actions-atom [actions-view])])
|