File

libs/xstanza.lua @ 415:37674f8ce263

verse.plugins.pep: Support taking an item id, default to "current" XEP-0060 recommends using "current" in section 'Singleton Nodes' and many PEP use cases follow this pattern.
author Kim Alvefur <zash@zash.se>
date Sun, 20 May 2018 00:56:24 +0200
parent 15:be4154ed4e3a
line wrap: on
line source

local stanza_mt = getmetatable(require "util.stanza".stanza());

local xmlns_stanzas = "urn:ietf:params:xml:ns:xmpp-stanzas";

function stanza_mt:get_error()
	local type, condition, text;
	
	local error_tag = self:get_child("error");
	if not error_tag then
		return nil, nil;
	end
	type = error_tag.attr.type;
	
	for child in error_tag:children() do
		if child.attr.xmlns == xmlns_stanzas then
			if child.name == "text" then
				text = child:get_text();
			else
				condition = child.name;
			end
			if condition and text then
				break;
			end
		end
	end
	return type, condition, text;
end