From 35fc287d55b3cfc3c5e87ed6ecf8cec46e166ed6 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Fri, 1 Feb 2019 13:25:47 -0600 Subject: [PATCH] Added support for reply to topic comments --- changelog.md | 2 +- src/interactors/postDisplayer.py | 2 +- src/presenters/postDisplayer.py | 44 ++++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index d79daec..6705880 100644 --- a/changelog.md +++ b/changelog.md @@ -27,7 +27,7 @@ * Added improvements to groups: * It is possible to load topics, audios and videos for a group. In order to do so, you need to go to the group buffer and press the menu key, or right mouse click, in the tree item representing the group. New buffers will be created inside the current group's buffer. * You can create or delete all buffers for groups by pressing the menu key or right mouse click in the "communities" buffer. - * There is some support for group topics. When opening them, they will be displayed as a list of posts. You can like or dislike such posts. + * There is support for group topics. When opening them, they will be displayed as a list of posts. You can like or reply to such posts, as well as adding new posts in the topic. ## Changes in version 0.18 (21.01.2019) diff --git a/src/interactors/postDisplayer.py b/src/interactors/postDisplayer.py index 9f81092..c49b455 100644 --- a/src/interactors/postDisplayer.py +++ b/src/interactors/postDisplayer.py @@ -90,7 +90,7 @@ class displayPostInteractor(base.baseInteractor): self.presenter.post_repost() def on_reply(self, *args, **kwargs): - if hasattr(self.view, "repost"): + if hasattr(self.view, "repost") or not hasattr(self, "post_view"): comment = self.view.comments.get_selected() self.presenter.reply(comment) else: diff --git a/src/presenters/postDisplayer.py b/src/presenters/postDisplayer.py index c216392..820a51b 100644 --- a/src/presenters/postDisplayer.py +++ b/src/presenters/postDisplayer.py @@ -144,6 +144,7 @@ class displayPostPresenter(base.basePresenter): def get_attachments(self, post, text): attachments = [] + self.attachments = [] if "attachments" in post: for i in post["attachments"]: # We don't need the photos_list attachment, so skip it. @@ -167,6 +168,8 @@ class displayPostPresenter(base.basePresenter): if len(self.attachments) > 0: self.send_message("enable_attachments") self.send_message("add_items", control="attachments", items=attachments) + else: + self.interactor.view.attachments.list.Enable(False) def check_image_load(self): if self.load_images and len(self.images) > 0 and self.session.settings["general"]["load_images"]: @@ -539,8 +542,6 @@ class displayTopicPresenter(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) -# print(self.comments["items"]) -# print(self.post) comments_ = [] for i in self.comments["items"]: # If comment has a "deleted" key it should not be displayed, obviously. @@ -581,11 +582,50 @@ class displayTopicPresenter(displayPostPresenter): def change_comment(self, comment): comment = self.comments["items"][comment] + self.send_message("clean_list", list="attachments") + self.get_attachments(comment, "") if comment["likes"]["user_likes"] == 1: self.send_message("set_label", control="like", label=_("&Dislike")) else: self.send_message("set_label", control="like", label=_("&Like")) + def add_comment(self): + comment = createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Add a comment"), message="", text="", mode="comment")) + if hasattr(comment, "text") or hasattr(comment, "privacy"): + group_id = self.group_id + topic_id = self.post["id"] + call_threaded(self.do_last, comment, group_id=group_id, topic_id=topic_id) + + def do_last(self, comment, **kwargs): + msg = comment.text + attachments = "" + if hasattr(comment, "attachments"): + attachments = self.upload_attachments(comment.attachments) + urls = utils.find_urls_in_text(msg) + if len(urls) != 0: + if len(attachments) == 0: attachments = urls[0] + else: attachments += urls[0] + msg = msg.replace(urls[0], "") + if msg != "": + kwargs.update(message=msg) + if attachments != "": + kwargs.update(attachments=attachments) + if "message" not in kwargs and "attachments" not in kwargs: + return # No comment made here. + result = self.session.vk.client.board.createComment(**kwargs) + self.clear_comments_list() + + def reply(self, comment): + c = self.comments["items"][comment] + comment = createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Reply to {user1_nom}").format(**self.session.get_user(c["from_id"])), message="", text="", mode="comment")) + if hasattr(comment, "text") or hasattr(comment, "privacy"): + user = self.session.get_user(c["from_id"]) + name = user["user1_nom"].split(" ")[0] + comment.text = "[post{post_id}|{name}], {text}".format(post_id=c["id"], text=comment.text, name=name) + group_id = self.group_id + topic_id = self.post["id"] + call_threaded(self.do_last, comment, group_id=group_id, topic_id=topic_id, reply_to_comment=c["id"]) + class displayAudioPresenter(base.basePresenter): def __init__(self, session, postObject, view, interactor): super(displayAudioPresenter, self).__init__(view=view, interactor=interactor, modulename="display_audio")