Real last message, chat icon

Former-commit-id: a5350f9b9b
This commit is contained in:
virvar 2016-05-19 11:51:13 +03:00
parent a1e47ce00f
commit c015d260e8
8 changed files with 100 additions and 48 deletions

View File

@ -32,13 +32,19 @@
(assoc msg :text-color text-color
:background-color background-color))))
(defn chat-photo [{:keys [photo-path]}]
[view {:margin 10
:borderRadius 50}
[image {:source (if (s/blank? photo-path)
res/user-no-photo
{:uri photo-path})
:style st/chat-photo}]])
(defview default-chat-icon []
[name [:chat :name]
color [:chat :color]]
[view (st/default-chat-icon color)
[text {:style st/default-chat-icon-text} (nth name 0)]])
(defview chat-photo []
[photo-path [:chat-photo]]
(if photo-path
[view st/contact-photo-container
[image {:source {:uri photo-path}
:style st/chat-photo}]]
[default-chat-icon]))
(defn contact-online [{:keys [online]}]
(when online

View File

@ -21,8 +21,10 @@
:elevation 2})
(def icon-view
{:width 56
:height 56})
{:width 56
:height 56
:paddingTop 10
:paddingLeft 10})
(def back-icon
{:marginTop 21
@ -153,6 +155,24 @@
:fontFamily font
:color text2-color})
(defn default-chat-icon [color]
{:width 36
:height 36
:alignItems :center
:justifyContent :center
:borderRadius 50
:backgroundColor color})
(def default-chat-icon-text
{:marginTop -2
:color color-white
:fontFamily font
:fontSize 16
:lineHeight 20})
(def contact-photo-container
{:borderRadius 50})
(def chat-photo
{:borderRadius 50
:width 36

View File

@ -8,6 +8,21 @@
text2-color
new-messages-count-color]]))
(defn default-chat-icon [color]
{:width 40
:height 40
:alignItems :center
:justifyContent :center
:borderRadius 50
:backgroundColor color})
(def default-chat-icon-text
{:marginTop -2
:color color-white
:fontFamily font
:fontSize 16
:lineHeight 20})
(def contact-photo-container
{:borderRadius 50})

View File

@ -13,8 +13,8 @@
{: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
{:photo-path nil
:delivery-status :seen
;; TODO stub data
{:delivery-status :seen
:new-messages-count 3
:timestamp "13:54"
:online true})]]])

View File

@ -1,16 +1,19 @@
(ns syng-im.chats-list.views.inner-item
(:require [clojure.string :as s]
[syng-im.components.react :refer [view image icon text]]
[syng-im.chats-list.styles :as st]
[syng-im.resources :as res]))
(:require-macros [syng-im.utils.views :refer [defview]])
(:require [syng-im.components.react :refer [view image icon text]]
[syng-im.chats-list.styles :as st]))
(defn default-chat-icon [{:keys [name color]}]
[view (st/default-chat-icon color)
[text {:style st/default-chat-icon-text} (nth name 0)]])
(defn contact-photo [photo-path]
[view st/contact-photo-container
[image {:source (if (s/blank? photo-path)
res/user-no-photo
{:uri photo-path})
:style st/contact-photo-image}]])
(defview contact-photo [chat]
[photo-path [:chat-photo (:chat-id chat)]]
(if photo-path
[view st/contact-photo-container
[image {:source {:uri photo-path}
:style st/contact-photo-image}]]
[default-chat-icon chat]))
(defn contact-online [online]
(when online
@ -19,11 +22,11 @@
[view st/online-dot-right]]))
(defn chat-list-item-inner-view
[{:keys [name photo-path delivery-status timestamp new-messages-count online
group-chat contacts]}]
[{:keys [chat-id name photo-path delivery-status timestamp new-messages-count online
group-chat contacts] :as chat}]
[view st/chat-container
[view st/photo-container
[contact-photo photo-path]
[contact-photo chat]
[contact-online online]]
[view st/item-container
[view st/name-view
@ -37,7 +40,8 @@
"1 member")])]
[text {:style st/last-message-text
:numberOfLines 2}
(repeatedly 5 #(str "Hi, I'm " name "! "))]]
(when-let [last-message (first (:messages chat))]
(:content last-message))]]
[view
[view st/status-container
(when delivery-status

View File

@ -4,18 +4,9 @@
(def server-address "http://rpc0.syng.im:20000/")
;; (def server-address "http://10.0.3.2:3000/")
;; (def server-address "http://localhost:3000/")
(def text-content-type "text/plain")
(def content-type-command "command")
(def content-type-command-request "command-request")
(def content-type-status "status")
(comment
(map (fn [c]
{:background c
:foreground c}) group-chat-colors)
(reverse group-chat-colors)
)

View File

@ -12,18 +12,21 @@
(let [contacts (reaction (:contacts @db))]
(reaction (sort-by :name (vals @contacts))))))
(defn contacts-by-current-chat [fn db]
(let [current-chat-id (:current-chat-id @db)
chat (reaction (get-in @db [:chats current-chat-id]))
contacts (reaction (:contacts @db))]
(defn contacts-by-chat [fn db chat-id]
(let [chat (reaction (get-in @db [:chats chat-id]))
contacts (reaction (:contacts @db))]
(reaction
(when @chat
(let [current-participants (->> @chat
:contacts
(map :identity)
set)]
(fn #(current-participants (:whisper-identity %))
(vals @contacts)))))))
(when @chat
(let [current-participants (->> @chat
:contacts
(map :identity)
set)]
(fn #(current-participants (:whisper-identity %))
(vals @contacts)))))))
(defn contacts-by-current-chat [fn db]
(let [current-chat-id (:current-chat-id @db)]
(contacts-by-chat fn db current-chat-id)))
(register-sub :contact
(fn [db _]
@ -37,3 +40,15 @@
(register-sub :current-chat-contacts
(fn [db _]
(contacts-by-current-chat filter db)))
(register-sub :chat-photo
(fn [db [_ chat-id]]
(let [chat-id (or chat-id (:current-chat-id @db))
chat (reaction (get-in @db [:chats chat-id]))
contacts (contacts-by-chat filter db chat-id)]
(reaction
(when @chat
(if (:group-chat @chat)
;; TODO return group chat icon
nil
(:photo-path (first @contacts))))))))

View File

@ -56,12 +56,13 @@
{:margin 10
:width 36
:height 36
:alignItems :center
:justifyContent :center
:borderRadius 50
:backgroundColor color})
(def chat-icon-text
{:marginTop 7
:marginLeft 13
{:marginTop -2
:color color-white
:fontFamily font
:fontSize 16