Show people who have liked a post if pressing the likes button in the post displayer

This commit is contained in:
Manuel Cortez 2019-04-15 17:50:56 -05:00
parent 903af03d15
commit 7c90103af4
4 changed files with 34 additions and 7 deletions

View File

@ -355,7 +355,7 @@ class baseBuffer(object):
if "type" in post and post["type"] == "audio":
a = presenters.displayAudioPresenter(session=self.session, postObject=post["audio"]["items"], interactor=interactors.displayAudioInteractor(), view=views.displayAudio())
elif "type" in post and post["type"] == "friend":
pub.sendMessage("open-post", post_object=post, controller_="displayFriendship")
pub.sendMessage("open-post", post_object=post, controller_="displayFriendship", vars=dict(caption=_("{user1_nom} added the following friends")))
else:
pub.sendMessage("open-post", post_object=post, controller_="displayPost")

View File

@ -327,12 +327,12 @@ class Controller(object):
log.debug("downloading %s URL to %s filename" % (url, filename,))
call_threaded(utils.download_file, url, filename, self.window)
def view_post(self, post_object, controller_):
def view_post(self, post_object, controller_, vars=dict()):
""" Display the passed post in the passed post presenter.
@ post_object dict: A post representation returned by the VK api. The fields present in this dict are different depending on the presenter used to render it.
@controller_ string: Name of the post controller, this name will be used for calling interactors, views and presenters. For example, displayPost, displayAudio, etc.
"""
p = getattr(presenters, controller_+"Presenter")(session=self.session, postObject=post_object, interactor=getattr(interactors, controller_+"Interactor")(), view=getattr(views, controller_)())
p = getattr(presenters, controller_+"Presenter")(session=self.session, postObject=post_object, interactor=getattr(interactors, controller_+"Interactor")(), view=getattr(views, controller_)(), **vars)
def update_status_bar(self, status):
""" Update the status bar present in the main Window.

View File

@ -50,6 +50,8 @@ class displayPostInteractor(base.baseInteractor):
widgetUtils.connect_event(self.view.like, widgetUtils.BUTTON_PRESSED, self.on_like)
widgetUtils.connect_event(self.view.comment, widgetUtils.BUTTON_PRESSED, self.on_add_comment)
widgetUtils.connect_event(self.view.tools, widgetUtils.BUTTON_PRESSED, self.on_show_tools_menu)
if hasattr(self.view, "likes"):
widgetUtils.connect_event(self.view.likes, widgetUtils.BUTTON_PRESSED, self.on_show_likes_menu)
if hasattr(self.view, "repost"):
widgetUtils.connect_event(self.view.repost, widgetUtils.BUTTON_PRESSED, self.on_repost)
self.view.comments.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_focus)
@ -134,6 +136,9 @@ class displayPostInteractor(base.baseInteractor):
comment = self.view.comments.get_selected()
self.presenter.change_comment(comment)
def on_show_likes_menu(self, *args, **kwargs):
self.presenter.show_likes()
class displayAudioInteractor(base.baseInteractor):
def set(self, control, value):

View File

@ -417,6 +417,14 @@ class displayPostPresenter(base.basePresenter):
self.send_message("clean_list", list="comments")
self.get_comments()
def show_likes(self):
""" show likes for the specified post."""
data = dict(type="post", owner_id=self.post[self.user_identifier], item_id=self.post["id"], extended=True, count=1000, skip_own=True)
result = self.session.vk.client.likes.getList(**data)
if result["count"] > 0:
post = {"source_id": self.post[self.user_identifier], "friends": {"items": result["items"]}}
pub.sendMessage("open-post", post_object=post, controller_="displayFriendship", vars=dict(caption=_("people who liked this")))
class displayCommentPresenter(displayPostPresenter):
def __init__(self, session, postObject, view, interactor):
@ -780,7 +788,7 @@ class displayAudioPresenter(base.basePresenter):
class displayFriendshipPresenter(base.basePresenter):
def __init__(self, session, postObject, view, interactor, caption=_("{user1_nom} added the following friends")):
def __init__(self, session, postObject, view, interactor, caption=""):
self.session = session
self.post = postObject
super(displayFriendshipPresenter, self).__init__(view=view, interactor=interactor, modulename="display_friendship")
@ -793,16 +801,30 @@ class displayFriendshipPresenter(base.basePresenter):
def get_friend_names(self):
self.friends = self.post["friends"]["items"]
return [self.session.get_user(i["user_id"])["user1_nom"] for i in self.friends]
friends = list()
for i in self.friends:
if "user_id" in i:
friends.append(self.session.get_user(i["user_id"])["user1_nom"])
else:
friends.append(self.session.get_user(i["id"])["user1_nom"])
return friends
def set_friends_list(self, friendslist):
self.send_message("add_items", control="friends", items=friendslist)
def view_profile(self, item):
user = self.friends[item]
pub.sendMessage("user-profile", person=user["user_id"])
if "user_id" in user:
id = user["user_id"]
else:
id = user["id"]
pub.sendMessage("user-profile", person=id)
def open_in_browser(self, item):
user = self.friends[item]
url = "https://vk.com/id{user_id}".format(user_id=user["user_id"])
if "user_id" in user:
id = user["user_id"]
else:
id = user["id"]
url = "https://vk.com/id{user_id}".format(user_id=id)
webbrowser.open_new_tab(url)