Commit a0f655f2 authored by Philipp Hörist's avatar Philipp Hörist

Refactor printing info and status messages

Add some methods to ChatControlBase to add status and info message to the ConversationTextview instead of going through
print_conversation() and print_conversation_line() which adds nothing to info and status messages
parent 603ad003
......@@ -560,7 +560,7 @@ class ChatControl(ChatControlBase):
if state in ('connecting', 'connected', 'stop', 'error') and reason:
info = _('%(type)s state : %(state)s, reason: %(reason)s') % {
'type': jingle_type.capitalize(), 'state': state, 'reason': reason}
self.print_conversation(info, 'info')
self.add_info_message(info)
states = {'connecting': self.JINGLE_STATE_CONNECTING,
'connection_received': self.JINGLE_STATE_CONNECTION_RECEIVED,
......@@ -967,17 +967,9 @@ class ChatControl(ChatControlBase):
if additional_data is None:
additional_data = AdditionalDataDict()
if frm == 'status':
if not app.config.get('print_status_in_chats'):
return
kind = 'status'
name = ''
elif frm == 'error':
if frm == 'error':
kind = 'error'
name = ''
elif frm == 'info':
kind = 'info'
name = ''
else:
if not frm:
kind = 'incoming'
......@@ -1217,12 +1209,12 @@ class ChatControl(ChatControlBase):
if self.contact != obj.contact:
return
if obj.name == 'ping-sent':
self.print_conversation(_('Ping?'), 'status')
self.add_info_message(_('Ping?'))
elif obj.name == 'ping-reply':
self.print_conversation(
_('Pong! (%s seconds)') % obj.seconds, 'status')
self.add_info_message(
_('Pong! (%s seconds)') % obj.seconds)
elif obj.name == 'ping-error':
self.print_conversation(_('Error.'), 'status')
self.add_info_message(_('Error.'))
def show_avatar(self):
if not app.config.get('show_avatar_in_chat'):
......@@ -1422,11 +1414,14 @@ class ChatControl(ChatControlBase):
self.update_ui()
self.parent_win.redraw_tab(self)
if not app.config.get('print_status_in_chats'):
return
if status:
status = '- %s' % status
status_line = _('%(name)s is now %(show)s %(status)s') % {
'name': name, 'show': uf_show, 'status': status or ''}
self.print_conversation(status_line, 'status')
self.add_status_message(status_line)
def _info_bar_show_message(self):
if self.info_bar.get_visible():
......
......@@ -922,6 +922,16 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
else:
self.received_history_pos = pos
def add_info_message(self, text):
jid = self.contact.jid
self.conv_textview.print_conversation_line(
text, jid, 'info', '', None, graphics=False)
def add_status_message(self, text):
jid = self.contact.jid
self.conv_textview.print_conversation_line(
text, jid, 'status', '', None)
def print_conversation_line(self, text, kind, name, tim,
other_tags_for_name=None, other_tags_for_time=None, other_tags_for_text=None,
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False,
......
......@@ -226,7 +226,7 @@ class Message(BaseModule):
if not event.msgtxt:
event.msgtxt = _('message')
if event.gc_control:
event.gc_control.print_conversation(event.msgtxt)
event.gc_control.add_info_message(event.msgtxt)
else:
self._log_error_message(event)
error_msg = event.stanza.getErrorMsg() or event.msgtxt
......
......@@ -1325,19 +1325,14 @@ class GroupchatControl(ChatControlBase):
additional_data = AdditionalDataDict()
other_tags_for_name = []
other_tags_for_text = []
if contact:
if contact == self.nick: # it's us
kind = 'outgoing'
elif contact == 'info':
kind = 'info'
contact = None
else:
kind = 'incoming'
# muc-specific chatstate
if self.parent_win:
self.parent_win.redraw_tab(self, 'newmsg')
if contact == self.nick: # it's us
kind = 'outgoing'
else:
kind = 'status'
kind = 'incoming'
# muc-specific chatstate
if self.parent_win:
self.parent_win.redraw_tab(self, 'newmsg')
if kind == 'incoming': # it's a message NOT from us
# highlighting and sounds
......@@ -1476,7 +1471,7 @@ class GroupchatControl(ChatControlBase):
just_joined = self.join_time > time.time() - 10
if app.config.get('show_subject_on_join') or not just_joined:
self.print_conversation(text)
self.add_info_message(text)
if event.subject == '':
self.subject_button.hide()
......@@ -1517,7 +1512,7 @@ class GroupchatControl(ChatControlBase):
self.is_anonymous = True
for change in changes:
self.print_conversation(change)
self.add_info_message(change)
def _nec_signed_in(self, obj):
if obj.conn.name != self.account:
......@@ -1552,13 +1547,13 @@ class GroupchatControl(ChatControlBase):
nick = obj.contact.get_shown_name()
if obj.name == 'ping-sent':
self.print_conversation(_('Ping? (%s)') % nick)
self.add_info_message(_('Ping? (%s)') % nick)
elif obj.name == 'ping-reply':
self.print_conversation(
self.add_info_message(
_('Pong! (%(nick)s %(delay)s s.)') % {'nick': nick,
'delay': obj.seconds})
elif obj.name == 'ping-error':
self.print_conversation(_('Error.'))
self.add_info_message(_('Error.'))
@property
def is_connected(self) -> bool:
......@@ -1769,8 +1764,7 @@ class GroupchatControl(ChatControlBase):
if not self.is_connected:
# We just joined the room
self.print_conversation(_('You (%s) joined the room') % nick,
'info', graphics=False)
self.add_info_message(_('You (%s) joined the room') % nick)
self.add_contact_to_roster(nick)
self.got_connected()
......@@ -1788,27 +1782,26 @@ class GroupchatControl(ChatControlBase):
# We just need to invite contacts
for jid in app.automatic_rooms[self.account][self.room_jid]['invities']:
con.get_module('MUC').invite(self.room_jid, jid)
self.print_conversation(
self.add_info_message(
_('%(jid)s has been '
'invited in this room') % {'jid': jid},
graphics=False)
'invited in this room') % {'jid': jid})
if StatusCode.NON_ANONYMOUS in status_codes:
self.print_conversation(
self.add_info_message(
_('Any occupant is allowed to see your full JID'))
self.is_anonymous = False
if StatusCode.CONFIG_ROOM_LOGGING in status_codes:
self.print_conversation(_('Room logging is enabled'))
self.add_info_message(_('Room logging is enabled'))
if StatusCode.NICKNAME_MODIFIED in status_codes:
self.print_conversation(\
self.add_info_message(\
_('The server has assigned or modified your roomnick'))
if event.properties.is_new_room:
app.connections[self.account].get_module('Discovery').disco_muc(
self.room_jid, self._on_room_created, update=True)
self.print_conversation(_('A new room has been created'))
self.add_info_message(_('A new room has been created'))
con = app.connections[self.account]
con.get_module('MUC').request_config(self.room_jid)
......@@ -1831,7 +1824,7 @@ class GroupchatControl(ChatControlBase):
'as {new_nick}').format(nick=nick, new_nick=new_nick)
self._nick_completion.contact_renamed(nick, new_nick)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
tv = self.conv_textview
if nick in tv.last_received_message_id:
......@@ -1858,14 +1851,14 @@ class GroupchatControl(ChatControlBase):
if event.properties.is_muc_self_presence:
message = _('You are now {show}{status}').format(show=show,
status=status)
self.print_conversation(message, 'info', graphics=False)
self.add_status_message(message)
elif app.config.get_per('rooms', self.room_jid,
'print_status', status_default):
message = _('{nick} is now {show}{status}').format(nick=nick,
show=show,
status=status)
self.print_conversation(message, 'info', graphics=False)
self.add_status_message(message)
self.draw_contact(nick)
......@@ -1899,7 +1892,7 @@ class GroupchatControl(ChatControlBase):
actor=actor,
reason=reason)
self.print_conversation(message, graphics=False)
self.add_info_message(message)
self.draw_contact(nick)
self.update_actions()
......@@ -1930,7 +1923,7 @@ class GroupchatControl(ChatControlBase):
actor=actor,
reason=reason)
self.print_conversation(message, graphics=False)
self.add_info_message(message)
self.remove_contact(nick)
self.add_contact_to_roster(nick)
self.update_actions()
......@@ -1960,39 +1953,39 @@ class GroupchatControl(ChatControlBase):
#Group Chat: Server kicked us because of an server error
message = _('You have left due '
'to an error{reason}').format(reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif StatusCode.REMOVED_KICKED in status_codes:
#Group Chat: We have been kicked by Alice: reason
message = _('You have been '
'kicked{actor}{reason}').format(actor=actor,
reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif StatusCode.REMOVED_BANNED in status_codes:
#Group Chat: We have been banned by Alice: reason
message = _('You have been '
'banned{actor}{reason}').format(actor=actor,
reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif StatusCode.REMOVED_AFFILIATION_CHANGE in status_codes:
#Group Chat: We were removed because of an affiliation change
reason = _(': Affiliation changed')
message = message.format(actor=actor, reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif StatusCode.REMOVED_NONMEMBER_IN_MEMBERS_ONLY in status_codes:
#Group Chat: Room configuration changed
reason = _(': Room configuration changed to members-only')
message = message.format(actor=actor, reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif StatusCode.REMOVED_SERVICE_SHUTDOWN in status_codes:
#Group Chat: Kicked because of server shutdown
reason = ': System shutdown'
message = message.format(actor=actor, reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
self.autorejoin = True
self.got_disconnected()
......@@ -2029,7 +2022,7 @@ class GroupchatControl(ChatControlBase):
#Group Chat: User was kicked because of an server error: reason
message = _('{nick} has left due to '
'an error{reason}').format(nick=nick, reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif StatusCode.REMOVED_KICKED in status_codes:
#Group Chat: User was kicked by Alice: reason
......@@ -2037,7 +2030,7 @@ class GroupchatControl(ChatControlBase):
'kicked{actor}{reason}').format(nick=nick,
actor=actor,
reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif StatusCode.REMOVED_BANNED in status_codes:
#Group Chat: User was banned by Alice: reason
......@@ -2045,22 +2038,22 @@ class GroupchatControl(ChatControlBase):
'banned{actor}{reason}').format(nick=nick,
actor=actor,
reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif StatusCode.REMOVED_AFFILIATION_CHANGE in status_codes:
reason = _(': Affiliation changed')
message = message.format(nick=nick, actor=actor, reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif StatusCode.REMOVED_NONMEMBER_IN_MEMBERS_ONLY in status_codes:
reason = _(': Room configuration changed to members-only')
message = message.format(nick=nick, actor=actor, reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
elif print_join_left:
message = _('{nick} has left{reason}').format(nick=nick,
reason=reason)
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
self.remove_contact(nick)
self.draw_all_roles()
......@@ -2079,8 +2072,7 @@ class GroupchatControl(ChatControlBase):
self.add_contact_to_roster(nick)
if self.is_connected and print_join_left:
self.print_conversation(_('%s has joined the group chat') % nick,
graphics=False)
self.add_info_message(_('%s has joined the group chat') % nick)
def _on_presence_error(self, event):
if event.account != self.account:
......@@ -2135,7 +2127,7 @@ class GroupchatControl(ChatControlBase):
self.account, self.room_jid, win)
else:
self.print_conversation(
self.add_info_message(
'Error %s: %s' % (error_type.value, error_message))
self.autorejoin = False
......@@ -2192,13 +2184,13 @@ class GroupchatControl(ChatControlBase):
reason = '' if reason is None else ': %s' % reason
message = _('Room has been destroyed')
self.print_conversation(message, 'info', graphics=False)
self.add_info_message(message)
alternate = destroyed.alternate
if alternate is not None:
join_message = _('You can join this room '
'instead: xmpp:%s?join') % alternate
self.print_conversation(join_message, 'info', graphics=False)
self.add_info_message(join_message)
self.autorejoin = False
self.got_disconnected()
......@@ -2492,8 +2484,8 @@ class GroupchatControl(ChatControlBase):
con = app.connections[self.account]
con.get_module('MUC').invite(self.room_jid, contact_jid)
self.print_conversation(_('%(jid)s has been invited in this room') %
{'jid': contact_jid}, graphics=False)
self.add_info_message(_('%(jid)s has been invited in this room') %
{'jid': contact_jid})
def _jid_not_blocked(self, bare_jid: str) -> bool:
fjid = self.room_jid + '/' + bare_jid
......
......@@ -206,7 +206,7 @@ class Interface:
ctrl = self.msg_win_mgr.get_control(event.properties.jid.getBare(),
event.account)
if ctrl and ctrl.type_id == message_control.TYPE_GC:
ctrl.print_conversation('Error: %s' % event.properties.error)
ctrl.add_info_message('Error: %s' % event.properties.error)
@staticmethod
def handle_event_connection_lost(obj):
......@@ -360,12 +360,12 @@ class Interface:
account=account, name=nick, show=show)
ctrl = self.new_private_chat(gc_c, account, session)
ctrl.print_conversation(_('Error %(code)s: %(msg)s') % {
'code': obj.error_code, 'msg': obj.error_msg}, 'status')
ctrl.add_info_message(_('Error %(code)s: %(msg)s') % {
'code': obj.error_code, 'msg': obj.error_msg})
return
gc_control.print_conversation(_('Error %(code)s: %(msg)s') % {
'code': obj.error_code, 'msg': obj.error_msg}, 'status')
gc_control.add_info_message(_('Error %(code)s: %(msg)s') % {
'code': obj.error_code, 'msg': obj.error_msg})
if gc_control.parent_win and \
gc_control.parent_win.get_active_jid() == jid:
gc_control.set_subject(gc_control.subject)
......@@ -509,9 +509,9 @@ class Interface:
gc_control = self.msg_win_mgr.get_gc_control(obj.jid,
account)
if gc_control:
gc_control.print_conversation(
gc_control.add_info_message(
_('%(jid)s has been invited in this room') % {
'jid': jid}, graphics=False)
'jid': jid})
del app.automatic_rooms[account][obj.jid]
else:
win = app.get_app_window('GroupchatConfig', account, obj.jid)
......@@ -525,14 +525,13 @@ class Interface:
event.account)
if gc_control:
if event.reason:
gc_control.print_conversation(
gc_control.add_info_message(
_('%(jid)s declined the invitation: %(reason)s') % {
'jid': event.from_, 'reason': event.reason},
graphics=False)
'jid': event.from_, 'reason': event.reason})
else:
gc_control.print_conversation(
gc_control.add_info_message(
_('%(jid)s declined the invitation') % {
'jid': event.from_}, graphics=False)
'jid': event.from_})
def handle_event_gc_invitation(self, event):
if helpers.allow_popup_window(event.account) or not self.systray_enabled:
......
......@@ -114,7 +114,7 @@ class PrivateChatControl(ChatControl):
message = _('{nick} is now known '
'as {new_nick}').format(nick=nick, new_nick=new_nick)
self.print_conversation(message, 'info')
self.add_info_message(message)
self.draw_banner()
app.interface.msg_win_mgr.change_key(str(event.properties.jid),
......@@ -140,14 +140,14 @@ class PrivateChatControl(ChatControl):
if event.properties.is_muc_self_presence:
message = _('You are now {show}{status}').format(show=show,
status=status)
self.print_conversation(message, 'info')
self.add_status_message(message)
elif app.config.get_per('rooms', self.room_name,
'print_status', status_default):
message = _('{nick} is now {show}{status}').format(nick=nick,
show=show,
status=status)
self.print_conversation(message, 'info')
self.add_status_message(message)
self.parent_win.redraw_tab(self)
self.update_ui()
......
......@@ -3013,9 +3013,9 @@ class RosterWindow:
gc_control = app.interface.msg_win_mgr.get_gc_control(room_jid,
room_account)
if gc_control:
gc_control.print_conversation(
gc_control.add_info_message(
_('%(jid)s has been invited in this room') % {
'jid': contact_jid}, graphics=False)
'jid': contact_jid})
def on_all_groupchat_maximized(self, widget, group_list):
for (contact, account) in group_list:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment