def update_status(self, status): old_status = self.__status if not (old_status.show != status.show or old_status.message != status.message): return self.__status = status hide_status_change = config.get_by_tabname('hide_status_change', self.jid.bare) now = datetime.now() dff = now - self.last_remote_message if hide_status_change > -1 and dff.total_seconds() > hide_status_change: return info_c = dump_tuple(get_theme().COLOR_INFORMATION_TEXT) nick = self.get_nick() remote = self.remote_user_color() msg = '\x19%(color)s}%(nick)s\x19%(info)s} changed: ' msg %= {'color': remote, 'nick': nick, 'info': info_c} if status.message != old_status.message and status.message: msg += 'status: %s, ' % status.message if status.show in SHOW_NAME: msg += 'show: %s, ' % SHOW_NAME[status.show] self.add_message( InfoMessage(txt=msg[:-2]), typ=2, )
def user_rejoined(self, nick): """ The user (or at least someone with the same nick) came back in the MUC """ self.activate() self.check_features() tab = self.parent_muc theme = get_theme() color = dump_tuple(theme.COLOR_REMOTE_USER) if tab and config.get_by_tabname('display_user_color_in_join_part', self.general_jid): user = tab.get_user_by_name(nick) if user: color = dump_tuple(user.color) self.add_message(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 add_line( text_buffer: TextBuffer, text: str, datetime: Optional[datetime] = None, ) -> None: """Adds a textual entry in the TextBuffer""" text_buffer.add_message(InfoMessage(text, time=datetime))
def on_muc_msg(self, message, tab): def format_timedelta(delta): """ Return a string of the form D days, H hours, M minutes, S seconds. If the number of total minutes is bigger than 10, we usually don’t care anymore about the number of seconds, so we don’t display it. Same thing if the number of days is bigger than one, we don’t display the minutes either. """ days = delta.days hours = delta.seconds // 3600 minutes = delta.seconds // 60 % 60 seconds = delta.seconds % 60 res = '' if days > 0: res = "%s days, " % days if hours > 0: res += "%s hours, " % hours if days == 0 and minutes != 0: res += "%s minutes, " % minutes if delta.total_seconds() < 600: res += "%s seconds, " % seconds return res[:-2] last_message_date = self.last_messages.get(tab.jid.bare) self.last_messages[tab.jid.bare] = datetime.now() if last_message_date: delta = datetime.now() - last_message_date if delta >= timedelta(0, self.config.get('delay', 900)): tab.add_message( InfoMessage("%s passed…" % (format_timedelta(delta), )))
def day_change(self): msg = _("Day changed to %s") % (datetime.date.today().isoformat()) for tab in self.core.tabs: if isinstance(tab, tabs.ChatTab): tab.add_message(InfoMessage(msg)) self.core.refresh_window() self.schedule_event()
def on_blocked_message(self, message): """ When we try to send a message to a blocked contact """ tab = self.core.get_conversation_by_jid(message['from'], False) if not tab: log.debug('Received message from nonexistent tab: %s', message['from']) message = 'Cannot send message to %(jid)s: contact blocked' % { 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT), 'jid': message['from'], } tab.add_message(InfoMessage(message), typ=0)
def user_left(self, status_message, user): """ The user left the associated MUC """ self.deactivate() theme = get_theme() if config.get_by_tabname('display_user_color_in_join_part', self.general_jid): color = dump_tuple(user.color) else: color = dump_tuple(theme.COLOR_REMOTE_USER) if not status_message: self.add_message(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(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
def rename_user(self, old_nick, user): """ The user changed her nick in the corresponding muc: update the tab’s name and display a message. """ self.add_message(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 return self.core.tabs.current_tab is self
def deactivate(self, reason=None): self.on = False if reason: self.add_message(InfoMessage(reason), typ=2)
def activate(self, reason=None): self.on = True if reason: self.add_message(InfoMessage(reason), typ=2)