From c1144e1d685e25ef33ebda2bdbf620eac302b1b2 Mon Sep 17 00:00:00 2001 From: michaelr Date: Thu, 7 Apr 2016 14:01:41 +0300 Subject: [PATCH] handle group chat invite acks Former-commit-id: ad4401a42eb4e9f2c021a92c8e8bf41a0de91906 --- src/syng_im/components/chat.cljs | 9 ++-- src/syng_im/components/chat/chat_message.cljs | 43 +++++++++---------- src/syng_im/handlers.cljs | 17 +++++++- src/syng_im/models/contacts.cljs | 4 ++ src/syng_im/protocol/protocol_handler.cljs | 4 +- 5 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/syng_im/components/chat.cljs b/src/syng_im/components/chat.cljs index 6ae060535a..8ddec07d9d 100644 --- a/src/syng_im/components/chat.cljs +++ b/src/syng_im/components/chat.cljs @@ -25,9 +25,12 @@ (into {}))) (defn add-msg-color [{:keys [from] :as msg} contact-by-identity] - (let [{:keys [text-color background-color]} (get contact-by-identity from)] - (assoc msg :text-color text-color - :background-color background-color))) + (if (= "system" from) + (assoc msg :text-color "#4A5258" + :background-color "#D3EEEF") + (let [{:keys [text-color background-color]} (get contact-by-identity from)] + (assoc msg :text-color text-color + :background-color background-color)))) (defn chat [{:keys [navigator]}] (let [messages (subscribe [:get-chat-messages]) diff --git a/src/syng_im/components/chat/chat_message.cljs b/src/syng_im/components/chat/chat_message.cljs index 8e2a3540c1..20ce00e755 100644 --- a/src/syng_im/components/chat/chat_message.cljs +++ b/src/syng_im/components/chat/chat_message.cljs @@ -86,28 +86,27 @@ content)]])) (defn message-content [{:keys [content-type content outgoing text-color background-color]}] - (let [_ (log/debug color)] - [view {:style (merge {:borderRadius 6} - (if (= content-type text-content-type) - {:paddingVertical 12 - :paddingHorizontal 16} - {:paddingVertical 14 - :paddingHorizontal 10}) - (if outgoing - {:backgroundColor "#D3EEEF"} - {:backgroundColor background-color}))} - (cond - (= content-type text-content-type) - [text {:style (merge {:fontSize 14 - :fontFamily "Avenir-Roman"} - (if outgoing - {:color "#4A5258"} - {:color text-color}))} - content] - (= content-type content-type-command) - [message-content-command content] - :else [message-content-audio {:content content - :content-type content-type}])])) + [view {:style (merge {:borderRadius 6} + (if (= content-type text-content-type) + {:paddingVertical 12 + :paddingHorizontal 16} + {:paddingVertical 14 + :paddingHorizontal 10}) + (if outgoing + {:backgroundColor "#D3EEEF"} + {:backgroundColor background-color}))} + (cond + (= content-type text-content-type) + [text {:style (merge {:fontSize 14 + :fontFamily "Avenir-Roman"} + (if outgoing + {:color "#4A5258"} + {:color text-color}))} + content] + (= content-type content-type-command) + [message-content-command content] + :else [message-content-audio {:content content + :content-type content-type}])]) (defn message-delivery-status [{:keys [delivery-status]}] [view {:style {:flexDirection "row" diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index fc462f3ea7..1d8ad2f762 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -110,6 +110,19 @@ (save-message chat-id msg) (signal-chat-updated db chat-id))) +(defn joined-chat-msg [chat-id from msg-id] + (let [contact-name (:name (contacts/contatct-by-identity from))] + (save-message chat-id {:from "system" + :msg-id msg-id + :content (str (or contact-name from) " received chat invitation") + :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) + (joined-chat-msg group-id from ack-msg-id) + (signal-chat-updated db group-id))) + (register-handler :acked-msg (fn [db [_ from msg-id]] (update-message! {:msg-id msg-id @@ -128,7 +141,7 @@ (log/debug action "chat-id" chat-id "text" text) (let [msg (if (= chat-id "console") (sign-up-service/send-console-msg text) - (let [{msg-id :msg-id + (let [{msg-id :msg-id {from :from to :to} :msg} (api/send-user-msg {:to chat-id :content text})] @@ -147,7 +160,7 @@ (let [msg (if (= chat-id "console") (sign-up-service/send-console-command command content) ;; TODO handle command, now sends as plain message - (let [{msg-id :msg-id + (let [{msg-id :msg-id {from :from to :to} :msg} (api/send-user-msg {:to chat-id :content content})] diff --git a/src/syng_im/models/contacts.cljs b/src/syng_im/models/contacts.cljs index 41cbd2742e..be6c25ffc7 100644 --- a/src/syng_im/models/contacts.cljs +++ b/src/syng_im/models/contacts.cljs @@ -91,6 +91,10 @@ (-> (r/get-all :contacts) (r/sorted :name :asc))) +(defn contatct-by-identity [identity] + (-> (r/get-by-field :contacts :whisper-identity identity) + (r/single-cljs))) + (comment (r/write #(create-contact {:phone-number "0543072333" diff --git a/src/syng_im/protocol/protocol_handler.cljs b/src/syng_im/protocol/protocol_handler.cljs index 9b1ab11206..dd40a08d2c 100644 --- a/src/syng_im/protocol/protocol_handler.cljs +++ b/src/syng_im/protocol/protocol_handler.cljs @@ -28,8 +28,8 @@ payload :payload} event] (dispatch [:group-received-msg (assoc payload :from from :group-id group-id)])) - ;:group-chat-invite-acked (let [{:keys [from group-id]} event] - ; (add-to-chat "group-chat" ":" (str "Received ACK for group chat invitation from " from " for group-id: " group-id))) + :group-chat-invite-acked (let [{:keys [from group-id ack-msg-id]} event] + (dispatch [:group-chat-invite-acked from group-id ack-msg-id])) ;:group-new-participant (let [{:keys [group-id identity from]} event] ; (add-to-chat "group-chat" ":" (str (shorten from) " added " (shorten identity) " to group chat")) ; (add-identity-to-group-list identity))