From b39ccb9f2c22e377b4c6a3966d2b3db5c916f341 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Fri, 17 May 2024 17:45:47 -0600 Subject: [PATCH] Started implementation of community timelines --- src/controller/mainController.py | 7 ++++ src/controller/mastodon/handler.py | 19 +++++++++- src/mastodon.defaults | 1 + .../dialogs/mastodon/communityTimeline.py | 38 +++++++++++++++++++ src/wxUI/view.py | 1 + 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/wxUI/dialogs/mastodon/communityTimeline.py diff --git a/src/controller/mainController.py b/src/controller/mainController.py index ca6c24b2..4cbe826b 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -153,6 +153,7 @@ class Controller(object): widgetUtils.connect_event(self.view, widgetUtils.MENU, self.toggle_buffer_mute, self.view.mute_buffer) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.open_timeline, self.view.timeline) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.open_favs_timeline, self.view.favs) + widgetUtils.connect_event(self.view, widgetUtils.MENU, self.new_community_buffer, self.view.new_community_buffer) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.open_conversation, menuitem=self.view.view_conversation) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.seekLeft, menuitem=self.view.seekLeft) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.seekRight, menuitem=self.view.seekRight) @@ -1148,3 +1149,9 @@ class Controller(object): handler = self.get_handler(type=buffer.session.type) if handler and hasattr(handler, 'openFollowingTimeline'): handler.openFollowingTimeline(self, buffer, user) + + def new_community_buffer(self, *args, user=None): + buffer = self.get_best_buffer() + handler = self.get_handler(type=buffer.session.type) + if handler and hasattr(handler, 'new_community_buffer'): + handler.new_community_buffer(self, buffer) diff --git a/src/controller/mastodon/handler.py b/src/controller/mastodon/handler.py index 633316cf..7f4da2c9 100644 --- a/src/controller/mastodon/handler.py +++ b/src/controller/mastodon/handler.py @@ -10,7 +10,7 @@ from wxUI.dialogs.mastodon import dialogs from wxUI.dialogs import userAliasDialogs from wxUI import commonMessageDialogs from wxUI.dialogs.mastodon import updateProfile as update_profile_dialogs -from wxUI.dialogs.mastodon import showUserProfile +from wxUI.dialogs.mastodon import showUserProfile, communityTimeline from sessions.mastodon.utils import html_filter from . import userActions, settings @@ -48,7 +48,7 @@ class Handler(object): details=_("Show user profile"), favs=None, # In buffer Menu. - trends=None, + new_community_buffer=_("New community buffer"), filter=None, manage_filters=None ) @@ -105,6 +105,8 @@ class Handler(object): searches_position =controller.view.search("searches", name) for term in session.settings["other_buffers"]["post_searches"]: pub.sendMessage("createBuffer", buffer_type="SearchBuffer", session_type=session.type, buffer_title=_("Search for {}").format(term), parent_tab=searches_position, start=True, kwargs=dict(parent=controller.view.nb, compose_func="compose_post", function="search", name="%s-searchterm" % (term,), sessionObject=session, account=session.get_name(), sound="search_updated.ogg", q=term, result_type="statuses")) + pub.sendMessage("createBuffer", buffer_type="EmptyBuffer", session_type="base", buffer_title=_("Communities"), parent_tab=root_position, start=False, kwargs=dict(parent=controller.view.nb, name="communities", account=name)) + communities_position =controller.view.search("communities", name) # for i in session.settings["other_buffers"]["trending_topic_buffers"]: # pub.sendMessage("createBuffer", buffer_type="TrendsBuffer", session_type=session.type, buffer_title=_("Trending topics for %s") % (i), parent_tab=root_position, start=False, kwargs=dict(parent=controller.view.nb, name="%s_tt" % (i,), sessionObject=session, name, trendsFor=i, sound="trends_updated.ogg")) @@ -359,3 +361,16 @@ class Handler(object): user = buffer.session.api.account(selectedUser[-1]) dlg = showUserProfile.ShowUserProfile(user) dlg.ShowModal() + + def new_community_buffer(self, buffer, *args, **kwargs): + dlg = communityTimeline.CommunityTimeline() + if dlg.ShowModal() != wx.ID_OK: + return + url = dlg.url.GetValue() + bufftype = dlg.get_action() + dlg.Destroy() + tl_info = f"{bufftype}@{url}" + if tl_info in buffer.session.settings["other_buffers"]["communities"]: + return # buffer already exists. + buffer.session.settings["other_buffers"]["communities"].append(tl_info) + buffer.session.settings.write() \ No newline at end of file diff --git a/src/mastodon.defaults b/src/mastodon.defaults index 8855f131..525bfc84 100644 --- a/src/mastodon.defaults +++ b/src/mastodon.defaults @@ -30,6 +30,7 @@ indicate_img = boolean(default=True) [other_buffers] timelines = list(default=list()) searches = list(default=list()) +communities = list(default=list()) lists = list(default=list()) followers_timelines = list(default=list()) following_timelines = list(default=list()) diff --git a/src/wxUI/dialogs/mastodon/communityTimeline.py b/src/wxUI/dialogs/mastodon/communityTimeline.py new file mode 100644 index 00000000..6c950ae3 --- /dev/null +++ b/src/wxUI/dialogs/mastodon/communityTimeline.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +import wx + +class CommunityTimeline(wx.Dialog): + def __init__(self, *args, **kwargs): + super(CommunityTimeline, self).__init__(parent=None, *args, **kwargs) + panel = wx.Panel(self) + communitySizer = wx.BoxSizer() + self.SetTitle(_("Create community buffer")) + communityLabel = wx.StaticText(panel, -1, _("Community URL")) + self.url = wx.TextCtrl(panel, -1) + self.url.SetFocus() + communitySizer.Add(communityLabel, 0, wx.ALL, 5) + communitySizer.Add(self.url, 0, wx.ALL, 5) + actionSizer = wx.BoxSizer(wx.VERTICAL) + label2 = wx.StaticText(panel, -1, _(u"Buffer type")) + self.local= wx.RadioButton(panel, -1, _("Local timeline"), style=wx.RB_GROUP) + self.federated= wx.RadioButton(panel, -1, _("Federated Timeline")) + hSizer = wx.BoxSizer(wx.HORIZONTAL) + hSizer.Add(label2, 0, wx.ALL, 5) + actionSizer.Add(self.local, 0, wx.ALL, 5) + actionSizer.Add(self.federated, 0, wx.ALL, 5) + hSizer.Add(actionSizer, 0, wx.ALL, 5) + sizer = wx.BoxSizer(wx.VERTICAL) + ok = wx.Button(panel, wx.ID_OK, _(u"&OK")) + ok.SetDefault() + cancel = wx.Button(panel, wx.ID_CANCEL, _(u"&Close")) + btnsizer = wx.BoxSizer() + btnsizer.Add(ok) + btnsizer.Add(cancel) + sizer.Add(communitySizer) + sizer.Add(hSizer, 0, wx.ALL, 5) + sizer.Add(btnsizer) + panel.SetSizer(sizer) + + def get_action(self): + if self.local.GetValue() == True: return "local" + elif self.federated.GetValue() == True: return "federated" diff --git a/src/wxUI/view.py b/src/wxUI/view.py index c3e37a2a..b7f66081 100644 --- a/src/wxUI/view.py +++ b/src/wxUI/view.py @@ -52,6 +52,7 @@ class mainFrame(wx.Frame): # buffer menu self.menubar_buffer = wx.Menu() self.update_buffer = self.menubar_buffer.Append(wx.ID_ANY, _(u"&Update buffer")) + self.new_community_buffer= self.menubar_buffer.Append(wx.ID_ANY, _("New community buffer")) self.trends = self.menubar_buffer.Append(wx.ID_ANY, _(u"New &trending topics buffer...")) self.filter = self.menubar_buffer.Append(wx.ID_ANY, _(u"Create a &filter")) self.manage_filters = self.menubar_buffer.Append(wx.ID_ANY, _(u"&Manage filters"))