display wall comments and replies in the same list.
This commit is contained in:
@@ -50,7 +50,9 @@ class displayPostInteractor(base.baseInteractor):
|
||||
|
||||
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)
|
||||
if hasattr(self.view, "comments"):
|
||||
self.view.comments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_show_comment)
|
||||
self.view.comments.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_comment_changed)
|
||||
self.view.attachments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_open_attachment)
|
||||
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)
|
||||
@@ -76,7 +78,6 @@ class displayPostInteractor(base.baseInteractor):
|
||||
pub.subscribe(self.enable_photo_controls, self.modulename+"_enable_photo_controls")
|
||||
pub.subscribe(self.post_deleted, self.modulename+"_post_deleted")
|
||||
pub.subscribe(self.clean_list, self.modulename+"_clean_list")
|
||||
self.view.comments.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_comment_changed)
|
||||
|
||||
def uninstall(self):
|
||||
super(displayPostInteractor, self).uninstall()
|
||||
@@ -103,7 +104,7 @@ class displayPostInteractor(base.baseInteractor):
|
||||
self.presenter.post_repost()
|
||||
|
||||
def on_reply(self, *args, **kwargs):
|
||||
if hasattr(self.view, "repost") or not hasattr(self, "post_view"):
|
||||
if hasattr(self.view, "comments") and (hasattr(self.view, "repost") or not hasattr(self, "post_view")):
|
||||
comment = self.view.comments.get_selected()
|
||||
self.presenter.reply(comment)
|
||||
else:
|
||||
|
@@ -70,7 +70,13 @@ class displayPostPresenter(base.basePresenter):
|
||||
""" Get comments and insert them in a list."""
|
||||
user = self.post[self.user_identifier]
|
||||
id = self.post[self.post_identifier]
|
||||
self.comments = self.session.vk.client.wall.getComments(owner_id=user, post_id=id, need_likes=1, count=100, extended=1, preview_length=0, thread_items_count=10)
|
||||
comments_data = self.session.vk.client.wall.getComments(owner_id=user, post_id=id, need_likes=1, count=100, extended=1, preview_length=0, thread_items_count=10)
|
||||
self.comments = dict(items=[], profiles=comments_data["profiles"])
|
||||
for i in comments_data["items"]:
|
||||
self.comments["items"].append(i)
|
||||
if i.get("thread") != None and i["thread"].get("count") > 0:
|
||||
for newI in i["thread"]["items"]:
|
||||
self.comments["items"].append(newI)
|
||||
comments_ = []
|
||||
# Save profiles in session local storage for a future usage.
|
||||
# Although community objects are returned here, we should not add those because their names are changed.
|
||||
@@ -94,8 +100,7 @@ class displayPostPresenter(base.basePresenter):
|
||||
original_date = arrow.get(i["date"])
|
||||
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
|
||||
likes = str(i["likes"]["count"])
|
||||
replies = str(i["thread"]["count"])
|
||||
comments_.append((from_, text, created_at, likes, replies))
|
||||
comments_.append((from_, text, created_at, likes))
|
||||
self.send_message("add_items", control="comments", items=comments_)
|
||||
|
||||
def get_post_information(self):
|
||||
|
@@ -49,7 +49,6 @@ class displayCommentPresenter(basePost.displayPostPresenter):
|
||||
self.get_post_information()
|
||||
self.get_likes()
|
||||
self.send_message("disable_control", control="comment")
|
||||
self.get_comments()
|
||||
if self.post["likes"]["can_like"] == 0 and self.post["likes"]["user_likes"] == 0:
|
||||
self.send_message("disable_control", "like")
|
||||
elif self.post["likes"]["user_likes"] == 1:
|
||||
@@ -77,46 +76,14 @@ class displayCommentPresenter(basePost.displayPostPresenter):
|
||||
attachments = comment.attachments
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint="wall", child_endpoint="createComment", attachments_list=attachments, post_arguments=post_arguments)
|
||||
|
||||
def get_comments(self):
|
||||
""" Get comments and insert them in a list."""
|
||||
comments_ = []
|
||||
if "thread" not in self.post:
|
||||
return
|
||||
for i in self.post["thread"]["items"]:
|
||||
# If comment has a "deleted" key it should not be displayed, obviously.
|
||||
if "deleted" in i:
|
||||
continue
|
||||
from_ = self.session.get_user(i["from_id"])
|
||||
if "reply_to_user" in i:
|
||||
extra_info = self.session.get_user(i["reply_to_user"], "user2")
|
||||
extra_info.update(from_)
|
||||
from_ = _("{user1_nom} > {user2_nom}").format(**extra_info)
|
||||
else:
|
||||
from_ = from_["user1_nom"]
|
||||
# As we set the comment reply properly in the from_ field, let's remove the first username from here if it exists.
|
||||
fixed_text = utils.clean_text(i["text"])
|
||||
if len(fixed_text) > 140:
|
||||
text = fixed_text[:141]
|
||||
else:
|
||||
text = fixed_text
|
||||
original_date = arrow.get(i["date"])
|
||||
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
|
||||
likes = str(i["likes"]["count"])
|
||||
replies = ""
|
||||
comments_.append((from_, text, created_at, likes, replies))
|
||||
self.send_message("add_items", control="comments", items=comments_)
|
||||
|
||||
def show_comment(self, comment_index):
|
||||
c = self.post["thread"]["items"][comment_index]
|
||||
c["post_id"] = self.post["post_id"]
|
||||
a = displayCommentPresenter(session=self.session, postObject=c, interactor=interactors.displayPostInteractor(), view=views.displayComment())
|
||||
self.clear_comments_list()
|
||||
|
||||
def show_likes(self):
|
||||
""" show likes for the specified post."""
|
||||
data = dict(type="comment", owner_id=self.post["owner_id"], item_id=self.post["id"], extended=True, count=100, skip_own=True)
|
||||
result = self.session.vk.client.likes.getList(**data)
|
||||
print(result)
|
||||
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")))
|
||||
|
||||
def posted(self, from_buffer=None):
|
||||
self.interactor.uninstall()
|
||||
return
|
@@ -40,7 +40,7 @@ class displayBasicPost(widgetUtils.BaseDialog):
|
||||
|
||||
def create_comments_list(self):
|
||||
lbl = wx.StaticText(self.panel, -1, _("Comments"))
|
||||
self.comments = widgetUtils.list(self.panel, _("User"), _("Comment"), _("Date"), _("Likes"), _("replies"), style=wx.LC_REPORT)
|
||||
self.comments = widgetUtils.list(self.panel, _("User"), _("Comment"), _("Date"), _("Likes"), style=wx.LC_REPORT)
|
||||
self.reply = wx.Button(self.panel, -1, _("Reply to comment"))
|
||||
self.reply.Enable(False)
|
||||
box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
@@ -170,22 +170,12 @@ class displayComment(displayBasicPost):
|
||||
self.sizer.Add(likes_box, 0, wx.ALL, 5)
|
||||
actions_box = self.create_action_buttons()
|
||||
self.sizer.Add(actions_box, 0, wx.ALL, 5)
|
||||
comments_box = self.create_comments_list()
|
||||
self.sizer.Add(comments_box, 0, wx.ALL, 5)
|
||||
self.sizer.Add(self.create_dialog_buttons())
|
||||
self.done()
|
||||
|
||||
def create_comments_list(self):
|
||||
lbl = wx.StaticText(self.panel, -1, _("Replies"))
|
||||
self.comments = widgetUtils.list(self.panel, _("User"), _("Comment"), _("Date"), _("Likes"), _("Replies"), style=wx.LC_REPORT)
|
||||
box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
box.Add(lbl, 0, wx.ALL, 5)
|
||||
box.Add(self.comments.list, 0, wx.ALL, 5)
|
||||
return box
|
||||
|
||||
def create_action_buttons(self, comment=True):
|
||||
self.like = wx.Button(self.panel, -1, _("&Like"))
|
||||
self.reply = wx.Button(self.panel, -1, _("Reply to thread"))
|
||||
self.reply = wx.Button(self.panel, -1, _("Reply"))
|
||||
if comment: self.comment = wx.Button(self.panel, -1, _("Add comment"))
|
||||
box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
box.Add(self.like, 0, wx.ALL, 5)
|
||||
|
Reference in New Issue
Block a user