[#6850] related refactoring
- remove unecessary subscriptions related to add-contact-bar Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
0cdc56401a
commit
77b792a37a
|
@ -3,7 +3,7 @@
|
|||
[clojure.string :as string]
|
||||
[status-im.chat.commands.core :as commands]
|
||||
[status-im.chat.commands.input :as commands.input]
|
||||
[status-im.utils.config :as utils.config]
|
||||
[status-im.group-chats.db :as group-chats.db]
|
||||
[status-im.utils.gfycat.core :as gfycat]))
|
||||
|
||||
(defn chat-name
|
||||
|
@ -18,16 +18,31 @@
|
|||
:else (or contact-name
|
||||
(gfycat/generate-gfy chat-id))))
|
||||
|
||||
(defn active-chats
|
||||
[contacts chats {:keys [dev-mode?]}]
|
||||
(reduce (fn [acc [chat-id {:keys [group-chat public? is-active] :as chat}]]
|
||||
(if is-active
|
||||
(assoc acc chat-id (if-let [contact (get contacts chat-id)]
|
||||
(defn enrich-active-chat
|
||||
[contacts {:keys [chat-id] :as chat} current-public-key]
|
||||
(if-let [contact (get contacts chat-id)]
|
||||
(-> chat
|
||||
(assoc :name (:name contact))
|
||||
(assoc :random-name (gfycat/generate-gfy (:public-key contact)))
|
||||
(assoc :contact contact
|
||||
:chat-name (chat-name chat contact)
|
||||
:name (:name contact)
|
||||
:random-name (gfycat/generate-gfy (:public-key contact)))
|
||||
(update :tags clojure.set/union (:tags contact)))
|
||||
chat))
|
||||
(let [pending-invite-inviter-name
|
||||
(group-chats.db/get-pending-invite-inviter-name contacts
|
||||
chat
|
||||
current-public-key)]
|
||||
(cond-> chat
|
||||
pending-invite-inviter-name
|
||||
(assoc :pending-invite-inviter-name pending-invite-inviter-name)
|
||||
:always
|
||||
(assoc :chat-name
|
||||
(chat-name chat nil))))))
|
||||
|
||||
(defn active-chats
|
||||
[contacts chats {:keys [public-key]}]
|
||||
(reduce (fn [acc [chat-id {:keys [is-active] :as chat}]]
|
||||
(if is-active
|
||||
(assoc acc chat-id (enrich-active-chat contacts chat public-key))
|
||||
acc))
|
||||
{}
|
||||
chats))
|
||||
|
|
|
@ -58,27 +58,6 @@
|
|||
(fn [[chat-ui-props id]]
|
||||
(get chat-ui-props id)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:chats/current-chat-contact
|
||||
:<- [:contacts/contacts]
|
||||
:<- [:chats/current-chat-id]
|
||||
(fn [[contacts chat-id]]
|
||||
(get contacts chat-id)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:chats/current-chat-name
|
||||
:<- [:chats/current-chat-contact]
|
||||
:<- [:chats/current-chat]
|
||||
(fn [[contact chat]]
|
||||
(chat.db/chat-name chat contact)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:chats/chat-name
|
||||
:<- [:contacts/contacts]
|
||||
:<- [::chats]
|
||||
(fn [[contacts chats] [_ chat-id]]
|
||||
(chat.db/chat-name (get chats chat-id) (get contacts chat-id))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:chats/current-chat-ui-prop
|
||||
:<- [:chats/current-chat-ui-props]
|
||||
|
|
|
@ -68,16 +68,6 @@
|
|||
#(contact.db/filter-dapps % dev-mode?)))
|
||||
dapps)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:contacts/contact-by-identity
|
||||
:<- [:contacts/contacts]
|
||||
:<- [:chats/current-chat]
|
||||
(fn [[all-contacts {:keys [contacts]}] [_ identity]]
|
||||
(let [identity' (or identity (first contacts))]
|
||||
(or
|
||||
(get all-contacts identity')
|
||||
(contact.db/public-key->new-contact identity')))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:contacts/dapps-by-name
|
||||
:<- [:contacts/all-dapps]
|
||||
|
|
|
@ -1,29 +1,25 @@
|
|||
(ns status-im.group-chats.core
|
||||
(:refer-clojure :exclude [remove])
|
||||
(:require [clojure.string :as string]
|
||||
(:require [clojure.set :as clojure.set]
|
||||
[clojure.spec.alpha :as spec]
|
||||
[clojure.set :as clojure.set]
|
||||
[clojure.string :as string]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.clocks :as utils.clocks]
|
||||
[status-im.accounts.db :as accounts.db]
|
||||
[status-im.chat.models :as models.chat]
|
||||
[status-im.chat.models.message :as models.message]
|
||||
[status-im.contact.core :as models.contact]
|
||||
[status-im.contact-code.core :as contact-code]
|
||||
[status-im.group-chats.db :as group-chats.db]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.native-module.core :as native-module]
|
||||
[status-im.transport.utils :as transport.utils]
|
||||
[status-im.transport.db :as transport.db]
|
||||
[status-im.transport.utils :as transport.utils]
|
||||
[status-im.transport.message.protocol :as protocol]
|
||||
[status-im.transport.chat.core :as transport.chat]
|
||||
[status-im.transport.message.group-chat :as message.group-chat]
|
||||
[status-im.transport.message.protocol :as protocol]
|
||||
[status-im.transport.message.public-chat :as transport.public-chat]
|
||||
[status-im.transport.partitioned-topic :as transport.topic]
|
||||
[status-im.transport.chat.core :as transport.chat]
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.chat.models :as models.chat]
|
||||
[status-im.accounts.db :as accounts.db]
|
||||
[status-im.transport.message.transit :as transit]))
|
||||
[status-im.utils.clocks :as utils.clocks]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.fx :as fx]))
|
||||
|
||||
;; Description of the flow:
|
||||
;; the flow is complicated a bit by 2 asynchronous call to status-go, which might make the logic a bit more opaque.
|
||||
|
@ -63,20 +59,9 @@
|
|||
first
|
||||
:from))
|
||||
|
||||
(defn joined-event? [public-key {:keys [members-joined] :as chat}]
|
||||
(contains? members-joined public-key))
|
||||
|
||||
(defn joined? [public-key {:keys [group-chat-local-version] :as chat}]
|
||||
;; We consider group chats with local version of 0 as joined for local events
|
||||
(or (zero? group-chat-local-version)
|
||||
(joined-event? public-key chat)))
|
||||
|
||||
(defn creator? [public-key chat]
|
||||
(= public-key (extract-creator chat)))
|
||||
|
||||
(defn invited? [my-public-key {:keys [contacts]}]
|
||||
(contains? contacts my-public-key))
|
||||
|
||||
(defn signature-material
|
||||
"Transform an update into a signable string"
|
||||
[chat-id events]
|
||||
|
@ -145,7 +130,7 @@
|
|||
destinations (map (fn [member]
|
||||
(if (and
|
||||
config/group-chats-publish-to-topic?
|
||||
(joined-event? member chat)
|
||||
(group-chats.db/joined-event? member chat)
|
||||
(not= creator member)
|
||||
(not= current-public-key member))
|
||||
{:public-key member
|
||||
|
@ -467,23 +452,6 @@
|
|||
(membership-changes->system-messages cofx clock-values)
|
||||
(models.message/add-system-messages cofx)))))
|
||||
|
||||
(defn- unwrap-events
|
||||
"Flatten all events, denormalizing from field"
|
||||
[all-updates]
|
||||
(mapcat
|
||||
(fn [{:keys [events from]}]
|
||||
(map #(assoc % :from from) events))
|
||||
all-updates))
|
||||
|
||||
(defn get-inviter-pk [my-public-key {:keys [membership-updates]}]
|
||||
(->> membership-updates
|
||||
unwrap-events
|
||||
(keep (fn [{:keys [from type members]}]
|
||||
(when (and (= type "members-added")
|
||||
(contains? members my-public-key))
|
||||
from)))
|
||||
last))
|
||||
|
||||
(fx/defn set-up-topic
|
||||
"Listen/Tear down the shared topic/contact-codes. Stop listening for members who
|
||||
have left the chat"
|
||||
|
@ -491,8 +459,8 @@
|
|||
(let [my-public-key (accounts.db/current-public-key cofx)
|
||||
new-chat (get-in cofx [:db :chats chat-id])]
|
||||
;; If we left the chat, teardown, otherwise upsert
|
||||
(if (and (joined? my-public-key previous-chat)
|
||||
(not (joined? my-public-key new-chat)))
|
||||
(if (and (group-chats.db/joined? my-public-key previous-chat)
|
||||
(not (group-chats.db/joined? my-public-key new-chat)))
|
||||
(apply fx/merge
|
||||
cofx
|
||||
(conj
|
||||
|
@ -524,7 +492,7 @@
|
|||
all-updates (clojure.set/union (set (:membership-updates previous-chat))
|
||||
(set (:membership-updates membership-update)))
|
||||
my-public-key (accounts.db/current-public-key cofx)
|
||||
unwrapped-events (unwrap-events all-updates)
|
||||
unwrapped-events (group-chats.db/unwrap-events all-updates)
|
||||
new-group (build-group unwrapped-events)
|
||||
member? (contains? (:contacts new-group) my-public-key)]
|
||||
(fx/merge cofx
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
(ns status-im.group-chats.db
|
||||
(:require [status-im.chat.models :as models.chat]
|
||||
[status-im.utils.gfycat.core :as gfycat]))
|
||||
|
||||
(defn unwrap-events
|
||||
"Flatten all events, denormalizing from field"
|
||||
[all-updates]
|
||||
(mapcat
|
||||
(fn [{:keys [events from]}]
|
||||
(map #(assoc % :from from) events))
|
||||
all-updates))
|
||||
|
||||
(defn joined-event?
|
||||
[public-key {:keys [members-joined] :as chat}]
|
||||
(contains? members-joined public-key))
|
||||
|
||||
(defn joined?
|
||||
[public-key {:keys [group-chat-local-version] :as chat}]
|
||||
;; We consider group chats with local version of 0 as joined for local events
|
||||
(or (zero? group-chat-local-version)
|
||||
(joined-event? public-key chat)))
|
||||
|
||||
(defn invited?
|
||||
[my-public-key {:keys [contacts]}]
|
||||
(contains? contacts my-public-key))
|
||||
|
||||
(defn get-inviter-pk
|
||||
[my-public-key {:keys [membership-updates]}]
|
||||
(->> membership-updates
|
||||
unwrap-events
|
||||
(keep (fn [{:keys [from type members]}]
|
||||
(when (and (= type "members-added")
|
||||
((set members) my-public-key))
|
||||
from)))
|
||||
last))
|
||||
|
||||
(defn get-pending-invite-inviter-name
|
||||
"when the chat is a private group chat in which the user has been
|
||||
invited and didn't accept the invitation yet, return inviter-name"
|
||||
[contacts chat my-public-key]
|
||||
(when (and (models.chat/group-chat? chat)
|
||||
(invited? my-public-key chat)
|
||||
(not (joined? my-public-key chat)))
|
||||
(let [inviter-pk (get-inviter-pk my-public-key chat)]
|
||||
(get-in contacts [inviter-pk :name]
|
||||
(gfycat/generate-gfy inviter-pk)))))
|
|
@ -58,12 +58,10 @@
|
|||
(i18n/label-pluralize cnt :t/members-active))))]])))
|
||||
|
||||
(defview toolbar-content-view []
|
||||
(letsubs [{:keys [group-chat color online contacts
|
||||
(letsubs [{:keys [group-chat color online contacts chat-name
|
||||
public? chat-id] :as chat} [:chats/current-chat]
|
||||
chat-name [:chats/current-chat-name]
|
||||
show-actions? [:chats/current-chat-ui-prop :show-actions?]
|
||||
accounts [:accounts/accounts]
|
||||
contact [:chats/current-chat-contact]
|
||||
sync-state [:sync-state]]
|
||||
(let [has-subtitle? (or group-chat (not= :done sync-state))]
|
||||
[react/view {:style st/toolbar-container}
|
||||
|
|
|
@ -1,60 +1,58 @@
|
|||
(ns status-im.ui.screens.chat.views
|
||||
(:require-macros [status-im.utils.views :refer [defview letsubs]])
|
||||
(:require [clojure.string :as string]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.contact.core :as models.contact]
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.chat.models :as models.chat]
|
||||
[status-im.group-chats.core :as models.group-chats]
|
||||
[status-im.ui.screens.chat.styles.main :as style]
|
||||
[status-im.utils.platform :as platform]
|
||||
[status-im.ui.screens.chat.input.input :as input]
|
||||
[status-im.ui.screens.chat.actions :as actions]
|
||||
[status-im.ui.screens.chat.bottom-info :as bottom-info]
|
||||
[status-im.ui.screens.chat.message.message :as message]
|
||||
[status-im.ui.screens.chat.message.options :as message-options]
|
||||
[status-im.ui.screens.chat.message.datemark :as message-datemark]
|
||||
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]
|
||||
[status-im.ui.screens.chat.toolbar-content :as toolbar-content]
|
||||
[status-im.contact.core :as models.contact]
|
||||
[status-im.group-chats.db :as group-chats.db]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.ui.components.animation :as animation]
|
||||
[status-im.ui.components.button.view :as buttons]
|
||||
[status-im.ui.components.list.views :as list]
|
||||
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]
|
||||
[status-im.ui.components.colors :as colors]
|
||||
[status-im.ui.components.connectivity.view :as connectivity]
|
||||
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
||||
[status-im.ui.components.list-selection :as list-selection]
|
||||
[status-im.ui.components.list.views :as list]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.ui.components.status-bar.view :as status-bar]
|
||||
[status-im.ui.components.connectivity.view :as connectivity]
|
||||
[status-im.ui.components.toolbar.view :as toolbar]
|
||||
[status-im.ui.components.animation :as animation]
|
||||
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
||||
[status-im.ui.components.colors :as colors]
|
||||
[status-im.ui.components.toolbar.actions :as toolbar.actions]
|
||||
[status-im.ui.screens.chat.stickers.views :as stickers]))
|
||||
[status-im.ui.components.toolbar.view :as toolbar]
|
||||
[status-im.ui.screens.chat.actions :as actions]
|
||||
[status-im.ui.screens.chat.bottom-info :as bottom-info]
|
||||
[status-im.ui.screens.chat.input.input :as input]
|
||||
[status-im.ui.screens.chat.message.datemark :as message-datemark]
|
||||
[status-im.ui.screens.chat.message.message :as message]
|
||||
[status-im.ui.screens.chat.message.options :as message-options]
|
||||
[status-im.ui.screens.chat.stickers.views :as stickers]
|
||||
[status-im.ui.screens.chat.styles.main :as style]
|
||||
[status-im.ui.screens.chat.toolbar-content :as toolbar-content]
|
||||
[status-im.utils.platform :as platform])
|
||||
(:require-macros [status-im.utils.views :refer [defview letsubs]]))
|
||||
|
||||
(defview add-contact-bar [contact-identity]
|
||||
(letsubs [{:keys [hide-contact?] :as contact} [:contacts/contact-by-identity]]
|
||||
(when (and (not hide-contact?)
|
||||
(models.contact/can-add-to-contacts? contact))
|
||||
(defn add-contact-bar [public-key]
|
||||
[react/view style/add-contact
|
||||
[react/view style/add-contact-left]
|
||||
[react/touchable-highlight
|
||||
{:on-press #(re-frame/dispatch [:contact.ui/add-to-contact-pressed contact-identity])
|
||||
{:on-press
|
||||
#(re-frame/dispatch [:contact.ui/add-to-contact-pressed public-key])
|
||||
:accessibility-label :add-to-contacts-button}
|
||||
[react/view style/add-contact-center
|
||||
[vector-icons/icon :main-icons/add {:color colors/blue}]
|
||||
[vector-icons/icon :main-icons/add
|
||||
{:color colors/blue}]
|
||||
[react/i18n-text {:style style/add-contact-text :key :add-to-contacts}]]]
|
||||
[react/touchable-highlight
|
||||
{:on-press #(re-frame/dispatch [:contact.ui/close-contact-pressed contact-identity])
|
||||
{:on-press
|
||||
#(re-frame/dispatch [:contact.ui/close-contact-pressed public-key])
|
||||
:accessibility-label :add-to-contacts-close-button}
|
||||
[vector-icons/icon :main-icons/close {:color colors/black
|
||||
:container-style style/add-contact-close-icon}]]])))
|
||||
[vector-icons/icon :main-icons/close
|
||||
{:color colors/black
|
||||
:container-style style/add-contact-close-icon}]]])
|
||||
|
||||
(defn- on-options [chat-id chat-name group-chat? public?]
|
||||
(list-selection/show {:title chat-name
|
||||
:options (actions/actions group-chat? chat-id public?)}))
|
||||
|
||||
(defview chat-toolbar [public? modal?]
|
||||
(letsubs [name [:chats/current-chat-name]
|
||||
{:keys [group-chat chat-id contacts]} [:chats/current-chat]]
|
||||
(letsubs [{:keys [chat-name group-chat chat-id contact]} [:chats/current-chat]]
|
||||
[react/view
|
||||
[status-bar/status-bar (when modal? {:type :modal-white})]
|
||||
[toolbar/platform-agnostic-toolbar {}
|
||||
|
@ -67,10 +65,11 @@
|
|||
[toolbar/actions [{:icon :main-icons/more
|
||||
:icon-opts {:color :black
|
||||
:accessibility-label :chat-menu-button}
|
||||
:handler #(on-options chat-id name group-chat public?)}]])]
|
||||
:handler #(on-options chat-id chat-name group-chat public?)}]])]
|
||||
[connectivity/connectivity-view]
|
||||
(when (and (not group-chat) (first contacts))
|
||||
[add-contact-bar (first contacts)])]))
|
||||
(when (and contact
|
||||
(models.contact/can-add-to-contacts? contact))
|
||||
[add-contact-bar (:public-key contact)])]))
|
||||
|
||||
(defmulti message-row (fn [{{:keys [type]} :row}] type))
|
||||
|
||||
|
@ -108,19 +107,20 @@
|
|||
[react/animated-view {:style (style/message-view-animated opacity)}
|
||||
message-view]]]))
|
||||
|
||||
(defview empty-chat-container [{:keys [group-chat chat-id]}]
|
||||
(letsubs [contact [:contacts/contact-by-identity chat-id]]
|
||||
(let [one-to-one (and (not group-chat)
|
||||
(not (:dapp? contact)))]
|
||||
(defn empty-chat-container
|
||||
[]
|
||||
[react/view style/empty-chat-container
|
||||
(when one-to-one
|
||||
[vector-icons/icon :tiny-icons/tiny-lock])
|
||||
[react/text {:style style/empty-chat-text}
|
||||
(if one-to-one
|
||||
(i18n/label :t/empty-chat-description)]])
|
||||
|
||||
(defn empty-chat-container-one-to-one
|
||||
[contact-name]
|
||||
[react/view style/empty-chat-container
|
||||
[vector-icons/icon :tiny-icons/tiny-lock]
|
||||
[react/text {:style style/empty-chat-text}
|
||||
[react/text style/empty-chat-container-one-to-one
|
||||
(i18n/label :t/empty-chat-description-one-to-one)
|
||||
[react/text {:style style/empty-chat-text-name} (:name contact)]]
|
||||
(i18n/label :t/empty-chat-description))]])))
|
||||
(i18n/label :t/empty-chat-description-one-to-one)]
|
||||
[react/text {:style style/empty-chat-text-name} contact-name]]])
|
||||
|
||||
(defn join-chat-button [chat-id]
|
||||
[buttons/secondary-button {:style style/join-button
|
||||
|
@ -134,11 +134,8 @@
|
|||
[react/text {:style style/decline-chat}
|
||||
(i18n/label :t/group-chat-decline-invitation)]])
|
||||
|
||||
(defview group-chat-join-section [my-public-key {:keys [name
|
||||
group-chat
|
||||
color
|
||||
chat-id] :as chat}]
|
||||
(letsubs [contact [:contacts/contact-by-identity (models.group-chats/get-inviter-pk my-public-key chat)]]
|
||||
(defn group-chat-join-section
|
||||
[inviter-name {:keys [name group-chat color chat-id]}]
|
||||
[react/view style/empty-chat-container
|
||||
[react/view {:style {:margin-bottom 170}}
|
||||
[chat-icon.screen/profile-icon-view nil name color false 100 {:default-chat-icon-text style/group-chat-icon}]]
|
||||
|
@ -148,12 +145,14 @@
|
|||
[react/text {:style style/group-chat-join-name} name]]
|
||||
[react/text {:style style/empty-chat-text}
|
||||
[react/text style/empty-chat-container-one-to-one
|
||||
(i18n/label :t/join-group-chat-description {:username (:name contact)
|
||||
(i18n/label :t/join-group-chat-description {:username inviter-name
|
||||
:group-name name})]]
|
||||
[join-chat-button chat-id]
|
||||
[decline-chat chat-id]]]]))
|
||||
[decline-chat chat-id]]]])
|
||||
|
||||
(defview messages-view [{:keys [group-chat] :as chat} modal?]
|
||||
(defview messages-view
|
||||
[{:keys [group-chat name pending-invite-inviter-name messages-initialized?] :as chat}
|
||||
modal?]
|
||||
(letsubs [messages [:chats/current-chat-messages-stream]
|
||||
current-public-key [:account/public-key]]
|
||||
{:component-did-mount
|
||||
|
@ -164,15 +163,14 @@
|
|||
{:messages-focused? true
|
||||
:input-focused? false}]))}
|
||||
(cond
|
||||
|
||||
(and (models.chat/group-chat? chat)
|
||||
(models.group-chats/invited? current-public-key chat)
|
||||
(not (models.group-chats/joined? current-public-key chat)))
|
||||
[group-chat-join-section current-public-key chat]
|
||||
pending-invite-inviter-name
|
||||
[group-chat-join-section pending-invite-inviter-name chat]
|
||||
|
||||
(and (empty? messages)
|
||||
(:messages-initialized? chat))
|
||||
[empty-chat-container chat]
|
||||
messages-initialized?)
|
||||
(if group-chat
|
||||
[empty-chat-container]
|
||||
[empty-chat-container-one-to-one name])
|
||||
|
||||
:else
|
||||
[list/flat-list {:data messages
|
||||
|
@ -193,7 +191,7 @@
|
|||
|
||||
(defn show-input-container? [my-public-key current-chat]
|
||||
(or (not (models.chat/group-chat? current-chat))
|
||||
(models.group-chats/joined? my-public-key current-chat)))
|
||||
(group-chats.db/joined? my-public-key current-chat)))
|
||||
|
||||
(defview chat-root [modal?]
|
||||
(letsubs [{:keys [public?] :as current-chat} [:chats/current-chat]
|
||||
|
|
|
@ -1,40 +1,35 @@
|
|||
(ns status-im.ui.screens.desktop.main.chat.views
|
||||
(:require-macros [status-im.utils.views :as views])
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.ui.components.icons.vector-icons :as icons]
|
||||
[clojure.string :as string]
|
||||
[status-im.ui.screens.chat.styles.message.message :as message.style]
|
||||
[status-im.ui.screens.chat.message.message :as message]
|
||||
[taoensso.timbre :as log]
|
||||
(:require [clojure.string :as string]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[status-im.chat.models :as models.chat]
|
||||
[status-im.group-chats.core :as models.group-chats]
|
||||
[status-im.ui.screens.chat.utils :as chat-utils]
|
||||
[status-im.utils.gfycat.core :as gfycat]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.utils.identicon :as identicon]
|
||||
[status-im.utils.datetime :as time]
|
||||
[status-im.utils.core :as core-utils]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.ui.components.connectivity.view :as connectivity]
|
||||
[status-im.ui.components.colors :as colors]
|
||||
[status-im.ui.screens.chat.message.datemark :as message.datemark]
|
||||
[status-im.ui.screens.desktop.main.tabs.profile.views :as profile.views]
|
||||
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
||||
[status-im.ui.screens.desktop.main.chat.styles :as styles]
|
||||
[status-im.contact.db :as contact.db]
|
||||
[status-im.ui.screens.chat.views :as views.chat]
|
||||
[status-im.ui.components.popup-menu.views :refer [show-desktop-menu
|
||||
get-chat-menu-items]]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.ui.screens.desktop.main.chat.events :as chat.events]
|
||||
[status-im.ui.screens.chat.message.message :as chat.message]))
|
||||
[status-im.ui.components.colors :as colors]
|
||||
[status-im.ui.components.connectivity.view :as connectivity]
|
||||
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
||||
[status-im.ui.components.popup-menu.views
|
||||
:refer
|
||||
[get-chat-menu-items show-desktop-menu]]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.ui.screens.chat.message.datemark :as message.datemark]
|
||||
[status-im.ui.screens.chat.message.message :as message]
|
||||
[status-im.ui.screens.chat.styles.message.message :as message.style]
|
||||
[status-im.ui.screens.chat.utils :as chat-utils]
|
||||
[status-im.ui.screens.chat.views :as views.chat]
|
||||
[status-im.ui.screens.desktop.main.chat.styles :as styles]
|
||||
[status-im.ui.screens.desktop.main.tabs.profile.views :as profile.views]
|
||||
[status-im.utils.core :as core-utils]
|
||||
[status-im.utils.datetime :as time]
|
||||
[status-im.utils.gfycat.core :as gfycat]
|
||||
[status-im.utils.identicon :as identicon]
|
||||
[status-im.utils.utils :as utils])
|
||||
(:require-macros [status-im.utils.views :as views]))
|
||||
|
||||
(views/defview toolbar-chat-view [{:keys [chat-id color public-key public? group-chat]
|
||||
(defn toolbar-chat-view
|
||||
[{:keys [chat-id chat-name contact color public-key public? group-chat]
|
||||
:as current-chat}]
|
||||
(views/letsubs [chat-name [:chats/current-chat-name]
|
||||
{:keys [pending? public-key photo-path]} [:chats/current-chat-contact]]
|
||||
(let [{:keys [pending? public-key photo-path]} contact]
|
||||
[react/view {:style styles/toolbar-chat-view}
|
||||
[react/view {:style {:flex-direction :row
|
||||
:flex 1}}
|
||||
|
@ -88,7 +83,7 @@
|
|||
(views/letsubs [username [:contacts/contact-name-by-identity from]]
|
||||
[react/view {:style styles/quoted-message-container}
|
||||
[react/view {:style styles/quoted-message-author-container}
|
||||
[icons/icon :tiny-icons/tiny-reply {:style (styles/reply-icon outgoing)
|
||||
[vector-icons/icon :tiny-icons/tiny-reply {:style (styles/reply-icon outgoing)
|
||||
:width 16
|
||||
:height 16
|
||||
:container-style (when outgoing {:opacity 0.4})}]
|
||||
|
@ -262,7 +257,7 @@
|
|||
(.focus @inp-ref)
|
||||
(re-frame/dispatch [:chat.ui/send-current-message])))}
|
||||
[react/view {:style (styles/send-icon inactive?)}
|
||||
[icons/icon :main-icons/arrow-left {:style (styles/send-icon-arrow inactive?)}]]])))
|
||||
[vector-icons/icon :main-icons/arrow-left {:style (styles/send-icon-arrow inactive?)}]]])))
|
||||
|
||||
(views/defview reply-message [from message-text]
|
||||
(views/letsubs [username [:contacts/contact-name-by-identity from]
|
||||
|
@ -290,7 +285,7 @@
|
|||
:on-press #(re-frame/dispatch [:chat.ui/cancel-message-reply])
|
||||
:accessibility-label :cancel-message-reply}
|
||||
[react/view {}
|
||||
[icons/icon :main-icons/close {:style styles/reply-close-icon}]]]])))
|
||||
[vector-icons/icon :main-icons/close {:style styles/reply-close-icon}]]]])))
|
||||
|
||||
(views/defview chat-text-input [chat-id input-text]
|
||||
(views/letsubs [inp-ref (atom nil)
|
||||
|
@ -325,19 +320,15 @@
|
|||
(re-frame/dispatch [:chat.ui/set-chat-input-text text])))}]
|
||||
[send-button inp-ref disconnected?]])))
|
||||
|
||||
(defn not-joined-group-chat? [chat current-public-key]
|
||||
(and (models.chat/group-chat? chat)
|
||||
(models.group-chats/invited? current-public-key chat)
|
||||
(not (models.group-chats/joined? current-public-key chat))))
|
||||
|
||||
(views/defview chat-view []
|
||||
(views/letsubs [{:keys [input-text chat-id] :as current-chat} [:chats/current-chat]
|
||||
(views/letsubs [{:keys [input-text chat-id pending-invite-inviter-name] :as current-chat}
|
||||
[:chats/current-chat]
|
||||
current-public-key [:account/public-key]]
|
||||
|
||||
[react/view {:style styles/chat-view}
|
||||
[toolbar-chat-view current-chat]
|
||||
[react/view {:style styles/separator}]
|
||||
(if (not-joined-group-chat? current-chat current-public-key)
|
||||
(if pending-invite-inviter-name
|
||||
[views.chat/group-chat-join-section current-public-key current-chat]
|
||||
[messages-view current-chat])
|
||||
[react/view {:style styles/separator}]
|
||||
|
|
|
@ -19,15 +19,15 @@
|
|||
[status-im.ui.components.action-button.action-button :as action-button]
|
||||
[status-im.utils.config :as config]))
|
||||
|
||||
(views/defview chat-list-item-inner-view [{:keys [chat-id name group-chat
|
||||
(views/defview chat-list-item-inner-view
|
||||
[{:keys [chat-id name group-chat
|
||||
color public? public-key
|
||||
timestamp
|
||||
timestamp chat-name
|
||||
last-message-content
|
||||
last-message-content-type]
|
||||
:as chat-item}]
|
||||
(views/letsubs [photo-path [:contacts/chat-photo chat-id]
|
||||
unviewed-messages-count [:chats/unviewed-messages-count chat-id]
|
||||
chat-name [:chats/chat-name chat-id]
|
||||
current-chat-id [:chats/current-chat-id]]
|
||||
(let [last-message {:content last-message-content
|
||||
:timestamp timestamp
|
||||
|
|
|
@ -92,13 +92,14 @@
|
|||
:accessibility-label :chat-name-text}
|
||||
chat-name]]]))
|
||||
|
||||
(defview home-list-chat-item-inner-view [{:keys [chat-id name color online
|
||||
(defn home-list-chat-item-inner-view
|
||||
[{:keys [chat-id chat-name
|
||||
name color online
|
||||
group-chat public?
|
||||
public-key
|
||||
timestamp
|
||||
last-message-content
|
||||
last-message-content-type]}]
|
||||
(letsubs [chat-name [:chats/chat-name chat-id]]
|
||||
(let [truncated-chat-name (utils/truncate-str chat-name 30)]
|
||||
[react/touchable-highlight {:on-press #(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id])}
|
||||
[react/view styles/chat-container
|
||||
|
@ -112,7 +113,7 @@
|
|||
[react/view styles/item-lower-container
|
||||
[message-content-text {:content last-message-content
|
||||
:content-type last-message-content-type}]
|
||||
[unviewed-indicator chat-id]]]]])))
|
||||
[unviewed-indicator chat-id]]]]]))
|
||||
|
||||
(defn home-list-browser-item-inner-view [{:keys [dapp url name browser-id] :as browser}]
|
||||
[react/touchable-highlight {:on-press #(re-frame/dispatch [:browser.ui/browser-item-selected browser-id])}
|
||||
|
|
|
@ -127,6 +127,5 @@
|
|||
2 active-chat-2
|
||||
3 {:is-active false :chat-id 3}}]
|
||||
(testing "it returns only chats with is-active"
|
||||
(is (= {1 active-chat-1
|
||||
2 active-chat-2}
|
||||
(s/active-chats {} chats {}))))))
|
||||
(is (= #{1 2}
|
||||
(set (keys (s/active-chats {} chats {}))))))))
|
||||
|
|
Loading…
Reference in New Issue