Use methods provided in vk_api for supporting conversations

This commit is contained in:
2018-12-09 07:25:30 -06:00
parent ba5d734a05
commit feb3215745
5 changed files with 41 additions and 28 deletions

View File

@@ -611,6 +611,7 @@ class empty(object):
def remove_buffer(self, mandatory=False): return False
class chatBuffer(baseBuffer):
random_id = 1
def insert(self, item, reversed=False):
""" Add a new item to the list. Uses session.composefunc for parsing the dictionary and create a valid result for putting it in the list."""
@@ -706,11 +707,15 @@ class chatBuffer(baseBuffer):
def _send_message(self, text):
# try:
# Let's take care about the random_id attribute.
# This should be unique per message and should be changed right after the message has been sent.
# If the message is tried to be sent twice this random_id should be the same for both copies.
# At the moment we just calculate len(text)_user_id, hope that will work.
random_id = "{0}_{1}".format(len(text), self.kwargs["user_id"])
if hasattr(self, "attachments_to_be_sent"):
response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text, attachment=self.attachments_to_be_sent)
print self.attachments_to_be_sent
response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text, attachment=self.attachments_to_be_sent, random_id=random_id)
else:
response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text)
response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text, random_id=random_id)
# 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."))