primitivus (chat) Q&D way to see attachments

This commit is contained in:
Goffi 2020-02-26 22:03:15 +01:00
commit bd490c1d19

View file

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from functools import total_ordering
from pathlib import Path
import bisect
import urwid
from urwid_satext import sat_widgets
@ -442,6 +443,20 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
False is generally used when printing history, when we don't want every
message to be notified.
"""
if message.attachments:
# FIXME: Q&D way to see attachments in Primitivus
# it should be done in a more user friendly way
for lang, body in message.message.items():
for attachment in message.attachments:
if 'url' in attachment:
body+=f"\n{attachment['url']}"
elif 'path' in attachment:
path = Path(attachment['path'])
body+=f"\n{path.as_uri()}"
else:
log.warning(f'No "url" nor "path" in attachment: {attachment}')
message.message[lang] = body
if self.filters:
if not all([f(message) for f in self.filters]):
return