Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0059.py @ 3308:384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
`data_format.serialise` is now used for `mbGet`, and RSM/MAM values are not transtyped to
strings anymore. A serialised dict is now used, items are put in the `items` key.
Comments handling has been refactored to use a list for the potentially multiple comments
nodes.
`rsm` data are now in a `rsm` key of the dict, and `mam` data are merged with other
metadata.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 16 Jul 2020 09:07:20 +0200 |
parents | 559a625a236b |
children | be6d91572633 |
comparison
equal
deleted
inserted
replaced
3307:9f0e28137cd0 | 3308:384283adcce1 |
---|---|
75 if rsm_args: | 75 if rsm_args: |
76 return rsm.RSMRequest(**rsm_args) | 76 return rsm.RSMRequest(**rsm_args) |
77 else: | 77 else: |
78 return None | 78 return None |
79 | 79 |
80 def serialise(self, rsm_response, data=None): | 80 def response2dict(self, rsm_response, data=None): |
81 """Serialise data for RSM | 81 """Return a dict with RSM response |
82 | 82 |
83 Key set in data can be: | 83 Key set in data can be: |
84 - rsm_first: first item id in the page | 84 - rsm_first: first item id in the page |
85 - rsm_last: last item id in the page | 85 - rsm_last: last item id in the page |
86 - rsm_index: position of the first item in the full set (may be approximate) | 86 - rsm_index: position of the first item in the full set (may be approximate) |
87 - rsm_count: total number of items in the full set (may be approximage) | 87 - rsm_count: total number of items in the full set (may be approximage) |
88 If a value doesn't exists, it's not set. | 88 If a value doesn't exists, it's not set. |
89 All values are set as strings. | 89 All values are set as strings. |
90 @param rsm_response(rsm.RSMResponse): response to serialise | 90 @param rsm_response(rsm.RSMResponse): response to parse |
91 @param data(dict, None): dict to update with rsm_* data. | 91 @param data(dict, None): dict to update with rsm_* data. |
92 If None, a new dict is created | 92 If None, a new dict is created |
93 @return (dict): data dict | 93 @return (dict): data dict |
94 """ | 94 """ |
95 if data is None: | 95 if data is None: |
96 data = {} | 96 data = {} |
97 if rsm_response.first is not None: | 97 if rsm_response.first is not None: |
98 data["rsm_first"] = rsm_response.first | 98 data["first"] = rsm_response.first |
99 if rsm_response.last is not None: | 99 if rsm_response.last is not None: |
100 data["rsm_last"] = rsm_response.last | 100 data["last"] = rsm_response.last |
101 if rsm_response.index is not None: | 101 if rsm_response.index is not None: |
102 data["rsm_index"] = str(rsm_response.index) | 102 data["index"] = rsm_response.index |
103 if rsm_response.index is not None: | |
104 data["rsm_index"] = str(rsm_response.index) | |
105 return data | 103 return data |
106 | 104 |
107 | 105 |
108 @implementer(iwokkel.IDisco) | 106 @implementer(iwokkel.IDisco) |
109 class XEP_0059_handler(xmlstream.XMPPHandler): | 107 class XEP_0059_handler(xmlstream.XMPPHandler): |