<commit_before>(ns status-im.group-chats.core
  (:refer-clojure :exclude [remove])
  (:require [clojure.spec.alpha :as spec]
            [clojure.string :as string]
            [re-frame.core :as re-frame]
            [status-im.chat.models :as models.chat]
            [status-im.ethereum.json-rpc :as json-rpc]
            [status-im.navigation :as navigation]
            [status-im.utils.fx :as fx]
            [status-im.constants :as constants]
            [status-im.i18n.i18n :as i18n]
            [status-im.notifications-center.core :as notification-center]))

(fx/defn navigate-chat-updated
  {:events [:navigate-chat-updated]}
  [cofx chat-id]
  (when (get-in cofx [:db :chats chat-id])
    (models.chat/navigate-to-chat cofx chat-id)))

(fx/defn handle-chat-removed
  {:events [:chat-removed]}
  [cofx response]
  (fx/merge cofx
            {:dispatch-n [[:sanitize-messages-and-process-response response]
                          [:pop-to-root-tab :chat-stack]]}
            (notification-center/get-activity-center-notifications-count)))

(fx/defn handle-chat-update
  {:events [:chat-updated]}
  [_ response]
  {:dispatch-n [[:sanitize-messages-and-process-response response]
                [:navigate-chat-updated (.-id (aget (.-chats response) 0))]]})

(fx/defn remove-member
  "Format group update message and sign membership"
  {:events [:group-chats.ui/remove-member-pressed]}
  [_ chat-id member]
  {::json-rpc/call [{:method     "wakuext_removeMemberFromGroupChat"
                     :params     [nil chat-id member]
                     :js-response true
                     :on-success #(re-frame/dispatch [:chat-updated %])}]})

(fx/defn join-chat
  {:events [:group-chats.ui/join-pressed]}
  [_ chat-id]
  {::json-rpc/call [{:method     "wakuext_confirmJoiningGroup"
                     :params     [chat-id]
                     :js-response true
                     :on-success #(re-frame/dispatch [:chat-updated %])}]})

(fx/defn create
  {:events [:group-chats.ui/create-pressed]<commit_msg>leave group chat fix (#13463)<commit_after>(ns status-im.group-chats.core
  (:refer-clojure :exclude [remove])
  (:require [clojure.spec.alpha :as spec]
            [clojure.string :as string]
            [re-frame.core :as re-frame]
            [status-im.chat.models :as models.chat]
            [status-im.ethereum.json-rpc :as json-rpc]
            [status-im.navigation :as navigation]
            [status-im.utils.fx :as fx]
            [status-im.constants :as constants]
            [status-im.i18n.i18n :as i18n]
            [status-im.notifications-center.core :as notification-center]))

(fx/defn navigate-chat-updated
  {:events [:navigate-chat-updated]}
  [cofx chat-id]
  (when (get-in cofx [:db :chats chat-id])
    (models.chat/navigate-to-chat cofx chat-id)))

(fx/defn handle-chat-removed
  {:events [:chat-removed]}
  [cofx response]
  (fx/merge cofx
            {:db (dissoc (:db cofx) :current-chat-id)
             :dispatch-n [[:sanitize-messages-and-process-response response]
                          [:pop-to-root-tab :chat-stack]]}
            (notification-center/get-activity-center-notifications-count)))

(fx/defn handle-chat-update
  {:events [:chat-updated]}
  [_ response]
  {:dispatch-n [[:sanitize-messages-and-process-response response]
                [:navigate-chat-updated (.-id (aget (.-chats response) 0))]]})

(fx/defn remove-member
  "Format group update message and sign membership"
  {:events [:group-chats.ui/remove-member-pressed]}
  [_ chat-id member]
  {::json-rpc/call [{:method     "wakuext_removeMemberFromGroupChat"
                     :params     [nil chat-id member]
                     :js-response true
                     :on-success #(re-frame/dispatch [:chat-updated %])}]})

(fx/defn join-chat
  {:events [:group-chats.ui/join-pressed]}
  [_ chat-id]
  {::json-rpc/call [{:method     "wakuext_confirmJoiningGroup"
                     :params     [chat-id]
                     :js-response true
                     :on-success #(re-frame/dispatch [:chat-updated %])}]})

(fx/defn create
  {:events [:group-chats.ui/create-pressed]
{'fraction_non_alphanumeric': 0.15310077519379844, 'fraction_numerical': 0.004602713178294574, 'mean_word_length': 2.316465863453815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5268633', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1382, 'n_words': 254}