|
610 | 610 |
|
611 | 611 | (re-frame/reg-sub
|
612 | 612 | :chats/active-chats
|
613 |
| - :<- [:contacts/contacts] |
614 | 613 | :<- [::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))) |
618 | 627 |
|
619 |
| -;; TODO: Fix me |
620 | 628 | (re-frame/reg-sub
|
621 | 629 | :chats/current-raw-chat
|
622 | 630 | :<- [::chats]
|
|
748 | 756 | :chats/unread-messages-number
|
749 | 757 | :<- [:chats/active-chats]
|
750 | 758 | (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))) |
754 | 768 |
|
755 | 769 | (re-frame/reg-sub
|
756 | 770 | :chats/cooldown-enabled?
|
|
803 | 817 |
|
804 | 818 | (re-frame/reg-sub
|
805 | 819 | :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)})) |
818 | 826 |
|
819 | 827 | (re-frame/reg-sub
|
820 | 828 | :chats/transaction-status
|
|
1559 | 1567 | (fn [contacts [_ identity]]
|
1560 | 1568 | (get contacts identity)))
|
1561 | 1569 |
|
| 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 | + |
1562 | 1577 | (re-frame/reg-sub
|
1563 | 1578 | :contacts/contact-name-by-identity
|
1564 | 1579 | (fn [[_ identity] _]
|
|
1567 | 1582 | (fn [[db-contact current-multiaccount] [_ identity]]
|
1568 | 1583 | (let [me? (= (:public-key current-multiaccount) identity)]
|
1569 | 1584 | (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))))))) |
1578 | 1591 |
|
1579 | 1592 | (re-frame/reg-sub
|
1580 | 1593 | :messages/quote-info
|
|
1623 | 1636 | (fn [[chat all-contacts] [_ query-fn]]
|
1624 | 1637 | (contact.db/query-chat-contacts chat all-contacts query-fn)))
|
1625 | 1638 |
|
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 |
| - |
1637 | 1639 | (re-frame/reg-sub
|
1638 | 1640 | :contacts/contact-by-address
|
1639 | 1641 | :<- [:contacts/contacts]
|
|
0 commit comments