diff --git a/src/controller/buffers.py b/src/controller/buffers.py index a3c569c..6ae8ad9 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -500,6 +500,25 @@ class topicBuffer(feedBuffer): return a = presenters.displayTopicPresenter(session=self.session, postObject=post, group_id=self.kwargs["group_id"], interactor=interactors.displayPostInteractor(), view=views.displayTopic()) +class documentBuffer(feedBuffer): + + def create_tab(self, parent): + self.tab = home.documentTab(parent) + self.connect_events() + self.tab.name = self.name + if hasattr(self, "can_post") and self.can_post == False and hasattr(self.tab, "post"): + self.tab.post.Enable(False) + + def onFocus(self, *args, **kwargs): + pass + + def open_post(self, *args, **kwargs): + """ Opens the currently focused post.""" + post = self.get_post() + if post == None: + return + print(post) + class audioBuffer(feedBuffer): """ this buffer was supposed to be used with audio elements but is deprecated as VK removed its audio support for third party apps.""" diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 270b64f..fc1a831 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -191,7 +191,7 @@ class Controller(object): # disable post loading if the community has already loaded posts. if current_buffer.can_get_items: menu.load_posts.Enable(False) - # Disable loading of audios, videos or topics depending in two conditions. + # Disable loading of audios, videos, documents or topics depending in two conditions. # 1. If the buffer already exists, which means they are already loaded, or # 2. If the group_info does not have counters for such items, which would indicate there are no items posted yet. if self.search(current_buffer.name+"_audios") != False: @@ -206,12 +206,17 @@ class Controller(object): menu.load_topics.Enable(False) elif hasattr(current_buffer, "group_info") and "topics" not in current_buffer.group_info["counters"]: menu.load_topics.Enable(False) + + if self.search(current_buffer.name+"_documents") != False: + menu.load_documents.Enable(False) + elif hasattr(current_buffer, "group_info") and "docs" not in current_buffer.group_info["counters"]: + menu.load_documents.Enable(False) # Connect the rest of the functions. widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_posts, menuitem=menu.load_posts) widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_topics, menuitem=menu.load_topics) widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_audios, menuitem=menu.load_audios) widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_videos, menuitem=menu.load_videos) - + widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_documents, menuitem=menu.load_documents) # Deal with the communities section itself. if current_buffer.name == "communities": menu = wx.Menu() @@ -819,6 +824,18 @@ class Controller(object): new_name = current_buffer.name+"_topics" wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="topicBuffer", buffer_title=_("Topics"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_topic", session=self.session, endpoint="getTopics", parent_endpoint="board", count=100, group_id=-1*current_buffer.kwargs["owner_id"], extended=1)) + def load_community_documents(self, *args, **kwargs): + current_buffer = self.get_current_buffer() + # Get group_info if the community buffer does not have it already, so future menus will be able to use it. + if not hasattr(current_buffer, "group_info"): + group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0] + current_buffer.group_info = group_info + if "docs" not in current_buffer.group_info["counters"]: + commonMessages.community_no_items() + return + new_name = current_buffer.name+"_documents" + wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="documentBuffer", buffer_title=_("Documents"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_document", session=self.session, endpoint="get", parent_endpoint="docs", owner_id=current_buffer.kwargs["owner_id"])) + def load_community_buffers(self, *args, **kwargs): """ Load all community buffers regardless of the setting present in optional buffers tab of the preferences dialog.""" call_threaded(self.get_communities, self.session.user_id, force_action=True) @@ -830,4 +847,5 @@ class Controller(object): buff = self.window.search(buffer.name) self.window.remove_buffer(buff) self.buffers.remove(buffer) - del self.session.groups \ No newline at end of file + del self.session.groups + diff --git a/src/sessionmanager/renderers.py b/src/sessionmanager/renderers.py index b76d171..c75b78a 100644 --- a/src/sessionmanager/renderers.py +++ b/src/sessionmanager/renderers.py @@ -4,6 +4,7 @@ Chat messages, audios, videos, photos, comments in posts, etc)""" import arrow import languageHandler import logging +from update.utils import convert_bytes from . utils import seconds_to_string, clean_text log = logging.getLogger(__file__) @@ -244,6 +245,8 @@ def render_audio_message(audio_message, session=None): return [seconds_to_string(audio_message["duration"])] def render_topic(topic, session): + """ Render topics for a community. + Reference: https://vk.com/dev/objects/topic""" user = session.get_user(topic["created_by"]) title = topic["title"] comments = topic["comments"] @@ -251,4 +254,13 @@ def render_topic(topic, session): last_update = arrow.get(topic["updated"]).humanize(locale=languageHandler.curLang[:2]) last_commenter.update(date=last_update) lastupdate = _("Last post by {user1_nom} {date}").format(**last_commenter) - return [user["user1_nom"], title, str(comments), lastupdate] \ No newline at end of file + return [user["user1_nom"], title, str(comments), lastupdate] + +def render_document(document, session): + doc_types = {1: _("Text document"), 2: _("Archive"), 3: _("Gif"), 4: _("Image"), 5: _("Audio"), 6: _("Video"), 7: _("Ebook"), 8: _("Unknown document")} + user = session.get_user(document["owner_id"]) + title = document["title"] + size = convert_bytes(document["size"]) + date = arrow.get(document["date"]).humanize(locale=languageHandler.curLang[:2]) + doc_type = doc_types[document["type"]] + return [user["user1_nom"], title, doc_type, size, date] \ No newline at end of file diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index f181588..aeaf378 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -68,7 +68,7 @@ class vkSession(object): # Example of this behaviour is when you upload an audio and inmediately delete the audio, VK still sends the post stating that you uploaded an audio file, # But without the audio data, making socializer to render an empty post. # Here we check if the post contains data of the type it advertises. - if i.get("type") != None and post_types.get(i["type"]) not in i: + if i.get("type") != None and isinstance(i["type"], str) and post_types.get(i["type"]) not in i: log.error("Detected invalid or unsupported post. Skipping...") log.error(i) continue diff --git a/src/wxUI/menus.py b/src/wxUI/menus.py index 3a5bb9b..2536610 100644 --- a/src/wxUI/menus.py +++ b/src/wxUI/menus.py @@ -110,4 +110,5 @@ class communityBufferMenu(wx.Menu): self.load_topics = load.Append(wx.NewId(), _("Load topics")) self.load_audios = load.Append(wx.NewId(), _("Load audios")) self.load_videos = load.Append(wx.NewId(), _("Load videos")) + self.load_documents = load.Append(wx.NewId(), _("Load documents")) self.Append(wx.NewId(), _("Load"), load) \ No newline at end of file diff --git a/src/wxUI/tabs/home.py b/src/wxUI/tabs/home.py index 6e66b74..0b2d64c 100644 --- a/src/wxUI/tabs/home.py +++ b/src/wxUI/tabs/home.py @@ -147,6 +147,18 @@ class topicTab(homeTab): self.list.set_size() self.list.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnKeyDown) +class documentTab(homeTab): + def create_list(self): + self.lbl = wx.StaticText(self, wx.NewId(), _("Documents")) + self.list = widgetUtils.list(self, *[_("User"), _("Title"), _("Type"), _("Size"), _("Date")], style=wx.LC_REPORT) + self.list.set_windows_size(0, 200) + self.list.set_windows_size(1, 128) + self.list.set_windows_size(2, 35) + self.list.set_windows_size(3, 15) + self.list.set_windows_size(4, 25) + self.list.set_size() + self.list.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnKeyDown) + class empty(wx.Panel): def __init__(self, parent, name): super(empty, self).__init__(parent=parent, name=name)