Merge branch 'nemanjan00-hide'

This commit is contained in:
Michael Lazar
2018-06-03 14:24:40 -04:00
13 changed files with 1778 additions and 7 deletions

View File

@@ -45,6 +45,7 @@ In addition to the basic commands, the following actions can be performed when y
:``l`` or ``►``: Enter the selected submission
:``o`` or ``ENTER``: Open the submission link with your web browser
:``SPACE``: Hide the selected submission
:``p``: Toggle between the front page and the last visited subreddit
:``f``: Open a prompt to search the current subreddit
:``/``: Open a prompt to switch subreddits

View File

@@ -188,6 +188,7 @@ class Content(object):
data['gold'] = comment.gilded > 0
data['author'] = author
data['flair'] = flair
data['hidden'] = False
return data
@@ -229,7 +230,7 @@ class Content(object):
data['gold'] = sub.gilded > 0
data['nsfw'] = sub.over_18
data['stickied'] = sub.stickied
data['hidden'] = False
data['hidden'] = sub.hidden
data['xpost_subreddit'] = None
data['index'] = None # This is filled in later by the method caller
data['saved'] = sub.saved

View File

@@ -63,7 +63,7 @@ https://github.com/michael-lazar/rtv
l : View comments, or open comment in pager
h : Return to subreddit
o : Open the submission or comment url
SPACE : Fold or expand the selected comment tree
SPACE : Hide a submission, or fold/expand the selected comment tree
b : Display urls with urlview
y : Copy submission permalink to clipboard
Y : Copy submission link to clipboard

View File

@@ -292,6 +292,21 @@ class SubredditPage(Page):
self.content = page.selected_subreddit
self.nav = Navigator(self.content.get)
@SubredditController.register(Command('SUBREDDIT_HIDE'))
@logged_in
def hide(self):
data = self.get_selected_item()
if not hasattr(data["object"], 'hide'):
self.term.flash()
elif data['hidden']:
with self.term.loader('Unhiding'):
data['object'].unhide()
data['hidden'] = False
else:
with self.term.loader('Hiding'):
data['object'].hide()
data['hidden'] = True
def _draw_item(self, win, data, inverted):
n_rows, n_cols = win.getmaxyx()
@@ -346,6 +361,11 @@ class SubredditPage(Page):
self.term.add_space(win)
self.term.add_line(win, '[saved]', attr=attr)
if data['hidden']:
attr = self.term.attr('Hidden')
self.term.add_space(win)
self.term.add_line(win, '[hidden]', attr=attr)
if data['stickied']:
attr = self.term.attr('Stickied')
self.term.add_space(win)

View File

@@ -154,6 +154,7 @@ SUBREDDIT_OPEN_IN_BROWSER = o, <LF>, <KEY_ENTER>
SUBREDDIT_OPEN_SUBSCRIPTIONS = s
SUBREDDIT_OPEN_MULTIREDDITS = S
SUBREDDIT_FRONTPAGE = p
SUBREDDIT_HIDE = 0x20
; Subscription page
SUBSCRIPTION_SELECT = l, <LF>, <KEY_ENTER>, <KEY_RIGHT>

View File

@@ -95,6 +95,7 @@ class Theme(object):
'NeutralVote': (None, None, curses.A_BOLD),
'NSFW': (curses.COLOR_RED, None, curses.A_BOLD | curses.A_REVERSE),
'Saved': (curses.COLOR_GREEN, None, None),
'Hidden': (curses.COLOR_YELLOW, None, None),
'Score': (None, None, None),
'Separator': (None, None, curses.A_BOLD),
'Stickied': (curses.COLOR_GREEN, None, None),

View File

@@ -34,6 +34,7 @@ MultiredditText = - - -
NeutralVote = - - bold
NSFW = red - bold+reverse
Saved = green - -
Hidden = yellow - -
Score = - - -
Separator = - - bold
Stickied = green - -

View File

@@ -57,6 +57,7 @@ MultiredditText = ansi_244 - -
NeutralVote = - - bold
NSFW = ansi_197 - bold+reverse
Saved = ansi_199 - -
Hidden = ansi_208 - -
Score = - - bold
Separator = ansi_241 - bold
Stickied = ansi_208 - -

View File

@@ -55,6 +55,7 @@ MultiredditText = ansi_102 - -
NeutralVote = - - bold
NSFW = ansi_160 - bold+reverse
Saved = ansi_31 - bold
Hidden = ansi_166 - bold
Score = - - bold
Separator = - - bold
Stickied = ansi_166 - bold

View File

@@ -53,6 +53,7 @@ MultiredditText = ansi_240 - -
NeutralVote = - - bold
NSFW = ansi_160 - bold+reverse
Saved = ansi_125 - -
Hidden = ansi_136 - -
Score = - - -
Separator = - - bold
Stickied = ansi_136 - -

View File

@@ -53,6 +53,7 @@ MultiredditText = ansi_245 - -
NeutralVote = - - bold
NSFW = ansi_160 - bold+reverse
Saved = ansi_125 - bold
Hidden = ansi_136 - bold
Score = - - -
Separator = - - bold
Stickied = ansi_136 - bold

File diff suppressed because it is too large Load Diff

View File

@@ -487,3 +487,35 @@ def test_subreddit_frontpage_toggle(subreddit_page, terminal):
assert subreddit_page.content.name == '/r/aww'
subreddit_page.controller.trigger('p')
assert subreddit_page.content.name == '/r/front'
def test_subreddit_hide_submission(subreddit_page, refresh_token):
# Log in
subreddit_page.config.refresh_token = refresh_token
subreddit_page.oauth.authorize()
# The api won't return hidden posts in the submission listing, so the
# first post should always have hidden set to false
data = subreddit_page.get_selected_item()
assert data['hidden'] is False
# Hide the first submission by pressing the space key
subreddit_page.controller.trigger(0x20)
assert subreddit_page.term.loader.exception is None
data = subreddit_page.get_selected_item()
assert data['hidden'] is True
# Make sure that the status was actually updated on the server side
data['object'].refresh()
assert data['object'].hidden is True
# Now undo the hide by pressing space again
subreddit_page.controller.trigger(0x20)
assert subreddit_page.term.loader.exception is None
data = subreddit_page.get_selected_item()
assert data['hidden'] is False
# Make sure that the status was actually updated on the server side
data['object'].refresh()
assert data['object'].hidden is False