diff --git a/src/core.py b/src/core.py index bcbc6bef..f5c0713e 100644 --- a/src/core.py +++ b/src/core.py @@ -219,32 +219,45 @@ class Core(object): self.information('%s' % messsage) def on_chatstate_active(self, message): - if message['type'] == 'chat': # normal conversation - self.on_chatstate_normal_conversation(message, "active") + self.on_chatstate(message, "active") def on_chatstate_inactive(self, message): - if message['type'] == 'chat': # normal conversation - self.on_chatstate_normal_conversation(message, "inactive") + self.on_chatstate(message, "inactive") def on_chatstate_composing(self, message): - if message['type'] == 'chat': - self.on_chatstate_normal_conversation(message, "composing") + self.on_chatstate(message, "composing") def on_chatstate_paused(self, message): - if message['type'] == 'chat': - self.on_chatstate_normal_conversation(message, "paused") + self.on_chatstate(message, "paused") def on_chatstate_gone(self, message): + self.on_chatstate(message, "gone") + + def on_chatstate(self, message, state): if message['type'] == 'chat': - self.on_chatstate_normal_conversation(message, "gone") + if not self.on_chatstate_normal_conversation(message, state): + room = self.get_room_by_name(message['from'].full) + if not room: + return + self.on_chatstate_private_conversation(message, state) def on_chatstate_normal_conversation(self, message,state): tab = self.get_tab_of_conversation_with_jid(message['from'], False) + if not tab: + return False + tab.chatstate = state + if tab == self.current_tab(): + self.refresh_window() + return True + + def on_chatstate_private_conversation(self, message, state): + tab = self.get_tab_by_name(message['from'].full, tabs.PrivateTab) if not tab: return tab.chatstate = state if tab == self.current_tab(): self.refresh_window() + return True def open_new_form(self, form, on_cancel, on_send, **kwargs): """ @@ -600,6 +613,12 @@ class Core(object): room.add_message(body, time=None, nickname=nick_from, colorized=False, forced_user=self.get_room_by_name(room_from).get_user_by_name(nick_from)) + conversation = self.get_tab_by_name(jid.full, tabs.PrivateTab) + if conversation.remote_wants_chatstates is None: + if message['chat_state']: + conversation.remote_wants_chatstates = True + else: + conversation.remote_wants_chatstates = False logger.log_message(jid.full.replace('/', '\\'), nick_from, body) self.refresh_window() self.doupdate() diff --git a/src/tabs.py b/src/tabs.py index 054bdccc..ffae2652 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -376,7 +376,7 @@ class MucTab(ChatTab, TabWithInfoWin): The tab containing a multi-user-chat room. It contains an userlist, an input, a topic, an information and a chat zone """ - message_type = 'chat' + message_type = 'groupchat' def __init__(self, core, room): ChatTab.__init__(self, core, room) TabWithInfoWin.__init__(self) @@ -733,9 +733,14 @@ class PrivateTab(ChatTab, TabWithInfoWin): self.complete_commands(self.input) def command_say(self, line): - muc.send_private_message(self.core.xmpp, self.get_name(), line) - self.core.add_message_to_text_buffer(self.get_room(), line, None, self.get_room().own_nick) - logger.log_message(self.get_name().replace('/', '\\'), self.get_room().own_nick, line) + msg = self.core.xmpp.make_message(self.get_name()) + msg['type'] = 'chat' + msg['body'] = line + if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False: + msg['chat_state'] = 'active' + msg.send() + self.core.add_message_to_text_buffer(self.get_room(), line, None, self.core.own_nick) + logger.log_message(JID(self.get_name()).bare, self.core.own_nick, line) def command_unquery(self, arg): """ @@ -762,7 +767,7 @@ class PrivateTab(ChatTab, TabWithInfoWin): if self.need_resize: self.resize() self.text_win.refresh(self._room) - self.info_header.refresh(self._room, self.text_win) + self.info_header.refresh(self._room, self.text_win, self.chatstate) self.info_win.refresh(informations) self.tab_win.refresh(tabs, tabs[0]) self.input.refresh() @@ -1330,7 +1335,6 @@ class MucListTab(Tab): Callback called when a disco#items result is received Used with command_list """ - log.debug('res: %s\n\n' % iq) if iq['type'] == 'error': self.set_error(iq['error']['type'], iq['error']['code'], iq['error']['text']) return diff --git a/src/windows.py b/src/windows.py index dc30d541..a18785ad 100644 --- a/src/windows.py +++ b/src/windows.py @@ -245,12 +245,13 @@ class PrivateInfoWin(InfoWin): def resize(self, height, width, y, x, stdscr): self._resize(height, width, y, x, stdscr) - def refresh(self, room, window): + def refresh(self, room, window, chatstate): with g_lock: self._win.erase() self.write_room_name(room) self.print_scroll_position(window) + self.write_chatstate(chatstate) self.finish_line(theme.COLOR_INFORMATION_BAR) self._refresh() @@ -261,6 +262,10 @@ class PrivateInfoWin(InfoWin): txt = ' from room %s' % room_name self.addstr(txt, common.curses_color_pair(theme.COLOR_INFORMATION_BAR)) + def write_chatstate(self, state): + if state: + self.addstr(' %s' % (state,), common.curses_color_pair(theme.COLOR_INFORMATION_BAR)) + class ConversationInfoWin(InfoWin): """ The line above the information window, displaying informations