Last message date

Former-commit-id: a782cf0726
This commit is contained in:
virvar 2016-05-20 12:41:55 +03:00
parent eab6dd79c8
commit 98d0afd034
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"
:branch "feature-discover"}}
[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"]
[lein-figwheel "0.5.0-2"]]
:clean-targets ["target/" "index.ios.js" "index.android.js"]

View File

@ -14,6 +14,7 @@
[syng-im.models.chats :as c]
[syng-im.handlers.server :as server]
[syng-im.utils.phone-number :refer [format-phone-number]]
[syng-im.utils.datetime :as time]
[syng-im.utils.handlers :as u]))
(register-handler :set-show-actions
@ -114,13 +115,14 @@
{:keys [command]} (suggestions/check-suggestion db (str text " "))
message (check-author-direction
db current-chat-id
{:msg-id (random/id)
:chat-id current-chat-id
:content text
:to current-chat-id
:from identity
:content-type text-content-type
:outgoing true})]
{:msg-id (random/id)
:chat-id current-chat-id
:content text
:to current-chat-id
:from identity
:content-type text-content-type
:outgoing true
:timestamp (time/now-ms)})]
(if command
(commands/set-chat-command db command)
(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}]
[touchable-highlight
{: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
;; TODO stub data
{:delivery-status :seen
:new-messages-count 3
:timestamp "13:54"
{:new-messages-count 3
:online true})]]])

View File

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