Fix activity timers for groupchat

- Dont add timers when we autojoin minimized
- Remove timers when the chatcontrol gets minimized
- Send inactive chatstate when the chatcontrol gets minimized
- Add timers when the chatcontrol gets maximized
This commit is contained in:
Philipp Hörist 2017-07-16 23:58:54 +02:00
parent 4ba143fd68
commit e675df1803
2 changed files with 11 additions and 3 deletions

View file

@ -376,7 +376,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
# chatstate timers and state # chatstate timers and state
self.reset_kbd_mouse_timeout_vars() self.reset_kbd_mouse_timeout_vars()
self._schedule_activity_timers() self.possible_paused_timeout_id = None
self.possible_inactive_timeout_id = None
message_tv_buffer = self.msg_textview.get_buffer() message_tv_buffer = self.msg_textview.get_buffer()
id_ = message_tv_buffer.connect('changed', id_ = message_tv_buffer.connect('changed',
self._on_message_tv_buffer_changed) self._on_message_tv_buffer_changed)
@ -385,6 +386,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
id_ = parent_win.window.connect('motion-notify-event', id_ = parent_win.window.connect('motion-notify-event',
self._on_window_motion_notify) self._on_window_motion_notify)
self.handlers[id_] = parent_win.window self.handlers[id_] = parent_win.window
self._schedule_activity_timers()
self.encryption = self.get_encryption_state() self.encryption = self.get_encryption_state()
if self.parent_win: if self.parent_win:
@ -836,6 +838,10 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
return True # loop forever return True # loop forever
def _schedule_activity_timers(self): def _schedule_activity_timers(self):
if self.possible_paused_timeout_id:
GLib.source_remove(self.possible_paused_timeout_id)
if self.possible_inactive_timeout_id:
GLib.source_remove(self.possible_inactive_timeout_id)
self.possible_paused_timeout_id = GLib.timeout_add_seconds(5, self.possible_paused_timeout_id = GLib.timeout_add_seconds(5,
self.check_for_possible_paused_chatstate, None) self.check_for_possible_paused_chatstate, None)
self.possible_inactive_timeout_id = GLib.timeout_add_seconds(30, self.possible_inactive_timeout_id = GLib.timeout_add_seconds(30,
@ -1143,8 +1149,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
else: else:
self.send_chatstate('active', self.contact) self.send_chatstate('active', self.contact)
self.reset_kbd_mouse_timeout_vars() self.reset_kbd_mouse_timeout_vars()
GLib.source_remove(self.possible_paused_timeout_id)
GLib.source_remove(self.possible_inactive_timeout_id)
self._schedule_activity_timers() self._schedule_activity_timers()
else: else:
self.send_chatstate('inactive', self.contact) self.send_chatstate('inactive', self.contact)

View file

@ -529,6 +529,7 @@ class GroupchatControl(ChatControlBase):
self.set_tooltip() self.set_tooltip()
self.add_window_actions() self.add_window_actions()
self.set_lock_image() self.set_lock_image()
self._schedule_activity_timers()
def set_tooltip(self): def set_tooltip(self):
widget = self.xml.get_object('list_treeview') widget = self.xml.get_object('list_treeview')
@ -2085,8 +2086,11 @@ class GroupchatControl(ChatControlBase):
control = win.notebook.get_nth_page(ctrl_page) control = win.notebook.get_nth_page(ctrl_page)
win.notebook.remove_page(ctrl_page) win.notebook.remove_page(ctrl_page)
GLib.source_remove(self.possible_paused_timeout_id)
GLib.source_remove(self.possible_inactive_timeout_id)
control.unparent() control.unparent()
ctrl.parent_win = None ctrl.parent_win = None
self.send_chatstate('inactive', self.contact)
gajim.interface.roster.add_groupchat(self.contact.jid, self.account, gajim.interface.roster.add_groupchat(self.contact.jid, self.account,
status = self.subject) status = self.subject)