Last message date

This commit is contained in:
virvar 2016-05-20 12:41:55 +03:00
parent 62fb91fba6
commit a782cf0726
5 changed files with 73 additions and 43 deletions

View File

@ -11,7 +11,8 @@
^{:voom {:repo "https://github.com/status-im/status-lib.git" ^{:voom {:repo "https://github.com/status-im/status-lib.git"
:branch "feature-discover"}} :branch "feature-discover"}}
[syng-im/protocol "0.1.1-20160506_171115-ge2c95c1"] [syng-im/protocol "0.1.1-20160506_171115-ge2c95c1"]
[natal-shell "0.1.6"]] [natal-shell "0.1.6"]
[com.andrewmcveigh/cljs-time "0.4.0"]]
:plugins [[lein-cljsbuild "1.1.1"] :plugins [[lein-cljsbuild "1.1.1"]
[lein-figwheel "0.5.0-2"]] [lein-figwheel "0.5.0-2"]]
:clean-targets ["target/" "index.ios.js" "index.android.js"] :clean-targets ["target/" "index.ios.js" "index.android.js"]

View File

@ -14,6 +14,7 @@
[syng-im.models.chats :as c] [syng-im.models.chats :as c]
[syng-im.handlers.server :as server] [syng-im.handlers.server :as server]
[syng-im.utils.phone-number :refer [format-phone-number]] [syng-im.utils.phone-number :refer [format-phone-number]]
[syng-im.utils.datetime :as time]
[syng-im.utils.handlers :as u])) [syng-im.utils.handlers :as u]))
(register-handler :set-show-actions (register-handler :set-show-actions
@ -114,13 +115,14 @@
{:keys [command]} (suggestions/check-suggestion db (str text " ")) {:keys [command]} (suggestions/check-suggestion db (str text " "))
message (check-author-direction message (check-author-direction
db current-chat-id db current-chat-id
{:msg-id (random/id) {:msg-id (random/id)
:chat-id current-chat-id :chat-id current-chat-id
:content text :content text
:to current-chat-id :to current-chat-id
:from identity :from identity
:content-type text-content-type :content-type text-content-type
:outgoing true})] :outgoing true
:timestamp (time/now-ms)})]
(if command (if command
(commands/set-chat-command db command) (commands/set-chat-command db command)
(assoc db :new-message (when-not (str/blank? text) message))))) (assoc db :new-message (when-not (str/blank? text) message)))))

View File

@ -11,10 +11,7 @@
(defn chat-list-item [{:keys [chat-id] :as chat}] (defn chat-list-item [{:keys [chat-id] :as chat}]
[touchable-highlight [touchable-highlight
{:on-press #(dispatch [:show-chat chat-id :push])} {:on-press #(dispatch [:show-chat chat-id :push])}
;; TODO add [photo-path delivery-status new-messages-count online] values to chat-obj
[view [chat-list-item-inner-view (merge chat [view [chat-list-item-inner-view (merge chat
;; TODO stub data ;; TODO stub data
{:delivery-status :seen {:new-messages-count 3
:new-messages-count 3
:timestamp "13:54"
:online true})]]]) :online true})]]])

View File

@ -2,37 +2,43 @@
(:require-macros [syng-im.utils.views :refer [defview]]) (:require-macros [syng-im.utils.views :refer [defview]])
(:require [syng-im.components.react :refer [view image icon text]] (:require [syng-im.components.react :refer [view image icon text]]
[syng-im.components.chat-icon.screen :refer [chat-icon-view-chat-list]] [syng-im.components.chat-icon.screen :refer [chat-icon-view-chat-list]]
[syng-im.chats-list.styles :as st])) [syng-im.chats-list.styles :as st]
[syng-im.utils.datetime :as time]))
(defn chat-list-item-inner-view (defn chat-list-item-inner-view
[{:keys [chat-id name color photo-path delivery-status timestamp new-messages-count [{:keys [chat-id name color photo-path new-messages-count
online group-chat contacts] :as chat}] online group-chat contacts] :as chat}]
[view st/chat-container (let [last-message (first (:messages chat))]
[view st/chat-icon-container [view st/chat-container
[chat-icon-view-chat-list chat-id group-chat name color online]] [view st/chat-icon-container
[view st/item-container [chat-icon-view-chat-list chat-id group-chat name color online]]
[view st/name-view [view st/item-container
[text {:style st/name-text} name] [view st/name-view
(when group-chat [text {:style st/name-text} name]
[icon :group st/group-icon]) (when group-chat
(when group-chat [icon :group st/group-icon])
[text {:style st/memebers-text} (when group-chat
(if (< 1 (count contacts)) [text {:style st/memebers-text}
(str (count contacts) " members") (if (< 1 (count contacts))
"1 member")])] (str (count contacts) " members")
[text {:style st/last-message-text "1 member")])]
:numberOfLines 2} [text {:style st/last-message-text
(when-let [last-message (first (:messages chat))] :numberOfLines 2}
(:content last-message))]] (when last-message
[view (:content last-message))]]
[view st/status-container [view
(when delivery-status (when last-message
[image {:source (if (= (keyword delivery-status) :seen) [view st/status-container
{:uri :icon_ok_small} ;; TODO currently there is not :delivery-status in last-message
;; todo change icon (when (:delivery-status last-message)
{:uri :icon_ok_small}) [image {:source (if (= (keyword (:delivery-status last-message)) :seen)
:style st/status-image}]) {:uri :icon_ok_small}
[text {:style st/datetime-text} timestamp]] ;; todo change icon
(when (pos? new-messages-count) {:uri :icon_ok_small})
[view st/new-messages-container :style st/status-image}])
[text {:style st/new-messages-text} new-messages-count]])]]) (when (:timestamp last-message)
[text {:style st/datetime-text}
(time/to-short-str (:timestamp last-message))])])
(when (pos? new-messages-count)
[view st/new-messages-container
[text {:style st/new-messages-text} new-messages-count]])]]))

View File

@ -0,0 +1,24 @@
(ns syng-im.utils.datetime
(:require [cljs-time.core :as t :refer [date-time now plus days hours before?]]
[cljs-time.coerce :refer [from-long to-long]]
[cljs-time.format :as format :refer [formatters
formatter
unparse]]))
(def time-zone-offset (hours (- (/ (.getTimezoneOffset (js/Date.)) 60))))
(defn to-short-str [ms]
(let [date (from-long ms)
local (plus date time-zone-offset)
today-date (t/today)
today (date-time (t/year today-date)
(t/month today-date)
(t/day today-date))
yesterday (plus today (days -1))]
(cond
(before? local yesterday) (unparse (formatter "dd MMM") local)
(before? local today) "Yesterday"
:else (unparse (formatters :hour-minute) local))))
(defn now-ms []
(to-long (now)))