diff options
Diffstat (limited to 'poezio/tabs')
-rw-r--r-- | poezio/tabs/basetabs.py | 58 | ||||
-rw-r--r-- | poezio/tabs/conversationtab.py | 25 | ||||
-rw-r--r-- | poezio/tabs/muctab.py | 106 | ||||
-rw-r--r-- | poezio/tabs/privatetab.py | 100 | ||||
-rw-r--r-- | poezio/tabs/rostertab.py | 5 | ||||
-rw-r--r-- | poezio/tabs/xmltab.py | 2 |
6 files changed, 157 insertions, 139 deletions
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index eadc9a3f..fbb0c4cf 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -47,6 +47,7 @@ from poezio.text_buffer import TextBuffer from poezio.theming import get_theme, dump_tuple from poezio.ui.funcs import truncate_nick from poezio.ui.consts import LONG_FORMAT_LENGTH +from poezio.ui.types import BaseMessage, InfoMessage from slixmpp import JID, InvalidJID, Message @@ -572,40 +573,19 @@ class ChatTab(Tab): def general_jid(self) -> JID: raise NotImplementedError - def log_message(self, - txt: str, - nickname: str, - time: Optional[datetime] = None, - typ=1): + def log_message(self, message: BaseMessage, typ=1): """ Log the messages in the archives. """ name = self.jid.bare - if not logger.log_message(name, nickname, txt, date=time, typ=typ): + if not isinstance(message, Message): + return + if not logger.log_message(name, message.nickname, message.txt, date=message.time, typ=typ): self.core.information('Unable to write in the log file', 'Error') - def add_message(self, - txt, - time=None, - nickname=None, - forced_user=None, - nick_color=None, - identifier=None, - jid=None, - history=None, - typ=1, - highlight=False): - self.log_message(txt, nickname, time=time, typ=typ) - self._text_buffer.add_message( - txt, - time=time, - nickname=nickname, - highlight=highlight, - nick_color=nick_color, - history=history, - user=forced_user, - identifier=identifier, - jid=jid) + def add_message(self, message: BaseMessage, typ=1): + self.log_message(message, typ=typ) + self._text_buffer.add_message(message) def modify_message(self, txt, @@ -614,10 +594,10 @@ class ChatTab(Tab): user=None, jid=None, nickname=None): - self.log_message(txt, nickname, typ=1) message = self._text_buffer.modify_message( - txt, old_id, new_id, time=time, user=user, jid=jid) + txt, old_id, new_id, user=user, jid=jid) if message: + self.log_message(message, typ=1) self.text_win.modify_message(message.identifier, message) self.core.refresh_window() return True @@ -1010,7 +990,10 @@ class OneToOneTab(ChatTab): msg += 'status: %s, ' % status.message if status.show in SHOW_NAME: msg += 'show: %s, ' % SHOW_NAME[status.show] - self.add_message(msg[:-2], typ=2) + self.add_message( + InfoMessage(txt=msg[:-2]), + typ=2, + ) def ack_message(self, msg_id: str, msg_jid: JID): """ @@ -1042,11 +1025,14 @@ class OneToOneTab(ChatTab): message.send() body = xhtml.xhtml_to_poezio_colors(xhtml_data, force=True) self._text_buffer.add_message( - body, - nickname=self.core.own_nick, - nick_color=get_theme().COLOR_OWN_NICK, - identifier=message['id'], - jid=self.core.xmpp.boundjid) + Message( + body, + nickname=self.core.own_nick, + nick_color=get_theme().COLOR_OWN_NICK, + identifier=message['id'], + jid=self.core.xmpp.boundjid, + ) + ) self.refresh() def check_features(self): diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py index 410c5eda..70005f0f 100644 --- a/poezio/tabs/conversationtab.py +++ b/poezio/tabs/conversationtab.py @@ -28,6 +28,7 @@ from poezio.roster import roster from poezio.text_buffer import CorrectionError from poezio.theming import get_theme, dump_tuple from poezio.decorators import command_args_parser +from poezio.ui.types import InfoMessage log = logging.getLogger(__name__) @@ -179,7 +180,7 @@ class ConversationTab(OneToOneTab): (' and their last status was %s' % status) if status else '', ) - self.add_message(msg) + self.add_message(InfoMessage(msg), typ=0) self.core.refresh_window() self.core.xmpp.plugin['xep_0012'].get_last_activity( @@ -200,17 +201,21 @@ class ConversationTab(OneToOneTab): if resource: status = ( 'Status: %s' % resource.status) if resource.status else '' - self._text_buffer.add_message( - "\x19%(info_col)s}Show: %(show)s, %(status)s\x19o" % { - 'show': resource.presence or 'available', - 'status': status, - 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT) - }) + self.add_message( + InfoMessage( + "Show: %(show)s, %(status)s" % { + 'show': resource.presence or 'available', + 'status': status, + } + ), + typ=0, + ) return True else: - self._text_buffer.add_message( - "\x19%(info_col)s}No information available\x19o" % - {'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)}) + self.add_message( + InfoMessage("No information available"), + typ=0, + ) return True @command_args_parser.quoted(0, 1) diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 73359610..ff8f6c07 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -40,6 +40,7 @@ from poezio.roster import roster from poezio.theming import get_theme, dump_tuple from poezio.user import User from poezio.core.structs import Completion, Status +from poezio.ui.types import BaseMessage, Message, InfoMessage, StatusMessage log = logging.getLogger(__name__) @@ -197,8 +198,7 @@ class MucTab(ChatTab): 'color_spec': spec_col, 'nick': self.own_nick, } - - self.add_message(msg, typ=2) + self.add_message(InfoMessage(msg), typ=2) self.disconnect() muc.leave_groupchat(self.core.xmpp, self.jid.bare, self.own_nick, message) @@ -301,7 +301,7 @@ class MucTab(ChatTab): 'role': user.role or 'None', 'status': '\n%s' % user.status if user.status else '' } - self.add_message(info, typ=0) + self.add_message(InfoMessage(info), typ=0) return True def change_topic(self, topic: str): @@ -327,9 +327,13 @@ class MucTab(ChatTab): else: user_string = '' - self._text_buffer.add_message( - "\x19%s}The subject of the room is: \x19%s}%s %s" % - (info_text, norm_text, self.topic, user_string)) + self.add_message( + InfoMessage( + "The subject of the room is: \x19%s}%s %s" % + (norm_text, self.topic, user_string), + ), + typ=0, + ) @refresh_wrapper.always def recolor(self, random_colors=False): @@ -558,28 +562,32 @@ class MucTab(ChatTab): 'nick_col': color, 'info_col': info_col, } - self.add_message(enable_message, typ=2) + self.add_message(InfoMessage(enable_message), typ=2) self.core.enable_private_tabs(self.jid.bare, enable_message) if '201' in status_codes: self.add_message( - '\x19%(info_col)s}Info: The room ' - 'has been created' % {'info_col': info_col}, - typ=0) + InfoMessage('Info: The room has been created'), + typ=0 + ) if '170' in status_codes: self.add_message( - '\x19%(warn_col)s}Warning:\x19%(info_col)s}' - ' This room is publicly logged' % { - 'info_col': info_col, - 'warn_col': warn_col - }, + InfoMessage( + '\x19%(warn_col)s}Warning:\x19%(info_col)s}' + ' This room is publicly logged' % { + 'info_col': info_col, + 'warn_col': warn_col + }, + ), typ=0) if '100' in status_codes: self.add_message( - '\x19%(warn_col)s}Warning:\x19%(info_col)s}' - ' This room is not anonymous.' % { - 'info_col': info_col, - 'warn_col': warn_col - }, + InfoMessage( + '\x19%(warn_col)s}Warning:\x19%(info_col)s}' + ' This room is not anonymous.' % { + 'info_col': info_col, + 'warn_col': warn_col + }, + ), typ=0) def handle_presence_joined(self, presence, status_codes): @@ -635,18 +643,20 @@ class MucTab(ChatTab): def on_non_member_kicked(self): """We have been kicked because the MUC is members-only""" self.add_message( - '\x19%(info_col)s}You have been kicked because you ' - 'are not a member and the room is now members-only.' % - {'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)}, + InfoMessage( + 'You have been kicked because you ' + 'are not a member and the room is now members-only.' + ), typ=2) self.disconnect() def on_muc_shutdown(self): """We have been kicked because the MUC service is shutting down""" self.add_message( - '\x19%(info_col)s}You have been kicked because the' - ' MUC service is shutting down.' % - {'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)}, + InfoMessage( + 'You have been kicked because the' + ' MUC service is shutting down.' + ), typ=2) self.disconnect() @@ -693,7 +703,7 @@ class MucTab(ChatTab): 'jid_color': dump_tuple(theme.COLOR_MUC_JID), 'color_spec': spec_col, } - self.add_message(msg, typ=2) + self.add_message(InfoMessage(msg), typ=2) self.core.on_user_rejoined_private_conversation(self.jid.bare, from_nick) def on_user_nick_change(self, presence, user, from_nick, from_room): @@ -723,14 +733,16 @@ class MucTab(ChatTab): old_color = color = 3 info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT) self.add_message( - '\x19%(old_color)s}%(old)s\x19%(info_col)s} is' - ' now known as \x19%(color)s}%(new)s' % { - 'old': from_nick, - 'new': new_nick, - 'color': color, - 'old_color': old_color, - 'info_col': info_col - }, + InfoMessage( + '\x19%(old_color)s}%(old)s\x19%(info_col)s} is' + ' now known as \x19%(color)s}%(new)s' % { + 'old': from_nick, + 'new': new_nick, + 'color': color, + 'old_color': old_color, + 'info_col': info_col + }, + ), typ=2) # rename the private tabs if needed self.core.rename_private_tabs(self.jid.bare, from_nick, user) @@ -814,7 +826,7 @@ class MucTab(ChatTab): 'reason': reason.text, 'info_col': info_col } - self.add_message(kick_msg, typ=2) + self.add_message(InfoMessage(kick_msg), typ=2) def on_user_kicked(self, presence, user, from_nick): """ @@ -892,7 +904,7 @@ class MucTab(ChatTab): 'reason': reason.text, 'info_col': info_col } - self.add_message(kick_msg, typ=2) + self.add_message(InfoMessage(kick_msg), typ=2) def on_user_leave_groupchat(self, user: User, @@ -957,7 +969,7 @@ class MucTab(ChatTab): } if status: leave_msg += ' (\x19o%s\x19%s})' % (status, info_col) - self.add_message(leave_msg, typ=2) + self.add_message(InfoMessage(leave_msg), typ=2) self.core.on_user_left_private_conversation(from_room, user, status) def on_user_change_status(self, user, from_nick, from_room, affiliation, @@ -1016,7 +1028,7 @@ class MucTab(ChatTab): or show != user.show or status != user.status)) or ( affiliation != user.affiliation or role != user.role): # display the message in the room - self._text_buffer.add_message(msg) + self.add_message(InfoMessage(msg)) self.core.on_user_changed_status_in_private( '%s/%s' % (from_room, from_nick), Status(show, status)) self.users.remove(user) @@ -1118,7 +1130,6 @@ class MucTab(ChatTab): nickname=None, user=None, jid=None): - self.log_message(txt, nickname, time=time, typ=1) highlight = self.do_highlight(txt, time, nickname, corrected=True) message = self._text_buffer.modify_message( txt, @@ -1129,6 +1140,7 @@ class MucTab(ChatTab): user=user, jid=jid) if message: + self.log_message(message, typ=1) self.text_win.modify_message(message.identifier, message) return highlight return False @@ -1192,9 +1204,11 @@ class MucTab(ChatTab): def on_self_ping_failed(self, iq): if not self.lagged: self.lagged = True - info_text = dump_tuple(get_theme().COLOR_INFORMATION_TEXT) self._text_buffer.add_message( - "\x19%s}MUC service not responding." % info_text) + InfoMessage( + "MUC service not responding." + ), + ) self._state = 'disconnected' self.core.refresh_window() self.enable_self_ping_event() @@ -1202,9 +1216,9 @@ class MucTab(ChatTab): def reset_lag(self): if self.lagged: self.lagged = False - info_text = dump_tuple(get_theme().COLOR_INFORMATION_TEXT) - self._text_buffer.add_message( - "\x19%s}MUC service is responding again." % info_text) + self.add_message( + InfoMessage("MUC service is responding again.") + ) if self != self.core.tabs.current_tab: self._state = 'joined' else: @@ -1551,7 +1565,7 @@ class MucTab(ChatTab): buff.append('\n') message = ' '.join(buff) - self._text_buffer.add_message(message) + self.add_message(InfoMessage(message), typ=0) self.text_win.refresh() self.input.refresh() diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index 7206240f..b43294a1 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -27,6 +27,7 @@ from poezio.decorators import refresh_wrapper from poezio.logger import logger from poezio.theming import get_theme, dump_tuple from poezio.decorators import command_args_parser +from poezio.ui.types import BaseMessage, Message, InfoMessage log = logging.getLogger(__name__) @@ -106,12 +107,14 @@ class PrivateTab(OneToOneTab): def remove_information_element(plugin_name): del PrivateTab.additional_information[plugin_name] - def log_message(self, txt, nickname, time=None, typ=1): + def log_message(self, msg: BaseMessage, typ=1): """ Log the messages in the archives. """ + if not isinstance(msg, Message): + return if not logger.log_message( - self.jid.full, nickname, txt, date=time, typ=typ): + self.jid.full, msg.nickname, msg.txt, date=msg.time, typ=typ): self.core.information('Unable to write in the log file', 'Error') def on_close(self): @@ -163,8 +166,6 @@ class PrivateTab(OneToOneTab): self.core.events.trigger('private_say', msg, self) if not msg['body']: return - user = self.parent_muc.get_user_by_name(self.own_nick) - replaced = False if correct or msg['replace']['id']: msg['replace']['id'] = self.last_sent_message['id'] else: @@ -311,13 +312,15 @@ class PrivateTab(OneToOneTab): display a message. """ self.add_message( - '\x19%(nick_col)s}%(old)s\x19%(info_col)s} is now ' - 'known as \x19%(nick_col)s}%(new)s' % { - 'old': old_nick, - 'new': user.nick, - 'nick_col': dump_tuple(user.color), - 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT) - }, + InfoMessage( + '\x19%(nick_col)s}%(old)s\x19%(info_col)s} is now ' + 'known as \x19%(nick_col)s}%(new)s' % { + 'old': old_nick, + 'new': user.nick, + 'nick_col': dump_tuple(user.color), + 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT) + }, + ), typ=2) new_jid = self.jid.bare + '/' + user.nick self.name = new_jid @@ -338,27 +341,31 @@ class PrivateTab(OneToOneTab): if not status_message: self.add_message( - '\x19%(quit_col)s}%(spec)s \x19%(nick_col)s}' - '%(nick)s\x19%(info_col)s} has left the room' % { - 'nick': user.nick, - 'spec': theme.CHAR_QUIT, - 'nick_col': color, - 'quit_col': dump_tuple(theme.COLOR_QUIT_CHAR), - 'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT) - }, + InfoMessage( + '\x19%(quit_col)s}%(spec)s \x19%(nick_col)s}' + '%(nick)s\x19%(info_col)s} has left the room' % { + 'nick': user.nick, + 'spec': theme.CHAR_QUIT, + 'nick_col': color, + 'quit_col': dump_tuple(theme.COLOR_QUIT_CHAR), + 'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT) + }, + ), typ=2) else: self.add_message( - '\x19%(quit_col)s}%(spec)s \x19%(nick_col)s}' - '%(nick)s\x19%(info_col)s} has left the room' - ' (%(status)s)' % { - 'status': status_message, - 'nick': user.nick, - 'spec': theme.CHAR_QUIT, - 'nick_col': color, - 'quit_col': dump_tuple(theme.COLOR_QUIT_CHAR), - 'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT) - }, + InfoMessage( + '\x19%(quit_col)s}%(spec)s \x19%(nick_col)s}' + '%(nick)s\x19%(info_col)s} has left the room' + ' (%(status)s)' % { + 'status': status_message, + 'nick': user.nick, + 'spec': theme.CHAR_QUIT, + 'nick_col': color, + 'quit_col': dump_tuple(theme.COLOR_QUIT_CHAR), + 'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT) + }, + ), typ=2) return self.core.tabs.current_tab is self @@ -378,26 +385,28 @@ class PrivateTab(OneToOneTab): if user: color = dump_tuple(user.color) self.add_message( - '\x19%(join_col)s}%(spec)s \x19%(color)s}%(nick)s\x19' - '%(info_col)s} joined the room' % { - 'nick': nick, - 'color': color, - 'spec': theme.CHAR_JOIN, - 'join_col': dump_tuple(theme.COLOR_JOIN_CHAR), - 'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT) - }, + InfoMessage( + '\x19%(join_col)s}%(spec)s \x19%(color)s}%(nick)s\x19' + '%(info_col)s} joined the room' % { + 'nick': nick, + 'color': color, + 'spec': theme.CHAR_JOIN, + 'join_col': dump_tuple(theme.COLOR_JOIN_CHAR), + 'info_col': dump_tuple(theme.COLOR_INFORMATION_TEXT) + }, + ), typ=2) return self.core.tabs.current_tab is self def activate(self, reason=None): self.on = True if reason: - self.add_message(txt=reason, typ=2) + self.add_message(InfoMessage(reason), typ=2) def deactivate(self, reason=None): self.on = False if reason: - self.add_message(txt=reason, typ=2) + self.add_message(InfoMessage(reason), typ=2) def matching_names(self): return [(3, self.jid.resource), (4, self.name)] @@ -407,9 +416,12 @@ class PrivateTab(OneToOneTab): error = '\x19%s}%s\x19o' % (dump_tuple(theme.COLOR_CHAR_NACK), error_message) self.add_message( - error, - highlight=True, - nickname='Error', - nick_color=theme.COLOR_ERROR_MSG, - typ=2) + Message( + error, + highlight=True, + nickname='Error', + nick_color=theme.COLOR_ERROR_MSG, + ), + typ=2, + ) self.core.refresh_window() diff --git a/poezio/tabs/rostertab.py b/poezio/tabs/rostertab.py index 6f43cca1..50b8c0d5 100644 --- a/poezio/tabs/rostertab.py +++ b/poezio/tabs/rostertab.py @@ -27,6 +27,7 @@ from poezio.theming import get_theme, dump_tuple from poezio.decorators import command_args_parser from poezio.core.structs import Command, Completion from poezio.tabs import Tab +from poezio.ui.types import InfoMessage log = logging.getLogger(__name__) @@ -402,11 +403,11 @@ class RosterInfoTab(Tab): if not tab: log.debug('Received message from nonexistent tab: %s', message['from']) - message = '\x19%(info_col)s}Cannot send message to %(jid)s: contact blocked' % { + message = 'Cannot send message to %(jid)s: contact blocked' % { 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT), 'jid': message['from'], } - tab.add_message(message) + tab.add_message(InfoMessage(message), typ=0) @command_args_parser.ignored def command_list_blocks(self): diff --git a/poezio/tabs/xmltab.py b/poezio/tabs/xmltab.py index c73eddd0..85828602 100644 --- a/poezio/tabs/xmltab.py +++ b/poezio/tabs/xmltab.py @@ -65,7 +65,7 @@ class XMLTab(Tab): self.filtered_buffer = text_buffer.TextBuffer() self.info_header = windows.XMLInfoWin() - self.text_win = windows.XMLTextWin() + self.text_win = windows.TextWin() self.core_buffer.add_window(self.text_win) self.default_help_message = windows.HelpText("/ to enter a command") |