Added support for loading all comments in topics
This commit is contained in:
@@ -29,6 +29,11 @@ class displayPostInteractor(base.baseInteractor):
|
||||
for i in items:
|
||||
getattr(self.view, control).insert_item(False, *i)
|
||||
|
||||
def add_item(self, control, item, reversed=False):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
getattr(self.view, control).insert_item(reversed, *item)
|
||||
|
||||
def enable_attachments(self):
|
||||
self.view.attachments.list.Enable(True)
|
||||
|
||||
@@ -59,11 +64,14 @@ class displayPostInteractor(base.baseInteractor):
|
||||
self.view.comments.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_focus)
|
||||
if hasattr(self.view, "reply"):
|
||||
widgetUtils.connect_event(self.view.reply, widgetUtils.BUTTON_PRESSED, self.on_reply)
|
||||
if hasattr(self.view, "load_more_comments"):
|
||||
widgetUtils.connect_event(self.view.load_more_comments, widgetUtils.BUTTON_PRESSED, self.on_load_more_comments)
|
||||
# self.view.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.on_show_menu, self.view.comments.list)
|
||||
# self.view.Bind(wx.EVT_LIST_KEY_DOWN, self.on_show_menu_by_key, self.view.comments.list)
|
||||
pub.subscribe(self.set, self.modulename+"_set")
|
||||
pub.subscribe(self.load_image, self.modulename+"_load_image")
|
||||
pub.subscribe(self.add_items, self.modulename+"_add_items")
|
||||
pub.subscribe(self.add_item, self.modulename+"_add_item")
|
||||
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")
|
||||
@@ -75,6 +83,7 @@ class displayPostInteractor(base.baseInteractor):
|
||||
pub.unsubscribe(self.set, self.modulename+"_set")
|
||||
pub.unsubscribe(self.load_image, self.modulename+"_load_image")
|
||||
pub.unsubscribe(self.add_items, self.modulename+"_add_items")
|
||||
pub.unsubscribe(self.add_item, self.modulename+"_add_item")
|
||||
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")
|
||||
@@ -103,6 +112,10 @@ class displayPostInteractor(base.baseInteractor):
|
||||
def on_add_comment(self, *args, **kwargs):
|
||||
self.presenter.add_comment()
|
||||
|
||||
def on_load_more_comments(self, *args, **kwargs):
|
||||
if hasattr(self.presenter, "load_more_comments"):
|
||||
self.presenter.load_more_comments()
|
||||
|
||||
def on_show_tools_menu(self, *args, **kwargs):
|
||||
menu = menus.toolsMenu()
|
||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.on_open_url, menuitem=menu.url)
|
||||
|
@@ -51,10 +51,19 @@ class displayTopicPresenter(basePost.displayPostPresenter):
|
||||
|
||||
def get_comments(self):
|
||||
""" Get comments and insert them in a list."""
|
||||
self.comments = self.session.vk.client.board.getComments(group_id=self.group_id, topic_id=self.post["id"], need_likes=1, count=100, extended=1)
|
||||
self.comments = self.session.vk.client.board.getComments(group_id=self.group_id, topic_id=self.post["id"], need_likes=1, count=100, extended=1, sort="desc")
|
||||
comments_ = []
|
||||
data = dict(profiles=self.comments["profiles"], groups=[])
|
||||
self.session.process_usernames(data)
|
||||
self.comments["items"].reverse()
|
||||
# If there are less than 100 comments in the topic we should disable the "load previous" button.
|
||||
if self.comments["count"] <= 100:
|
||||
self.send_message("disable_control", control="load_more_comments")
|
||||
else:
|
||||
left_comments = self.comments["count"]-len(self.comments["items"])
|
||||
if left_comments > 100:
|
||||
left_comments = 100
|
||||
self.send_message("set_label", control="load_more_comments", label=_("Load {comments} previous comments").format(comments=left_comments))
|
||||
for i in self.comments["items"]:
|
||||
# If comment has a "deleted" key it should not be displayed, obviously.
|
||||
if "deleted" in i:
|
||||
@@ -134,4 +143,31 @@ class displayTopicPresenter(basePost.displayPostPresenter):
|
||||
def show_comment(self, comment_index):
|
||||
c = self.comments["items"][comment_index]
|
||||
c["post_id"] = self.post["id"]
|
||||
a = displayTopicCommentPresenter(session=self.session, postObject=c, interactor=interactors.displayPostInteractor(), view=views.displayComment())
|
||||
a = displayTopicCommentPresenter(session=self.session, postObject=c, interactor=interactors.displayPostInteractor(), view=views.displayComment())
|
||||
|
||||
def load_more_comments(self):
|
||||
offset = len(self.comments["items"])
|
||||
comments = self.session.vk.client.board.getComments(group_id=self.group_id, topic_id=self.post["id"], need_likes=1, count=100, extended=1, sort="desc", offset=offset)
|
||||
data = dict(profiles=comments["profiles"], groups=[])
|
||||
self.session.process_usernames(data)
|
||||
# If there are less than 100 comments in the topic we should disable the "load previous" button.
|
||||
for i in comments["items"]:
|
||||
self.comments["items"].insert(0, i)
|
||||
for i in comments["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"])["user1_nom"]
|
||||
# match user mentions inside text comment.
|
||||
original_date = arrow.get(i["date"])
|
||||
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
|
||||
likes = str(i["likes"]["count"])
|
||||
text = utils.clean_text(text=i["text"])
|
||||
self.send_message("add_item", control="comments", item=(from_, text, created_at, likes), reversed=True)
|
||||
if len(self.comments["items"]) == self.comments["count"]:
|
||||
self.send_message("disable_control", control="load_more_comments")
|
||||
else:
|
||||
left_comments = self.comments["count"]-len(self.comments["items"])
|
||||
if left_comments > 100:
|
||||
left_comments = 100
|
||||
self.send_message("set_label", control="load_more_comments", label=_("Load {comments} previous comments").format(comments=left_comments))
|
||||
|
@@ -221,6 +221,7 @@ class displayTopic(displayBasicPost):
|
||||
def create_comments_list(self):
|
||||
lbl = wx.StaticText(self.panel, -1, _("Posts"))
|
||||
self.comments = widgetUtils.list(self.panel, _("User"), _("Comment"), _("Date"), _("Likes"), style=wx.LC_REPORT)
|
||||
self.load_more_comments = wx.Button(self.panel, wx.NewId(), _("Load previous comments"))
|
||||
self.reply = wx.Button(self.panel, -1, _("Reply"))
|
||||
box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
box.Add(lbl, 0, wx.ALL, 5)
|
||||
|
Reference in New Issue
Block a user