parent
b8f3f2899c
commit
f57711aec1
|
@ -22,8 +22,6 @@
|
||||||
[status-im.chat.handlers.animation :refer [update-response-height
|
[status-im.chat.handlers.animation :refer [update-response-height
|
||||||
get-response-height]]))
|
get-response-height]]))
|
||||||
|
|
||||||
(def delta 1)
|
|
||||||
|
|
||||||
(register-handler :set-show-actions
|
(register-handler :set-show-actions
|
||||||
(fn [db [_ show-actions]]
|
(fn [db [_ show-actions]]
|
||||||
(assoc db :show-actions show-actions)))
|
(assoc db :show-actions show-actions)))
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
[status-im.components.chat-icon.screen :refer [chat-icon-view-action
|
[status-im.components.chat-icon.screen :refer [chat-icon-view-action
|
||||||
chat-icon-view-menu-item]]
|
chat-icon-view-menu-item]]
|
||||||
[status-im.chat.styles.screen :as st]
|
[status-im.chat.styles.screen :as st]
|
||||||
[status-im.utils.listview :refer [to-datasource]]
|
[status-im.utils.listview :refer [to-datasource-inverted]]
|
||||||
[status-im.utils.utils :refer [truncate-str]]
|
[status-im.utils.utils :refer [truncate-str]]
|
||||||
[status-im.components.invertible-scroll-view :refer [invertible-scroll-view]]
|
[status-im.components.invertible-scroll-view :refer [invertible-scroll-view]]
|
||||||
[status-im.components.toolbar :refer [toolbar]]
|
[status-im.components.toolbar :refer [toolbar]]
|
||||||
|
@ -61,12 +61,12 @@
|
||||||
(for [member ["Geoff" "Justas"]]
|
(for [member ["Geoff" "Justas"]]
|
||||||
^{:key member} [typing member])])
|
^{:key member} [typing member])])
|
||||||
|
|
||||||
(defn message-row [contact-by-identity group-chat]
|
(defn message-row [contact-by-identity group-chat messages-count]
|
||||||
(fn [row _ idx]
|
(fn [row _ idx]
|
||||||
(let [msg (-> row
|
(let [msg (-> row
|
||||||
(add-msg-color contact-by-identity)
|
(add-msg-color contact-by-identity)
|
||||||
(assoc :group-chat group-chat)
|
(assoc :group-chat group-chat)
|
||||||
(assoc :last-msg (zero? (js/parseInt idx))))]
|
(assoc :last-msg (= (js/parseInt idx) (dec messages-count))))]
|
||||||
(list-item [chat-message msg]))))
|
(list-item [chat-message msg]))))
|
||||||
|
|
||||||
(defn on-action-selected [position]
|
(defn on-action-selected [position]
|
||||||
|
@ -222,12 +222,12 @@
|
||||||
[messages [:chat :messages]
|
[messages [:chat :messages]
|
||||||
contacts [:chat :contacts]]
|
contacts [:chat :contacts]]
|
||||||
(let [contacts' (contacts-by-identity contacts)]
|
(let [contacts' (contacts-by-identity contacts)]
|
||||||
[list-view {:renderRow (message-row contacts' group-chat)
|
[list-view {:renderRow (message-row contacts' group-chat (count messages))
|
||||||
:renderScrollComponent #(invertible-scroll-view (js->clj %))
|
:renderScrollComponent #(invertible-scroll-view (js->clj %))
|
||||||
:onEndReached #(dispatch [:load-more-messages])
|
:onEndReached #(dispatch [:load-more-messages])
|
||||||
:enableEmptySections true
|
:enableEmptySections true
|
||||||
:keyboardShouldPersistTaps true
|
:keyboardShouldPersistTaps true
|
||||||
:dataSource (to-datasource messages)}]))
|
:dataSource (to-datasource-inverted messages)}]))
|
||||||
|
|
||||||
(defn messages-container-animation-logic [{:keys [to-value val]}]
|
(defn messages-container-animation-logic [{:keys [to-value val]}]
|
||||||
(fn [_]
|
(fn [_]
|
||||||
|
|
|
@ -316,6 +316,9 @@
|
||||||
(def message-date-text
|
(def message-date-text
|
||||||
(assoc style-sub-text :textAlign :center))
|
(assoc style-sub-text :textAlign :center))
|
||||||
|
|
||||||
|
(defn message-container [height]
|
||||||
|
{:height height})
|
||||||
|
|
||||||
(def new-message-container
|
(def new-message-container
|
||||||
{:backgroundColor color-white
|
{:backgroundColor color-white
|
||||||
:elevation 4})
|
:elevation 4})
|
||||||
|
|
|
@ -1,24 +1,28 @@
|
||||||
(ns status-im.chat.views.message
|
(ns status-im.chat.views.message
|
||||||
(:require [clojure.string :as s]
|
(:require [clojure.string :as s]
|
||||||
[re-frame.core :refer [subscribe dispatch]]
|
[re-frame.core :refer [subscribe dispatch]]
|
||||||
|
[reagent.core :as r]
|
||||||
[status-im.components.react :refer [view
|
[status-im.components.react :refer [view
|
||||||
|
animated-view
|
||||||
text
|
text
|
||||||
image
|
image
|
||||||
touchable-highlight]]
|
touchable-highlight]]
|
||||||
|
[status-im.components.animation :as anim]
|
||||||
[status-im.chat.views.request-message :refer [message-content-command-request]]
|
[status-im.chat.views.request-message :refer [message-content-command-request]]
|
||||||
[status-im.chat.styles.message :as st]
|
[status-im.chat.styles.message :as st]
|
||||||
[status-im.models.commands :refer [parse-command-msg-content
|
[status-im.models.commands :refer [parse-command-msg-content
|
||||||
parse-command-request]]
|
parse-command-request]]
|
||||||
[status-im.resources :as res]
|
[status-im.resources :as res]
|
||||||
|
[status-im.utils.datetime :as time]
|
||||||
[status-im.constants :refer [text-content-type
|
[status-im.constants :refer [text-content-type
|
||||||
content-type-status
|
content-type-status
|
||||||
content-type-command
|
content-type-command
|
||||||
content-type-command-request]]))
|
content-type-command-request]]))
|
||||||
|
|
||||||
(defn message-date [{:keys [date]}]
|
(defn message-date [timestamp]
|
||||||
[view {}
|
[view {}
|
||||||
[view st/message-date-container
|
[view st/message-date-container
|
||||||
[text {:style st/message-date-text} date]]])
|
[text {:style st/message-date-text} (time/to-short-str timestamp)]]])
|
||||||
|
|
||||||
(defn contact-photo [{:keys [photo-path]}]
|
(defn contact-photo [{:keys [photo-path]}]
|
||||||
[view st/contact-photo-container
|
[view st/contact-photo-container
|
||||||
|
@ -156,12 +160,47 @@
|
||||||
(when (and outgoing delivery-status)
|
(when (and outgoing delivery-status)
|
||||||
[message-delivery-status {:delivery-status delivery-status}])]))
|
[message-delivery-status {:delivery-status delivery-status}])]))
|
||||||
|
|
||||||
|
(defn message-container-animation-logic [{:keys [to-value val]}]
|
||||||
|
(fn [_]
|
||||||
|
(let [to-value @to-value]
|
||||||
|
(when (< 0 to-value)
|
||||||
|
(anim/start
|
||||||
|
(anim/spring val {:toValue to-value
|
||||||
|
:friction 4
|
||||||
|
:tension 10})
|
||||||
|
(fn [arg]
|
||||||
|
(when (.-finished arg)
|
||||||
|
;; todo ???
|
||||||
|
nil)))))))
|
||||||
|
|
||||||
|
(defn message-container [& children]
|
||||||
|
(let [layout-height (r/atom 0)
|
||||||
|
anim-value (anim/create-value 1)
|
||||||
|
context {:to-value layout-height
|
||||||
|
:val anim-value}
|
||||||
|
on-update (message-container-animation-logic context)]
|
||||||
|
(r/create-class
|
||||||
|
{:component-did-mount
|
||||||
|
on-update
|
||||||
|
:component-did-update
|
||||||
|
on-update
|
||||||
|
:reagent-render
|
||||||
|
(fn [& children]
|
||||||
|
@layout-height
|
||||||
|
[animated-view {:style (st/message-container anim-value)}
|
||||||
|
(into [view {:onLayout (fn [event]
|
||||||
|
(let [height (.. event -nativeEvent -layout -height)]
|
||||||
|
(reset! layout-height height)))}]
|
||||||
|
children)])})))
|
||||||
|
|
||||||
(defn chat-message
|
(defn chat-message
|
||||||
[{:keys [outgoing delivery-status date new-day group-chat]
|
[{:keys [outgoing delivery-status timestamp new-day group-chat]
|
||||||
:as message}]
|
:as message}]
|
||||||
[view {}
|
[message-container
|
||||||
(when new-day [message-date {:date date}])
|
;; TODO there is no new-day info in message
|
||||||
[view {}
|
(when new-day
|
||||||
|
[message-date timestamp])
|
||||||
|
[view
|
||||||
(let [incoming-group (and group-chat (not outgoing))]
|
(let [incoming-group (and group-chat (not outgoing))]
|
||||||
[message-content
|
[message-content
|
||||||
(if incoming-group
|
(if incoming-group
|
||||||
|
|
|
@ -48,9 +48,10 @@
|
||||||
|
|
||||||
(defn get-messages [chat-id]
|
(defn get-messages [chat-id]
|
||||||
(->> (-> (r/get-by-field :msgs :chat-id chat-id)
|
(->> (-> (r/get-by-field :msgs :chat-id chat-id)
|
||||||
(r/sorted :timestamp :asc)
|
(r/sorted :timestamp :desc)
|
||||||
(r/collection->map))
|
(r/collection->map))
|
||||||
(into '())
|
(into '())
|
||||||
|
reverse
|
||||||
(map (fn [{:keys [content-type] :as message}]
|
(map (fn [{:keys [content-type] :as message}]
|
||||||
(if (command-type? content-type)
|
(if (command-type? content-type)
|
||||||
(update message :content str-to-map)
|
(update message :content str-to-map)
|
||||||
|
|
|
@ -7,3 +7,12 @@
|
||||||
|
|
||||||
(defn to-datasource [items]
|
(defn to-datasource [items]
|
||||||
(clone-with-rows (data-source {:rowHasChanged not=}) items))
|
(clone-with-rows (data-source {:rowHasChanged not=}) items))
|
||||||
|
|
||||||
|
(defn clone-with-rows-inverted [ds rows]
|
||||||
|
(let [rows (reduce (fn [ac el] (.push ac el) ac)
|
||||||
|
(clj->js []) (reverse rows))
|
||||||
|
row-ids (.reverse (.map rows (fn [_ index] index)))]
|
||||||
|
(.cloneWithRows ds rows row-ids)))
|
||||||
|
|
||||||
|
(defn to-datasource-inverted [items]
|
||||||
|
(clone-with-rows-inverted (data-source {:rowHasChanged not=}) items))
|
||||||
|
|
Loading…
Reference in New Issue