Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
1 r2/r2/controllers/api.py
@@ -1731,6 +1731,7 @@ def POST_distinguish(self, form, jquery, thing, how):
@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(),
View
8 r2/r2/lib/pages/pages.py
@@ -474,6 +474,8 @@ def page_classes(self):
classes.add('cname')
if c.site.is_moderator(c.user):
classes.add('moderator')
+ if c.user.gold:
+ classes.add('gold')
if isinstance(c.site, MultiReddit):
classes.add('multi-page')
@@ -1161,6 +1163,7 @@ def renderer():
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
@@ -1171,9 +1174,12 @@ def renderer():
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()
View
1 r2/r2/lib/pages/things.py
@@ -149,6 +149,7 @@ def __init__(self, thing, delete = True, report = True):
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,
View
19 r2/r2/models/link.py
@@ -677,6 +677,12 @@ def _new(cls, author, link, parent, body, ip):
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 @@ def add_props(cls, user, wrapped):
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 @@ def add_props(cls, user, wrapped):
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
View
5 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; }
View
11 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 = '<li class="comment-unsave-button"><form action="/post/unsave" method="post" class="state-button unsave-button">'
+ form = form + '<input type="hidden" name="executed" value="unsaved"/><span>'
+ form = form + '<a href="javascript:void(0)" onclick="return change_state(this, \'unsave\', unsave_thing);">unsave</a></span></form></li>'
+ save.replaceWith(form)
+ comment.addClass('saved')
+}
+
function search_feedback(elem, approval) {
f = $("form#search");
var q = f.find('input[name="q"]').val();
View
11 r2/r2/templates/printablebuttons.html
@@ -251,6 +251,17 @@
<li class="first">
${self.bylink_button(_("permalink"), thing.permalink)}
</li>
+ %if thing.saved:
+ <li class="comment-unsave-button">
+ ${self.state_button("unsave", _("unsave"), \
+ "return change_state(this, 'unsave', unsave_thing);", _("unsaved"))}
+ </li>
+ %else:
+ <li class="comment-save-button">
+ ${self.state_button("save", _("save"), \
+ "return change_state(this, 'save', save_thing);", _("saved"))}
+ </li>
+ %endif
%if c.profilepage:
<li>
${self.bylink_button(_("context"), thing.permalink + "?context=3")}
View
3 r2/r2/templates/thingupdater.html
@@ -35,4 +35,7 @@
});
$.map(friends, show_friend);
+ var saves = ${unsafe(simplejson.dumps(list(thing.saves)))};
+ $.map(saves, show_saved);
+
</script>

No commit comments for this range

Something went wrong with that request. Please try again.