diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 145c71fb3..4b8ddef59 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -1731,6 +1731,7 @@ class ApiController(RedditController, OAuth2ResourceController): @api_doc(api_section.links_and_comments) def POST_save(self, thing): if not thing: return + if isinstance(thing, Comment) and not c.user.gold: return r = thing._save(c.user) @noresponse(VUser(), diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 06be6ec52..fc4dad480 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -1163,6 +1163,7 @@ class CommentPane(Templated): likes = [] dislikes = [] is_friend = set() + saves = set() for t in self.listing_iter(my_listing): if not hasattr(t, "likes"): # this is for MoreComments and MoreRecursion @@ -1173,9 +1174,12 @@ class CommentPane(Templated): likes.append(t._fullname) if t.likes is False: dislikes.append(t._fullname) + if t.saved: + saves.add(t._fullname) self.rendered += ThingUpdater(likes = likes, dislikes = dislikes, - is_friend = is_friend).render() + is_friend = is_friend, + saves = saves).render() g.log.debug("using comment page cache") else: self.rendered = my_listing.render() diff --git a/r2/r2/lib/pages/things.py b/r2/r2/lib/pages/things.py index 25d947875..eaa3e717b 100644 --- a/r2/r2/lib/pages/things.py +++ b/r2/r2/lib/pages/things.py @@ -149,6 +149,7 @@ class CommentButtons(PrintableButtons): is_author = is_author, profilepage = c.profilepage, permalink = thing.permalink, + saved = thing.saved, new_window = c.user.pref_newwindow, full_comment_path = thing.full_comment_path, deleted = thing.deleted, diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index 07730bdae..becad21e9 100755 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -677,6 +677,12 @@ class Comment(Thing, Printable): return (c, inbox_rel) + def _save(self, user): + CommentSavesByAccount._save(user, self) + + def _unsave(self, user): + CommentSavesByAccount._unsave(user, self) + @property def subreddit_slow(self): from subreddit import Subreddit @@ -758,6 +764,15 @@ class Comment(Thing, Printable): cname = c.cname site = c.site + if user_is_loggedin: + try: + saved = CommentSavesByAccount.fast_query(user, wrapped) + except tdb_cassandra.TRANSIENT_EXCEPTIONS as e: + g.log.warning("Cassandra comment save lookup failed: %r", e) + saved = {} + else: + saved = {} + for item in wrapped: # for caching: item.profilepage = c.profilepage @@ -791,6 +806,10 @@ class Comment(Thing, Printable): if item.link.promoted or age.days < g.REPLY_AGE_LIMIT: item.can_reply = True + if user_is_loggedin: + item.saved = (user, item) in saved + else: + item.saved = False # not deleted on profile pages, # deleted if spam and not author or admin diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index d14f07db7..7827eb410 100755 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -6252,3 +6252,8 @@ table.diff {font-size: small;} .diff_add {background-color:lightgreen} .diff_chg {background-color:yellow} .diff_sub {background-color:lightcoral} + +.buttons li.comment-save-button { display: none; } +.buttons li.comment-unsave-button { display: inline; } + +body.gold .buttons li.comment-save-button { display: inline; } diff --git a/r2/r2/public/static/js/reddit.js b/r2/r2/public/static/js/reddit.js index 12c34b479..4d5ef4cfb 100644 --- a/r2/r2/public/static/js/reddit.js +++ b/r2/r2/public/static/js/reddit.js @@ -1307,6 +1307,17 @@ function show_unfriend(account_fullname) { }); } +function show_saved(comment_fullname) { + var comment = $('.id-' + comment_fullname), + buttons = comment.find('.buttons').first(), + save = buttons.find('.comment-save-button') + form = '
' + save.replaceWith(form) + comment.addClass('saved') +} + function search_feedback(elem, approval) { f = $("form#search"); var q = f.find('input[name="q"]').val(); diff --git a/r2/r2/templates/printablebuttons.html b/r2/r2/templates/printablebuttons.html index 26c7b7dcc..df91eb217 100644 --- a/r2/r2/templates/printablebuttons.html +++ b/r2/r2/templates/printablebuttons.html @@ -251,6 +251,17 @@