Remove username from 1-to-1 chat
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
parent
53349ef31f
commit
c27418cd2f
|
@ -19,8 +19,9 @@
|
|||
:height 16})
|
||||
|
||||
(defn message-padding-top
|
||||
[{:keys [first-in-group?]}]
|
||||
(if first-in-group?
|
||||
[{:keys [first-in-group? display-username?]}]
|
||||
(if (and display-username?
|
||||
first-in-group?)
|
||||
8
|
||||
4))
|
||||
|
||||
|
|
|
@ -146,8 +146,15 @@
|
|||
(conj messages-with-datemarks {:value (:datemark (peek messages-with-datemarks))
|
||||
:type :datemark}))))
|
||||
|
||||
(defn- set-previous-message-first-in-group [stream]
|
||||
(conj (pop stream) (assoc (peek stream) :first-in-group? true)))
|
||||
(defn- set-previous-message-info [stream]
|
||||
(let [{:keys [display-photo?] :as previous-message} (peek stream)]
|
||||
(conj (pop stream) (assoc previous-message
|
||||
:display-username? display-photo?
|
||||
:first-in-group? true))))
|
||||
|
||||
(defn display-photo? [{:keys [outgoing message-type]}]
|
||||
(and (not outgoing)
|
||||
(not= message-type :user-message)))
|
||||
|
||||
; any message that comes after this amount of ms will be grouped separately
|
||||
(def ^:private group-ms 60000)
|
||||
|
@ -156,7 +163,7 @@
|
|||
"Reduce step which adds positional metadata to a message and conditionally
|
||||
update the previous message with :first-in-group?."
|
||||
[{:keys [stream last-outgoing-seen]}
|
||||
{:keys [type from datemark outgoing timestamp] :as message}]
|
||||
{:keys [type message-type from datemark outgoing timestamp] :as message}]
|
||||
(let [previous-message (peek stream)
|
||||
; Was the previous message from a different author or this message
|
||||
; comes after x ms
|
||||
|
@ -172,13 +179,14 @@
|
|||
previous-first-in-group? (or datemark?
|
||||
last-in-group?)
|
||||
new-message (assoc message
|
||||
:display-photo? (display-photo? message)
|
||||
:same-direction? same-direction?
|
||||
:last-in-group? last-in-group?
|
||||
:last-outgoing? last-outgoing?)]
|
||||
:last-in-group? last-in-group?
|
||||
:last-outgoing? last-outgoing?)]
|
||||
{:stream (cond-> stream
|
||||
previous-first-in-group?
|
||||
; update previuous message if necessary
|
||||
set-previous-message-first-in-group
|
||||
set-previous-message-info
|
||||
|
||||
:always
|
||||
(conj new-message))
|
||||
|
@ -195,6 +203,7 @@
|
|||
message-with-metadata (assoc initial-message
|
||||
:last-in-group? true
|
||||
:last? true
|
||||
:display-photo? (display-photo? initial-message)
|
||||
:last-outgoing? (:outgoing initial-message))]
|
||||
(->> (rest ordered-messages)
|
||||
(reduce add-positional-metadata
|
||||
|
|
|
@ -304,18 +304,22 @@
|
|||
(gfycat/generate-gfy from))])) ; TODO: We defensively generate the name for now, to be revisited when new protocol is defined
|
||||
|
||||
(defn message-body
|
||||
[{:keys [last-in-group? first-in-group? group-chat from outgoing username] :as message} content]
|
||||
[{:keys [last-in-group?
|
||||
display-photo?
|
||||
display-username?
|
||||
from
|
||||
outgoing
|
||||
username] :as message} content]
|
||||
[react/view (style/group-message-wrapper message)
|
||||
[react/view (style/message-body message)
|
||||
(when (and (not outgoing)
|
||||
group-chat)
|
||||
(when display-photo?
|
||||
[react/view style/message-author
|
||||
(when last-in-group?
|
||||
[react/touchable-highlight {:on-press #(re-frame/dispatch [:show-profile from])}
|
||||
[react/view
|
||||
[photos/member-photo from]]])])
|
||||
[react/view (style/group-message-view outgoing)
|
||||
(when first-in-group?
|
||||
(when display-username?
|
||||
[message-author-name from username])
|
||||
[react/view {:style (style/timestamp-content-wrapper message)}
|
||||
content]]]
|
||||
|
|
|
@ -87,6 +87,14 @@
|
|||
(is (:first-in-group? actual-m1))
|
||||
(is (not (:first-in-group? actual-m2)))
|
||||
(is (:first-in-group? actual-m3)))
|
||||
(testing "it marks messages with display-photo? when they are not outgoing and we are in a group chat"
|
||||
(is (:display-photo? actual-m1))
|
||||
(is (not (:display-photo? actual-m2)))
|
||||
(is (not (:display-photo? actual-m3))))
|
||||
(testing "it marks messages with display-username? when we display the photo and are the first in a group"
|
||||
(is (:display-username? actual-m1))
|
||||
(is (not (:display-username? actual-m2)))
|
||||
(is (not (:display-username? actual-m3))))
|
||||
(testing "it marks the last message from the same author with :last-in-group?"
|
||||
(is (:last-in-group? actual-m1))
|
||||
(is (:last-in-group? actual-m2))
|
||||
|
|
Loading…
Reference in New Issue