diff --git a/rtv/content.py b/rtv/content.py index 6ee6d44..8a1f9ba 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -154,6 +154,7 @@ class Content(object): data['gold'] = sub.gilded > 0 data['nsfw'] = sub.over_18 data['stickied'] = sub.stickied + data['saved'] = sub.saved data['index'] = None # This is filled in later by the method caller if sub.url.split('/r/')[-1] == sub.permalink.split('/r/')[-1]: @@ -384,6 +385,14 @@ class SubredditContent(Content): else: submissions = reddit.user.get_submitted() + if name == 'saved': + if not reddit.is_oauth_session(): + raise exceptions.AccountError('Not logged in') + elif order: + submissions = reddit.user.get_saved(sort=order) + else: + submissions = reddit.user.get_saved() + elif query: if name == 'front': submissions = reddit.search(query, subreddit=None, sort=order) diff --git a/rtv/docs.py b/rtv/docs.py index eb7503f..555183c 100644 --- a/rtv/docs.py +++ b/rtv/docs.py @@ -34,6 +34,7 @@ Basic Commands Authenticated Commands `a/z` : Upvote/downvote + `w` : Save/unsave a post `c` : Compose a new post or comment `e` : Edit an existing post or comment `d` : Delete an existing post or comment @@ -80,4 +81,4 @@ SUBMISSION_EDIT_FILE = """{content} # and an empty message aborts the submission. # # Editing {name} -""" \ No newline at end of file +""" diff --git a/rtv/page.py b/rtv/page.py index b3c6162..74775c7 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -155,6 +155,23 @@ class Page(object): if not self.term.loader.exception: data['likes'] = None + @PageController.register('w') + @logged_in + def savepost(self): + data = self.content.get(self.nav.absolute_index) + if 'saved' not in data: + self.term.flash() + elif not data['saved']: + with self.term.loader('Saving'): + data['object'].save() + if not self.term.loader.exception: + data['saved'] = True + else: + with self.term.loader('Unsaving'): + data['object'].unsave() + if not self.term.loader.exception: + data['saved'] = False + @PageController.register('u') def login(self): """ @@ -393,4 +410,4 @@ class Page(object): n_rows, _ = window.getmaxyx() for row in range(n_rows): - window.chgat(row, 0, 1, attribute) \ No newline at end of file + window.chgat(row, 0, 1, attribute) diff --git a/rtv/subreddit.py b/rtv/subreddit.py index 2d79133..7d2632a 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -114,7 +114,7 @@ class SubredditPage(Page): # Check that the subreddit can be submitted to name = self.content.name - if '+' in name or name in ('/r/all', '/r/front', '/r/me'): + if '+' in name or name in ('/r/all', '/r/front', '/r/me','/r/saved'): self.term.show_notification("Can't post to {0}".format(name)) return @@ -191,6 +191,11 @@ class SubredditPage(Page): text, attr = self.term.get_arrow(data['likes']) self.term.add_line(win, text, attr=attr) self.term.add_line(win, ' {created} {comments} '.format(**data)) + + if data['saved']: + text, attr = self.term.saved + self.term.add_line(win, text, attr=attr) + if data['stickied']: text, attr = self.term.stickied self.term.add_line(win, text, attr=attr) @@ -211,4 +216,4 @@ class SubredditPage(Page): self.term.add_line(win, text, attr=Color.YELLOW) if data['flair']: text = ' {flair}'.format(**data) - self.term.add_line(win, text, attr=Color.RED) \ No newline at end of file + self.term.add_line(win, text, attr=Color.RED) diff --git a/rtv/terminal.py b/rtv/terminal.py index 39da5b8..8774c64 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -73,6 +73,12 @@ class Terminal(object): attr = Color.GREEN return text, attr + @property + def saved(self): + text = '[saved]' + attr = Color.GREEN + return text, attr + @property def vline(self): return getattr(curses, 'ACS_VLINE', ord('|'))