diff sat/plugins/plugin_xep_0313.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 569f4cf7183b
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0313.py	Fri Jun 19 15:47:16 2020 +0200
+++ b/sat/plugins/plugin_xep_0313.py	Thu Jul 16 09:07:20 2020 +0200
@@ -216,24 +216,6 @@
 
         return mam.MAMRequest(**mam_args) if mam_args else None
 
-    def serialise(self, mam_response, data=None):
-        """Serialise data for MAM
-
-        Key set in data can be:
-            - mam_complete: a bool const indicating if all items have been received
-            - mam_stable: a bool const which is False if items order may be changed
-        All values are set as strings.
-        @param mam_response(dict): response data to serialise
-        @param data(dict, None): dict to update with mam_* data.
-            If None, a new dict is created
-        @return (dict): data dict
-        """
-        if data is None:
-            data = {}
-        data["mam_complete"] = C.boolConst(mam_response['complete'])
-        data["mam_stable"] = C.boolConst(mam_response['stable'])
-        return data
-
     def getMessageFromResult(self, client, mess_elt, mam_req, service=None):
         """Extract usable <message/> from MAM query result
 
@@ -345,8 +327,10 @@
                                                         service=service)
             mess_data = client.messageProt.parseMessage(fwd_message_elt)
             mess_list.append(client.messageGetBridgeArgs(mess_data))
-        metadata = self._rsm.serialise(rsm_response)
-        self.serialise(mam_response, metadata)
+        metadata = {
+            'rsm': self._rsm.response2dict(rsm_response),
+            'mam': mam_response
+        }
         return mess_list, metadata, client.profile
 
     def _getArchives(self, service, extra_ser, profile_key):
@@ -354,8 +338,8 @@
         @return: tuple with:
             - list of message with same data as in bridge.messageNew
             - response metadata with:
-                - rsm data (rsm_first, rsm_last, rsm_count, rsm_index)
-                - mam data (mam_complete, mam_stable)
+                - rsm data (first, last, count, index)
+                - mam data (complete, stable)
             - profile
         """
         client = self.host.getClient(profile_key)