Fix chatstate flood
The new Placeholder text inside MessageTextView was causing many buffer changed events. - Add a method that lets us know if there is user input - Add logging
This commit is contained in:
parent
1455db7522
commit
a344a94102
|
@ -1116,12 +1116,14 @@ class ChatControl(ChatControlBase):
|
||||||
# if wel're inactive prevent composing (XEP violation)
|
# if wel're inactive prevent composing (XEP violation)
|
||||||
if contact.our_chatstate == 'inactive' and state == 'composing':
|
if contact.our_chatstate == 'inactive' and state == 'composing':
|
||||||
# go active before
|
# go active before
|
||||||
|
app.log('chatstates').info('%-10s - %s', 'active', self.contact.jid)
|
||||||
app.nec.push_outgoing_event(MessageOutgoingEvent(None,
|
app.nec.push_outgoing_event(MessageOutgoingEvent(None,
|
||||||
account=self.account, jid=self.contact.jid, chatstate='active',
|
account=self.account, jid=self.contact.jid, chatstate='active',
|
||||||
control=self))
|
control=self))
|
||||||
contact.our_chatstate = 'active'
|
contact.our_chatstate = 'active'
|
||||||
self.reset_kbd_mouse_timeout_vars()
|
self.reset_kbd_mouse_timeout_vars()
|
||||||
|
|
||||||
|
app.log('chatstates').info('%-10s - %s', state, self.contact.jid)
|
||||||
app.nec.push_outgoing_event(MessageOutgoingEvent(None,
|
app.nec.push_outgoing_event(MessageOutgoingEvent(None,
|
||||||
account=self.account, jid=self.contact.jid, chatstate=state,
|
account=self.account, jid=self.contact.jid, chatstate=state,
|
||||||
control=self))
|
control=self))
|
||||||
|
|
|
@ -797,18 +797,16 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
self.possible_paused_timeout_id = None
|
self.possible_paused_timeout_id = None
|
||||||
return False # stop looping
|
return False # stop looping
|
||||||
|
|
||||||
message_buffer = self.msg_textview.get_buffer()
|
if current_state == 'composing':
|
||||||
if (self.kbd_activity_in_last_5_secs and
|
if not self.kbd_activity_in_last_5_secs:
|
||||||
message_buffer.get_char_count()):
|
if self.msg_textview.has_text():
|
||||||
# Only composing if the keyboard activity was in text entry
|
self.send_chatstate('paused', self.contact)
|
||||||
self.send_chatstate('composing', self.contact)
|
else:
|
||||||
elif (self.mouse_over_in_last_5_secs and
|
self.send_chatstate('active', self.contact)
|
||||||
current_state == 'inactive' and
|
elif current_state == 'inactive':
|
||||||
|
if (self.mouse_over_in_last_5_secs and
|
||||||
jid == self.parent_win.get_active_jid()):
|
jid == self.parent_win.get_active_jid()):
|
||||||
self.send_chatstate('active', self.contact)
|
self.send_chatstate('active', self.contact)
|
||||||
else:
|
|
||||||
if current_state == 'composing':
|
|
||||||
self.send_chatstate('paused', self.contact) # pause composing
|
|
||||||
|
|
||||||
# assume no activity and let the motion-notify or 'insert-text' make them
|
# assume no activity and let the motion-notify or 'insert-text' make them
|
||||||
# True refresh 30 seconds vars too or else it's 30 - 5 = 25 seconds!
|
# True refresh 30 seconds vars too or else it's 30 - 5 = 25 seconds!
|
||||||
|
@ -870,10 +868,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
def _on_message_tv_buffer_changed(self, textbuffer):
|
def _on_message_tv_buffer_changed(self, textbuffer):
|
||||||
self.kbd_activity_in_last_5_secs = True
|
self.kbd_activity_in_last_5_secs = True
|
||||||
self.kbd_activity_in_last_30_secs = True
|
self.kbd_activity_in_last_30_secs = True
|
||||||
if textbuffer.get_char_count():
|
if not self.msg_textview.has_text():
|
||||||
|
return
|
||||||
self.send_chatstate('composing', self.contact)
|
self.send_chatstate('composing', self.contact)
|
||||||
else:
|
|
||||||
self.send_chatstate('active', self.contact)
|
|
||||||
|
|
||||||
def save_message(self, message, msg_type):
|
def save_message(self, message, msg_type):
|
||||||
# save the message, so user can scroll though the list with key up/down
|
# save the message, so user can scroll though the list with key up/down
|
||||||
|
@ -1146,8 +1143,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
self.redraw_after_event_removed(jid)
|
self.redraw_after_event_removed(jid)
|
||||||
# send chatstate inactive to the one we're leaving
|
# send chatstate inactive to the one we're leaving
|
||||||
# and active to the one we visit
|
# and active to the one we visit
|
||||||
message_buffer = self.msg_textview.get_buffer()
|
if self.msg_textview.has_text():
|
||||||
if message_buffer.get_char_count():
|
|
||||||
self.send_chatstate('paused', self.contact)
|
self.send_chatstate('paused', self.contact)
|
||||||
else:
|
else:
|
||||||
self.send_chatstate('active', self.contact)
|
self.send_chatstate('active', self.contact)
|
||||||
|
|
|
@ -100,10 +100,16 @@ class MessageTextView(Gtk.TextView):
|
||||||
buf = self.get_buffer()
|
buf = self.get_buffer()
|
||||||
start, end = buf.get_bounds()
|
start, end = buf.get_bounds()
|
||||||
text = buf.get_text(start, end, True)
|
text = buf.get_text(start, end, True)
|
||||||
return text != self.PLACEHOLDER
|
return text != self.PLACEHOLDER and text != ''
|
||||||
|
|
||||||
|
def is_placeholder(self):
|
||||||
|
buf = self.get_buffer()
|
||||||
|
start, end = buf.get_bounds()
|
||||||
|
text = buf.get_text(start, end, True)
|
||||||
|
return text == self.PLACEHOLDER
|
||||||
|
|
||||||
def _on_focus_in(self, *args):
|
def _on_focus_in(self, *args):
|
||||||
if not self.has_text():
|
if self.is_placeholder():
|
||||||
self.get_buffer().set_text('')
|
self.get_buffer().set_text('')
|
||||||
self.toggle_speller(True)
|
self.toggle_speller(True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue