From 7cd2803161ee05303371cd681f8ae00a0838d07f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 7 Mar 2021 01:41:39 +0100 Subject: util.datamapper: Add logic for "boolean" tags here the presence means true --- spec/util_datamapper_spec.lua | 6 ++++++ teal-src/util/datamapper.tl | 12 +++++++++--- util/datamapper.lua | 12 +++++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/spec/util_datamapper_spec.lua b/spec/util_datamapper_spec.lua index 2a149b1c..7f6ef75e 100644 --- a/spec/util_datamapper_spec.lua +++ b/spec/util_datamapper_spec.lua @@ -31,6 +31,10 @@ describe("util.datampper", function() type = "string"; xml = {x_name_is_value = true; namespace = "http://jabber.org/protocol/chatstates"}; }; + fallback = { + type = "boolean"; + xml = {x_name_is_value = true; name = "fallback"; namespace = "urn:xmpp:fallback:0"}; + }; }; }; @@ -39,6 +43,7 @@ describe("util.datampper", function() Hello Becasue + ]]; @@ -51,6 +56,7 @@ describe("util.datampper", function() body = "Hello"; delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"}; state = "active"; + fallback = true; }; end); diff --git a/teal-src/util/datamapper.tl b/teal-src/util/datamapper.tl index 4db153da..9546809a 100644 --- a/teal-src/util/datamapper.tl +++ b/teal-src/util/datamapper.tl @@ -49,8 +49,10 @@ local function parse_object (schema : js.schema_t, s : st.stanza_t) : table if name_is_value then local c = s:get_child(nil, namespace); - if c then + if c and proptype == "string" then out[prop] = c.name; + elseif proptype == "boolean" and c then + out[prop] = true; end elseif is_attribute then local attr = name @@ -183,8 +185,12 @@ local function unparse ( schema : js.schema_t, t : table, current_name : string, if namespace ~= current_ns then propattr = { xmlns = namespace } end - if name_is_value and v is string then - out:tag(v, propattr):up(); + if name_is_value then + if proptype == "string" and v is string then + out:tag(v, propattr):up(); + elseif proptype == "boolean" and v == true then + out:tag(name, propattr):up(); + end elseif proptype == "string" and v is string then out:text_tag(name, v, propattr) elseif proptype == "number" and v is number then diff --git a/util/datamapper.lua b/util/datamapper.lua index 82532f0c..a87b21ae 100644 --- a/util/datamapper.lua +++ b/util/datamapper.lua @@ -48,8 +48,10 @@ local function parse_object(schema, s) if name_is_value then local c = s:get_child(nil, namespace); - if c then + if c and proptype == "string" then out[prop] = c.name; + elseif proptype == "boolean" and c then + out[prop] = true; end elseif is_attribute then local attr = name @@ -182,8 +184,12 @@ local function unparse(schema, t, current_name, current_ns) if namespace ~= current_ns then propattr = {xmlns = namespace} end - if name_is_value and type(v) == "string" then - out:tag(v, propattr):up(); + if name_is_value then + if proptype == "string" and type(v) == "string" then + out:tag(v, propattr):up(); + elseif proptype == "boolean" and v == true then + out:tag(name, propattr):up(); + end elseif proptype == "string" and type(v) == "string" then out:text_tag(name, v, propattr) elseif proptype == "number" and type(v) == "number" then -- cgit v1.2.3