parent
16bf960e3c
commit
e28add5118
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -55,16 +55,22 @@
|
|||
:style {:backgroundColor "white"
|
||||
:height 56
|
||||
:elevation 2}
|
||||
:actions [{:title "Add Contact to chat"
|
||||
:actions (when (and (:group-chat @chat)
|
||||
(:is-active @chat))
|
||||
[{:title "Add Contact to chat"
|
||||
:icon res/add-icon
|
||||
:showWithText true}
|
||||
{:title "Remove Contact from chat"
|
||||
:icon res/trash-icon
|
||||
:showWithText true}]
|
||||
:showWithText true}
|
||||
{:title "Leave Chat"
|
||||
:icon res/leave-icon
|
||||
:showWithText true}])
|
||||
:onActionSelected (fn [position]
|
||||
(case position
|
||||
0 (dispatch [:show-add-participants navigator])
|
||||
1 (dispatch [:show-remove-participants navigator])))
|
||||
1 (dispatch [:show-remove-participants navigator])
|
||||
2 (dispatch [:leave-group-chat navigator])))
|
||||
:onIconClicked (fn []
|
||||
(nav-pop navigator))}])
|
||||
[list-view {:dataSource datasource
|
||||
|
@ -75,4 +81,5 @@
|
|||
(add-msg-color contact-by-identity))]
|
||||
(r/as-element [chat-message msg])))
|
||||
:style {:backgroundColor "white"}}]
|
||||
[chat-message-new]]))))
|
||||
(when (:is-active @chat)
|
||||
[chat-message-new])]))))
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
|
||||
[syng-im.models.chats :refer [create-chat
|
||||
chat-add-participants
|
||||
chat-remove-participants]]
|
||||
chat-remove-participants
|
||||
set-chat-active]]
|
||||
[syng-im.models.chat :refer [signal-chat-updated
|
||||
set-current-chat-id
|
||||
current-chat-id
|
||||
|
@ -144,6 +145,13 @@
|
|||
:content (str (or remover-name from) " removed " (or removed-name identity))
|
||||
:content-type text-content-type})))
|
||||
|
||||
(defn you-removed-from-group-msg [chat-id from msg-id]
|
||||
(let [remover-name (:name (contacts/contact-by-identity from))]
|
||||
(save-message chat-id {:from "system"
|
||||
:msg-id msg-id
|
||||
:content (str (or remover-name from) " removed you from group chat")
|
||||
:content-type text-content-type})))
|
||||
|
||||
(defn removed-participant-msg [chat-id identity]
|
||||
(let [contact-name (:name (contacts/contact-by-identity identity))]
|
||||
(save-message chat-id {:from "system"
|
||||
|
@ -151,6 +159,12 @@
|
|||
:content (str "You've removed " (or contact-name identity))
|
||||
:content-type text-content-type})))
|
||||
|
||||
(defn left-chat-msg [chat-id]
|
||||
(save-message chat-id {:from "system"
|
||||
:msg-id (random/id)
|
||||
:content "You left this chat"
|
||||
:content-type text-content-type}))
|
||||
|
||||
(register-handler :group-chat-invite-acked
|
||||
(fn [db [action from group-id ack-msg-id]]
|
||||
(log/debug action from group-id ack-msg-id)
|
||||
|
@ -164,6 +178,13 @@
|
|||
(participant-removed-from-group-msg group-id identity from msg-id)
|
||||
(signal-chat-updated db group-id)))
|
||||
|
||||
(register-handler :you-removed-from-group
|
||||
(fn [db [action from group-id msg-id]]
|
||||
(log/debug action msg-id from group-id)
|
||||
(you-removed-from-group-msg group-id from msg-id)
|
||||
(set-chat-active group-id false)
|
||||
(signal-chat-updated db group-id)))
|
||||
|
||||
(register-handler :participant-invited-to-group
|
||||
(fn [db [action from group-id identity msg-id]]
|
||||
(log/debug action msg-id from group-id identity)
|
||||
|
@ -203,6 +224,15 @@
|
|||
(save-message chat-id msg)
|
||||
(signal-chat-updated db chat-id))))
|
||||
|
||||
(register-handler :leave-group-chat
|
||||
(fn [db [action navigator]]
|
||||
(log/debug action)
|
||||
(let [chat-id (current-chat-id db)]
|
||||
(api/leave-group-chat chat-id)
|
||||
(set-chat-active chat-id false)
|
||||
(left-chat-msg chat-id)
|
||||
(signal-chat-updated db chat-id))))
|
||||
|
||||
(register-handler :send-chat-command
|
||||
(fn [db [action chat-id command content]]
|
||||
(log/debug action "chat-id" chat-id "command" command "content" content)
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
:background-color background
|
||||
:text-color text}) identities group-chat-colors)]
|
||||
(r/create :chats {:chat-id chat-id
|
||||
:is-active true
|
||||
:name chat-name
|
||||
:group-chat group-chat?
|
||||
:timestamp (timestamp)
|
||||
|
@ -94,11 +95,18 @@
|
|||
|
||||
(defn active-group-chats []
|
||||
(let [results (-> (r/get-all :chats)
|
||||
(r/filtered "group-chat = true"))]
|
||||
(r/filtered "group-chat = true && is-active = true"))]
|
||||
(->> (.map results (fn [object index collection]
|
||||
(aget object "chat-id")))
|
||||
(js->clj))))
|
||||
|
||||
|
||||
(defn set-chat-active [chat-id active?]
|
||||
(r/write (fn []
|
||||
(-> (r/get-by-field :chats :chat-id chat-id)
|
||||
(r/single)
|
||||
(aset "is-active" active?)))))
|
||||
|
||||
(comment
|
||||
(active-group-chats)
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
:name "string"
|
||||
:group-chat {:type "bool"
|
||||
:indexed true}
|
||||
:is-active "bool"
|
||||
:timestamp "int"
|
||||
:contacts {:type "list"
|
||||
:objectType "chat-contact"}}}]})
|
||||
|
@ -130,22 +131,4 @@
|
|||
|
||||
(comment
|
||||
|
||||
(write #(.create realm "msgs" (clj->js {:msg-id "12"
|
||||
:content "sdfd"
|
||||
:from "sdfsd"
|
||||
:chat-id "56"
|
||||
:content-type "fg"
|
||||
:timestamp 2
|
||||
:outgoing true
|
||||
:to "sfs"
|
||||
:delivery-status "seen"}) true))
|
||||
|
||||
(.addListener realm "change" (fn [& args]
|
||||
(log/debug args)))
|
||||
|
||||
;realm.addListener('change', () => {
|
||||
; // Update UI
|
||||
; ...
|
||||
; });
|
||||
|
||||
)
|
|
@ -36,8 +36,8 @@
|
|||
(dispatch [:participant-invited-to-group from group-id identity msg-id]))
|
||||
:group-removed-participant (let [{:keys [group-id identity from msg-id]} event]
|
||||
(dispatch [:participant-removed-from-group from group-id identity msg-id]))
|
||||
;:removed-from-group (let [{:keys [group-id from]} event]
|
||||
; (add-to-chat "group-chat" ":" (str (shorten from) " removed you from group chat")))
|
||||
:removed-from-group (let [{:keys [group-id from msg-id]} event]
|
||||
(dispatch [:you-removed-from-group from group-id msg-id]))
|
||||
;:participant-left-group (let [{:keys [group-id from]} event]
|
||||
; (add-to-chat "group-chat" ":" (str (shorten from) " left group chat")))
|
||||
;(add-to-chat "chat" ":" (str "Don't know how to handle " event-type))
|
||||
|
|
|
@ -15,3 +15,4 @@
|
|||
(def v (js/require "./images/v.png"))
|
||||
(def add-icon (js/require "./images/add.png"))
|
||||
(def trash-icon (js/require "./images/trash.png"))
|
||||
(def leave-icon (js/require "./images/leave.png"))
|
||||
|
|
|
@ -60,10 +60,13 @@
|
|||
(register-sub :get-current-chat
|
||||
(fn [db _]
|
||||
(let [current-chat-id (-> (current-chat-id @db)
|
||||
(reaction))
|
||||
chat-updated (-> (chat-updated? @db @current-chat-id)
|
||||
(reaction))]
|
||||
(-> (when-let [chat-id @current-chat-id]
|
||||
(chat-by-id chat-id))
|
||||
(reaction)))))
|
||||
(reaction
|
||||
(let [_ @chat-updated]
|
||||
(when-let [chat-id @current-chat-id]
|
||||
(chat-by-id chat-id)))))))
|
||||
|
||||
;; -- User data --------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue