primitivus (chat): use the factorised code for user moved info messages.
This commit is contained in:
parent
a28d1d136a
commit
47bd1495df
1 changed files with 13 additions and 55 deletions
|
|
@ -38,7 +38,7 @@ import bisect
|
|||
OCCUPANTS_FOOTER = _(u"{} occupants")
|
||||
|
||||
|
||||
class MessageWidget(urwid.WidgetWrap):
|
||||
class MessageWidget(urwid.WidgetWrap, quick_chat.MessageWidget):
|
||||
def __init__(self, mess_data):
|
||||
"""
|
||||
@param mess_data(quick_chat.Message, None): message data
|
||||
|
|
@ -276,16 +276,8 @@ class OccupantsWidget(urwid.WidgetWrap):
|
|||
|
||||
|
||||
class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
||||
def __init__(
|
||||
self,
|
||||
host,
|
||||
target,
|
||||
type_=C.CHAT_ONE2ONE,
|
||||
nick=None,
|
||||
occupants=None,
|
||||
subject=None,
|
||||
profiles=None,
|
||||
):
|
||||
def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None,
|
||||
subject=None, profiles=None):
|
||||
quick_chat.QuickChat.__init__(
|
||||
self, host, target, type_, nick, occupants, subject, profiles=profiles
|
||||
)
|
||||
|
|
@ -315,6 +307,10 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
self.show_title = 1 # 0: clip title; 1: full title; 2: no title
|
||||
self.postInit()
|
||||
|
||||
@property
|
||||
def message_widgets_rev(self):
|
||||
return reversed(self.mess_walker)
|
||||
|
||||
def keypress(self, size, key):
|
||||
if key == a_key["OCCUPANTS_HIDE"]: # user wants to (un)hide the occupants panel
|
||||
if self.type == C.CHAT_GROUP:
|
||||
|
|
@ -329,9 +325,8 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
elif key == a_key["SHORT_NICKNAME"]: # user wants to (not) use short nick
|
||||
self.show_short_nick = not self.show_short_nick
|
||||
self.redraw()
|
||||
elif (
|
||||
key == a_key["SUBJECT_SWITCH"]
|
||||
): # user wants to (un)hide group's subject or change its apperance
|
||||
elif (key == a_key["SUBJECT_SWITCH"]):
|
||||
# user wants to (un)hide group's subject or change its apperance
|
||||
if self.subject:
|
||||
self.show_title = (self.show_title + 1) % 3
|
||||
if self.show_title == 0:
|
||||
|
|
@ -420,20 +415,6 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
def createMessage(self, message):
|
||||
self.appendMessage(message)
|
||||
|
||||
def _user_moved(self, message):
|
||||
"""return true if message is a user left/joined message
|
||||
|
||||
@param message(quick_chat.Message): message to add
|
||||
"""
|
||||
if message.type != C.MESS_TYPE_INFO:
|
||||
return False
|
||||
try:
|
||||
info_type = message.extra["info_type"]
|
||||
except KeyError:
|
||||
return False
|
||||
else:
|
||||
return info_type in quick_chat.ROOM_USER_MOVED
|
||||
|
||||
def _scrollDown(self):
|
||||
"""scroll down message only if we are already at the bottom (minus 1)"""
|
||||
current_focus = self.mess_widgets.focus_position
|
||||
|
|
@ -451,32 +432,9 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
if self.filters:
|
||||
if not all([f(message) for f in self.filters]):
|
||||
return
|
||||
if self._user_moved(message):
|
||||
for wid in reversed(self.mess_walker):
|
||||
# we merge in/out messages if no message was sent meanwhile
|
||||
if not isinstance(wid, MessageWidget):
|
||||
continue
|
||||
if wid.mess_data.type != C.MESS_TYPE_INFO:
|
||||
break
|
||||
if (
|
||||
wid.info_type in quick_chat.ROOM_USER_MOVED
|
||||
and wid.mess_data.nick == message.nick
|
||||
):
|
||||
try:
|
||||
count = wid.reentered_count
|
||||
except AttributeError:
|
||||
count = wid.reentered_count = 1
|
||||
nick = wid.mess_data.nick
|
||||
if message.info_type == quick_chat.ROOM_USER_LEFT:
|
||||
wid.message = _(u"<= {nick} has left the room ({count})").format(
|
||||
nick=nick, count=count
|
||||
)
|
||||
else:
|
||||
wid.message = _(
|
||||
u"<=> {nick} re-entered the room ({count})"
|
||||
).format(nick=nick, count=count)
|
||||
wid.reentered_count += 1
|
||||
return
|
||||
|
||||
if self.handleUserMoved(message):
|
||||
return
|
||||
|
||||
if (
|
||||
self.host.selected_widget != self or not self.host.x_notify.hasFocus()
|
||||
|
|
@ -495,7 +453,7 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
wid = MessageWidget(message)
|
||||
self.mess_walker.append(wid)
|
||||
self._scrollDown()
|
||||
if self._user_moved(message):
|
||||
if self.isUserMoved(message):
|
||||
return # no notification for moved messages
|
||||
|
||||
# notifications
|
||||
|
|
|
|||
Loading…
Reference in a new issue