end and handle chatstates in privateconversations
This commit is contained in:
parent
e4b96eb752
commit
cccbad13d5
3 changed files with 44 additions and 16 deletions
37
src/core.py
37
src/core.py
|
@ -219,32 +219,45 @@ class Core(object):
|
||||||
self.information('%s' % messsage)
|
self.information('%s' % messsage)
|
||||||
|
|
||||||
def on_chatstate_active(self, message):
|
def on_chatstate_active(self, message):
|
||||||
if message['type'] == 'chat': # normal conversation
|
self.on_chatstate(message, "active")
|
||||||
self.on_chatstate_normal_conversation(message, "active")
|
|
||||||
|
|
||||||
def on_chatstate_inactive(self, message):
|
def on_chatstate_inactive(self, message):
|
||||||
if message['type'] == 'chat': # normal conversation
|
self.on_chatstate(message, "inactive")
|
||||||
self.on_chatstate_normal_conversation(message, "inactive")
|
|
||||||
|
|
||||||
def on_chatstate_composing(self, message):
|
def on_chatstate_composing(self, message):
|
||||||
if message['type'] == 'chat':
|
self.on_chatstate(message, "composing")
|
||||||
self.on_chatstate_normal_conversation(message, "composing")
|
|
||||||
|
|
||||||
def on_chatstate_paused(self, message):
|
def on_chatstate_paused(self, message):
|
||||||
if message['type'] == 'chat':
|
self.on_chatstate(message, "paused")
|
||||||
self.on_chatstate_normal_conversation(message, "paused")
|
|
||||||
|
|
||||||
def on_chatstate_gone(self, message):
|
def on_chatstate_gone(self, message):
|
||||||
|
self.on_chatstate(message, "gone")
|
||||||
|
|
||||||
|
def on_chatstate(self, message, state):
|
||||||
if message['type'] == 'chat':
|
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):
|
def on_chatstate_normal_conversation(self, message,state):
|
||||||
tab = self.get_tab_of_conversation_with_jid(message['from'], False)
|
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:
|
if not tab:
|
||||||
return
|
return
|
||||||
tab.chatstate = state
|
tab.chatstate = state
|
||||||
if tab == self.current_tab():
|
if tab == self.current_tab():
|
||||||
self.refresh_window()
|
self.refresh_window()
|
||||||
|
return True
|
||||||
|
|
||||||
def open_new_form(self, form, on_cancel, on_send, **kwargs):
|
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,
|
room.add_message(body, time=None, nickname=nick_from,
|
||||||
colorized=False,
|
colorized=False,
|
||||||
forced_user=self.get_room_by_name(room_from).get_user_by_name(nick_from))
|
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)
|
logger.log_message(jid.full.replace('/', '\\'), nick_from, body)
|
||||||
self.refresh_window()
|
self.refresh_window()
|
||||||
self.doupdate()
|
self.doupdate()
|
||||||
|
|
16
src/tabs.py
16
src/tabs.py
|
@ -376,7 +376,7 @@ class MucTab(ChatTab, TabWithInfoWin):
|
||||||
The tab containing a multi-user-chat room.
|
The tab containing a multi-user-chat room.
|
||||||
It contains an userlist, an input, a topic, an information and a chat zone
|
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):
|
def __init__(self, core, room):
|
||||||
ChatTab.__init__(self, core, room)
|
ChatTab.__init__(self, core, room)
|
||||||
TabWithInfoWin.__init__(self)
|
TabWithInfoWin.__init__(self)
|
||||||
|
@ -733,9 +733,14 @@ class PrivateTab(ChatTab, TabWithInfoWin):
|
||||||
self.complete_commands(self.input)
|
self.complete_commands(self.input)
|
||||||
|
|
||||||
def command_say(self, line):
|
def command_say(self, line):
|
||||||
muc.send_private_message(self.core.xmpp, self.get_name(), line)
|
msg = self.core.xmpp.make_message(self.get_name())
|
||||||
self.core.add_message_to_text_buffer(self.get_room(), line, None, self.get_room().own_nick)
|
msg['type'] = 'chat'
|
||||||
logger.log_message(self.get_name().replace('/', '\\'), self.get_room().own_nick, line)
|
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):
|
def command_unquery(self, arg):
|
||||||
"""
|
"""
|
||||||
|
@ -762,7 +767,7 @@ class PrivateTab(ChatTab, TabWithInfoWin):
|
||||||
if self.need_resize:
|
if self.need_resize:
|
||||||
self.resize()
|
self.resize()
|
||||||
self.text_win.refresh(self._room)
|
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.info_win.refresh(informations)
|
||||||
self.tab_win.refresh(tabs, tabs[0])
|
self.tab_win.refresh(tabs, tabs[0])
|
||||||
self.input.refresh()
|
self.input.refresh()
|
||||||
|
@ -1330,7 +1335,6 @@ class MucListTab(Tab):
|
||||||
Callback called when a disco#items result is received
|
Callback called when a disco#items result is received
|
||||||
Used with command_list
|
Used with command_list
|
||||||
"""
|
"""
|
||||||
log.debug('res: %s\n\n' % iq)
|
|
||||||
if iq['type'] == 'error':
|
if iq['type'] == 'error':
|
||||||
self.set_error(iq['error']['type'], iq['error']['code'], iq['error']['text'])
|
self.set_error(iq['error']['type'], iq['error']['code'], iq['error']['text'])
|
||||||
return
|
return
|
||||||
|
|
|
@ -245,12 +245,13 @@ class PrivateInfoWin(InfoWin):
|
||||||
def resize(self, height, width, y, x, stdscr):
|
def resize(self, height, width, y, x, stdscr):
|
||||||
self._resize(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:
|
with g_lock:
|
||||||
self._win.erase()
|
self._win.erase()
|
||||||
self.write_room_name(room)
|
self.write_room_name(room)
|
||||||
self.print_scroll_position(window)
|
self.print_scroll_position(window)
|
||||||
|
self.write_chatstate(chatstate)
|
||||||
self.finish_line(theme.COLOR_INFORMATION_BAR)
|
self.finish_line(theme.COLOR_INFORMATION_BAR)
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
|
@ -261,6 +262,10 @@ class PrivateInfoWin(InfoWin):
|
||||||
txt = ' from room %s' % room_name
|
txt = ' from room %s' % room_name
|
||||||
self.addstr(txt, common.curses_color_pair(theme.COLOR_INFORMATION_BAR))
|
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):
|
class ConversationInfoWin(InfoWin):
|
||||||
"""
|
"""
|
||||||
The line above the information window, displaying informations
|
The line above the information window, displaying informations
|
||||||
|
|
Loading…
Reference in a new issue