Add specific types for own leave and join

This commit is contained in:
mathieui 2020-05-10 15:16:24 +02:00
parent 4c1ab027ac
commit ea438438f2
2 changed files with 26 additions and 7 deletions

View file

@ -40,7 +40,14 @@ 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
from poezio.ui.types import (
BaseMessage,
InfoMessage,
Message,
MucOwnJoinMessage,
MucOwnLeaveMessage,
StatusMessage,
)
log = logging.getLogger(__name__)
@ -200,7 +207,7 @@ class MucTab(ChatTab):
'color_spec': spec_col,
'nick': self.own_nick,
}
self.add_message(InfoMessage(msg), typ=2)
self.add_message(MucOwnLeaveMessage(msg), typ=2)
self.disconnect()
muc.leave_groupchat(self.core.xmpp, self.jid.bare, self.own_nick,
message)
@ -567,7 +574,7 @@ class MucTab(ChatTab):
'nick_col': color,
'info_col': info_col,
}
self.add_message(InfoMessage(enable_message), typ=2)
self.add_message(MucOwnJoinMessage(enable_message), typ=2)
self.core.enable_private_tabs(self.jid.bare, enable_message)
if '201' in status_codes:
self.add_message(
@ -651,7 +658,7 @@ class MucTab(ChatTab):
def on_non_member_kicked(self):
"""We have been kicked because the MUC is members-only"""
self.add_message(
InfoMessage(
MucOwnLeaveMessage(
'You have been kicked because you '
'are not a member and the room is now members-only.'
),
@ -661,7 +668,7 @@ class MucTab(ChatTab):
def on_muc_shutdown(self):
"""We have been kicked because the MUC service is shutting down"""
self.add_message(
InfoMessage(
MucOwnLeaveMessage(
'You have been kicked because the'
' MUC service is shutting down.'
),
@ -759,6 +766,7 @@ class MucTab(ChatTab):
"""
When someone is banned from a muc
"""
cls = InfoMessage
self.users.remove(user)
by = presence.xml.find('{%s}x/{%s}item/{%s}actor' %
(NS_MUC_USER, NS_MUC_USER, NS_MUC_USER))
@ -774,6 +782,7 @@ class MucTab(ChatTab):
char_kick = theme.CHAR_KICK
if from_nick == self.own_nick: # we are banned
cls = MucOwnLeaveMessage
if by:
kick_msg = ('\x191}%(spec)s \x193}You\x19%(info_col)s}'
' have been banned by \x194}%(by)s') % {
@ -834,12 +843,13 @@ class MucTab(ChatTab):
'reason': reason.text,
'info_col': info_col
}
self.add_message(InfoMessage(kick_msg), typ=2)
self.add_message(cls(kick_msg), typ=2)
def on_user_kicked(self, presence, user, from_nick):
"""
When someone is kicked from a muc
"""
cls = InfoMessage
self.users.remove(user)
actor_elem = presence.xml.find('{%s}x/{%s}item/{%s}actor' %
(NS_MUC_USER, NS_MUC_USER, NS_MUC_USER))
@ -852,6 +862,7 @@ class MucTab(ChatTab):
if actor_elem is not None:
by = actor_elem.get('nick') or actor_elem.get('jid')
if from_nick == self.own_nick: # we are kicked
cls = MucOwnLeaveMessage
if by:
kick_msg = ('\x191}%(spec)s \x193}You\x19'
'%(info_col)s} have been kicked'
@ -912,7 +923,7 @@ class MucTab(ChatTab):
'reason': reason.text,
'info_col': info_col
}
self.add_message(InfoMessage(kick_msg), typ=2)
self.add_message(cls(kick_msg), typ=2)
def on_user_leave_groupchat(self,
user: User,

View file

@ -33,6 +33,14 @@ class InfoMessage(BaseMessage):
super().__init__(txt=txt, identifier=identifier, time=time)
class MucOwnLeaveMessage(InfoMessage):
"""Status message displayed on our room leave/kick/ban"""
class MucOwnJoinMessage(InfoMessage):
"""Status message displayed on our room join"""
class XMLLog(BaseMessage):
"""XML Log message"""
__slots__ = ('txt', 'time', 'identifier', 'incoming')