Commit a344a941 authored by Philipp Hörist's avatar Philipp Hörist

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
parent 1455db75
......@@ -1116,12 +1116,14 @@ class ChatControl(ChatControlBase):
# if wel're inactive prevent composing (XEP violation)
if contact.our_chatstate == 'inactive' and state == 'composing':
# go active before
app.log('chatstates').info('%-10s - %s', 'active', self.contact.jid)
app.nec.push_outgoing_event(MessageOutgoingEvent(None,
account=self.account, jid=self.contact.jid, chatstate='active',
control=self))
contact.our_chatstate = 'active'
self.reset_kbd_mouse_timeout_vars()
app.log('chatstates').info('%-10s - %s', state, self.contact.jid)
app.nec.push_outgoing_event(MessageOutgoingEvent(None,
account=self.account, jid=self.contact.jid, chatstate=state,
control=self))
......
......@@ -797,18 +797,16 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.possible_paused_timeout_id = None
return False # stop looping
message_buffer = self.msg_textview.get_buffer()
if (self.kbd_activity_in_last_5_secs and
message_buffer.get_char_count()):
# Only composing if the keyboard activity was in text entry
self.send_chatstate('composing', self.contact)
elif (self.mouse_over_in_last_5_secs and
current_state == 'inactive' and
jid == self.parent_win.get_active_jid()):
self.send_chatstate('active', self.contact)
else:
if current_state == 'composing':
self.send_chatstate('paused', self.contact) # pause composing
if current_state == 'composing':
if not self.kbd_activity_in_last_5_secs:
if self.msg_textview.has_text():
self.send_chatstate('paused', self.contact)
else:
self.send_chatstate('active', self.contact)
elif current_state == 'inactive':
if (self.mouse_over_in_last_5_secs and
jid == self.parent_win.get_active_jid()):
self.send_chatstate('active', self.contact)
# 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!
......@@ -870,10 +868,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
def _on_message_tv_buffer_changed(self, textbuffer):
self.kbd_activity_in_last_5_secs = True
self.kbd_activity_in_last_30_secs = True
if textbuffer.get_char_count():
self.send_chatstate('composing', self.contact)
else:
self.send_chatstate('active', self.contact)
if not self.msg_textview.has_text():
return
self.send_chatstate('composing', self.contact)
def save_message(self, message, msg_type):
# 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)
# send chatstate inactive to the one we're leaving
# and active to the one we visit
message_buffer = self.msg_textview.get_buffer()
if message_buffer.get_char_count():
if self.msg_textview.has_text():
self.send_chatstate('paused', self.contact)
else:
self.send_chatstate('active', self.contact)
......
......@@ -100,10 +100,16 @@ class MessageTextView(Gtk.TextView):
buf = self.get_buffer()
start, end = buf.get_bounds()
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):
if not self.has_text():
if self.is_placeholder():
self.get_buffer().set_text('')
self.toggle_speller(True)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment