Added fault tolerance to wall coments and reposts

This commit is contained in:
Manuel Cortez 2019-09-19 17:52:04 -05:00
parent cf0e001cfc
commit 926db6007a

View File

@ -340,19 +340,34 @@ class Controller(object):
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. """
""" Function to be called when the post (using the pubsub method) fails. 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.
if parent_endpoint == "wall":
if child_endpoint == "post": # 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 child_endpoint == "repost": # repost
p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Repost"), message="", text=post_arguments.get("message"), mode="comment"))
if hasattr(p, "text") or hasattr(p, "privacy"):
post_arguments.update(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 child_endpoint == "createComment": # comments.
p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Add a comment"), message="", text=post_arguments.get("message"), mode="comment"))
if hasattr(p, "text") or hasattr(p, "privacy"):
post_arguments.update(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")))
@ -364,9 +379,7 @@ class Controller(object):
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()