Skip to content

Commit 3026a9c

Browse files
committed
fixup! WIP
1 parent 5e2d40c commit 3026a9c

File tree

13 files changed

+214
-258
lines changed

13 files changed

+214
-258
lines changed

src/status_im/chat/db.cljs

-53
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,6 @@
1111
[{:keys [public? name]}]
1212
(str (when public? "#") name))
1313

14-
(defn enrich-active-chat
15-
[contacts {:keys [chat-id
16-
identicon
17-
alias
18-
group-chat] :as chat} current-public-key]
19-
(if group-chat
20-
(let [pending-invite-inviter-name
21-
(group-chats.db/get-pending-invite-inviter-name contacts
22-
chat
23-
current-public-key)
24-
inviter-name
25-
(group-chats.db/get-inviter-name contacts
26-
chat
27-
current-public-key)]
28-
(cond-> chat
29-
pending-invite-inviter-name
30-
(assoc :pending-invite-inviter-name pending-invite-inviter-name)
31-
inviter-name
32-
(assoc :inviter-name inviter-name)
33-
:always
34-
(assoc :chat-name (group-chat-name chat))))
35-
(let [photo (if (seq identicon)
36-
identicon
37-
(identicon/identicon chat-id))
38-
alias (if (seq alias)
39-
alias
40-
(gfycat/generate-gfy chat-id))
41-
{contact-name :name :as contact}
42-
(get contacts chat-id
43-
{:public-key chat-id
44-
:identicon photo
45-
:alias alias
46-
:name alias
47-
:system-tags #{}})]
48-
(-> chat
49-
(assoc :contact contact
50-
:chat-name (multiaccounts/displayed-name contact)
51-
:name contact-name
52-
:identicon photo
53-
:alias alias)
54-
(update :tags clojure.set/union (:tags contact))))))
55-
56-
(defn active-chats
57-
[contacts chats {:keys [public-key]}]
58-
(reduce-kv (fn [acc chat-id {:keys [is-active] :as chat}]
59-
(if is-active
60-
(assoc acc
61-
chat-id
62-
(enrich-active-chat contacts chat public-key))
63-
acc))
64-
{}
65-
chats))
66-
6714
(defn datemark? [{:keys [type]}]
6815
(= type :datemark))
6916

src/status_im/group_chats/db.cljs

-18
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,3 @@
2323

2424
(defn group-chat? [chat]
2525
(and (:group-chat chat) (not (:public? chat))))
26-
27-
(defn get-pending-invite-inviter-name
28-
"when the chat is a private group chat in which the user has been
29-
invited and didn't accept the invitation yet, return inviter-name"
30-
[contacts chat my-public-key]
31-
(when (and (group-chat? chat)
32-
(invited? my-public-key chat)
33-
(not (joined? my-public-key chat)))
34-
(let [inviter-pk (get-inviter-pk my-public-key chat)]
35-
(multiaccounts/displayed-name (or (get contacts inviter-pk) {:public-key inviter-pk})))))
36-
37-
(defn get-inviter-name
38-
"when the chat is a private group chat in which the user has been
39-
invited and didn't accept the invitation yet, return inviter-name"
40-
[contacts chat my-public-key]
41-
(when (group-chat? chat)
42-
(let [inviter-pk (get-inviter-pk my-public-key chat)]
43-
(multiaccounts/displayed-name (or (get contacts inviter-pk) {:public-key inviter-pk})))))

src/status_im/subs.cljs

+41-39
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,21 @@
610610

611611
(re-frame/reg-sub
612612
:chats/active-chats
613-
:<- [:contacts/contacts]
614613
:<- [::chats]
615-
:<- [:multiaccount]
616-
(fn [[contacts chats multiaccount]]
617-
(chat.db/active-chats contacts chats multiaccount)))
614+
(fn [chats]
615+
(reduce-kv (fn [acc id {:keys [is-active] :as chat}]
616+
(if is-active
617+
(assoc acc id chat)
618+
acc))
619+
{}
620+
chats)))
621+
622+
(re-frame/reg-sub
623+
::chat
624+
:<- [::chats]
625+
(fn [chats [_ chat-id]]
626+
(get chats chat-id)))
618627

619-
;; TODO: Fix me
620628
(re-frame/reg-sub
621629
:chats/current-raw-chat
622630
:<- [::chats]
@@ -748,9 +756,15 @@
748756
:chats/unread-messages-number
749757
:<- [:chats/active-chats]
750758
(fn [chats _]
751-
(let [grouped-chats (group-by :public? (vals chats))]
752-
{:public (apply + (map :unviewed-messages-count (get grouped-chats true)))
753-
:other (apply + (map :unviewed-messages-count (get grouped-chats false)))})))
759+
(reduce-kv (fn [{:keys [public other]} _ {:keys [unviewed-messages-count public?]}]
760+
(if public?
761+
{:public (+ public unviewed-messages-count)
762+
:other other}
763+
{:other (+ other unviewed-messages-count)
764+
:public public}))
765+
{:public 0
766+
:other 0}
767+
chats)))
754768

