This reverts commit 88238ed2c8 [formerly 71cb0fde6c].


Former-commit-id: b65c71bbb5
This commit is contained in:
virvar 2016-05-02 13:56:25 +03:00
parent 88238ed2c8
commit 086f9d826f
7 changed files with 57 additions and 87 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,10 @@
(ns syng-im.models.chats
(: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?]]
[syng-im.db :as db]
[syng-im.utils.logging :as log]
[syng-im.constants :refer [group-chat-colors
content-type-status]]
[syng-im.models.messages :refer [save-message]]
[syng-im.constants :refer [group-chat-colors]]
[syng-im.persistence.realm-queries :refer [include-query]]))
(defn signal-chats-updated [db]
@ -33,18 +31,6 @@
(or (chat-name-from-contacts identities)
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
([db chat-id identities group-chat?]
(create-chat db chat-id identities group-chat? nil))
@ -66,7 +52,6 @@
:group-chat group-chat?
:timestamp (timestamp)
:contacts contacts}))))
(add-status-message chat-id)
(signal-chats-updated db)))))
(defn chats-list []

View File

@ -27,13 +27,6 @@
(defn message-by-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}]
(log/debug "update-message!" msg)
(r/write

View File

@ -7,8 +7,7 @@
[syng-im.models.chats :refer [chats-list
chats-updated?
chat-by-id]]
[syng-im.models.messages :refer [get-messages
get-chat-last-message]]
[syng-im.models.messages :refer [get-messages]]
[syng-im.models.contacts :refer [contacts-list
contacts-list-exclude
contacts-list-include]]
@ -66,10 +65,6 @@
(fn [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 --------------------------------------------------------------
(register-sub :get-chats