From 97915f0fbe6949794cdcaec1aa7a8408077a3db2 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 10 Dec 2018 20:34:45 +0100 Subject: [PATCH] plugin XEP-0059: added serialise method --- sat/plugins/plugin_xep_0059.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sat/plugins/plugin_xep_0059.py b/sat/plugins/plugin_xep_0059.py index 5906e0a8..080f5f0d 100644 --- a/sat/plugins/plugin_xep_0059.py +++ b/sat/plugins/plugin_xep_0059.py @@ -74,6 +74,33 @@ class XEP_0059(object): else: return None + def serialise(self, rsm_response, data=None): + """Serialise data for RSM + + Key set in data can be: + - rsm_first: first item id in the page + - rsm_last: last item id in the page + - rsm_index: position of the first item in the full set (may be approximate) + - rsm_count: total number of items in the full set (may be approximage) + If a value doesn't exists, it's not set. + All values are set as strings. + @param rsm_response(rsm.RSMResponse): response to serialise + @param data(dict, None): dict to update with rsm_* data. + If None, a new dict is created + @return (dict): data dict + """ + if data is None: + data = {} + if rsm_response.first is not None: + data[u"rsm_first"] = rsm_response.first + if rsm_response.last is not None: + data[u"rsm_last"] = rsm_response.last + if rsm_response.index is not None: + data[u"rsm_index"] = unicode(rsm_response.index) + if rsm_response.index is not None: + data[u"rsm_index"] = unicode(rsm_response.index) + return data + class XEP_0059_handler(xmlstream.XMPPHandler): implements(iwokkel.IDisco)