Fixup command validation

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2018-10-02 23:45:19 +02:00
parent df6432240a
commit 0caab1f7ce
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
2 changed files with 6 additions and 7 deletions

View File

@ -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/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 :message.content/params (spec/map-of keyword? any?))
(spec/def ::content (spec/conformer (fn [content] (spec/def ::content-type #{"text/plain" "command" "command-request"})
(cond
(string? content) {:text content}
(map? content) content
:else :clojure.spec/invalid))))
(spec/def ::content-type #{"text/plain" "command"})
(spec/def ::message-type #{:group-user-message :public-group-user-message :user-message}) (spec/def ::message-type #{:group-user-message :public-group-user-message :user-message})
(spec/def ::clock-value (spec/nilable pos-int?)) (spec/def ::clock-value (spec/nilable pos-int?))
(spec/def ::timestamp (spec/nilable pos-int?)) (spec/def ::timestamp (spec/nilable pos-int?))
@ -91,6 +86,10 @@
(spec/merge :message/message-common (spec/merge :message/message-common
(spec/keys :req-un [:message.command/content]))) (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 [_] (defmethod content-type :default [_]
(spec/merge :message/message-common (spec/merge :message/message-common
(spec/keys :req-un [:message.text/content]))) (spec/keys :req-un [:message.text/content])))

View File

@ -111,7 +111,7 @@
:js-obj (:js-obj cofx))]}) :js-obj (:js-obj cofx))]})
(validate [this] (validate [this]
(when (spec/valid? :message/message this) (when (spec/valid? :message/message this)
(spec/conform :message/message this)))) this)))
(defrecord MessagesSeen [message-ids] (defrecord MessagesSeen [message-ids]
message/StatusMessage message/StatusMessage