Fixed error that was making some links to redirect to 404 errors in chat messages, posts and comments

This commit is contained in:
2019-11-20 16:18:16 -06:00
parent bb92a8a8d4
commit 55193a958d
4 changed files with 27 additions and 12 deletions

View File

@@ -567,9 +567,10 @@ class Controller(object):
return
# If the chat already exists, let's create a dictionary wich will contains data of the received message.
message.update(id=obj.message_id, user_id=uid, date=obj.timestamp, body=utils.clean_text(obj.text), attachments=obj.attachments)
# if attachments is true, let's request for the full message with attachments formatted in a better way.
# if attachments is true or body contains at least an URL, let's request for the full message with attachments formatted in a better way.
# ToDo: code improvements. We shouldn't need to request the same message again just for these attachments.
if len(message["attachments"]) != 0:
if len(message["attachments"]) != 0 or len(utils.find_urls_in_text(message["body"])) != 0:
print(message["body"])
message_ids = message["id"]
results = self.session.vk.client.messages.getById(message_ids=message_ids)
message = results["items"][0]

View File

@@ -147,6 +147,7 @@ class vkSession(object):
self.logged = True
self.get_my_data()
except VkApiError as error:
print(error)
if error.code == 5: # this means invalid access token.
self.settings["vk"]["user"] = ""
self.settings["vk"]["password"] = ""
@@ -330,17 +331,18 @@ class vkSession(object):
log.error("Error calling method %s.%s with arguments: %r. Failed during loading attachments. Error: %s" % (parent_endpoint, child_endpoint, post_arguments, str(error)))
# Report a failed function here too with same arguments so the client should be able to recreate it again.
wx.CallAfter(pub.sendMessage, "postFailed", parent_endpoint=parent_endpoint, child_endpoint=child_endpoint, from_buffer=from_buffer, attachments_list=attachments_list, post_arguments=post_arguments)
### ToDo: Let's avoid this piece of code cause it seems VK changes everything to lowercase letters.
# VK generally defines all kind of messages under "text", "message" or "body" so let's try with all of those
possible_message_keys = ["text", "message", "body"]
for i in possible_message_keys:
if post_arguments.get(i):
urls = utils.find_urls_in_text(post_arguments[i])
if len(urls) != 0:
if len(attachments) == 0:
attachments = urls[0]
else:
attachments += urls[0]
post_arguments[i] = post_arguments[i].replace(urls[0], "")
# possible_message_keys = ["text", "message", "body"]
# for i in possible_message_keys:
# if post_arguments.get(i):
# urls = utils.find_urls_in_text(post_arguments[i])
# if len(urls) != 0:
# if len(attachments) == 0:
# attachments = urls[0]
# else:
# attachments += urls[0]
# post_arguments[i] = post_arguments[i].replace(urls[0], "")
# After modifying everything, let's update the post arguments if needed.
if len(attachments) > 0:
if parent_endpoint == "messages":