Show error dialogs when attempting to send audio messages to banned or blocked users

This commit is contained in:
2019-12-20 08:09:11 -06:00
parent 1d96a4807b
commit d286674cee
5 changed files with 23 additions and 18 deletions

View File

@@ -322,6 +322,7 @@ class Controller(object):
pub.subscribe(self.user_typing, "user-typing")
pub.subscribe(self.get_chat, "order-sent-message")
pub.subscribe(self.create_timeline, "create-timeline")
pub.subscribe(self.api_error, "api-error")
def disconnect_events(self):
log.debug("Disconnecting some events...")
@@ -394,6 +395,10 @@ class Controller(object):
buffer.tab.text.SetFocus()
buffer.attachments_to_be_sent = attachments_list
def api_error(self, code):
""" Display an understandable error dialog to users. """
commonMessages.vk_error(code)
def download(self, url, filename):
""" Download a file to te current user's computer.
@ url: The URl from where the file can be directly accessed.

View File

@@ -14,7 +14,6 @@ import output
import logging
import keys
import application
from wxUI.commonMessages import alpha_reminder
if hasattr(sys, "frozen"):
sys.excepthook = lambda x, y, z: logging.critical(''.join(traceback.format_exception(x, y, z)))
from mysc.thread_utils import call_threaded
@@ -53,9 +52,6 @@ def setup():
from sessionmanager import sessionManager
log.debug("Created Application mainloop object")
if application.is_pyinstaller():
log.debug("Showing reminder about next Socializer alpha... ")
alpha_reminder()
sm = sessionManager.sessionManagerController()
sm.show()
del sm

View File

@@ -319,6 +319,8 @@ class vkSession(object):
""" Generic function to be called whenever user wants to post something to VK.
This function should be capable of uploading all attachments before posting, and send a special event in case the post has failed,
So the program can recreate the post and show it back to the user."""
# Define a list of error codes that are handled by the application.
handled_errors = [7, 900]
# ToDo: this function will occasionally be called with attachments already set to post_arguments, example if the user could upload the files but was unable to send the post due to a connection problem.
# We should see what can be done (reuploading everything vs using the already added attachments).
attachments = ""
@@ -331,18 +333,6 @@ 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], "")
# After modifying everything, let's update the post arguments if needed.
if len(attachments) > 0:
if parent_endpoint == "messages":
@@ -358,8 +348,12 @@ class vkSession(object):
pub.sendMessage("posted", from_buffer=from_buffer)
except Exception as error:
log.exception("Error calling method %s.%s with arguments: %r. 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)
# Send handled errors to the corresponding function, call the default handler otherwise.
if error.code in handled_errors:
wx.CallAfter(pub.sendMessage, "api-error", code=error.code)
else:
# 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)
def upload_attachments(self, attachments, peer_id=None):
""" Upload attachments to VK before posting them.

View File

@@ -81,3 +81,12 @@ def exit():
dlg = wx.MessageDialog(None, _("Do you really want to close Socializer?"), _("Exit"), wx.YES_NO|wx.ICON_QUESTION)
return dlg.ShowModal()
def vk_error(code):
title = _("VK error")
if code == 7:
msg = _("You are not allowed to perform this action. Please be sure you are not attempting to post or send a message to a blocked or banned user. Error code 7.")
elif code == 900:
msg = _("You cannot send messages to users in your blacklist.")
else:
msg = str(code)
return wx.MessageDialog(None, msg, title, wx.ICON_ERROR).ShowModal()