Improved handling for deleted posts. Now they should display an error

This commit is contained in:
Manuel Cortez 2019-01-25 10:36:28 -06:00
parent 76f0ee3ef0
commit 94106a11c0
4 changed files with 20 additions and 2 deletions

View File

@ -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)) * 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. * 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. * 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) ## Changes in version 0.18 (21.01.2019)

View File

@ -5,6 +5,7 @@ import widgetUtils
import wx import wx
from pubsub import pub from pubsub import pub
from wxUI import menus from wxUI import menus
from wxUI import commonMessages
from .import base from .import base
class displayPostInteractor(base.baseInteractor): class displayPostInteractor(base.baseInteractor):
@ -39,6 +40,9 @@ class displayPostInteractor(base.baseInteractor):
raise AttributeError("The control is not present in the view.") raise AttributeError("The control is not present in the view.")
getattr(self.view, control).clear() getattr(self.view, control).clear()
def post_deleted(self):
msg = commonMessages.post_deleted()
def install(self, *args, **kwargs): def install(self, *args, **kwargs):
super(displayPostInteractor, self).install(*args, **kwargs) super(displayPostInteractor, self).install(*args, **kwargs)
self.view.comments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_show_comment) 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.add_items, self.modulename+"_add_items")
pub.subscribe(self.enable_attachments, self.modulename+"_enable_attachments") pub.subscribe(self.enable_attachments, self.modulename+"_enable_attachments")
pub.subscribe(self.enable_photo_controls, self.modulename+"_enable_photo_controls") pub.subscribe(self.enable_photo_controls, self.modulename+"_enable_photo_controls")
pub.subscribe(self.post_deleted, self.modulename+"_post_deleted")
def uninstall(self): def uninstall(self):
super(displayPostInteractor, self).uninstall() super(displayPostInteractor, self).uninstall()
@ -66,6 +71,7 @@ class displayPostInteractor(base.baseInteractor):
pub.unsubscribe(self.add_items, self.modulename+"_add_items") pub.unsubscribe(self.add_items, self.modulename+"_add_items")
pub.unsubscribe(self.enable_attachments, self.modulename+"_enable_attachments") pub.unsubscribe(self.enable_attachments, self.modulename+"_enable_attachments")
pub.unsubscribe(self.enable_photo_controls, self.modulename+"_enable_photo_controls") 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): def on_focus(self, *args, **kwargs):
item = self.view.comments.get_selected() item = self.view.comments.get_selected()

View File

@ -56,6 +56,11 @@ class displayPostPresenter(base.basePresenter):
else: else:
self.user_identifier = "owner_id" self.user_identifier = "owner_id"
self.post_identifier = "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 = threading.Thread(target=self.load_all_components)
self.worker.finished = threading.Event() self.worker.finished = threading.Event()
self.worker.start() 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. # Retrieve again the post, so we'll make sure to get the most up to date information.
# And we add a counter for views. # 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])) 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] self.post = post[0]
if "views" in self.post and self.post["views"]["count"] > 0: if "views" in self.post and self.post["views"]["count"] > 0:
self.send_message("set", control="views", value=str(self.post["views"]["count"])) self.send_message("set", control="views", value=str(self.post["views"]["count"]))
@ -204,7 +213,6 @@ class displayPostPresenter(base.basePresenter):
return url return url
def load_all_components(self): def load_all_components(self):
self.get_post_information()
self.get_likes() self.get_likes()
self.get_reposts() self.get_reposts()
self.get_comments() self.get_comments()

View File

@ -52,3 +52,6 @@ def proxy_question():
def remove_friend(user): 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() 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()