From 94106a11c08b6a8d6f1d767c0c45a156a789175f Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Fri, 25 Jan 2019 10:36:28 -0600 Subject: [PATCH] Improved handling for deleted posts. Now they should display an error --- changelog.md | 1 + src/interactors/postDisplayer.py | 6 ++++++ src/presenters/postDisplayer.py | 10 +++++++++- src/wxUI/commonMessages.py | 5 ++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 0495254..af398b6 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,7 @@ * Chats with unread messages will be placed at the top of the chats section. When a chat buffer receives a new message, socializer will move the buffer to the first position in the chats list. This should make easier for everyone to determine which chats contain unread items. ([#24,](https://code.manuelcortez.net/manuelcortez/socializer/issues/24)) * In dialogs for displaying posts and comments, and also in the two edit boxes present in chat buffers, it is possible to select all by pressing Control+A. * Now it is possible to remove friends directly from the friends buffer. There is a new option for this purpose in the context menu for the focused friend. After being removed, the person will be placed in the subscribers buffer. +* Deleted posts will display an error message when trying to view details about those. Before, the dialog was created and left blank. ## Changes in version 0.18 (21.01.2019) diff --git a/src/interactors/postDisplayer.py b/src/interactors/postDisplayer.py index a391adb..295ab5f 100644 --- a/src/interactors/postDisplayer.py +++ b/src/interactors/postDisplayer.py @@ -5,6 +5,7 @@ import widgetUtils import wx from pubsub import pub from wxUI import menus +from wxUI import commonMessages from .import base class displayPostInteractor(base.baseInteractor): @@ -39,6 +40,9 @@ class displayPostInteractor(base.baseInteractor): raise AttributeError("The control is not present in the view.") getattr(self.view, control).clear() + def post_deleted(self): + msg = commonMessages.post_deleted() + def install(self, *args, **kwargs): super(displayPostInteractor, self).install(*args, **kwargs) self.view.comments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_show_comment) @@ -58,6 +62,7 @@ class displayPostInteractor(base.baseInteractor): pub.subscribe(self.add_items, self.modulename+"_add_items") pub.subscribe(self.enable_attachments, self.modulename+"_enable_attachments") pub.subscribe(self.enable_photo_controls, self.modulename+"_enable_photo_controls") + pub.subscribe(self.post_deleted, self.modulename+"_post_deleted") def uninstall(self): super(displayPostInteractor, self).uninstall() @@ -66,6 +71,7 @@ class displayPostInteractor(base.baseInteractor): pub.unsubscribe(self.add_items, self.modulename+"_add_items") pub.unsubscribe(self.enable_attachments, self.modulename+"_enable_attachments") pub.unsubscribe(self.enable_photo_controls, self.modulename+"_enable_photo_controls") + pub.unsubscribe(self.post_deleted, self.modulename+"_post_deleted") def on_focus(self, *args, **kwargs): item = self.view.comments.get_selected() diff --git a/src/presenters/postDisplayer.py b/src/presenters/postDisplayer.py index 4c12bd9..6b861e7 100644 --- a/src/presenters/postDisplayer.py +++ b/src/presenters/postDisplayer.py @@ -56,6 +56,11 @@ class displayPostPresenter(base.basePresenter): else: self.user_identifier = "owner_id" self.post_identifier = "id" + result = self.get_post_information() + # Stop loading everything else if post was deleted. + if result == False: + self.interactor.uninstall() + return self.worker = threading.Thread(target=self.load_all_components) self.worker.finished = threading.Event() self.worker.start() @@ -110,6 +115,10 @@ class displayPostPresenter(base.basePresenter): # Retrieve again the post, so we'll make sure to get the most up to date information. # And we add a counter for views. post = self.session.vk.client.wall.getById(posts="{owner_id}_{post_id}".format(owner_id=self.post[self.user_identifier], post_id=self.post[self.post_identifier])) + # If this post has been deleted, let's send an event to the interactor so it won't be displayed. + if len(post) == 0: + self.send_message("post_deleted") + return False self.post = post[0] if "views" in self.post and self.post["views"]["count"] > 0: self.send_message("set", control="views", value=str(self.post["views"]["count"])) @@ -204,7 +213,6 @@ class displayPostPresenter(base.basePresenter): return url def load_all_components(self): - self.get_post_information() self.get_likes() self.get_reposts() self.get_comments() diff --git a/src/wxUI/commonMessages.py b/src/wxUI/commonMessages.py index f31e313..f2748a9 100644 --- a/src/wxUI/commonMessages.py +++ b/src/wxUI/commonMessages.py @@ -51,4 +51,7 @@ def proxy_question(): return wx.MessageDialog(None, _("If you live in a country where VK is blocked, you can use a proxy to bypass such restrictions. Socializer includes a working proxy to ensure all users can connect to VK. Do you want to use Socializer through the proxy?"), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal() def remove_friend(user): - return wx.MessageDialog(None, _("Are you sure you want to remove {user1_nom} from your friends?").format(**user), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal() \ No newline at end of file + return wx.MessageDialog(None, _("Are you sure you want to remove {user1_nom} from your friends?").format(**user), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal() + +def post_deleted(): + return wx.MessageDialog(None, _("This post has been removed."), _("Error"), wx.ICON_ERROR).ShowModal() \ No newline at end of file