Mercurial > prosody-modules
comparison mod_rest/jsonmap.lib.lua @ 4927:77b7e1322281
mod_rest: Add some notes about custom disco#info mapping code
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 17 Apr 2022 12:51:45 +0200 |
| parents | 3dc8e329d233 |
| children | a85efae90e21 |
comparison
equal
deleted
inserted
replaced
| 4926:b8366e31c829 | 4927:77b7e1322281 |
|---|---|
| 48 st2json = function (s) --> array of features | 48 st2json = function (s) --> array of features |
| 49 if s.tags[1] == nil then | 49 if s.tags[1] == nil then |
| 50 return s.attr.node or true; | 50 return s.attr.node or true; |
| 51 end | 51 end |
| 52 local identities, features, extensions = array(), array(), {}; | 52 local identities, features, extensions = array(), array(), {}; |
| 53 | |
| 54 -- features and identities could be done with util.datamapper | |
| 53 for tag in s:childtags() do | 55 for tag in s:childtags() do |
| 54 if tag.name == "identity" and tag.attr.category and tag.attr.type then | 56 if tag.name == "identity" and tag.attr.category and tag.attr.type then |
| 55 identities:push({ category = tag.attr.category, type = tag.attr.type, name = tag.attr.name }); | 57 identities:push({ category = tag.attr.category, type = tag.attr.type, name = tag.attr.name }); |
| 56 elseif tag.name == "feature" and tag.attr.var then | 58 elseif tag.name == "feature" and tag.attr.var then |
| 57 features:push(tag.attr.var); | 59 features:push(tag.attr.var); |
| 58 end | 60 end |
| 59 end | 61 end |
| 62 | |
| 63 -- Especially this would be hard to do with util.datamapper | |
| 60 for form in s:childtags("x", "jabber:x:data") do | 64 for form in s:childtags("x", "jabber:x:data") do |
| 61 local jform = field_mappings.formdata.st2json(form); | 65 local jform = field_mappings.formdata.st2json(form); |
| 62 local form_type = jform["FORM_TYPE"]; | 66 local form_type = jform["FORM_TYPE"]; |
| 63 if jform then | 67 if jform then |
| 64 jform["FORM_TYPE"] = nil; | 68 jform["FORM_TYPE"] = nil; |
| 65 extensions[form_type] = jform; | 69 extensions[form_type] = jform; |
| 66 end | 70 end |
| 67 end | 71 end |
| 72 | |
| 68 if next(extensions) == nil then extensions = nil; end | 73 if next(extensions) == nil then extensions = nil; end |
| 69 return { node = s.attr.node, identities = identities, features = features, extensions = extensions }; | 74 return { node = s.attr.node, identities = identities, features = features, extensions = extensions }; |
| 70 end; | 75 end; |
| 71 json2st = function (s) | 76 json2st = function (s) |
| 72 if type(s) == "table" and s ~= json.null then | 77 if type(s) == "table" and s ~= json.null then |
