Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0329.py @ 3314:5887fb414758
component file sharing: add/parse affiliation when possible
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jul 2020 13:00:10 +0200 |
parents | 9d0df638c8b4 |
children | bb92085720c8 |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0329.py Fri Jul 17 12:58:57 2020 +0200 +++ b/sat/plugins/plugin_xep_0329.py Fri Jul 17 13:00:10 2020 +0200 @@ -417,7 +417,8 @@ size = os.path.getsize(path) mime_type = mimetypes.guess_type(path, strict=False)[0] file_elt = self._jf.buildFileElement( - name=name, size=size, mime_type=mime_type, modified=os.path.getmtime(path) + client=client, name=name, size=size, mime_type=mime_type, + modified=os.path.getmtime(path) ) query_elt.addChild(file_elt) @@ -590,16 +591,32 @@ query_elt = iq_result_elt.addElement((NS_FIS, "query")) query_elt["node"] = node_path if not self.host.trigger.point( - "XEP-0329_compGetFilesFromNode", client, iq_elt, owner, node_path, files_data + "XEP-0329_compGetFilesFromNode", + client, + iq_elt, + iq_result_elt, + owner, + node_path, + files_data ): return for file_data in files_data: if file_data['type'] == C.FILE_TYPE_DIRECTORY: directory_elt = query_elt.addElement("directory") directory_elt['name'] = file_data['name'] + self.host.trigger.point( + "XEP-0329_compGetFilesFromNode_build_directory", + client, + file_data, + directory_elt, + owner, + node_path, + ) else: file_elt = self._jf.buildFileElementFromDict( - file_data, modified=file_data.get("modified", file_data["created"]) + client, + file_data, + modified=file_data.get("modified", file_data["created"]) ) query_elt.addChild(file_elt) client.send(iq_result_elt) @@ -609,7 +626,7 @@ client, iq_elt, self._compGetRootNodesCb, self._compGetFilesFromNodeCb ) - def _parseResult(self, iq_elt): + def _parseResult(self, iq_elt, client): query_elt = next(iq_elt.elements(NS_FIS, "query")) files = [] @@ -617,7 +634,7 @@ if elt.name == "file": # we have a file try: - file_data = self._jf.parseFileElement(elt) + file_data = self._jf.parseFileElement(client, elt) except exceptions.DataError: continue file_data["type"] = C.FILE_TYPE_FILE @@ -625,6 +642,12 @@ # we have a directory file_data = {"name": elt["name"], "type": C.FILE_TYPE_DIRECTORY} + self.host.trigger.point( + "XEP-0329_parseResult_directory", + client, + elt, + file_data, + ) else: log.warning( _(f"unexpected element, ignoring: {elt.toXml()}") @@ -665,7 +688,7 @@ if path: query_elt["node"] = path d = iq_elt.send() - d.addCallback(self._parseResult) + d.addCallback(self._parseResult, client) return d def _localSharesGet(self, profile):