Fixed exception when message is blank in a post. Fixes #20

This commit is contained in:
Manuel Cortez 2019-01-09 05:14:35 -06:00
parent 7168b874aa
commit 9465cf03ac
3 changed files with 10 additions and 6 deletions

View File

View File

@ -119,14 +119,13 @@ class baseBuffer(object):
""" Create a post in the current user's wall. """ Create a post in the current user's wall.
This process is handled in two parts. This is the first part, where the GUI is created and user can send the post. This process is handled in two parts. This is the first part, where the GUI is created and user can send the post.
During the second part (threaded), the post will be sent to the API.""" During the second part (threaded), the post will be sent to the API."""
p = presenters.createPostPresenter(session=self.session, interactor=interactors.postInteractor(), view=views.post(title=_("Write your post"), message="", text="")) p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Write your post"), message="", text=""))
if hasattr(p, "text") or hasattr(p, "privacy"): if hasattr(p, "text") or hasattr(p, "privacy"):
call_threaded(self.do_last, p=p) call_threaded(self.do_last, p=p)
def do_last(self, p, parent_endpoint="wall", child_endpoint="post", *args, **kwargs): def do_last(self, p, parent_endpoint="wall", child_endpoint="post", *args, **kwargs):
""" Second part of post function. Here everything is going to be sent to the API""" """ Second part of post function. Here everything is going to be sent to the API"""
msg = p.text msg = p.text
privacy_opts = p.privacy
attachments = "" attachments = ""
if hasattr(p, "attachments"): if hasattr(p, "attachments"):
attachments = self.upload_attachments(p.attachments) attachments = self.upload_attachments(p.attachments)
@ -135,12 +134,16 @@ class baseBuffer(object):
if len(attachments) == 0: attachments = urls[0] if len(attachments) == 0: attachments = urls[0]
else: attachments += urls[0] else: attachments += urls[0]
msg = msg.replace(urls[0], "") msg = msg.replace(urls[0], "")
if msg != "":
kwargs.update(message=msg)
kwargs.update(privacy=p.privacy)
if attachments != "":
kwargs.update(attachments=attachments)
# Determines the correct functions to call here. # Determines the correct functions to call here.
parent_endpoint = getattr(self.session.vk.client, parent_endpoint) parent_endpoint = getattr(self.session.vk.client, parent_endpoint)
endpoint = getattr(parent_endpoint, child_endpoint) endpoint = getattr(parent_endpoint, child_endpoint)
post = endpoint(message=msg, friends_only=privacy_opts, attachments=attachments, *args, **kwargs) post = endpoint(**kwargs)
pub.sendMessage("posted", buffer=self.name) pub.sendMessage("posted", buffer=self.name)
p.message.Destroy()
def upload_attachments(self, attachments): def upload_attachments(self, attachments):
""" Upload attachments to VK before posting them. """ Upload attachments to VK before posting them.
@ -264,7 +267,7 @@ class baseBuffer(object):
post = self.get_post() post = self.get_post()
if post == None: if post == None:
return return
comment = presenters.createPostPresenter(session=self.session, interactor=interactors.postInteractor(), view=views.post(title=_("Add a comment"), message="", text="", mode="comment")) comment = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Add a comment"), message="", text="", mode="comment"))
if hasattr(comment, "text") or hasattr(comment, "privacy"): if hasattr(comment, "text") or hasattr(comment, "privacy"):
msg = comment.text msg = comment.text
try: try:
@ -441,7 +444,7 @@ class feedBuffer(baseBuffer):
return super(feedBuffer, self).post() return super(feedBuffer, self).post()
owner_id = self.kwargs["owner_id"] owner_id = self.kwargs["owner_id"]
user = self.session.get_user_name(owner_id) user = self.session.get_user_name(owner_id)
p = presenters.createPostPresenter(session=self.session, interactor=interactors.postInteractor(), view=views.post(title=_("Write your post"), message="", text="")) p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Write your post"), message="", text=""))
if hasattr(p, "text") or hasattr(p, "privacy"): if hasattr(p, "text") or hasattr(p, "privacy"):
call_threaded(self.do_last, p=p, owner_id=owner_id) call_threaded(self.do_last, p=p, owner_id=owner_id)

View File

@ -20,6 +20,7 @@ from mysc import localization
from sessionmanager import session, utils, renderers from sessionmanager import session, utils, renderers
from wxUI import (mainWindow, commonMessages) from wxUI import (mainWindow, commonMessages)
from wxUI.dialogs import search as searchDialogs from wxUI.dialogs import search as searchDialogs
from wxUI.dialogs import timeline
from update import updater from update import updater
from issueReporter import issueReporter from issueReporter import issueReporter
from . import buffers from . import buffers