2018-03-31 14:00:47 +00:00
|
|
|
"""
|
|
|
|
Display an image URL as an embedded image in some clients like Conversations.
|
|
|
|
Uses: https://xmpp.org/extensions/xep-0066.html#x-oob
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
|
|
|
|
/embed <image_url>
|
|
|
|
|
|
|
|
Run this command to send the <image_url> as an
|
|
|
|
embedded image in your contact's client.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from poezio import tabs
|
|
|
|
from poezio.plugin import BasePlugin
|
|
|
|
from poezio.theming import get_theme
|
|
|
|
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
class Plugin(BasePlugin):
|
2018-03-31 14:00:47 +00:00
|
|
|
def init(self):
|
2018-11-27 12:37:11 +00:00
|
|
|
for tab_t in [tabs.MucTab, tabs.StaticConversationTab, tabs.DynamicConversationTab, tabs.PrivateTab]:
|
2018-08-15 11:13:17 +00:00
|
|
|
self.api.add_tab_command(
|
|
|
|
tab_t,
|
|
|
|
'embed',
|
|
|
|
self.embed_image_url,
|
|
|
|
help='Embed an image url into the contact\'s client',
|
|
|
|
usage='<image_url>')
|
2018-03-31 14:00:47 +00:00
|
|
|
|
|
|
|
def embed_image_url(self, args):
|
|
|
|
tab = self.api.current_tab()
|
2019-09-15 10:26:50 +00:00
|
|
|
message = self.core.xmpp.make_message(tab.jid)
|
2018-03-31 14:00:47 +00:00
|
|
|
message['body'] = args
|
|
|
|
message['oob']['url'] = args
|
|
|
|
if isinstance(tab, tabs.MucTab):
|
|
|
|
message['type'] = 'groupchat'
|
|
|
|
else:
|
|
|
|
message['type'] = 'chat'
|
|
|
|
tab.add_message(
|
|
|
|
message['body'],
|
|
|
|
nickname=tab.core.own_nick,
|
|
|
|
nick_color=get_theme().COLOR_OWN_NICK,
|
|
|
|
identifier=message['id'],
|
|
|
|
jid=tab.core.xmpp.boundjid,
|
|
|
|
typ=1,
|
|
|
|
)
|
|
|
|
message.send()
|