diff --git a/tuir/docs.py b/tuir/docs.py index 3df9b4c54fb40a431e7dc661224830c82a35a4ae..9d792f5067c77f8e113c3daba6f67e1400ee7110 100644 --- a/tuir/docs.py +++ b/tuir/docs.py @@ -68,6 +68,10 @@ https://gitlab.com/Chocimier/tuir SPACE : Mark the selected submission as hidden p : Toggle between the currently viewed subreddit and /r/front f : Open a prompt to search the current subreddit for a text string + t : Join this subreddit + T : Leave this subreddit + v : Open the subreddit for the selected submission + V : Open the authors user page for the selected submission [Submission Mode] h : Close the submission and return to the previous page @@ -77,6 +81,7 @@ https://gitlab.com/Chocimier/tuir b : Send the comment text to the system's urlviewer application J : Move the cursor down the the next comment at the same indentation K : Move the cursor up to the parent comment + V : Open the authors user page for the selected comment [Subscription Mode] h : Close your subscriptions and return to the previous page diff --git a/tuir/page.py b/tuir/page.py index 35547dd2500c3871bb692d89b952335324002e17..8caa8788506cd045b13604739779108f1b04f30d 100644 --- a/tuir/page.py +++ b/tuir/page.py @@ -290,6 +290,31 @@ class Page(object): if not self.term.loader.exception: data['likes'] = None + @PageController.register(Command('OPEN_SUBREDDIT')) + def open_subreddit(self): + """ + Open the subreddit associated with the currently selected item. + """ + data = self.get_selected_item() + if 'subreddit' in data: + subreddit = data['subreddit'] + self.selected_page = self.open_subreddit_page(subreddit) + else: + self.term.flash() + + @PageController.register(Command('OPEN_USERPAGE')) + def open_userpage(self): + """ + Open the authors user page for the currently selected item. + """ + data = self.get_selected_item() + if 'author' in data: + author = data['author'] + if isinstance(author, str): + self.selected_page = self.open_subreddit_page('u/' + author) + else: + self.term.flash() + @PageController.register(Command('SAVE')) @logged_in def save(self): @@ -643,7 +668,14 @@ class Page(object): """ from .subreddit_page import SubredditPage - with self.term.loader('Loading subreddit'): + if 'u/' in name: + pagetypename = "userpage /" + elif 'r/' in name: + pagetypename = "subreddit " + else: + pagetypename = "subreddit /r/" + + with self.term.loader('Loading {0}{1}'.format(pagetypename, name)): page = SubredditPage(self.reddit, self.term, self.config, self.oauth, name) if not self.term.loader.exception: diff --git a/tuir/subreddit_page.py b/tuir/subreddit_page.py index 49b6d5de355ab50ea899f2bee0c62c134b6c9a12..9c6e6e14273bee916a4bd9d28731cb93d98567d4 100644 --- a/tuir/subreddit_page.py +++ b/tuir/subreddit_page.py @@ -271,6 +271,30 @@ class SubredditPage(Page): data['object'].hide() data['hidden'] = True + @SubredditController.register(Command('SUBREDDIT_JOIN')) + @logged_in + def subreddit_subscribe(self): + name = self.content.name + + if 'u/' in name or name in ('/r/all', '/r/front', '/r/me', '/u/saved'): + self.term.show_notification("Not a valid subreddit {0}".format(name)) + return + + self.reddit.subscribe(name) + self.term.show_notification("Joining {0}".format(name), 1) + + @SubredditController.register(Command('SUBREDDIT_LEAVE')) + @logged_in + def subreddit_unsubscribe(self): + name = self.content.name + + if 'u/' in name or name in ('/r/all', '/r/front', '/r/me', '/u/saved'): + self.term.show_notification("Not a valid subreddit {0}".format(name)) + return + + self.reddit.unsubscribe(name) + self.term.show_notification("Leaving {0}".format(name), 1) + def _submission_attr(self, data): if data['url_full'] in self.config.history: return self.term.attr('SubmissionTitleSeen') diff --git a/tuir/templates/tuir.cfg b/tuir/templates/tuir.cfg index 8d6b6bfe71418cdd9ef78fb4ce24d70db8ffd894..683ae74dc60af13cda3cb9a34956fb0fc1efa995 100644 --- a/tuir/templates/tuir.cfg +++ b/tuir/templates/tuir.cfg @@ -210,6 +210,8 @@ COPY_URL = Y PRIVATE_MESSAGE = C SUBSCRIPTIONS = s MULTIREDDITS = S +OPEN_SUBREDDIT = v +OPEN_USERPAGE = V ; Submission page SUBMISSION_TOGGLE_COMMENT = 0x20 @@ -228,6 +230,8 @@ SUBREDDIT_OPEN = l, SUBREDDIT_OPEN_IN_BROWSER = o, , SUBREDDIT_FRONTPAGE = p SUBREDDIT_HIDE = 0x20 +SUBREDDIT_JOIN = t +SUBREDDIT_LEAVE = T ; Subscription page SUBSCRIPTION_SELECT = l, , ,