changeset 3351:19bad15f4c0a

plugin invitation: if "thumb_url" is not set, try to use one from list of interests
author Goffi <goffi@goffi.org>
date Sat, 05 Sep 2020 20:23:25 +0200
parents cc6164a4973b
children a3f940e3d72e
files sat/plugins/plugin_exp_invitation.py
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_invitation.py	Sat Sep 05 20:22:23 2020 +0200
+++ b/sat/plugins/plugin_exp_invitation.py	Sat Sep 05 20:23:25 2020 +0200
@@ -175,6 +175,22 @@
         except Exception as e:
             log.warning(f"Can't set affiliation: {e}")
 
+        if "thumb_url" not in extra:
+            # we have no thumbnail, we check in our own list of interests if there is one
+            try:
+                item_id = li_plg.getFileSharingId(service, namespace, path)
+                own_interest = await li_plg.get(client, item_id)
+            except exceptions.NotFound:
+                log.debug(
+                    "no thumbnail found for file sharing interest at "
+                    f"[{service}/{namespace}]{path}"
+                )
+            else:
+                try:
+                    extra['thumb_url'] = own_interest['thumb_url']
+                except KeyError:
+                    pass
+
         mess_data, invitation_elt = self._generateBaseInvitation(
             client, invitee_jid, name, extra)
         file_sharing_elt = invitation_elt.addElement("file_sharing")