755769
(re-frame/reg-sub
756770
:chats/cooldown-enabled?
@@ -803,18 +817,12 @@
803817

804818
(re-frame/reg-sub
805819
:group-chat/inviter-info
806-
(fn []
807-
{:pending-invite-inviter-name "test 1"
808-
:inviter-name "test 2"}))
809-
810-
(re-frame/reg-sub
811-
:group-chat/chat-joined?
812-
:<- [:multiaccount/public-key]
813-
:<- [::chats]
814-
(fn [[my-public-key chats] [_ chat-id]]
815-
(let [current-chat (get chats chat-id)]
816-
(and (chat.models/group-chat? current-chat)
817-
(group-chats.db/joined? my-public-key current-chat)))))
820+
(fn [[_ chat-id] _]
821+
[(re-frame/subscribe [::chat chat-id])
822+
(re-frame/subscribe [:multiaccount/public-key])])
823+
(fn [[chat my-public-key]]
824+
{:joined? (group-chats.db/joined? my-public-key chat)
825+
:inviter-pk (group-chats.db/get-inviter-pk my-public-key chat)}))
818826

819827
(re-frame/reg-sub
820828
:chats/transaction-status
@@ -1559,6 +1567,13 @@
15591567
(fn [contacts [_ identity]]
15601568
(get contacts identity)))
15611569

1570+
(re-frame/reg-sub
1571+
:contacts/contact-added?
1572+
(fn [[_ identity] _]
1573+
[(re-frame/subscribe [:contacts/contact-by-identity identity])])
1574+
(fn [[contact] _]
1575+
(contact.db/added? contact)))
1576+
15621577
(re-frame/reg-sub
15631578
:contacts/contact-name-by-identity
15641579
(fn [[_ identity] _]
@@ -1567,14 +1582,12 @@
15671582
(fn [[db-contact current-multiaccount] [_ identity]]
15681583
(let [me? (= (:public-key current-multiaccount) identity)]
15691584
(if me?
1570-
{:ens-name (:preferred-name current-multiaccount)
1571-
:alias (gfycat/generate-gfy identity)}
1572-
(let [contact (or db-contact
1573-
(contact.db/public-key->new-contact identity))]
1574-
{:ens-name (when (:ens-verified contact)
1575-
(:name contact))
1576-
:alias (or (:alias contact)
1577-
(gfycat/generate-gfy identity))})))))
1585+
(or (:preferred-name current-multiaccount)
1586+
(gfycat/generate-gfy identity))
1587+
(if (and (:ens-verified db-contact) (seq (:name db-contact)))
1588+
(str "@" (:name db-contact))
1589+
(or (:alias db-contact)
1590+
(gfycat/generate-gfy identity)))))))
15781591

15791592
(re-frame/reg-sub
15801593
:messages/quote-info
@@ -1623,17 +1636,6 @@
16231636
(fn [[chat all-contacts] [_ query-fn]]
16241637
(contact.db/query-chat-contacts chat all-contacts query-fn)))
16251638

1626-
(re-frame/reg-sub
1627-
:contacts/chat-photo
1628-
(fn [[_ chat-id] _]
1629-
[(re-frame/subscribe [:chats/chat chat-id])
1630-
(re-frame/subscribe [:contacts/contacts-by-chat filter chat-id])])
1631-
(fn [[chat contacts] [_ _]]
1632-
(when (and chat (not (:group-chat chat)))
1633-
(if (pos? (count contacts))
1634-
(multiaccounts/displayed-photo (first contacts))
1635-
(multiaccounts/displayed-photo chat)))))
1636-
16371639
(re-frame/reg-sub
16381640
:contacts/contact-by-address
16391641
:<- [:contacts/contacts]

src/status_im/ui/components/chat_icon/screen.cljs

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
[status-im.ui.screens.chat.photos :as photos]
99
[status-im.utils.platform :as platform]))
1010

