Added fault tolerance to socializer in posts, topic creation and chat messages
This commit is contained in:
@@ -523,7 +523,7 @@ class topicBuffer(feedBuffer):
|
||||
owner_id = self.kwargs["group_id"]
|
||||
user = self.session.get_user(-1*owner_id, key="user1")
|
||||
title = _("Create topic in {user1_nom}").format(**user)
|
||||
p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createTopicDialog(title=title, message="", text=""))
|
||||
p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createTopicDialog(title=title, message="", text="", topic_title=""))
|
||||
if hasattr(p, "text") or hasattr(p, "privacy"):
|
||||
title = p.view.title.GetValue()
|
||||
msg = p.text
|
||||
@@ -1189,7 +1189,7 @@ class chatBuffer(baseBuffer):
|
||||
attachments = self.attachments_to_be_sent[::]
|
||||
else:
|
||||
attachments = []
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint="messages", child_endpoint="send", attachments_list=attachments, post_arguments=post_arguments)
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint="messages", child_endpoint="send", from_buffer=self.name, attachments_list=attachments, post_arguments=post_arguments)
|
||||
if hasattr(self, "attachments_to_be_sent"):
|
||||
del self.attachments_to_be_sent
|
||||
|
||||
|
@@ -304,6 +304,7 @@ class Controller(object):
|
||||
def connect_pubsub_events(self):
|
||||
log.debug("Connecting events to responses...")
|
||||
pub.subscribe(self.in_post, "posted")
|
||||
pub.subscribe(self.post_failed, "postFailed")
|
||||
pub.subscribe(self.download, "download-file")
|
||||
pub.subscribe(self.view_post, "open-post")
|
||||
pub.subscribe(self.update_status_bar, "update-status-bar")
|
||||
@@ -333,11 +334,44 @@ class Controller(object):
|
||||
pub.subscribe(self.create_timeline, "create-timeline")
|
||||
|
||||
def in_post(self, from_buffer=None):
|
||||
if from_buffer != None:
|
||||
if from_buffer != None and "_messages" not in from_buffer:
|
||||
log.debug("Post received in buffer %s, updating... " % (from_buffer,))
|
||||
buffer = self.search(from_buffer)
|
||||
buffer.get_items()
|
||||
|
||||
def post_failed(self, parent_endpoint, child_endpoint, from_buffer=None, attachments_list=[], post_arguments={}):
|
||||
""" Function to be called when the post (using the pubsub method) will fail. It takes the same params than post() and use the parent and child endpoints to call the appropiate dialogs. """
|
||||
# Ask the user if he/she wants to attempt to post the same again.
|
||||
msgdialog = commonMessages.post_failed()
|
||||
if msgdialog != widgetUtils.YES: # Cancelled.
|
||||
return
|
||||
# Let's check which kind of post has failed, and do something about it.
|
||||
if parent_endpoint == "wall": # A wall post has failed, so let's create it in a dialogue.
|
||||
p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Write your post"), message="", text=post_arguments.get("message")))
|
||||
if hasattr(p, "text") or hasattr(p, "privacy"):
|
||||
post_arguments.update(privacy=p.privacy, message=p.text)
|
||||
if hasattr(p, "attachments"):
|
||||
attachments_list = p.attachments
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint=parent_endpoint, child_endpoint=child_endpoint, from_buffer=from_buffer, attachments_list=attachments_list, post_arguments=post_arguments)
|
||||
elif parent_endpoint == "board": # topic creation and comments.
|
||||
if child_endpoint == "addTopic":
|
||||
p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createTopicDialog(title=_("Create topic"), message="", topic_title=post_arguments.get("title"), text=post_arguments.get("text")))
|
||||
if hasattr(p, "text") or hasattr(p, "privacy"):
|
||||
post_arguments.update(title=p.view.title.GetValue(), text=p.text)
|
||||
if hasattr(p, "attachments"):
|
||||
attachments_list = p.attachments
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint=parent_endpoint, child_endpoint=child_endpoint, from_buffer=from_buffer, attachments_list=attachments_list, post_arguments=post_arguments)
|
||||
elif parent_endpoint == "messages": # Private messages
|
||||
if child_endpoint == "send":
|
||||
buffer = self.search(from_buffer)
|
||||
print(buffer)
|
||||
buffer_window = self.window.search(buffer.name)
|
||||
print(buffer_window)
|
||||
self.window.change_buffer(buffer_window)
|
||||
buffer.tab.text.SetValue(post_arguments.get("message"))
|
||||
buffer.tab.text.SetFocus()
|
||||
buffer.attachments_to_be_sent = attachments_list
|
||||
|
||||
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.
|
||||
|
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
||||
import os
|
||||
import logging
|
||||
import warnings
|
||||
import wx
|
||||
import languageHandler
|
||||
import paths
|
||||
import config
|
||||
@@ -323,7 +324,7 @@ class vkSession(object):
|
||||
except Exception as error:
|
||||
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.
|
||||
pub.sendMessage("postFailed", parent_endpoint=parent_endpoint, child_endpoint=child_endpoint, from_buffer=from_buffer, attachments_list=attachments_list, post_arguments=post_arguments)
|
||||
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)
|
||||
# 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:
|
||||
@@ -351,7 +352,7 @@ class vkSession(object):
|
||||
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.
|
||||
pub.sendMessage("postFailed", parent_endpoint=parent_endpoint, child_endpoint=child_endpoint, from_buffer=from_buffer, attachments_list=attachments_list, post_arguments=post_arguments)
|
||||
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.
|
||||
|
@@ -91,7 +91,7 @@ class createPostDialog(createTextMessage):
|
||||
self.SetClientSize(self.mainBox.CalcMin())
|
||||
|
||||
class createCommentDialog(createTextMessage):
|
||||
def createControls(self, title, message, text):
|
||||
def createControls(self, title, message, text, **kwargs):
|
||||
self.mainBox = wx.BoxSizer(wx.VERTICAL)
|
||||
self.createTextArea(message, text)
|
||||
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
|
||||
@@ -117,17 +117,17 @@ class createCommentDialog(createTextMessage):
|
||||
self.panel.SetSizer(self.mainBox)
|
||||
self.SetTitle(title)
|
||||
|
||||
def __init__(self, title, message, text):
|
||||
def __init__(self, title, message, text, *args, **kwargs):
|
||||
super(createCommentDialog, self).__init__()
|
||||
self.createControls(message, title, text)
|
||||
self.createControls(message, title, text, **kwargs)
|
||||
self.SetClientSize(self.mainBox.CalcMin())
|
||||
self.SetTitle(title)
|
||||
|
||||
class createTopicDialog(createCommentDialog):
|
||||
def createTextArea(self, message="", text=""):
|
||||
def createTextArea(self, message="", text="", topic_title=""):
|
||||
self.panel = wx.Panel(self)
|
||||
label = wx.StaticText(self.panel, -1, _("Title"))
|
||||
self.title = wx.TextCtrl(self.panel, wx.NewId())
|
||||
self.title = wx.TextCtrl(self.panel, wx.NewId(), topic_title)
|
||||
label2 = wx.StaticText(self.panel, -1, _("Message"))
|
||||
self.text = wx.TextCtrl(self.panel, -1, text, size=(439, -1), style=wx.TE_MULTILINE)
|
||||
self.title.SetFocus()
|
||||
@@ -141,9 +141,9 @@ class createTopicDialog(createCommentDialog):
|
||||
textb.Add(self.text, 0, wx.ALL, 5)
|
||||
self.textBox.Add(textb, 0, wx.ALL, 5)
|
||||
|
||||
def createControls(self, title, message, text):
|
||||
def createControls(self, title, message, text, topic_title):
|
||||
self.mainBox = wx.BoxSizer(wx.VERTICAL)
|
||||
self.createTextArea(message, text)
|
||||
self.createTextArea(message, text, topic_title)
|
||||
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
|
||||
self.attach = wx.Button(self.panel, -1, _("Attach"), size=wx.DefaultSize)
|
||||
self.mention = wx.Button(self.panel, wx.NewId(), _("Tag a friend"))
|
||||
|
@@ -67,3 +67,6 @@ def community_no_items():
|
||||
|
||||
def delete_conversation():
|
||||
return wx.MessageDialog(None, _("do you really want to delete all messages of this conversation in VK?"), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal()
|
||||
|
||||
def post_failed():
|
||||
return wx.MessageDialog(None, _("Unfortunately, we could not send your last post or message to VK. Would you like to try again?"), _("Post failed"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal()
|
Reference in New Issue
Block a user