mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 03:26:31 +00:00
[#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]
|
[clojure.string :as string]
|
||||||
[status-im.chat.commands.core :as commands]
|
[status-im.chat.commands.core :as commands]
|
||||||
[status-im.chat.commands.input :as commands.input]
|
[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]))
|
[status-im.utils.gfycat.core :as gfycat]))
|
||||||
|
|
||||||
(defn chat-name
|
(defn chat-name
|
||||||
@ -18,16 +18,31 @@
|
|||||||
:else (or contact-name
|
:else (or contact-name
|
||||||
(gfycat/generate-gfy chat-id))))
|
(gfycat/generate-gfy chat-id))))
|
||||||
|
|
||||||
(defn active-chats
|
(defn enrich-active-chat
|
||||||
[contacts chats {:keys [dev-mode?]}]
|
[contacts {:keys [chat-id] :as chat} current-public-key]
|
||||||
(reduce (fn [acc [chat-id {:keys [group-chat public? is-active] :as chat}]]
|
(if-let [contact (get contacts chat-id)]
|
||||||
(if is-active
|
|
||||||
(assoc acc chat-id (if-let [contact (get contacts chat-id)]
|
|
||||||
(-> chat
|
(-> chat
|
||||||
(assoc :name (:name contact))
|
(assoc :contact contact
|
||||||
(assoc :random-name (gfycat/generate-gfy (:public-key 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)))
|
(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))
|
acc))
|
||||||
{}
|
{}
|
||||||
chats))
|
chats))
|
||||||
|
@ -58,27 +58,6 @@
|
|||||||
(fn [[chat-ui-props id]]
|
(fn [[chat-ui-props id]]
|
||||||
(get 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
|
(re-frame/reg-sub
|
||||||
:chats/current-chat-ui-prop
|
:chats/current-chat-ui-prop
|
||||||
:<- [:chats/current-chat-ui-props]
|
:<- [:chats/current-chat-ui-props]
|
||||||
|
@ -68,16 +68,6 @@
|
|||||||
#(contact.db/filter-dapps % dev-mode?)))
|
#(contact.db/filter-dapps % dev-mode?)))
|
||||||
dapps)))
|
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
|
(re-frame/reg-sub
|
||||||
:contacts/dapps-by-name
|
:contacts/dapps-by-name
|
||||||
:<- [:contacts/all-dapps]
|
:<- [:contacts/all-dapps]
|
||||||
|
@ -1,29 +1,25 @@
|
|||||||
(ns status-im.group-chats.core
|
(ns status-im.group-chats.core
|
||||||
(:refer-clojure :exclude [remove])
|
(:refer-clojure :exclude [remove])
|
||||||
(:require [clojure.string :as string]
|
(:require [clojure.set :as clojure.set]
|
||||||
[clojure.spec.alpha :as spec]
|
[clojure.spec.alpha :as spec]
|
||||||
[clojure.set :as clojure.set]
|
[clojure.string :as string]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.accounts.db :as accounts.db]
|
||||||
[status-im.constants :as constants]
|
[status-im.chat.models :as models.chat]
|
||||||
[status-im.utils.config :as config]
|
|
||||||
[status-im.utils.clocks :as utils.clocks]
|
|
||||||
[status-im.chat.models.message :as models.message]
|
[status-im.chat.models.message :as models.message]
|
||||||
[status-im.contact.core :as models.contact]
|
[status-im.contact.core :as models.contact]
|
||||||
[status-im.contact-code.core :as contact-code]
|
[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.native-module.core :as native-module]
|
||||||
[status-im.transport.utils :as transport.utils]
|
[status-im.transport.chat.core :as transport.chat]
|
||||||
[status-im.transport.db :as transport.db]
|
|
||||||
[status-im.transport.utils :as transport.utils]
|
|
||||||
[status-im.transport.message.protocol :as protocol]
|
|
||||||
[status-im.transport.message.group-chat :as message.group-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.message.public-chat :as transport.public-chat]
|
||||||
[status-im.transport.partitioned-topic :as transport.topic]
|
[status-im.transport.partitioned-topic :as transport.topic]
|
||||||
[status-im.transport.chat.core :as transport.chat]
|
[status-im.utils.clocks :as utils.clocks]
|
||||||
[status-im.utils.fx :as fx]
|
[status-im.utils.config :as config]
|
||||||
[status-im.chat.models :as models.chat]
|
[status-im.utils.fx :as fx]))
|
||||||
[status-im.accounts.db :as accounts.db]
|
|
||||||
[status-im.transport.message.transit :as transit]))
|
|
||||||
|
|
||||||
;; Description of the flow:
|
;; 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.
|
;; 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
|
first
|
||||||
:from))
|
: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]
|
(defn creator? [public-key chat]
|
||||||
(= public-key (extract-creator chat)))
|
(= public-key (extract-creator chat)))
|
||||||
|
|
||||||
(defn invited? [my-public-key {:keys [contacts]}]
|
|
||||||
(contains? contacts my-public-key))
|
|
||||||
|
|
||||||
(defn signature-material
|
(defn signature-material
|
||||||
"Transform an update into a signable string"
|
"Transform an update into a signable string"
|
||||||
[chat-id events]
|
[chat-id events]
|
||||||
@ -145,7 +130,7 @@
|
|||||||
destinations (map (fn [member]
|
destinations (map (fn [member]
|
||||||
(if (and
|
(if (and
|
||||||
config/group-chats-publish-to-topic?
|
config/group-chats-publish-to-topic?
|
||||||
(joined-event? member chat)
|
(group-chats.db/joined-event? member chat)
|
||||||
(not= creator member)
|
(not= creator member)
|
||||||
(not= current-public-key member))
|
(not= current-public-key member))
|
||||||
{:public-key member
|
{:public-key member
|
||||||
@ -467,23 +452,6 @@
|
|||||||
(membership-changes->system-messages cofx clock-values)
|
(membership-changes->system-messages cofx clock-values)
|
||||||
(models.message/add-system-messages cofx)))))
|
(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
|
(fx/defn set-up-topic
|
||||||
"Listen/Tear down the shared topic/contact-codes. Stop listening for members who
|
"Listen/Tear down the shared topic/contact-codes. Stop listening for members who
|
||||||
have left the chat"
|
have left the chat"
|
||||||
@ -491,8 +459,8 @@
|
|||||||
(let [my-public-key (accounts.db/current-public-key cofx)
|
(let [my-public-key (accounts.db/current-public-key cofx)
|
||||||
new-chat (get-in cofx [:db :chats chat-id])]
|
new-chat (get-in cofx [:db :chats chat-id])]
|
||||||
;; If we left the chat, teardown, otherwise upsert
|
;; If we left the chat, teardown, otherwise upsert
|
||||||
(if (and (joined? my-public-key previous-chat)
|
(if (and (group-chats.db/joined? my-public-key previous-chat)
|
||||||
(not (joined? my-public-key new-chat)))
|
(not (group-chats.db/joined? my-public-key new-chat)))
|
||||||
(apply fx/merge
|
(apply fx/merge
|
||||||
cofx
|
cofx
|
||||||
(conj
|
(conj
|
||||||
@ -524,7 +492,7 @@
|
|||||||
all-updates (clojure.set/union (set (:membership-updates previous-chat))
|
all-updates (clojure.set/union (set (:membership-updates previous-chat))
|
||||||
(set (:membership-updates membership-update)))
|
(set (:membership-updates membership-update)))
|
||||||
my-public-key (accounts.db/current-public-key cofx)
|
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)
|
new-group (build-group unwrapped-events)
|
||||||
member? (contains? (:contacts new-group) my-public-key)]
|
member? (contains? (:contacts new-group) my-public-key)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
|
46
src/status_im/group_chats/db.cljs
Normal file
46
src/status_im/group_chats/db.cljs
Normal file
@ -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))))]])))
|
(i18n/label-pluralize cnt :t/members-active))))]])))
|
||||||
|
|
||||||
(defview toolbar-content-view []
|
(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]
|
public? chat-id] :as chat} [:chats/current-chat]
|
||||||
chat-name [:chats/current-chat-name]
|
|
||||||
show-actions? [:chats/current-chat-ui-prop :show-actions?]
|
show-actions? [:chats/current-chat-ui-prop :show-actions?]
|
||||||
accounts [:accounts/accounts]
|
accounts [:accounts/accounts]
|
||||||
contact [:chats/current-chat-contact]
|
|
||||||
sync-state [:sync-state]]
|
sync-state [:sync-state]]
|
||||||
(let [has-subtitle? (or group-chat (not= :done sync-state))]
|
(let [has-subtitle? (or group-chat (not= :done sync-state))]
|
||||||
[react/view {:style st/toolbar-container}
|
[react/view {:style st/toolbar-container}
|
||||||
|
@ -1,60 +1,58 @@
|
|||||||
(ns status-im.ui.screens.chat.views
|
(ns status-im.ui.screens.chat.views
|
||||||
(:require-macros [status-im.utils.views :refer [defview letsubs]])
|
(:require [re-frame.core :as re-frame]
|
||||||
(:require [clojure.string :as string]
|
|
||||||
[re-frame.core :as re-frame]
|
|
||||||
[status-im.i18n :as i18n]
|
|
||||||
[status-im.contact.core :as models.contact]
|
|
||||||
[status-im.chat.models :as models.chat]
|
[status-im.chat.models :as models.chat]
|
||||||
[status-im.group-chats.core :as models.group-chats]
|
[status-im.contact.core :as models.contact]
|
||||||
[status-im.ui.screens.chat.styles.main :as style]
|
[status-im.group-chats.db :as group-chats.db]
|
||||||
[status-im.utils.platform :as platform]
|
[status-im.i18n :as i18n]
|
||||||
[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.ui.components.animation :as animation]
|
[status-im.ui.components.animation :as animation]
|
||||||
[status-im.ui.components.button.view :as buttons]
|
[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-selection :as list-selection]
|
||||||
|
[status-im.ui.components.list.views :as list]
|
||||||
[status-im.ui.components.react :as react]
|
[status-im.ui.components.react :as react]
|
||||||
[status-im.ui.components.status-bar.view :as status-bar]
|
[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.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]
|
(defn add-contact-bar [public-key]
|
||||||
(letsubs [{:keys [hide-contact?] :as contact} [:contacts/contact-by-identity]]
|
|
||||||
(when (and (not hide-contact?)
|
|
||||||
(models.contact/can-add-to-contacts? contact))
|
|
||||||
[react/view style/add-contact
|
[react/view style/add-contact
|
||||||
[react/view style/add-contact-left]
|
[react/view style/add-contact-left]
|
||||||
[react/touchable-highlight
|
[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}
|
:accessibility-label :add-to-contacts-button}
|
||||||
[react/view style/add-contact-center
|
[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/i18n-text {:style style/add-contact-text :key :add-to-contacts}]]]
|
||||||
[react/touchable-highlight
|
[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}
|
:accessibility-label :add-to-contacts-close-button}
|
||||||
[vector-icons/icon :main-icons/close {:color colors/black
|
[vector-icons/icon :main-icons/close
|
||||||
:container-style style/add-contact-close-icon}]]])))
|
{:color colors/black
|
||||||
|
:container-style style/add-contact-close-icon}]]])
|
||||||
|
|
||||||
(defn- on-options [chat-id chat-name group-chat? public?]
|
(defn- on-options [chat-id chat-name group-chat? public?]
|
||||||
(list-selection/show {:title chat-name
|
(list-selection/show {:title chat-name
|
||||||
:options (actions/actions group-chat? chat-id public?)}))
|
:options (actions/actions group-chat? chat-id public?)}))
|
||||||
|
|
||||||
(defview chat-toolbar [public? modal?]
|
(defview chat-toolbar [public? modal?]
|
||||||
(letsubs [name [:chats/current-chat-name]
|
(letsubs [{:keys [chat-name group-chat chat-id contact]} [:chats/current-chat]]
|
||||||
{:keys [group-chat chat-id contacts]} [:chats/current-chat]]
|
|
||||||
[react/view
|
[react/view
|
||||||
[status-bar/status-bar (when modal? {:type :modal-white})]
|
[status-bar/status-bar (when modal? {:type :modal-white})]
|
||||||
[toolbar/platform-agnostic-toolbar {}
|
[toolbar/platform-agnostic-toolbar {}
|
||||||
@ -67,10 +65,11 @@
|
|||||||
[toolbar/actions [{:icon :main-icons/more
|
[toolbar/actions [{:icon :main-icons/more
|
||||||
:icon-opts {:color :black
|
:icon-opts {:color :black
|
||||||
:accessibility-label :chat-menu-button}
|
: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]
|
[connectivity/connectivity-view]
|
||||||
(when (and (not group-chat) (first contacts))
|
(when (and contact
|
||||||
[add-contact-bar (first contacts)])]))
|
(models.contact/can-add-to-contacts? contact))
|
||||||
|
[add-contact-bar (:public-key contact)])]))
|
||||||
|
|
||||||
(defmulti message-row (fn [{{:keys [type]} :row}] type))
|
(defmulti message-row (fn [{{:keys [type]} :row}] type))
|
||||||
|
|
||||||
@ -108,19 +107,20 @@
|
|||||||
[react/animated-view {:style (style/message-view-animated opacity)}
|
[react/animated-view {:style (style/message-view-animated opacity)}
|
||||||
message-view]]]))
|
message-view]]]))
|
||||||
|
|
||||||
(defview empty-chat-container [{:keys [group-chat chat-id]}]
|
(defn empty-chat-container
|
||||||
(letsubs [contact [:contacts/contact-by-identity chat-id]]
|
[]
|
||||||
(let [one-to-one (and (not group-chat)
|
|
||||||
(not (:dapp? contact)))]
|
|
||||||
[react/view style/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}
|
[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
|
[react/text style/empty-chat-container-one-to-one
|
||||||
(i18n/label :t/empty-chat-description-one-to-one)
|
(i18n/label :t/empty-chat-description-one-to-one)]
|
||||||
[react/text {:style style/empty-chat-text-name} (:name contact)]]
|
[react/text {:style style/empty-chat-text-name} contact-name]]])
|
||||||
(i18n/label :t/empty-chat-description))]])))
|
|
||||||
|
|
||||||
(defn join-chat-button [chat-id]
|
(defn join-chat-button [chat-id]
|
||||||
[buttons/secondary-button {:style style/join-button
|
[buttons/secondary-button {:style style/join-button
|
||||||
@ -134,11 +134,8 @@
|
|||||||
[react/text {:style style/decline-chat}
|
[react/text {:style style/decline-chat}
|
||||||
(i18n/label :t/group-chat-decline-invitation)]])
|
(i18n/label :t/group-chat-decline-invitation)]])
|
||||||
|
|
||||||
(defview group-chat-join-section [my-public-key {:keys [name
|
(defn group-chat-join-section
|
||||||
group-chat
|
[inviter-name {:keys [name group-chat color chat-id]}]
|
||||||
color
|
|
||||||
chat-id] :as chat}]
|
|
||||||
(letsubs [contact [:contacts/contact-by-identity (models.group-chats/get-inviter-pk my-public-key chat)]]
|
|
||||||
[react/view style/empty-chat-container
|
[react/view style/empty-chat-container
|
||||||
[react/view {:style {:margin-bottom 170}}
|
[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}]]
|
[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/group-chat-join-name} name]]
|
||||||
[react/text {:style style/empty-chat-text}
|
[react/text {:style style/empty-chat-text}
|
||||||
[react/text style/empty-chat-container-one-to-one
|
[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})]]
|
:group-name name})]]
|
||||||
[join-chat-button chat-id]
|
[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]
|
(letsubs [messages [:chats/current-chat-messages-stream]
|
||||||
current-public-key [:account/public-key]]
|
current-public-key [:account/public-key]]
|
||||||
{:component-did-mount
|
{:component-did-mount
|
||||||
@ -164,15 +163,14 @@
|
|||||||
{:messages-focused? true
|
{:messages-focused? true
|
||||||
:input-focused? false}]))}
|
:input-focused? false}]))}
|
||||||
(cond
|
(cond
|
||||||
|
pending-invite-inviter-name
|
||||||
(and (models.chat/group-chat? chat)
|
[group-chat-join-section pending-invite-inviter-name 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]
|
|
||||||
|
|
||||||
(and (empty? messages)
|
(and (empty? messages)
|
||||||
(:messages-initialized? chat))
|
messages-initialized?)
|
||||||
[empty-chat-container chat]
|
(if group-chat
|
||||||
|
[empty-chat-container]
|
||||||
|
[empty-chat-container-one-to-one name])
|
||||||
|
|
||||||
:else
|
:else
|
||||||
[list/flat-list {:data messages
|
[list/flat-list {:data messages
|
||||||
@ -193,7 +191,7 @@
|
|||||||
|
|
||||||
(defn show-input-container? [my-public-key current-chat]
|
(defn show-input-container? [my-public-key current-chat]
|
||||||
(or (not (models.chat/group-chat? 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?]
|
(defview chat-root [modal?]
|
||||||
(letsubs [{:keys [public?] :as current-chat} [:chats/current-chat]
|
(letsubs [{:keys [public?] :as current-chat} [:chats/current-chat]
|
||||||
|
@ -1,40 +1,35 @@
|
|||||||
(ns status-im.ui.screens.desktop.main.chat.views
|
(ns status-im.ui.screens.desktop.main.chat.views
|
||||||
(:require-macros [status-im.utils.views :as views])
|
(:require [clojure.string :as string]
|
||||||
(:require [re-frame.core :as re-frame]
|
[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]
|
|
||||||
[reagent.core :as reagent]
|
[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.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.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.i18n :as i18n]
|
||||||
[status-im.ui.screens.desktop.main.chat.events :as chat.events]
|
[status-im.ui.components.colors :as colors]
|
||||||
[status-im.ui.screens.chat.message.message :as chat.message]))
|
[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}]
|
:as current-chat}]
|
||||||
(views/letsubs [chat-name [:chats/current-chat-name]
|
(let [{:keys [pending? public-key photo-path]} contact]
|
||||||
{:keys [pending? public-key photo-path]} [:chats/current-chat-contact]]
|
|
||||||
[react/view {:style styles/toolbar-chat-view}
|
[react/view {:style styles/toolbar-chat-view}
|
||||||
[react/view {:style {:flex-direction :row
|
[react/view {:style {:flex-direction :row
|
||||||
:flex 1}}
|
:flex 1}}
|
||||||
@ -88,7 +83,7 @@
|
|||||||
(views/letsubs [username [:contacts/contact-name-by-identity from]]
|
(views/letsubs [username [:contacts/contact-name-by-identity from]]
|
||||||
[react/view {:style styles/quoted-message-container}
|
[react/view {:style styles/quoted-message-container}
|
||||||
[react/view {:style styles/quoted-message-author-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
|
:width 16
|
||||||
:height 16
|
:height 16
|
||||||
:container-style (when outgoing {:opacity 0.4})}]
|
:container-style (when outgoing {:opacity 0.4})}]
|
||||||
@ -262,7 +257,7 @@
|
|||||||
(.focus @inp-ref)
|
(.focus @inp-ref)
|
||||||
(re-frame/dispatch [:chat.ui/send-current-message])))}
|
(re-frame/dispatch [:chat.ui/send-current-message])))}
|
||||||
[react/view {:style (styles/send-icon inactive?)}
|
[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/defview reply-message [from message-text]
|
||||||
(views/letsubs [username [:contacts/contact-name-by-identity from]
|
(views/letsubs [username [:contacts/contact-name-by-identity from]
|
||||||
@ -290,7 +285,7 @@
|
|||||||
:on-press #(re-frame/dispatch [:chat.ui/cancel-message-reply])
|
:on-press #(re-frame/dispatch [:chat.ui/cancel-message-reply])
|
||||||
:accessibility-label :cancel-message-reply}
|
:accessibility-label :cancel-message-reply}
|
||||||
[react/view {}
|
[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/defview chat-text-input [chat-id input-text]
|
||||||
(views/letsubs [inp-ref (atom nil)
|
(views/letsubs [inp-ref (atom nil)
|
||||||
@ -325,19 +320,15 @@
|
|||||||
(re-frame/dispatch [:chat.ui/set-chat-input-text text])))}]
|
(re-frame/dispatch [:chat.ui/set-chat-input-text text])))}]
|
||||||
[send-button inp-ref disconnected?]])))
|
[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/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]]
|
current-public-key [:account/public-key]]
|
||||||
|
|
||||||
[react/view {:style styles/chat-view}
|
[react/view {:style styles/chat-view}
|
||||||
[toolbar-chat-view current-chat]
|
[toolbar-chat-view current-chat]
|
||||||
[react/view {:style styles/separator}]
|
[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]
|
[views.chat/group-chat-join-section current-public-key current-chat]
|
||||||
[messages-view current-chat])
|
[messages-view current-chat])
|
||||||
[react/view {:style styles/separator}]
|
[react/view {:style styles/separator}]
|
||||||
|
@ -19,15 +19,15 @@
|
|||||||
[status-im.ui.components.action-button.action-button :as action-button]
|
[status-im.ui.components.action-button.action-button :as action-button]
|
||||||
[status-im.utils.config :as config]))
|
[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
|
color public? public-key
|
||||||
timestamp
|
timestamp chat-name
|
||||||
last-message-content
|
last-message-content
|
||||||
last-message-content-type]
|
last-message-content-type]
|
||||||
:as chat-item}]
|
:as chat-item}]
|
||||||
(views/letsubs [photo-path [:contacts/chat-photo chat-id]
|
(views/letsubs [photo-path [:contacts/chat-photo chat-id]
|
||||||
unviewed-messages-count [:chats/unviewed-messages-count 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]]
|
current-chat-id [:chats/current-chat-id]]
|
||||||
(let [last-message {:content last-message-content
|
(let [last-message {:content last-message-content
|
||||||
:timestamp timestamp
|
:timestamp timestamp
|
||||||
|
@ -92,13 +92,14 @@
|
|||||||
:accessibility-label :chat-name-text}
|
:accessibility-label :chat-name-text}
|
||||||
chat-name]]]))
|
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?
|
group-chat public?
|
||||||
public-key
|
public-key
|
||||||
timestamp
|
timestamp
|
||||||
last-message-content
|
last-message-content
|
||||||
last-message-content-type]}]
|
last-message-content-type]}]
|
||||||
(letsubs [chat-name [:chats/chat-name chat-id]]
|
|
||||||
(let [truncated-chat-name (utils/truncate-str chat-name 30)]
|
(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/touchable-highlight {:on-press #(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id])}
|
||||||
[react/view styles/chat-container
|
[react/view styles/chat-container
|
||||||
@ -112,7 +113,7 @@
|
|||||||
[react/view styles/item-lower-container
|
[react/view styles/item-lower-container
|
||||||
[message-content-text {:content last-message-content
|
[message-content-text {:content last-message-content
|
||||||
:content-type last-message-content-type}]
|
: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}]
|
(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])}
|
[react/touchable-highlight {:on-press #(re-frame/dispatch [:browser.ui/browser-item-selected browser-id])}
|
||||||
|
@ -127,6 +127,5 @@
|
|||||||
2 active-chat-2
|
2 active-chat-2
|
||||||
3 {:is-active false :chat-id 3}}]
|
3 {:is-active false :chat-id 3}}]
|
||||||
(testing "it returns only chats with is-active"
|
(testing "it returns only chats with is-active"
|
||||||
(is (= {1 active-chat-1
|
(is (= #{1 2}
|
||||||
2 active-chat-2}
|
(set (keys (s/active-chats {} chats {}))))))))
|
||||||
(s/active-chats {} chats {}))))))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user