11-
;;TODO REWORK THIS NAMESPACE
12-
1311
(defn default-chat-icon [name styles]
1412
(when-not (string/blank? name)
1513
[react/view (:default-chat-icon styles)
@@ -32,15 +30,16 @@
3230
[react/view online-dot-right]]]])
3331

3432
(defn chat-icon-view
35-
[contact group-chat name styles]
33+
[chat-id group-chat name styles]
3634
[react/view (:container styles)
37-
(if-not group-chat
38-
[photos/photo (multiaccounts/displayed-photo contact) styles]
39-
[default-chat-icon name styles])])
35+
(if group-chat
36+
[default-chat-icon name styles]
37+
(let [photo-path @(re-frame.core/subscribe [:chats/photo-path chat-id])]
38+
[photos/photo photo-path styles]))])
4039

4140
(defn chat-icon-view-toolbar
42-
[contact group-chat name color]
43-
[chat-icon-view contact group-chat name
41+
[chat-id group-chat name color]
42+
[chat-icon-view chat-id group-chat name
4443
{:container styles/container-chat-toolbar
4544
:online-view-wrapper styles/online-view-wrapper
4645
:online-view styles/online-view
@@ -52,8 +51,8 @@
5251
:default-chat-icon-text (styles/default-chat-icon-text 36)}])
5352

5453
(defn chat-icon-view-chat-list
55-
[contact group-chat name color]
56-
[chat-icon-view contact group-chat name
54+
[chat-id group-chat name color]
55+
[chat-icon-view chat-id group-chat name
5756
{:container styles/container-chat-list
5857
:online-view-wrapper styles/online-view-wrapper
5958
:online-view styles/online-view
@@ -65,8 +64,8 @@
6564
:default-chat-icon-text (styles/default-chat-icon-text 40)}])
6665

6766
(defn chat-icon-view-chat-sheet
68-
[contact group-chat name color]
69-
[chat-icon-view contact group-chat name
67+
[chat-id group-chat name color]
68+
[chat-icon-view chat-id group-chat name
7069
{:container styles/container-chat-list
7170
:online-view-wrapper styles/online-view-wrapper
7271
:online-view styles/online-view
@@ -116,11 +115,12 @@
116115
:default-chat-icon (styles/default-chat-icon-profile colors/default-chat-color size)
117116
:default-chat-icon-text (styles/default-chat-icon-text size)}])
118117

119-
(defn chat-intro-icon-view [icon-text chat-id styles]
120-
(let [photo-path (re-frame.core/subscribe [:contacts/chat-photo chat-id])]
121-
(if-not (string/blank? @photo-path)
122-
[photos/photo @photo-path styles]
123-
[default-chat-icon icon-text styles])))
118+
(defn chat-intro-icon-view [icon-text chat-id group-chat styles]
119+
(if group-chat
120+
[default-chat-icon icon-text styles]
121+
(let [photo-path @(re-frame.core/subscribe [:chats/photo-path chat-id])]
122+
(if-not (string/blank? photo-path)
123+
[photos/photo photo-path styles]))))
124124

125125
(defn profile-icon-view [photo-path name color edit? size override-styles]
126126
(let [styles (merge {:container {:width size :height size}

src/status_im/ui/screens/chat/group.cljs

+40-23
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
[react/text {:style style/decline-chat}
2323
(i18n/label :t/group-chat-decline-invitation)]])
2424

25-
(defn group-chat-footer
25+
(defview group-chat-footer
2626
[chat-id]
27-
[react/view {:style style/group-chat-join-footer}
28-
[react/view {:style style/group-chat-join-container}
29-
[join-chat-button chat-id]
30-
[decline-chat chat-id]]])
27+
(letsubs [{:keys [joined?]} [:group-chat/inviter-info chat-id]]
28+
(when-not joined?
29+
[react/view {:style style/group-chat-join-footer}
30+
[react/view {:style style/group-chat-join-container}
31+
[join-chat-button chat-id]
32+
[decline-chat chat-id]]])))
3133

3234
(def group-chat-description-loading
3335
[react/view {:style (merge style/intro-header-description-container
@@ -60,29 +62,44 @@
6062
:t/share-public-chat-text {:link (links/generate-link :public-chat :external chat-id)})})}
6163
(i18n/label :t/empty-chat-description-public-share-this)]]))
6264

65+
(defview pending-invitation-description
66+
[inviter-pk chat-name]
67+
(letsubs [inviter-name [:contacts/contact-name-by-identity inviter-pk]]
68+
[react/nested-text {:style style/intro-header-description}
69+
[{:style {:color colors/black}} inviter-name]
70+
(i18n/label :t/join-group-chat-description
71+
{:username ""
72+
:group-name chat-name})]))
73+
74+
(defview joined-group-chat-description
75+
[inviter-pk chat-name]
76+
(letsubs [inviter-name [:contacts/contact-name-by-identity inviter-pk]]
77+
[react/nested-text {:style style/intro-header-description}
78+
(i18n/label :t/joined-group-chat-description
79+
{:username ""
80+
:group-name chat-name})
81+
[{:style {:color colors/black}} inviter-name]]))
82+
83+
(defn created-group-chat-description [chat-name]
84+
[react/text {:style style/intro-header-description}
85+
(i18n/label :t/created-group-chat-description
86+
{:group-name chat-name})])
87+
6388
(defview group-chat-inviter-description-container [chat-id chat-name]
64-
(letsubs [{:keys [pending-invite-inviter-name
65-
inviter-name]}
89+
(letsubs [{:keys [joined? inviter-pk]}
6690
[:group-chat/inviter-info chat-id]]
67-
(if pending-invite-inviter-name
68-
[react/nested-text {:style style/intro-header-description}
69-
[{:style {:color colors/black}} pending-invite-inviter-name]
70-
(i18n/label :t/join-group-chat-description
71-
{:username ""
72-
:group-name chat-name})]
73-
(if (not= inviter-name "Unknown")
74-
[react/nested-text {:style style/intro-header-description}
75-
(i18n/label :t/joined-group-chat-description
76-
{:username ""
77-
:group-name chat-name})
78-
[{:style {:color colors/black}} inviter-name]]
79-
[react/text {:style style/intro-header-description}
80-
(i18n/label :t/created-group-chat-description
81-
{:group-name chat-name})]))))
91+
(cond
92+
(not joined?)
93+
[pending-invitation-description inviter-pk chat-name]
94+
inviter-pk
95+
[joined-group-chat-description inviter-pk chat-name]
96+
:else
97+
[created-group-chat-description chat-name])))
8298

8399
(defn group-chat-description-container
84100
[{:keys [public?
85101
chat-id
102+
chat-name
86103
loading-messages?
87104
no-messages?]}]
88105
(cond loading-messages?
@@ -92,4 +109,4 @@
92109
[no-messages-group-chat-description-container chat-id]
93110

94111
(not public?)
95-
[group-chat-inviter-description-container chat-id]))
112+
[group-chat-inviter-description-container chat-id chat-name]))

