2013-04-13 20:33:06 +00:00
|
|
|
"""
|
|
|
|
Lists old versions of a corrected message.
|
2012-12-26 16:58:16 +00:00
|
|
|
|
2013-04-13 20:33:06 +00:00
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
|
|
|
|
/display_corrections
|
|
|
|
**Usage:** ``/display_corrections [number]``
|
|
|
|
|
|
|
|
This command lists the old versions of a message.
|
|
|
|
|
|
|
|
Without argument, it will list the last corrected message if there
|
|
|
|
is any. If you give an integer as an argument, ``/display_corrections``
|
|
|
|
will go back gradually in the buffer to find the message matching
|
|
|
|
that number (starting from 1, for the last corrected message).
|
|
|
|
|
|
|
|
If you are scrolling in the buffer, Poezio will list the corrected messages
|
|
|
|
starting from the first you can see. (although there are some problems with
|
|
|
|
multiline messages).
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.plugin import BasePlugin
|
|
|
|
from poezio.common import shell_split
|
|
|
|
from poezio import tabs
|
2020-05-26 15:04:20 +00:00
|
|
|
from poezio.ui.types import Message
|
2020-08-14 20:12:16 +00:00
|
|
|
from poezio.theming import get_theme
|
2012-12-26 16:58:16 +00:00
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
2012-12-26 16:58:16 +00:00
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
2019-07-19 16:55:16 +00:00
|
|
|
for tab_type in (tabs.MucTab, tabs.PrivateTab, tabs.DynamicConversationTab, tabs.StaticConversationTab):
|
2018-08-15 11:13:17 +00:00
|
|
|
self.api.add_tab_command(
|
|
|
|
tab_type,
|
|
|
|
'display_corrections',
|
|
|
|
handler=self.command_display_corrections,
|
|
|
|
usage='<number>',
|
|
|
|
help=
|
|
|
|
'Display all the corrections of the number-th last corrected message.',
|
|
|
|
short='Display the corrections of a message')
|
2012-12-26 16:58:16 +00:00
|
|
|
|
|
|
|
def find_corrected(self, nb):
|
2013-03-08 21:53:35 +00:00
|
|
|
messages = self.api.get_conversation_messages()
|
2012-12-26 16:58:16 +00:00
|
|
|
if not messages:
|
|
|
|
return None
|
2020-04-03 22:20:57 +00:00
|
|
|
for message in reversed(messages):
|
2020-05-26 15:04:20 +00:00
|
|
|
if not isinstance(message, Message):
|
|
|
|
continue
|
2012-12-26 16:58:16 +00:00
|
|
|
if message.old_message:
|
|
|
|
if nb == 1:
|
|
|
|
return message
|
|
|
|
else:
|
|
|
|
nb -= 1
|
|
|
|
return None
|
|
|
|
|
|
|
|
def command_display_corrections(self, args):
|
2020-08-14 20:12:16 +00:00
|
|
|
theme = get_theme()
|
2012-12-26 16:58:16 +00:00
|
|
|
args = shell_split(args)
|
|
|
|
if len(args) == 1:
|
|
|
|
try:
|
|
|
|
nb = int(args[0])
|
|
|
|
except:
|
2013-03-08 21:53:35 +00:00
|
|
|
return self.api.run_command('/help display_corrections')
|
2012-12-26 16:58:16 +00:00
|
|
|
else:
|
|
|
|
nb = 1
|
|
|
|
message = self.find_corrected(nb)
|
|
|
|
if message:
|
|
|
|
display = []
|
|
|
|
while message:
|
2020-08-14 20:12:16 +00:00
|
|
|
str_time = message.time.strftime(theme.SHORT_TIME_FORMAT)
|
2018-08-15 11:13:17 +00:00
|
|
|
display.append('%s %s%s%s %s' %
|
2020-05-26 15:04:20 +00:00
|
|
|
(str_time, '* '
|
2018-08-15 11:13:17 +00:00
|
|
|
if message.me else '', message.nickname, ''
|
|
|
|
if message.me else '>', message.txt))
|
2012-12-26 16:58:16 +00:00
|
|
|
message = message.old_message
|
2018-08-15 11:13:17 +00:00
|
|
|
self.api.information(
|
|
|
|
'Older versions:\n' + '\n'.join(display[::-1]), 'Info')
|
2012-12-26 16:58:16 +00:00
|
|
|
else:
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.information('No corrected message found.', 'Warning')
|
2012-12-26 16:58:16 +00:00
|
|
|
|
|
|
|
def cleanup(self):
|
|
|
|
del self.config
|