# HG changeset patch # User Kim Alvefur # Date 1615077699 -3600 # Node ID b7807583de3447070e1a1921090ca86affc105bd # Parent 87a684df4b65f6b21de9467d1791c18bfc738a05 util.datamapper: Add logic for "boolean" tags here the presence means true diff -r 87a684df4b65 -r b7807583de34 spec/util_datamapper_spec.lua --- a/spec/util_datamapper_spec.lua Sat Mar 06 23:14:23 2021 +0100 +++ b/spec/util_datamapper_spec.lua Sun Mar 07 01:41:39 2021 +0100 @@ -31,6 +31,10 @@ 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 @@ Hello Becasue + ]]; @@ -51,6 +56,7 @@ body = "Hello"; delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"}; state = "active"; + fallback = true; }; end); diff -r 87a684df4b65 -r b7807583de34 teal-src/util/datamapper.tl --- a/teal-src/util/datamapper.tl Sat Mar 06 23:14:23 2021 +0100 +++ b/teal-src/util/datamapper.tl Sun Mar 07 01:41:39 2021 +0100 @@ -49,8 +49,10 @@ 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 @@ 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 -r 87a684df4b65 -r b7807583de34 util/datamapper.lua --- a/util/datamapper.lua Sat Mar 06 23:14:23 2021 +0100 +++ b/util/datamapper.lua Sun Mar 07 01:41:39 2021 +0100 @@ -48,8 +48,10 @@ 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 @@ 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