From 0caab1f7ce7dc190e9543b5117f8853656bd04fc Mon Sep 17 00:00:00 2001 From: yenda Date: Tue, 2 Oct 2018 23:45:19 +0200 Subject: [PATCH] Fixup command validation Signed-off-by: yenda --- src/status_im/transport/db.cljs | 11 +++++------ src/status_im/transport/message/v1/protocol.cljs | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/status_im/transport/db.cljs b/src/status_im/transport/db.cljs index 2fca3df1dd..6f3aaa7ee3 100644 --- a/src/status_im/transport/db.cljs +++ b/src/status_im/transport/db.cljs @@ -51,12 +51,7 @@ (spec/def :message.content/command-path (spec/tuple string? (spec/coll-of (spec/or :scope keyword? :chat-id string?) :kind set? :min-count 1))) (spec/def :message.content/params (spec/map-of keyword? any?)) -(spec/def ::content (spec/conformer (fn [content] - (cond - (string? content) {:text content} - (map? content) content - :else :clojure.spec/invalid)))) -(spec/def ::content-type #{"text/plain" "command"}) +(spec/def ::content-type #{"text/plain" "command" "command-request"}) (spec/def ::message-type #{:group-user-message :public-group-user-message :user-message}) (spec/def ::clock-value (spec/nilable pos-int?)) (spec/def ::timestamp (spec/nilable pos-int?)) @@ -91,6 +86,10 @@ (spec/merge :message/message-common (spec/keys :req-un [:message.command/content]))) +(defmethod content-type "command-request" [_] + (spec/merge :message/message-common + (spec/keys :req-un [:message.command/content]))) + (defmethod content-type :default [_] (spec/merge :message/message-common (spec/keys :req-un [:message.text/content]))) diff --git a/src/status_im/transport/message/v1/protocol.cljs b/src/status_im/transport/message/v1/protocol.cljs index 34f6d9b52b..8d5c742a88 100644 --- a/src/status_im/transport/message/v1/protocol.cljs +++ b/src/status_im/transport/message/v1/protocol.cljs @@ -111,7 +111,7 @@ :js-obj (:js-obj cofx))]}) (validate [this] (when (spec/valid? :message/message this) - (spec/conform :message/message this)))) + this))) (defrecord MessagesSeen [message-ids] message/StatusMessage