This reverts commit 71cb0fde6c.
This commit is contained in:
virvar 2016-05-02 13:56:25 +03:00
parent 71cb0fde6c
commit b65c71bbb5
7 changed files with 57 additions and 87 deletions

View File

@ -19,6 +19,7 @@
[syng-im.utils.logging :as log] [syng-im.utils.logging :as log]
[syng-im.navigation :refer [nav-pop]] [syng-im.navigation :refer [nav-pop]]
[syng-im.resources :as res] [syng-im.resources :as res]
[syng-im.constants :refer [content-type-status]]
[syng-im.utils.listview :refer [to-realm-datasource]] [syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [syng-im.components.invertible-scroll-view :refer [invertible-scroll-view]]
[reagent.core :as r] [reagent.core :as r]
@ -77,7 +78,8 @@
(defn typing [member] (defn typing [member]
[view {:style {:width 260 [view {:style {:width 260
:marginTop 10 :paddingTop 2
:paddingBottom 8
:paddingLeft 8 :paddingLeft 8
:paddingRight 8 :paddingRight 8
:alignItems "flex-start" :alignItems "flex-start"
@ -93,7 +95,7 @@
(str member " is typing")]]]) (str member " is typing")]]])
(defn typing-all [] (defn typing-all []
[view {:style {:marginBottom 20}} [view {:style {:marginBottom 12}}
(for [member ["Geoff" "Justas"]] (for [member ["Geoff" "Justas"]]
^{:key member} [typing member])]) ^{:key member} [typing member])])
@ -142,13 +144,24 @@
(defn chat [{:keys [navigator]}] (defn chat [{:keys [navigator]}]
(let [messages (subscribe [:get-chat-messages]) (let [messages (subscribe [:get-chat-messages])
chat (subscribe [:get-current-chat]) chat (subscribe [:get-current-chat])]
last-message-atom (subscribe [:get-chat-last-message])]
(fn [] (fn []
(let [msgs @messages (let [msgs @messages
;_ (log/debug "messages=" msgs) ;_ (log/debug "messages=" msgs)
;; temp ;; temp to show first status
msgs-clj (as-> (js->clj msgs) ms msgs-clj (as-> (js->clj msgs) ms
(assoc ms "-1"
{:msg-id "-1"
:content (str "The brash businessmans braggadocio "
"and public exchange with candidates "
"in the US presidential election")
:delivery-status "seen"
:from "Status"
:chat-id "-"
:content-type content-type-status
:timestamp 1
"outgoing" false
:to nil})
(reduce (fn [items [n m]] (reduce (fn [items [n m]]
(assoc items (.parseInt js/window n) m (assoc items (.parseInt js/window n) m
;; (assoc m "from" (if (< 0.5 (rand)) ;; (assoc m "from" (if (< 0.5 (rand))
@ -166,14 +179,14 @@
(assoc :same-direction (assoc :same-direction
(if next (if next
(= (get current "outgoing") (get next "outgoing")) (= (get current "outgoing") (get next "outgoing"))
true))) true))
(assoc :last-msg (= 0 n)))
current]) current])
ms (conj (vec (rest ms)) nil)) ms (conj (vec (rest ms)) nil))
(reduce (fn [items [n m]] (reduce (fn [items [n m]]
(assoc items n m)) (assoc items n m))
{} ms)) {} ms))
msgs (clj->js msgs-clj) msgs (clj->js msgs-clj)
typing (:group-chat @chat)
;; end temp ;; end temp
datasource (to-realm-datasource msgs) datasource (to-realm-datasource msgs)
contacts (:contacts @chat) contacts (:contacts @chat)
@ -205,16 +218,15 @@
:onIconClicked (fn [] :onIconClicked (fn []
(nav-pop navigator))} (nav-pop navigator))}
[toolbar-content-chat @chat]]) [toolbar-content-chat @chat]])
(let [last-message @last-message-atom]
[list-view {:dataSource datasource [list-view {:dataSource datasource
:renderScrollComponent (fn [props] :renderScrollComponent (fn [props]
(invertible-scroll-view (js->clj props))) (invertible-scroll-view (js->clj props)))
:renderRow (fn [row section-id row-id] :renderRow (fn [row section-id row-id]
(let [msg (-> (js->clj row :keywordize-keys true) (let [msg (-> (js->clj row :keywordize-keys true)
(add-msg-color contact-by-identity) (add-msg-color contact-by-identity)
(assoc :group-chat (:group-chat @chat)) (assoc :group-chat (:group-chat @chat)))]
(assoc :typing typing))] (r/as-element [chat-message msg])))
(r/as-element [chat-message msg last-message])))}]) :style {:backgroundColor "white"}}]
(when (:group-chat @chat) (when (:group-chat @chat)
[typing-all]) [typing-all])
(when (:is-active @chat) (when (:is-active @chat)

View File

@ -287,7 +287,7 @@
(defn incoming-group-message-body [{:keys [msg-id from content content-type outgoing (defn incoming-group-message-body [{:keys [msg-id from content content-type outgoing
delivery-status selected new-day same-author delivery-status selected new-day same-author
same-direction last-msg typing]}] same-direction last-msg]}]
(let [delivery-status :seen-by-everyone] (let [delivery-status :seen-by-everyone]
[view {:style {:flexDirection "column"}} [view {:style {:flexDirection "column"}}
(when selected (when selected
@ -306,7 +306,7 @@
:else 10) :else 10)
:paddingRight 8 :paddingRight 8
:paddingLeft 8} :paddingLeft 8}
(when (and last-msg (not typing)) (when last-msg
{:paddingBottom 20}))} {:paddingBottom 20}))}
[view {:style {:width 24}} [view {:style {:width 24}}
(when (not same-author) (when (not same-author)
@ -327,7 +327,7 @@
[message-delivery-status {:delivery-status delivery-status}])]]])) [message-delivery-status {:delivery-status delivery-status}])]]]))
(defn message-body [{:keys [msg-id content content-type outgoing delivery-status (defn message-body [{:keys [msg-id content content-type outgoing delivery-status
group-chat new-day same-author same-direction last-msg typing]}] group-chat new-day same-author same-direction last-msg]}]
(let [delivery-status :seen] (let [delivery-status :seen]
[view {:style (merge {:flexDirection "column" [view {:style (merge {:flexDirection "column"
:width 260 :width 260
@ -343,7 +343,7 @@
:alignItems "flex-end"} :alignItems "flex-end"}
{:alignItems "flex-start" {:alignItems "flex-start"
:alignSelf "flex-start"}) :alignSelf "flex-start"})
(when (and last-msg (not typing)) (when last-msg
{:paddingBottom 20}))} {:paddingBottom 20}))}
[message-content {:msg-id msg-id [message-content {:msg-id msg-id
:content-type content-type :content-type content-type
@ -353,10 +353,7 @@
(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 chat-message [{:keys [msg-id from content content-type outgoing delivery-status (defn chat-message [{:keys [msg-id from content content-type outgoing delivery-status date new-day group-chat selected same-author same-direction last-msg] :as msg}]
date new-day group-chat selected same-author same-direction
last-msg typing] :as msg}
last-message]
[view {} [view {}
(when new-day (when new-day
[message-date {:date date}]) [message-date {:date date}])
@ -371,8 +368,7 @@
:new-day new-day :new-day new-day
:same-author same-author :same-author same-author
:same-direction same-direction :same-direction same-direction
:last-msg (= (:msg-id last-message) msg-id) :last-msg last-msg}]
:typing typing}]
[view {} [view {}
(when (= content-type content-type-status) (when (= content-type content-type-status)
[message-content-status from content]) [message-content-status from content])

View File

@ -9,8 +9,7 @@
:identity-password "replace-me-with-user-entered-password" :identity-password "replace-me-with-user-entered-password"
:contacts [] :contacts []
:chat {:current-chat-id "0x0479a5ed1f38cadfad1db6cd56c4b659b0ebe052bbe9efa950f6660058519fa4ca6be2dda66afa80de96ab00eb97a2605d5267a1e8f4c2a166ab551f6826608cdd" :chat {:current-chat-id "0x0479a5ed1f38cadfad1db6cd56c4b659b0ebe052bbe9efa950f6660058519fa4ca6be2dda66afa80de96ab00eb97a2605d5267a1e8f4c2a166ab551f6826608cdd"
:command nil :command nil}
:last-message nil}
:chats {} :chats {}
:chats-updated-signal 0 :chats-updated-signal 0
:new-group #{} :new-group #{}
@ -38,7 +37,5 @@
[:chats chat-id :command-requests]) [:chats chat-id :command-requests])
(defn chat-command-request-path [chat-id msg-id] (defn chat-command-request-path [chat-id msg-id]
[:chats chat-id :command-requests msg-id]) [:chats chat-id :command-requests msg-id])
(defn chat-last-message-path [chat-id]
[:chats chat-id :last-message])
(def new-group-path [:new-group]) (def new-group-path [:new-group])
(def new-participants-path [:new-participants]) (def new-participants-path [:new-participants])

View File

@ -1,25 +1,17 @@
(ns syng-im.models.chat (ns syng-im.models.chat
(:require [syng-im.db :as db] (:require [syng-im.db :as db]))
[syng-im.models.messages :refer [update-chat-last-message]]))
(defn on-chat-update [db chat-id]
(update-chat-last-message db chat-id))
(defn set-current-chat-id [db chat-id] (defn set-current-chat-id [db chat-id]
(-> db (assoc-in db db/current-chat-id-path chat-id))
(assoc-in db/current-chat-id-path chat-id)
(on-chat-update chat-id)))
(defn current-chat-id [db] (defn current-chat-id [db]
(get-in db db/current-chat-id-path)) (get-in db db/current-chat-id-path))
(defn signal-chat-updated [db chat-id] (defn signal-chat-updated [db chat-id]
(-> db (update-in db (db/updated-chat-signal-path chat-id) (fn [current]
(on-chat-update chat-id)
(update-in (db/updated-chat-signal-path chat-id) (fn [current]
(if current (if current
(inc current) (inc current)
0))))) 0))))
(defn chat-updated? [db chat-id] (defn chat-updated? [db chat-id]
(get-in db (db/updated-chat-signal-path chat-id))) (get-in db (db/updated-chat-signal-path chat-id)))

View File

@ -1,12 +1,10 @@
(ns syng-im.models.chats (ns syng-im.models.chats
(:require [syng-im.persistence.realm :as r] (:require [syng-im.persistence.realm :as r]
[syng-im.utils.random :as random :refer [timestamp]] [syng-im.utils.random :refer [timestamp]]
[clojure.string :refer [join blank?]] [clojure.string :refer [join blank?]]
[syng-im.db :as db] [syng-im.db :as db]
[syng-im.utils.logging :as log] [syng-im.utils.logging :as log]
[syng-im.constants :refer [group-chat-colors [syng-im.constants :refer [group-chat-colors]]
content-type-status]]
[syng-im.models.messages :refer [save-message]]
[syng-im.persistence.realm-queries :refer [include-query]])) [syng-im.persistence.realm-queries :refer [include-query]]))
(defn signal-chats-updated [db] (defn signal-chats-updated [db]
@ -33,18 +31,6 @@
(or (chat-name-from-contacts identities) (or (chat-name-from-contacts identities)
chat-id)) chat-id))
(defn add-status-message [chat-id]
;; TODO Get real status
(save-message chat-id
{:from "Status"
:to nil
:msg-id (random/id)
:content (str "The brash businessmans braggadocio "
"and public exchange with candidates "
"in the US presidential election")
:content-type content-type-status
:outgoing false}))
(defn create-chat (defn create-chat
([db chat-id identities group-chat?] ([db chat-id identities group-chat?]
(create-chat db chat-id identities group-chat? nil)) (create-chat db chat-id identities group-chat? nil))
@ -66,7 +52,6 @@
:group-chat group-chat? :group-chat group-chat?
:timestamp (timestamp) :timestamp (timestamp)
:contacts contacts})))) :contacts contacts}))))
(add-status-message chat-id)
(signal-chats-updated db))))) (signal-chats-updated db)))))
(defn chats-list [] (defn chats-list []

View File

@ -27,13 +27,6 @@
(defn message-by-id [msg-id] (defn message-by-id [msg-id]
(r/single-cljs (r/get-by-field :msgs :msg-id msg-id))) (r/single-cljs (r/get-by-field :msgs :msg-id msg-id)))
(defn update-chat-last-message [db chat-id]
(let [last-message (r/single-cljs (get-messages chat-id))]
(assoc-in db (db/chat-last-message-path chat-id) last-message)))
(defn get-chat-last-message [db chat-id]
(get-in db (db/chat-last-message-path chat-id)))
(defn update-message! [{:keys [msg-id] :as msg}] (defn update-message! [{:keys [msg-id] :as msg}]
(log/debug "update-message!" msg) (log/debug "update-message!" msg)
(r/write (r/write

View File

@ -7,8 +7,7 @@
[syng-im.models.chats :refer [chats-list [syng-im.models.chats :refer [chats-list
chats-updated? chats-updated?
chat-by-id]] chat-by-id]]
[syng-im.models.messages :refer [get-messages [syng-im.models.messages :refer [get-messages]]
get-chat-last-message]]
[syng-im.models.contacts :refer [contacts-list [syng-im.models.contacts :refer [contacts-list
contacts-list-exclude contacts-list-exclude
contacts-list-include]] contacts-list-include]]
@ -66,10 +65,6 @@
(fn [db _] (fn [db _]
(reaction (get-chat-command-request @db)))) (reaction (get-chat-command-request @db))))
(register-sub :get-chat-last-message
(fn [db _]
(reaction (get-chat-last-message @db (current-chat-id @db)))))
;; -- Chats list -------------------------------------------------------------- ;; -- Chats list --------------------------------------------------------------
(register-sub :get-chats (register-sub :get-chats