src/status_im/ui/screens/chat/input/input.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
:auto-capitalize :sentences}])
3434

3535
(defview reply-message [from alias message-text]
36-
(letsubs [{:keys [ens-name]} [:contacts/contact-name-by-identity from]
36+
(letsubs [contact-name [:contacts/contact-name-by-identity from]
3737
current-public-key [:multiaccount/public-key]]
3838
[react/scroll-view {:style style/reply-message-content}
3939
[react/view {:style style/reply-message-to-container}
40-
(chat-utils/format-reply-author from alias ens-name current-public-key style/reply-message-author)]
40+
(chat-utils/format-reply-author from contact-name current-public-key style/reply-message-author)]
4141
[react/text {:style (assoc (message-style/style-message-text false) :font-size 14) :number-of-lines 3} message-text]]))
4242

4343
(defview reply-message-view []

src/status_im/ui/screens/chat/message/gap.cljs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121

2222
(views/defview gap
2323
[{:keys [gaps first-gap?]} idx list-ref]
24-
(views/letsubs [{:keys [range intro-status]} [:chats/current-chat]
24+
(views/letsubs [range [:chats/range]
25+
{:keys [might-have-join-time-messages?]} [:chats/current-raw-chat]
2526
in-progress? [:chats/fetching-gap-in-progress?
2627
(if first-gap?
2728
[:first-gap]
2829
(:ids gaps))]
2930
connected? [:mailserver/connected?]]
30-
(let [ids (:ids gaps)
31-
intro-loading? (= intro-status :loading)]
32-
(when-not (and first-gap? intro-loading?)
31+
(let [ids (:ids gaps)]
32+
(when-not (and first-gap? might-have-join-time-messages?)
3333
[react/view {:style style/gap-container}
3434
[react/touchable-highlight
3535
{:on-press (when (and connected? (not in-progress?))

0 commit comments

Comments
 (0)