Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix improper use of current-chat-id and rename subs #18389

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions src/legacy/status_im/group_chats/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@

(rf/defn remove-members
{:events [:group-chats.ui/remove-members-pressed]}
[{{:keys [current-chat-id] :group-chat/keys [deselected-members]} :db :as cofx}]
[{{:group-chat/keys [deselected-members]} :db :as cofx} chat-id]
{:json-rpc/call [{:method "wakuext_removeMembersFromGroupChat"
:params [nil current-chat-id deselected-members]
:params [nil chat-id deselected-members]
:js-response true
:on-success #(re-frame/dispatch [:chat-updated % true])
:on-error #()}]})
Expand Down Expand Up @@ -97,19 +97,19 @@
(rf/defn add-members
"Add members to a group chat"
{:events [:group-chats.ui/add-members-pressed]}
[{{:keys [current-chat-id] :group-chat/keys [selected-participants]} :db :as cofx}]
[{{:group-chat/keys [selected-participants]} :db :as cofx} chat-id]
{:json-rpc/call [{:method "wakuext_addMembersToGroupChat"
:params [nil current-chat-id selected-participants]
:params [nil chat-id selected-participants]
:js-response true
:on-success #(re-frame/dispatch [:chat-updated % true])}]})

(rf/defn add-members-from-invitation
"Add members to a group chat"
{:events [:group-chats.ui/add-members-from-invitation]}
[{{:keys [current-chat-id] :as db} :db :as cofx} id participant]
[{:keys [db]} id participant chat-id]
{:db (assoc-in db [:group-chat/invitations id :state] constants/invitation-state-approved)
:json-rpc/call [{:method "wakuext_addMembersToGroupChat"
:params [nil current-chat-id [participant]]
:params [nil chat-id [participant]]
:js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]})

Expand Down Expand Up @@ -150,23 +150,23 @@

(rf/defn membership-retry
{:events [:group-chats.ui/membership-retry]}
[{{:keys [current-chat-id] :as db} :db}]
{:db (assoc-in db [:chat/memberships current-chat-id :retry?] true)})
[{:keys [db]} chat-id]
{:db (assoc-in db [:chat/memberships chat-id :retry?] true)})

(rf/defn membership-message
{:events [:group-chats.ui/update-membership-message]}
[{{:keys [current-chat-id] :as db} :db} message]
{:db (assoc-in db [:chat/memberships current-chat-id :message] message)})
[{:keys [db]} message chat-id]
{:db (assoc-in db [:chat/memberships chat-id :message] message)})

(rf/defn send-group-chat-membership-request
"Send group chat membership request"
{:events [:send-group-chat-membership-request]}
[{{:keys [current-chat-id chats] :as db} :db :as cofx}]
(let [{:keys [invitation-admin]} (get chats current-chat-id)
message (get-in db [:chat/memberships current-chat-id :message])]
{:db (assoc-in db [:chat/memberships current-chat-id] nil)
[{{:keys [chats] :as db} :db :as cofx} chat-id]
(let [{:keys [invitation-admin]} (get chats chat-id)
message (get-in db [:chat/memberships chat-id :message])]
{:db (assoc-in db [:chat/memberships chat-id] nil)
:json-rpc/call [{:method "wakuext_sendGroupChatInvitationRequest"
:params [nil current-chat-id invitation-admin message]
:params [nil chat-id invitation-admin message]
:js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]}))

Expand Down Expand Up @@ -242,15 +242,6 @@
[{db :db}]
{:db (assoc db :group-chat/deselected-members #{})})

(rf/defn show-group-chat-profile
{:events [:show-group-chat-profile]}
[{:keys [db] :as cofx} chat-id]
(rf/merge cofx
{:db (-> db
(assoc :new-chat-name (get-in db [:chats chat-id :name]))
(assoc :current-chat-id chat-id))}
(navigation/navigate-to :group-chat-profile nil)))

(rf/defn ui-leave-chat-pressed
{:events [:group-chats.ui/leave-chat-pressed]}
[{:keys [db]} chat-id]
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/status_im/ui/screens/chat/group.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(def message-max-length 100)

(defn request-membership
[{:keys [state introduction-message] :as invitation}]
[{:keys [state introduction-message] :as invitation} chat-id]
(let [{:keys [message retry?]} @(re-frame/subscribe [:chats/current-chat-membership])
message-length (count message)]
[react/view {:margin-horizontal 16 :margin-top 10}
Expand Down Expand Up @@ -47,7 +47,7 @@
[react/text (i18n/label :t/introduce-yourself)]
[quo/text-input
{:placeholder (i18n/label :t/message)
:on-change-text #(re-frame/dispatch [:group-chats.ui/update-membership-message %])
:on-change-text #(re-frame/dispatch [:group-chats.ui/update-membership-message % chat-id])
:max-length (if platform/android?
message-max-length
(when (>= message-length message-max-length)
Expand All @@ -63,4 +63,4 @@
[chat-id invitation-admin]
(letsubs [invitations [:group-chat/invitations-by-chat-id chat-id]]
(when invitation-admin
[request-membership (first invitations)])))
[request-membership (first invitations) chat-id])))
2 changes: 1 addition & 1 deletion src/status_im/common/home/actions/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
[chat-id]
(entry {:icon :i/members
:label (i18n/label :t/group-details)
:on-press #(hide-sheet-and-dispatch [:show-group-chat-profile chat-id])
:on-press #(hide-sheet-and-dispatch [:navigate-to :group-chat-profile chat-id])
:danger? false
:accessibility-label :group-details
:sub-label nil
Expand Down
193 changes: 89 additions & 104 deletions src/status_im/contexts/chat/group_details/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,20 @@
:icon-only? true
:container-style {:margin-left 20}
:accessibility-label :back-button
:on-press (fn []
(rf/dispatch [:navigate-back])
(rf/dispatch [:chat/close]))}
:on-press #(rf/dispatch [:navigate-back])}
ibrkhalil marked this conversation as resolved.
Show resolved Hide resolved
:i/arrow-left])

(defn options-button
[]
(let [group (rf/sub [:chats/current-chat])]
[quo/button
{:type :grey
:size 32
:icon-only? true
:container-style {:margin-right 20}
:accessibility-label :options-button
:on-press #(rf/dispatch [:show-bottom-sheet
{:content (fn [] [actions/group-details-actions group])}])}
:i/options]))

(defn top-buttons
[]
[rn/view
{:style {:flex-direction :row
:padding-horizontal 20
:justify-content :space-between}}
[back-button] [options-button]])
[group]
[quo/button
{:type :grey
:size 32
:icon-only? true
:container-style {:margin-right 20}
:accessibility-label :options-button
:on-press #(rf/dispatch [:show-bottom-sheet
{:content (fn [] [actions/group-details-actions group])}])}
:i/options])

(defn count-container
[amount accessibility-label]
Expand Down Expand Up @@ -100,7 +89,8 @@
[]
(let [selected-participants (rf/sub [:group-chat/selected-participants])
deselected-members (rf/sub [:group-chat/deselected-members])
{:keys [admins] :as group} (rf/sub [:chats/current-chat])
chat-id (rf/sub [:get-screen-params :group-chat-profile])
{:keys [admins] :as group} (rf/sub [:chats/chat-by-id chat-id])
admin? (get admins (rf/sub [:multiaccount/public-key]))]
[rn/view {:flex 1 :margin-top 20}
[rn/touchable-opacity
Expand Down Expand Up @@ -130,9 +120,9 @@
(rf/dispatch [:navigate-back])
(js/setTimeout (fn []
(rf/dispatch
[:group-chats.ui/remove-members-pressed]))
[:group-chats.ui/remove-members-pressed chat-id]))
500)
(rf/dispatch [:group-chats.ui/add-members-pressed]))
(rf/dispatch [:group-chats.ui/add-members-pressed chat-id]))
:disabled? (and (zero? (count selected-participants))
(zero? (count deselected-members)))}
(i18n/label :t/save)]]]))
Expand All @@ -151,84 +141,79 @@
:on-press show-profile-actions}})
item]))

