Chats can be sent by pressing enter in the text box

This commit is contained in:
2016-08-14 02:12:49 -05:00
parent 4491a600f3
commit 4ae167e461
4 changed files with 19 additions and 1 deletions

View File

@@ -490,7 +490,16 @@ class chatBuffer(baseBuffer):
def send_chat_to_user(self, *args, **kwargs):
text = self.tab.text.GetValue()
if text == "": return
response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text)
call_threaded(self._send_message, text=text)
def _send_message(self, text):
try:
response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text)
except VkAPIMethodError as ex:
if ex.code == 9:
output.speak(_(u"You have been sending a message that is already sent. Try to update the buffer if you can't see the new message in the history."))
finally:
self.tab.text.SetValue("")
def __init__(self, *args, **kwargs):
super(chatBuffer, self).__init__(*args, **kwargs)

View File

@@ -2,16 +2,21 @@
import threading
from vk import longpool
from pubsub import pub
from logging import getLogger
log = getLogger("controller.longpolThread")
class worker(threading.Thread):
def __init__(self, session):
super(worker, self).__init__()
log.debug("Instanciating longPoll server")
self.session = session
self.l = longpool.LongPoll(self.session.vk.client)
def run(self):
while self.session.is_logged == True:
log.debug("Calling to check...")
p = self.l.check()
# log.debug("check has returned " + p)
for i in p:
# print i.message_id, i.flags, i.from_id, i.user_id, i.mask, i.byself, i.message_flags
# if i.flags == 4 or i.flags == 51 or i.flags == 49: