From 7ef6dd30e89f0eff1a700f03774f1c7eb76c84f8 Mon Sep 17 00:00:00 2001 From: faethon Date: Wed, 5 Feb 2025 20:17:04 +0100 Subject: [PATCH 1/7] Added keybinds to open subreddit and user page, conform merge request 688 from goggle (https://github.com/michael-lazar/rtv/pull/688) --- tuir/docs.py | 3 +++ tuir/page.py | 24 ++++++++++++++++++++++++ tuir/templates/tuir.cfg | 2 ++ 3 files changed, 29 insertions(+) diff --git a/tuir/docs.py b/tuir/docs.py index 3df9b4c5..55f2fe11 100644 --- a/tuir/docs.py +++ b/tuir/docs.py @@ -68,6 +68,8 @@ 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 + 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 +79,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 35547dd2..462c8ea8 100644 --- a/tuir/page.py +++ b/tuir/page.py @@ -290,6 +290,30 @@ 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'] + self.selected_page = self.open_subreddit_page('u/' + author) + else: + self.term.flash() + @PageController.register(Command('SAVE')) @logged_in def save(self): diff --git a/tuir/templates/tuir.cfg b/tuir/templates/tuir.cfg index 8d6b6bfe..cdb3f01d 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 -- GitLab From 3d1ceb2b336caed186d30702ca5b09b8e1b3e159 Mon Sep 17 00:00:00 2001 From: faethon Date: Wed, 5 Feb 2025 21:22:11 +0100 Subject: [PATCH 2/7] Prevent crash when the requesting the user page when already on the user page --- tuir/page.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tuir/page.py b/tuir/page.py index 462c8ea8..ebcc5fc4 100644 --- a/tuir/page.py +++ b/tuir/page.py @@ -310,7 +310,8 @@ class Page(object): data = self.get_selected_item() if 'author' in data: author = data['author'] - self.selected_page = self.open_subreddit_page('u/' + author) + if type(author) == str: + self.selected_page = self.open_subreddit_page('u/' + author) else: self.term.flash() -- GitLab From 8866b24f22652c9d7ba81515089d29a7f52f3345 Mon Sep 17 00:00:00 2001 From: faethon Date: Sun, 9 Feb 2025 16:10:39 +0100 Subject: [PATCH 3/7] Added keybind to join or leave a subreddit --- tuir/docs.py | 2 ++ tuir/subreddit_page.py | 14 ++++++++++++++ tuir/templates/tuir.cfg | 2 ++ 3 files changed, 18 insertions(+) diff --git a/tuir/docs.py b/tuir/docs.py index 55f2fe11..edca9c7e 100644 --- a/tuir/docs.py +++ b/tuir/docs.py @@ -68,6 +68,8 @@ 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 + j : Join this subreddit + J : Leave this subreddit v : Open the subreddit for the selected submission V : Open the authors user page for the selected submission diff --git a/tuir/subreddit_page.py b/tuir/subreddit_page.py index 49b6d5de..7210de6a 100644 --- a/tuir/subreddit_page.py +++ b/tuir/subreddit_page.py @@ -271,6 +271,20 @@ class SubredditPage(Page): data['object'].hide() data['hidden'] = True + @SubredditController.register(Command('SUBREDDIT_JOIN')) + @logged_in + def subreddit_subscribe(self): + name = self.content.name + 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 + 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 cdb3f01d..608c5bd9 100644 --- a/tuir/templates/tuir.cfg +++ b/tuir/templates/tuir.cfg @@ -230,6 +230,8 @@ SUBREDDIT_OPEN = l, SUBREDDIT_OPEN_IN_BROWSER = o, , SUBREDDIT_FRONTPAGE = p SUBREDDIT_HIDE = 0x20 +SUBREDDIT_JOIN = j +SUBREDDIT_LEAVE = J ; Subscription page SUBSCRIPTION_SELECT = l, , , -- GitLab From c9223a25b832a56d2f016577af5a002e92a8cdc2 Mon Sep 17 00:00:00 2001 From: faethon Date: Sun, 9 Feb 2025 17:11:45 +0100 Subject: [PATCH 4/7] Notify user of opening subreddit or userpage --- tuir/page.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tuir/page.py b/tuir/page.py index ebcc5fc4..b6dcb005 100644 --- a/tuir/page.py +++ b/tuir/page.py @@ -668,7 +668,12 @@ class Page(object): """ from .subreddit_page import SubredditPage - with self.term.loader('Loading subreddit'): + if 'u/' in name: + pagetypename = "userpage" + else: + pagetypename = "subreddit" + + with self.term.loader('Loading {0}'.format(pagetypename)): page = SubredditPage(self.reddit, self.term, self.config, self.oauth, name) if not self.term.loader.exception: -- GitLab From 9753f9d406707ae087705dc7ffb2f5eeb50337b3 Mon Sep 17 00:00:00 2001 From: faethon Date: Sun, 9 Feb 2025 20:48:05 +0100 Subject: [PATCH 5/7] Change keybinds for joining and leaving to prevent double assignment --- tuir/docs.py | 4 ++-- tuir/subreddit_page.py | 10 ++++++++++ tuir/templates/tuir.cfg | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tuir/docs.py b/tuir/docs.py index edca9c7e..9d792f50 100644 --- a/tuir/docs.py +++ b/tuir/docs.py @@ -68,8 +68,8 @@ 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 - j : Join this subreddit - J : Leave this subreddit + 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 diff --git a/tuir/subreddit_page.py b/tuir/subreddit_page.py index 7210de6a..9c6e6e14 100644 --- a/tuir/subreddit_page.py +++ b/tuir/subreddit_page.py @@ -275,6 +275,11 @@ class SubredditPage(Page): @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) @@ -282,6 +287,11 @@ class SubredditPage(Page): @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) diff --git a/tuir/templates/tuir.cfg b/tuir/templates/tuir.cfg index 608c5bd9..683ae74d 100644 --- a/tuir/templates/tuir.cfg +++ b/tuir/templates/tuir.cfg @@ -230,8 +230,8 @@ SUBREDDIT_OPEN = l, SUBREDDIT_OPEN_IN_BROWSER = o, , SUBREDDIT_FRONTPAGE = p SUBREDDIT_HIDE = 0x20 -SUBREDDIT_JOIN = j -SUBREDDIT_LEAVE = J +SUBREDDIT_JOIN = t +SUBREDDIT_LEAVE = T ; Subscription page SUBSCRIPTION_SELECT = l, , , -- GitLab From 629471d69362b6b6fc070a988500cbd6871ee09c Mon Sep 17 00:00:00 2001 From: faethon Date: Mon, 3 Mar 2025 22:12:25 +0100 Subject: [PATCH 6/7] Cosmetics --- tuir/page.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tuir/page.py b/tuir/page.py index b6dcb005..e69e0c78 100644 --- a/tuir/page.py +++ b/tuir/page.py @@ -310,7 +310,7 @@ class Page(object): data = self.get_selected_item() if 'author' in data: author = data['author'] - if type(author) == str: + if isinstance(author, str): self.selected_page = self.open_subreddit_page('u/' + author) else: self.term.flash() @@ -669,11 +669,11 @@ class Page(object): from .subreddit_page import SubredditPage if 'u/' in name: - pagetypename = "userpage" + pagetypename = "userpage " else: - pagetypename = "subreddit" + pagetypename = "subreddit r/" - with self.term.loader('Loading {0}'.format(pagetypename)): + 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: -- GitLab From 8b43055ce11ee196b7fabc2a9e6b29ba132523b5 Mon Sep 17 00:00:00 2001 From: faethon Date: Tue, 4 Mar 2025 23:18:37 +0100 Subject: [PATCH 7/7] Unify notification text when opening subreddit or user page --- tuir/page.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tuir/page.py b/tuir/page.py index e69e0c78..8caa8788 100644 --- a/tuir/page.py +++ b/tuir/page.py @@ -669,9 +669,11 @@ class Page(object): from .subreddit_page import SubredditPage if 'u/' in name: - pagetypename = "userpage " + pagetypename = "userpage /" + elif 'r/' in name: + pagetypename = "subreddit " else: - pagetypename = "subreddit r/" + pagetypename = "subreddit /r/" with self.term.loader('Loading {0}{1}'.format(pagetypename, name)): page = SubredditPage(self.reddit, self.term, self.config, -- GitLab