mirror of
https://github.com/bjc/prosody.git
synced 2025-04-04 13:47:41 +03:00
util.datamapper: Add logic for "boolean" tags here the presence means true
This commit is contained in:
parent
d20ea9b87e
commit
7cd2803161
3 changed files with 24 additions and 6 deletions
|
@ -31,6 +31,10 @@ describe("util.datampper", function()
|
||||||
type = "string";
|
type = "string";
|
||||||
xml = {x_name_is_value = true; namespace = "http://jabber.org/protocol/chatstates"};
|
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()
|
||||||
<body>Hello</body>
|
<body>Hello</body>
|
||||||
<delay xmlns='urn:xmpp:delay' from='test' stamp='2021-03-07T15:59:08+00:00'>Becasue</delay>
|
<delay xmlns='urn:xmpp:delay' from='test' stamp='2021-03-07T15:59:08+00:00'>Becasue</delay>
|
||||||
<active xmlns='http://jabber.org/protocol/chatstates'/>
|
<active xmlns='http://jabber.org/protocol/chatstates'/>
|
||||||
|
<fallback xmlns='urn:xmpp:fallback:0'/>
|
||||||
</message>
|
</message>
|
||||||
]];
|
]];
|
||||||
|
|
||||||
|
@ -51,6 +56,7 @@ describe("util.datampper", function()
|
||||||
body = "Hello";
|
body = "Hello";
|
||||||
delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"};
|
delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"};
|
||||||
state = "active";
|
state = "active";
|
||||||
|
fallback = true;
|
||||||
};
|
};
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,10 @@ local function parse_object (schema : js.schema_t, s : st.stanza_t) : table
|
||||||
|
|
||||||
if name_is_value then
|
if name_is_value then
|
||||||
local c = s:get_child(nil, namespace);
|
local c = s:get_child(nil, namespace);
|
||||||
if c then
|
if c and proptype == "string" then
|
||||||
out[prop] = c.name;
|
out[prop] = c.name;
|
||||||
|
elseif proptype == "boolean" and c then
|
||||||
|
out[prop] = true;
|
||||||
end
|
end
|
||||||
elseif is_attribute then
|
elseif is_attribute then
|
||||||
local attr = name
|
local attr = name
|
||||||
|
@ -183,8 +185,12 @@ local function unparse ( schema : js.schema_t, t : table, current_name : string,
|
||||||
if namespace ~= current_ns then
|
if namespace ~= current_ns then
|
||||||
propattr = { xmlns = namespace }
|
propattr = { xmlns = namespace }
|
||||||
end
|
end
|
||||||
if name_is_value and v is string then
|
if name_is_value then
|
||||||
out:tag(v, propattr):up();
|
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
|
elseif proptype == "string" and v is string then
|
||||||
out:text_tag(name, v, propattr)
|
out:text_tag(name, v, propattr)
|
||||||
elseif proptype == "number" and v is number then
|
elseif proptype == "number" and v is number then
|
||||||
|
|
|
@ -48,8 +48,10 @@ local function parse_object(schema, s)
|
||||||
|
|
||||||
if name_is_value then
|
if name_is_value then
|
||||||
local c = s:get_child(nil, namespace);
|
local c = s:get_child(nil, namespace);
|
||||||
if c then
|
if c and proptype == "string" then
|
||||||
out[prop] = c.name;
|
out[prop] = c.name;
|
||||||
|
elseif proptype == "boolean" and c then
|
||||||
|
out[prop] = true;
|
||||||
end
|
end
|
||||||
elseif is_attribute then
|
elseif is_attribute then
|
||||||
local attr = name
|
local attr = name
|
||||||
|
@ -182,8 +184,12 @@ local function unparse(schema, t, current_name, current_ns)
|
||||||
if namespace ~= current_ns then
|
if namespace ~= current_ns then
|
||||||
propattr = {xmlns = namespace}
|
propattr = {xmlns = namespace}
|
||||||
end
|
end
|
||||||
if name_is_value and type(v) == "string" then
|
if name_is_value then
|
||||||
out:tag(v, propattr):up();
|
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
|
elseif proptype == "string" and type(v) == "string" then
|
||||||
out:text_tag(name, v, propattr)
|
out:text_tag(name, v, propattr)
|
||||||
elseif proptype == "number" and type(v) == "number" then
|
elseif proptype == "number" and type(v) == "number" then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue