participant added to chat

Former-commit-id: 16f00678fa
This commit is contained in:
michaelr 2016-04-11 16:45:01 +03:00
parent b2d5321104
commit 7db7f9be5d
3 changed files with 23 additions and 10 deletions

View File

@ -116,18 +116,32 @@
(signal-chat-updated db chat-id))) (signal-chat-updated db chat-id)))
(defn joined-chat-msg [chat-id from msg-id] (defn joined-chat-msg [chat-id from msg-id]
(let [contact-name (:name (contacts/contatct-by-identity from))] (let [contact-name (:name (contacts/contact-by-identity from))]
(save-message chat-id {:from "system" (save-message chat-id {:from "system"
:msg-id msg-id :msg-id msg-id
:content (str (or contact-name from) " received chat invitation") :content (str (or contact-name from) " received chat invitation")
:content-type text-content-type}))) :content-type text-content-type})))
(defn participant-invited-to-group-msg [chat-id identity from msg-id]
(let [inviter-name (:name (contacts/contact-by-identity from))
invitee-name (:name (contacts/contact-by-identity identity))]
(save-message chat-id {:from "system"
:msg-id msg-id
:content (str (or inviter-name from) " invited " (or invitee-name identity))
:content-type text-content-type})))
(register-handler :group-chat-invite-acked (register-handler :group-chat-invite-acked
(fn [db [action from group-id ack-msg-id]] (fn [db [action from group-id ack-msg-id]]
(log/debug action from group-id ack-msg-id) (log/debug action from group-id ack-msg-id)
(joined-chat-msg group-id from ack-msg-id) (joined-chat-msg group-id from ack-msg-id)
(signal-chat-updated db group-id))) (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)
(participant-invited-to-group-msg group-id identity from msg-id)
(signal-chat-updated db group-id)))
(register-handler :acked-msg (register-handler :acked-msg
(fn [db [action from msg-id]] (fn [db [action from msg-id]]
(log/debug action from msg-id) (log/debug action from msg-id)
@ -137,7 +151,7 @@
(register-handler :msg-delivery-failed (register-handler :msg-delivery-failed
(fn [db [action msg-id]] (fn [db [action msg-id]]
(log/debug action from msg-id) (log/debug action msg-id)
(update-message! {:msg-id msg-id (update-message! {:msg-id msg-id
:delivery-status :failed}) :delivery-status :failed})
(let [{:keys [chat-id]} (message-by-id msg-id)] (let [{:keys [chat-id]} (message-by-id msg-id)]

View File

@ -101,29 +101,29 @@
(r/filtered exclude-query) (r/filtered exclude-query)
(r/sorted :name :asc)))) (r/sorted :name :asc))))
(defn contatct-by-identity [identity] (defn contact-by-identity [identity]
(-> (r/get-by-field :contacts :whisper-identity identity) (-> (r/get-by-field :contacts :whisper-identity identity)
(r/single-cljs))) (r/single-cljs)))
(comment (comment
(r/write #(create-contact {:phone-number "0543072333" (r/write #(create-contact {:phone-number "0543072333"
:whisper-identity "0x045326d94f999c3e17d11d6a09e13cf9a34b30f62687a970053887b8f8d1fefac3f185e6ba6f02f8217b6947227c7dbfa8d4ee3a4a2864b0cac9968c819ba9c17c" :whisper-identity "0x043e3a8344049fb48fef030084212a9d41577a5dea18aeb4c8f285c16f783aa84e43f84c32eb8601e22827b12d5f93f14e545f9023034a0521dc18484bbbc44704"
:name "Mr. Bean" :name "Mr. Bean"
:photo-path ""})) :photo-path ""}))
(r/write #(create-contact {:phone-number "0544828649" (r/write #(create-contact {:phone-number "0544828649"
:whisper-identity "0x0496152b9bb6640fddb3a156747baa961792762264ab459c8d7c9ac179ddceb2abb701357a9b6691ef858ef8ce2eb306754825b8267add96e7a01d854a576b9fda" :whisper-identity "0x04e9b01298dd12c4d8f0393d7890302b25762966d825158d1fdffe124703c0efcd7f23a6cf71c466ca50b2af3d54264ea5f224a19ba7775779c1ddbcb237258c5c"
:name "Mr. Batman" :name "Mr. Batman"
:photo-path ""})) :photo-path ""}))
(r/write #(create-contact {:phone-number "0522222222" (r/write #(create-contact {:phone-number "0522222222"
:whisper-identity "0x04ef1f45303a14cb30af0458fabc2c7b1fd1bc9bb69fae5bb4ec63ae5b52cd53c2a194398b6674cc335899bbf6a24bfe48813a134ce9b8b85877690c1a99f0b19f" :whisper-identity "0x0487954e7fa746d8cf787403c2c491aadad540b9bb1f0f7b8184792e91c33b6a394079295f5777ec6d4af9ad5ba24794b3ff1ec8be9ff6a708c85a163733192665"
:name "Mr. Eagle" :name "Mr. Eagle"
:photo-path ""})) :photo-path ""}))
(r/write #(create-contact {:phone-number "0533333333" (r/write #(create-contact {:phone-number "0533333333"
:whisper-identity "0x04e9e31a92ab16dbac9cdce47f59545ac646175087f4eeb6e4442e36d37b09e20dcb6239ac743ddd3f1fa17377c1789dc60a1ebb8774d247f3df69ebd0082d46fe" :whisper-identity "0x04e43e861a6dd99ad9eee7bd58af89dcaa430188ebec8698de7b7bad54573324fff4ac5cb9bb277af317efd7abfc917b91bf48cc41e40bf70062fd79400016a1f9"
:name "Mr. PiggyBear" :name "Mr. PiggyBear"
:photo-path ""})) :photo-path ""}))

View File

@ -32,9 +32,8 @@
:group-id group-id)])) :group-id group-id)]))
:group-chat-invite-acked (let [{:keys [from group-id ack-msg-id]} event] :group-chat-invite-acked (let [{:keys [from group-id ack-msg-id]} event]
(dispatch [:group-chat-invite-acked from group-id ack-msg-id])) (dispatch [:group-chat-invite-acked from group-id ack-msg-id]))
;:group-new-participant (let [{:keys [group-id identity from]} event] :group-new-participant (let [{:keys [group-id identity from msg-id]} event]
; (add-to-chat "group-chat" ":" (str (shorten from) " added " (shorten identity) " to group chat")) (dispatch [:participant-invited-to-group from group-id identity msg-id]))
; (add-identity-to-group-list identity))
;:group-removed-participant (let [{:keys [group-id identity from]} event] ;:group-removed-participant (let [{:keys [group-id identity from]} event]
; (add-to-chat "group-chat" ":" (str (shorten from) " removed " (shorten identity) " from group chat")) ; (add-to-chat "group-chat" ":" (str (shorten from) " removed " (shorten identity) " from group chat"))
; (remove-identity-from-group-list identity)) ; (remove-identity-from-group-list identity))