(defn f-group-details
[]
(fn []
(rn/use-effect (fn []
#(rf/dispatch [:chat/close])))
ibrkhalil marked this conversation as resolved.
Show resolved Hide resolved
(let [{:keys [admins chat-id chat-name color public?
muted contacts]} (rf/sub [:chats/current-chat])
members (rf/sub [:contacts/group-members-sections])
pinned-messages (rf/sub [:chats/pinned chat-id])
current-pk (rf/sub [:multiaccount/public-key])
admin? (get admins current-pk)]
[rn/view
{:style {:flex 1
:background-color (colors/theme-colors colors/white colors/neutral-95)}}
[quo/header
{:left-component [back-button]
:right-component [options-button]
:background (colors/theme-colors colors/white colors/neutral-95)}]
[rn/view
{:style {:flex-direction :row
:margin-top 24
:padding-horizontal 20}}
[quo/group-avatar
{:customization-color color
:size :size-32}]
[quo/text
{:weight :semi-bold
:size :heading-1
:style {:margin-horizontal 8}} chat-name]
[rn/view {:style {:margin-top 8}}
[quo/icon (if public? :i/world :i/privacy)
{:size 20 :color (colors/theme-colors colors/neutral-50 colors/neutral-40)}]]]
[rn/view {:style (style/actions-view)}
[rn/touchable-opacity
{:style (style/action-container color)
:accessibility-label :pinned-messages
:on-press (fn []
(rf/dispatch [:dismiss-keyboard])
(rf/dispatch [:pin-message/show-pins-bottom-sheet chat-id]))}
[rn/view
{:style {:flex-direction :row
:justify-content :space-between}}
[quo/icon :i/pin {:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[count-container (count pinned-messages) :pinned-count]]
[quo/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium}
(i18n/label :t/pinned-messages)]]
[rn/touchable-opacity
{:style (style/action-container color)
:accessibility-label :toggle-mute
:on-press #(rf/dispatch [:chat.ui/mute chat-id (not muted)
(when-not muted constants/mute-till-unmuted)])}
[quo/icon (if muted :i/muted :i/activity-center)
{:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[quo/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium}
(i18n/label (if muted :unmute-group :mute-group))]]
[rn/touchable-opacity
{:style (style/action-container color)
:accessibility-label :manage-members
:on-press (fn []
(rf/dispatch [:group/clear-added-participants])
(rf/dispatch [:group/clear-removed-members])
(rf/dispatch [:open-modal :group-add-manage-members]))}
[rn/view
{:style {:flex-direction :row
:justify-content :space-between}}
[quo/icon :i/add-user {:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[count-container (count contacts) :members-count]]
[quo/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium}
(i18n/label (if admin? :t/manage-members :t/add-members))]]]
[rn/section-list
{:key-fn :title
:sticky-section-headers-enabled false
:sections members
:render-section-header-fn contacts-section-header
:render-data {:chat-id chat-id
:admin? admin?}
:render-fn contact-item-render}]])))

(defn group-details
[]
[:f> f-group-details])
(let [chat-id (rf/sub [:get-screen-params :group-chat-profile])
{:keys [admins chat-id chat-name color public?
muted contacts]
:as group} (rf/sub [:chats/chat-by-id chat-id])
members (rf/sub [:contacts/group-members-sections chat-id])
pinned-messages (rf/sub [:chats/pinned chat-id])
current-pk (rf/sub [:multiaccount/public-key])
admin? (get admins current-pk)]
[rn/view
{:style {:flex 1
:background-color (colors/theme-colors colors/white colors/neutral-95)}}
[quo/header
{:left-component [back-button]
:right-component [options-button group]
:background (colors/theme-colors colors/white colors/neutral-95)}]
[rn/view
{:style {:flex-direction :row
:margin-top 24
:padding-horizontal 20}}
[quo/group-avatar
{:customization-color color
:size :size-32}]
[quo/text
{:weight :semi-bold
:size :heading-1
:style {:margin-horizontal 8}} chat-name]
[rn/view {:style {:margin-top 8}}
[quo/icon (if public? :i/world :i/privacy)
{:size 20 :color (colors/theme-colors colors/neutral-50 colors/neutral-40)}]]]
[rn/view {:style (style/actions-view)}
[rn/touchable-opacity
{:style (style/action-container color)
:accessibility-label :pinned-messages
:on-press (fn []
(rf/dispatch [:dismiss-keyboard])
(rf/dispatch [:pin-message/show-pins-bottom-sheet chat-id]))}
[rn/view
{:style {:flex-direction :row
:justify-content :space-between}}
[quo/icon :i/pin {:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[count-container (count pinned-messages) :pinned-count]]
[quo/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium}
(i18n/label :t/pinned-messages)]]
[rn/touchable-opacity
{:style (style/action-container color)
:accessibility-label :toggle-mute
:on-press #(rf/dispatch [:chat.ui/mute chat-id (not muted)
(when-not muted constants/mute-till-unmuted)])}
[quo/icon (if muted :i/muted :i/activity-center)
{:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[quo/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium}
(i18n/label (if muted :unmute-group :mute-group))]]
[rn/touchable-opacity
{:style (style/action-container color)
:accessibility-label :manage-members
:on-press (fn []
(rf/dispatch [:group/clear-added-participants])
(rf/dispatch [:group/clear-removed-members])
(rf/dispatch [:open-modal :group-add-manage-members chat-id]))}
[rn/view
{:style {:flex-direction :row
:justify-content :space-between}}
[quo/icon :i/add-user {:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[count-container (count contacts) :members-count]]
[quo/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium}
(i18n/label (if admin? :t/manage-members :t/add-members))]]]
[rn/section-list
{:key-fn :title
:sticky-section-headers-enabled false
:sections members
:render-section-header-fn contacts-section-header
:render-data {:chat-id chat-id
:admin? admin?}
:render-fn contact-item-render}]]))
2 changes: 1 addition & 1 deletion src/status_im/contexts/chat/home/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

(defn chats
[{:keys [theme selected-tab set-scroll-ref scroll-shared-value]}]
(let [unfiltered-items (rf/sub [:chats-stack-items])
(let [unfiltered-items (rf/sub [:chats/chats-stack-items])
items (filter-and-sort-items-by-tab selected-tab unfiltered-items)]
(if (empty? items)
[common.empty-state/view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
[chat-id]
(let [pinned (rf/sub [:chats/pinned-sorted-list chat-id])
render-data (rf/sub [:chats/current-chat-message-list-view-context :in-pinned-view])
current-chat (rf/sub [:chat-by-id chat-id])
current-chat (rf/sub [:chats/chat-by-id chat-id])
{:keys [community-id]} current-chat
community (rf/sub [:communities/community community-id])
community-images (rf/sub [:community/images community-id])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
[chat-id cover-bg-color]
(let [latest-pin-text (rf/sub [:chats/last-pinned-message-text chat-id])
pins-count (rf/sub [:chats/pin-messages-count chat-id])
{:keys [muted muted-till chat-type]} (rf/sub [:chat-by-id chat-id])
{:keys [muted muted-till chat-type]} (rf/sub [:chats/chat-by-id chat-id])
community-channel? (= constants/community-chat-type chat-type)
muted? (and muted (some? muted-till))
mute-chat-label (if community-channel? :t/mute-channel :t/mute-chat)
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/contexts/communities/actions/chat/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

(defn actions
[{:keys [locked? chat-id]} inside-chat?]
(let [{:keys [muted muted-till chat-type]} (rf/sub [:chat-by-id chat-id])]
(let [{:keys [muted muted-till chat-type]} (rf/sub [:chats/chat-by-id chat-id])]
(cond
locked?
[quo/action-drawer
Expand Down
Loading