diff options
-rw-r--r-- | doc/source/plugins/embed.rst | 6 | ||||
-rw-r--r-- | doc/source/plugins/index.rst | 6 | ||||
-rw-r--r-- | plugins/embed.py | 45 | ||||
-rw-r--r-- | poezio/tabs/basetabs.py | 7 |
4 files changed, 64 insertions, 0 deletions
diff --git a/doc/source/plugins/embed.rst b/doc/source/plugins/embed.rst new file mode 100644 index 00000000..4a24592c --- /dev/null +++ b/doc/source/plugins/embed.rst @@ -0,0 +1,6 @@ +.. _embed-plugin: + +Embed +===== + +.. automodule:: embed diff --git a/doc/source/plugins/index.rst b/doc/source/plugins/index.rst index 2bfea11f..afff857e 100644 --- a/doc/source/plugins/index.rst +++ b/doc/source/plugins/index.rst @@ -108,6 +108,11 @@ Plugin index Lists old versions of a corrected message. + Embed + :ref:`Documentation <embed-plugin>` + + Send an URL annotating it as embedded. + Exec :ref:`Documentation <exec-plugin>` @@ -306,6 +311,7 @@ Plugin index amsg day_change display_corrections + embed exec figlet gpg diff --git a/plugins/embed.py b/plugins/embed.py new file mode 100644 index 00000000..717fc3c5 --- /dev/null +++ b/plugins/embed.py @@ -0,0 +1,45 @@ +""" +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 + +class Plugin(BasePlugin): + + def init(self): + for tab_t in [tabs.MucTab, tabs.ConversationTab, tabs.PrivateTab]: + 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>') + + def embed_image_url(self, args): + tab = self.api.current_tab() + message = self.core.xmpp.make_message(tab.name) + 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() diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 7418722d..13c54c27 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -473,6 +473,7 @@ class ChatTab(Tab): # We keep a reference of the event that will set our chatstate to "paused", so that # we can delete it or change it if we need to self.timed_event_paused = None + self.timed_event_not_paused = None # Keeps the last sent message to complete it easily in completion_correct, and to replace it. self.last_sent_message = {} self.key_func['M-v'] = self.move_separator @@ -684,6 +685,10 @@ class ChatTab(Tab): 'paused') self.core.add_timed_event(new_event) self.timed_event_paused = new_event + new_event = timed_events.DelayedEvent(30, self.send_chat_state, + 'inactive' if self.inactive else 'active') + self.core.add_timed_event(new_event) + self.timed_event_not_paused = new_event def cancel_paused_delay(self): """ @@ -694,6 +699,8 @@ class ChatTab(Tab): if self.timed_event_paused is not None: self.core.remove_timed_event(self.timed_event_paused) self.timed_event_paused = None + self.core.remove_timed_event(self.timed_event_not_paused) + self.timed_event_not_paused = None @command_args_parser.raw def command_correct(self, line): |