Do not send chatstates when the contact is offline

This commit is contained in:
mathieui 2011-11-09 22:34:16 +01:00
parent 7f322e7d88
commit f55a0c92f2
2 changed files with 20 additions and 6 deletions

View file

@ -626,7 +626,7 @@ class Core(object):
self.events.trigger('conversation_msg', message, conversation) self.events.trigger('conversation_msg', message, conversation)
body = xhtml.get_body_from_message_stanza(message) body = xhtml.get_body_from_message_stanza(message)
if roster.get_contact_by_jid(jid.bare): if roster.get_contact_by_jid(jid.bare):
remote_nick = roster.get_contact_by_jid(jid.bare).get_name() or jid.user remote_nick = roster.get_contact_by_jid(jid.bare).name or jid.user
else: else:
remote_nick = jid.user remote_nick = jid.user
conversation._text_buffer.add_message(body, nickname=remote_nick, nick_color=get_theme().COLOR_REMOTE_USER) conversation._text_buffer.add_message(body, nickname=remote_nick, nick_color=get_theme().COLOR_REMOTE_USER)
@ -1590,10 +1590,10 @@ class Core(object):
when enter is pressed on the roster window when enter is pressed on the roster window
""" """
if isinstance(roster_row, Contact): if isinstance(roster_row, Contact):
if not self.get_conversation_by_jid(roster_row.get_bare_jid()): if not self.get_conversation_by_jid(roster_row.bare_jid):
self.open_conversation_window(roster_row.get_bare_jid()) self.open_conversation_window(roster_row.bare_jid)
else: else:
self.focus_tab_named(roster_row.get_bare_jid()) self.focus_tab_named(roster_row.bare_jid)
if isinstance(roster_row, Resource): if isinstance(roster_row, Resource):
if not self.get_conversation_by_jid(roster_row.get_jid().full): if not self.get_conversation_by_jid(roster_row.get_jid().full):
self.open_conversation_window(roster_row.get_jid().full) self.open_conversation_window(roster_row.get_jid().full)

View file

@ -1975,16 +1975,30 @@ class ConversationTab(ChatTab):
return False return False
def on_lose_focus(self): def on_lose_focus(self):
contact = roster.get_contact_by_jid(self.get_name())
jid = JID(self.get_name())
if jid.resource:
resource = contact.get_resource_by_fulljid(jid.full)
else:
resource = contact.get_highest_priority_resource()
self.state = 'normal' self.state = 'normal'
self.text_win.remove_line_separator() self.text_win.remove_line_separator()
self.text_win.add_line_separator() self.text_win.add_line_separator()
if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'): if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'):
if resource:
self.send_chat_state('inactive') self.send_chat_state('inactive')
def on_gain_focus(self): def on_gain_focus(self):
contact = roster.get_contact_by_jid(self.get_name())
jid = JID(self.get_name())
if jid.resource:
resource = contact.get_resource_by_fulljid(jid.full)
else:
resource = contact.get_highest_priority_resource()
self.state = 'current' self.state = 'current'
curses.curs_set(1) curses.curs_set(1)
if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'): if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'):
if resource:
self.send_chat_state('active') self.send_chat_state('active')
def on_scroll_up(self): def on_scroll_up(self):