mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 11:34:45 +00:00
Merge develop into group-chat-settings
This commit is contained in:
commit
e93e7724e2
@ -25,15 +25,15 @@
|
|||||||
;; todo: it might be better always return false from
|
;; todo: it might be better always return false from
|
||||||
;; this listener and handle application's closing
|
;; this listener and handle application's closing
|
||||||
;; in handlers
|
;; in handlers
|
||||||
(let [stack (subscribe [:navigation-stack])]
|
(let [stack (subscribe [:get :navigation-stack])]
|
||||||
(when (< 1 (count @stack))
|
(when (< 1 (count @stack))
|
||||||
(dispatch [:navigate-back])
|
(dispatch [:navigate-back])
|
||||||
true)))]
|
true)))]
|
||||||
(add-event-listener "hardwareBackPress" new-listener)))
|
(add-event-listener "hardwareBackPress" new-listener)))
|
||||||
|
|
||||||
(defn app-root []
|
(defn app-root []
|
||||||
(let [signed-up (subscribe [:signed-up])
|
(let [signed-up (subscribe [:get :signed-up])
|
||||||
view-id (subscribe [:view-id])]
|
view-id (subscribe [:get :view-id])]
|
||||||
(fn []
|
(fn []
|
||||||
(case (if @signed-up @view-id :chat)
|
(case (if @signed-up @view-id :chat)
|
||||||
:discovery [discovery]
|
:discovery [discovery]
|
||||||
|
@ -9,10 +9,11 @@
|
|||||||
content-type-command]]
|
content-type-command]]
|
||||||
[syng-im.utils.random :as random]
|
[syng-im.utils.random :as random]
|
||||||
[syng-im.components.react :as r]
|
[syng-im.components.react :as r]
|
||||||
[syng-im.handlers.sign-up :as sign-up-service]
|
[syng-im.chat.sign-up :as sign-up-service]
|
||||||
[syng-im.models.chats :as chats]
|
[syng-im.models.chats :as chats]
|
||||||
[syng-im.navigation.handlers :as nav]
|
[syng-im.navigation.handlers :as nav]
|
||||||
[syng-im.models.chats :as c]))
|
[syng-im.models.chats :as c]
|
||||||
|
[syng-im.utils.handlers :as u]))
|
||||||
|
|
||||||
(register-handler :set-show-actions
|
(register-handler :set-show-actions
|
||||||
(fn [db [_ show-actions]]
|
(fn [db [_ show-actions]]
|
||||||
@ -71,17 +72,18 @@
|
|||||||
((enrich update-command) update-text))
|
((enrich update-command) update-text))
|
||||||
|
|
||||||
(register-handler :send-group-chat-msg
|
(register-handler :send-group-chat-msg
|
||||||
(fn [db [_ chat-id text]]
|
(u/side-effect!
|
||||||
(let [{msg-id :msg-id
|
(fn [_ [_ chat-id text]]
|
||||||
{from :from} :msg} (api/send-group-user-msg {:group-id chat-id
|
(let [{msg-id :msg-id
|
||||||
:content text})
|
{from :from} :msg} (api/send-group-user-msg {:group-id chat-id
|
||||||
msg {:msg-id msg-id
|
:content text})
|
||||||
:from from
|
msg {:msg-id msg-id
|
||||||
:to nil
|
:from from
|
||||||
:content text
|
:to nil
|
||||||
:content-type text-content-type
|
:content text
|
||||||
:outgoing true}]
|
:content-type text-content-type
|
||||||
(messages/save-message chat-id msg))))
|
:outgoing true}]
|
||||||
|
(messages/save-message chat-id msg)))))
|
||||||
|
|
||||||
(defn console? [s]
|
(defn console? [s]
|
||||||
(= "console" s))
|
(= "console" s))
|
||||||
@ -236,7 +238,6 @@
|
|||||||
(fn [db [_ signed-up]]
|
(fn [db [_ signed-up]]
|
||||||
(sign-up-service/set-signed-up db signed-up)))
|
(sign-up-service/set-signed-up db signed-up)))
|
||||||
|
|
||||||
|
|
||||||
(defn load-messages!
|
(defn load-messages!
|
||||||
([db] (load-messages! db nil))
|
([db] (load-messages! db nil))
|
||||||
([db _]
|
([db _]
|
||||||
@ -289,15 +290,9 @@
|
|||||||
((after store-message!))))
|
((after store-message!))))
|
||||||
|
|
||||||
(register-handler :group-received-msg
|
(register-handler :group-received-msg
|
||||||
(fn [db [_ {chat-id :group-id :as msg}]]
|
(u/side-effect!
|
||||||
(messages/save-message chat-id msg)
|
(fn [_ [_ {chat-id :group-id :as msg}]]
|
||||||
db))
|
(messages/save-message chat-id msg))))
|
||||||
|
|
||||||
(defn load-chat!
|
|
||||||
[{:keys [chats current-chat-id] :as db}]
|
|
||||||
(when-not (chats current-chat-id)
|
|
||||||
(c/create-chat {}))
|
|
||||||
db)
|
|
||||||
|
|
||||||
(defmethod nav/preload-data! :chat
|
(defmethod nav/preload-data! :chat
|
||||||
[{:keys [current-chat-id] :as db} [_ _ id]]
|
[{:keys [current-chat-id] :as db} [_ _ id]]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
(ns syng-im.handlers.sign-up
|
(ns syng-im.chat.sign-up
|
||||||
|
;syng-im.handlers.sign-up
|
||||||
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||||
[syng-im.persistence.simple-kv-store :as kv]
|
[syng-im.persistence.simple-kv-store :as kv]
|
||||||
[syng-im.protocol.state.storage :as s]
|
[syng-im.protocol.state.storage :as s]
|
@ -46,18 +46,15 @@
|
|||||||
@username]]
|
@username]]
|
||||||
[view st/menu-items-container
|
[view st/menu-items-container
|
||||||
[menu-item {:name "Profile"
|
[menu-item {:name "Profile"
|
||||||
:handler (fn []
|
:handler #(dispatch [:navigate-to :my-profile])}]
|
||||||
(dispatch [:show-my-profile]))}]
|
|
||||||
[menu-item {:name "Settings"
|
[menu-item {:name "Settings"
|
||||||
:handler (fn []
|
:handler (fn []
|
||||||
;; TODO not implemented
|
;; TODO not implemented
|
||||||
)}]
|
)}]
|
||||||
[menu-item {:name "Discovery"
|
[menu-item {:name "Discovery"
|
||||||
:handler (fn []
|
:handler #(dispatch [:navigate-to :discovery])}]
|
||||||
(dispatch [:navigate-to :discovery]))}]
|
|
||||||
[menu-item {:name "Contacts"
|
[menu-item {:name "Contacts"
|
||||||
:handler (fn []
|
:handler #(dispatch [:show-contacts navigator])}]
|
||||||
(dispatch [:show-contacts navigator]))}]
|
|
||||||
[menu-item {:name "Invite friends"
|
[menu-item {:name "Invite friends"
|
||||||
:handler (fn []
|
:handler (fn []
|
||||||
;; TODO not implemented
|
;; TODO not implemented
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
[syng-im.models.commands :refer [set-commands]]
|
[syng-im.models.commands :refer [set-commands]]
|
||||||
[syng-im.handlers.server :as server]
|
[syng-im.handlers.server :as server]
|
||||||
[syng-im.chat.suggestions :refer [load-commands]]
|
[syng-im.chat.suggestions :refer [load-commands]]
|
||||||
[syng-im.handlers.sign-up :as sign-up-service]
|
|
||||||
[syng-im.models.chats :refer [chat-exists?
|
[syng-im.models.chats :refer [chat-exists?
|
||||||
create-chat
|
create-chat
|
||||||
chat-add-participants
|
chat-add-participants
|
||||||
|
@ -18,29 +18,28 @@
|
|||||||
(keywordize-keys (apply hash-map (split s #"[;=]"))))
|
(keywordize-keys (apply hash-map (split s #"[;=]"))))
|
||||||
|
|
||||||
(defn save-message
|
(defn save-message
|
||||||
[chat-id {:keys [from to msg-id content content-type outgoing
|
;; todo remove chat-id parameter
|
||||||
same-author same-direction]
|
[chat-id {:keys [to msg-id content outgoing]
|
||||||
|
;; outgoing should be explicitely defined in handlers
|
||||||
:or {outgoing false
|
:or {outgoing false
|
||||||
to nil} :as msg}]
|
to nil} :as message}]
|
||||||
(log/debug "save-message" chat-id msg)
|
|
||||||
(when-not (r/exists? :msgs :msg-id msg-id)
|
(when-not (r/exists? :msgs :msg-id msg-id)
|
||||||
(r/write
|
(r/write
|
||||||
(fn []
|
(fn []
|
||||||
(let [content (if (string? content)
|
(let [content' (if (string? content)
|
||||||
content
|
content
|
||||||
(map-to-str content))]
|
(map-to-str content))
|
||||||
(r/create :msgs {:chat-id chat-id
|
message' (merge message
|
||||||
:msg-id msg-id
|
{:chat-id chat-id
|
||||||
:from from
|
:content content'
|
||||||
:to to
|
:timestamp (timestamp)
|
||||||
:content content
|
:delivery-status nil})]
|
||||||
:content-type content-type
|
(r/create :msgs message' true))))))
|
||||||
:outgoing outgoing
|
|
||||||
:timestamp (timestamp)
|
(defn command-type? [type]
|
||||||
:delivery-status nil
|
(contains?
|
||||||
;; TODO 'some?' is temp
|
#{c/content-type-command c/content-type-command-request}
|
||||||
:same-author (some? same-author)
|
type))
|
||||||
:same-direction (some? same-direction)} true))))))
|
|
||||||
|
|
||||||
(defn get-messages [chat-id]
|
(defn get-messages [chat-id]
|
||||||
(->> (-> (r/get-by-field :msgs :chat-id chat-id)
|
(->> (-> (r/get-by-field :msgs :chat-id chat-id)
|
||||||
@ -48,8 +47,7 @@
|
|||||||
(r/collection->map))
|
(r/collection->map))
|
||||||
(into '())
|
(into '())
|
||||||
(map (fn [{:keys [content-type] :as message}]
|
(map (fn [{:keys [content-type] :as message}]
|
||||||
(if (#{c/content-type-command c/content-type-command-request}
|
(if (command-type? content-type)
|
||||||
content-type)
|
|
||||||
(update message :content str-to-map)
|
(update message :content str-to-map)
|
||||||
message)))))
|
message)))))
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
(ns syng-im.navigation.handlers
|
(ns syng-im.navigation.handlers
|
||||||
(:require [re-frame.core :refer [register-handler dispatch debug enrich]]))
|
(:require [re-frame.core :refer [register-handler dispatch debug enrich
|
||||||
|
after]]))
|
||||||
|
|
||||||
(defn push-view [db view-id]
|
(defn push-view [db view-id]
|
||||||
(-> db
|
(-> db
|
||||||
@ -71,14 +72,10 @@
|
|||||||
(push-view :add-participants)
|
(push-view :add-participants)
|
||||||
clear-new-participants)))
|
clear-new-participants)))
|
||||||
|
|
||||||
(register-handler :show-profile
|
(defn show-profile
|
||||||
(debug
|
[db [_ identity]]
|
||||||
(fn [db [_ identity]]
|
(-> db
|
||||||
(let [db (assoc db :contact-identity identity)]
|
(assoc :contact-identity identity)
|
||||||
(dispatch [:navigate-to :profile])
|
(push-view :profile)))
|
||||||
db))))
|
|
||||||
|
|
||||||
(register-handler :show-my-profile
|
(register-handler :show-profile show-profile)
|
||||||
(fn [db _]
|
|
||||||
(dispatch [:navigate-to :my-profile])
|
|
||||||
db))
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
(ns syng-im.navigation.subs
|
|
||||||
(:require-macros [reagent.ratom :refer [reaction]])
|
|
||||||
(:require [re-frame.core :refer [register-sub]]))
|
|
||||||
|
|
||||||
(register-sub :view-id
|
|
||||||
(fn [db _]
|
|
||||||
(reaction (@db :view-id))))
|
|
||||||
|
|
||||||
(register-sub :navigation-stack
|
|
||||||
(fn [db _]
|
|
||||||
(reaction (:navigation-stack @db))))
|
|
@ -3,21 +3,9 @@
|
|||||||
(:require [re-frame.core :refer [register-sub]]
|
(:require [re-frame.core :refer [register-sub]]
|
||||||
syng-im.chat.subs
|
syng-im.chat.subs
|
||||||
syng-im.group-settings.subs
|
syng-im.group-settings.subs
|
||||||
syng-im.navigation.subs
|
|
||||||
syng-im.discovery.subs
|
syng-im.discovery.subs
|
||||||
syng-im.contacts.subs))
|
syng-im.contacts.subs))
|
||||||
|
|
||||||
;; -- Chats list --------------------------------------------------------------
|
|
||||||
|
|
||||||
(register-sub :get
|
(register-sub :get
|
||||||
(fn [db [_ k]]
|
(fn [db [_ k]]
|
||||||
(reaction (k @db))))
|
(reaction (k @db))))
|
||||||
|
|
||||||
;; -- User data --------------------------------------------------------------
|
|
||||||
(register-sub
|
|
||||||
:signed-up
|
|
||||||
(fn [db _]
|
|
||||||
(reaction (:signed-up @db))))
|
|
||||||
|
|
||||||
(register-sub :db
|
|
||||||
(fn [db _] (reaction @db)))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user