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
@ -120,7 +121,8 @@
: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,11 +2,13 @@
(: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}]
(let [last-message (first (:messages chat))]
[view st/chat-container [view st/chat-container
[view st/chat-icon-container [view st/chat-icon-container
[chat-icon-view-chat-list chat-id group-chat name color online]] [chat-icon-view-chat-list chat-id group-chat name color online]]
@ -22,17 +24,21 @@
"1 member")])] "1 member")])]
[text {:style st/last-message-text [text {:style st/last-message-text
:numberOfLines 2} :numberOfLines 2}
(when-let [last-message (first (:messages chat))] (when last-message
(:content last-message))]] (:content last-message))]]
[view [view
(when last-message
[view st/status-container [view st/status-container
(when delivery-status ;; TODO currently there is not :delivery-status in last-message
[image {:source (if (= (keyword delivery-status) :seen) (when (:delivery-status last-message)
[image {:source (if (= (keyword (:delivery-status last-message)) :seen)
{:uri :icon_ok_small} {:uri :icon_ok_small}
;; todo change icon ;; todo change icon
{:uri :icon_ok_small}) {:uri :icon_ok_small})
:style st/status-image}]) :style st/status-image}])
[text {:style st/datetime-text} timestamp]] (when (:timestamp last-message)
[text {:style st/datetime-text}
(time/to-short-str (:timestamp last-message))])])
(when (pos? new-messages-count) (when (pos? new-messages-count)
[view st/new-messages-container [view st/new-messages-container
[text {:style st/new-messages-text} new-messages-count]])]]) [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)))