add links to individuals comments in walls + fix awards for wall comments

master
Aevann1 2022-12-05 05:01:50 +02:00
parent 6cfe0fceb4
commit af3b028ca5
4 changed files with 55 additions and 11 deletions

View File

@ -159,6 +159,8 @@ class Comment(Base):
@property
@lazy
def shortlink(self):
if self.wall_user_id:
return f"/@{self.wall_user.username}/wall/comment/{self.id}?context=8#context"
return f"{self.post.shortlink}/{self.id}?context=8#context"
@property

View File

@ -131,7 +131,7 @@ def award_thing(v, thing_type, id):
thing = get_post(id)
else:
thing = get_comment(id)
if not thing.parent_submission: abort(404) # don't let users award messages
if not thing.parent_submission and not thing.wall_user_id: abort(404) # don't let users award messages
if v.shadowbanned: abort(500)
author = thing.author

View File

@ -760,6 +760,52 @@ def u_username_wall(username, v=None):
return render_template("userpage/wall.html", u=u, v=v, listing=comments, page=page, next_exists=next_exists, is_following=is_following, standalone=True, render_replies=True)
@app.get("/@<username>/wall/comment/<cid>")
@app.get("/@<username>/wall/comment/<cid>.json")
@auth_desired_with_logingate
def u_username_wall_comment(username, cid, v=None):
comment = get_comment(cid, v=v)
if not comment.wall_user_id: abort(400)
if not User.can_see(v, comment): abort(404)
u = comment.wall_user
is_following = v and u.has_follower(v)
if not u.is_visible_to(v):
if g.is_api_or_xhr or request.path.endswith(".json"):
abort(403, f"@{u.username}'s userpage is private")
return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403
if v and hasattr(u, 'is_blocking') and u.is_blocking:
if g.is_api_or_xhr or request.path.endswith(".json"):
abort(403, f"You are blocking @{u.username}.")
return render_template("userpage/blocking.html", u=u, v=v), 403
if v and request.values.get("read"):
notif = g.db.query(Notification).filter_by(comment_id=cid, user_id=v.id, read=False).one_or_none()
if notif:
notif.read = True
g.db.add(notif)
try: context = min(int(request.values.get("context", 0)), 8)
except: context = 0
comment_info = comment
c = comment
while context and c.level > 1:
c = c.parent_comment
context -= 1
top_comment = c
if v:
# this is required because otherwise the vote and block
# props won't save properly unless you put them in a list
output = get_comments_v_properties(v, False, None, Comment.top_comment_id == c.top_comment_id)[1]
if v and v.client: return top_comment.json(db=g.db)
return render_template("userpage/wall.html", u=u, v=v, listing=[top_comment], page=1, is_following=is_following, standalone=True, render_replies=True, comment_info=comment_info)
@app.get("/@<username>/posts")
@app.get("/@<username>/posts.json")
@auth_desired_with_logingate

View File

@ -408,11 +408,9 @@
{% if v and ((not c.ghost and v.admin_level >= PERMS['VOTES_VISIBLE']) or v.id == AEVANN_ID) %}<a href="/votes/{{c.fullname}}" class="btn caction nobackground px-1 text-muted"><i class="fas fa-arrows-v"></i>Votes</a>{% endif %}
{% if not c.wall_user_id %}
<a class="btn caction nobackground px-1 text-muted" href="{{c.permalink}}"><i class="fas fa-book-open"></i>Context</a>
<a class="btn caction nobackground px-1 text-muted" href="{{c.permalink}}"><i class="fas fa-book-open"></i>Context</a>
<button type="button" class="btn caction py-0 nobackground px-1 text-muted copy-link" data-clipboard-text="{% if SITE == 'rdrama.net' %}https://{{BAN_EVASION_DOMAIN}}{{c.shortlink}}{% else %}{{c.permalink}}{% endif %}"><i class="fas fa-copy"></i>Copy link</button>
{% endif %}
<button type="button" class="btn caction py-0 nobackground px-1 text-muted copy-link" data-clipboard-text="{% if SITE == 'rdrama.net' %}https://{{BAN_EVASION_DOMAIN}}{{c.shortlink}}{% else %}{{c.permalink}}{% endif %}"><i class="fas fa-copy"></i>Copy link</button>
{% if v %}
{% if not c.deleted_utc %}
@ -421,7 +419,7 @@
<button type="button" class="btn caction py-0 nobackground px-1 text-muted" data-bs-toggle="modal" data-bs-target="#reportCommentModal" onclick="report_commentModal('{{c.id}}','{{c.author_name}}',)"><i class="fas fa-flag fa-fw"></i>Report</button>
{% if FEATURES['AWARDS'] and not c.wall_user_id -%}
{% if FEATURES['AWARDS'] -%}
<button type="button" class="btn caction py-0 nobackground px-1 text-muted" data-bs-toggle="modal" data-bs-target="#awardModal" data-url="/award/comment/{{c.id}}" onclick="document.getElementById('giveaward').dataset.action = this.dataset.url"><i class="fas fa-gift" aria-hidden="true"></i>Give Award</button>
{%- endif %}
@ -625,16 +623,14 @@
{% if v and ((not c.ghost and v.admin_level >= PERMS['VOTES_VISIBLE']) or v.id == AEVANN_ID) %}<a href="/votes/{{c.fullname}}"><li class="list-group-item"><i class="fas fa-arrows-v mr-2"></i>Votes</li></a>{% endif %}
{% if not c.wall_user_id %}
<a class="list-group-item" href="{{c.permalink}}"><i class="fas fa-book-open mr-2"></i>Context</a>
<a class="list-group-item" href="{{c.permalink}}"><i class="fas fa-book-open mr-2"></i>Context</a>
<button type="button" class="list-group-item copy-link" data-bs-dismiss="modal" data-clipboard-text="{% if SITE == 'rdrama.net' %}https://{{BAN_EVASION_DOMAIN}}{{c.shortlink}}{% else %}{{c.permalink}}{% endif %}"><i class="fas fa-copy mr-2"></i>Copy link</button>
{% endif %}
<button type="button" class="list-group-item copy-link" data-bs-dismiss="modal" data-clipboard-text="{% if SITE == 'rdrama.net' %}https://{{BAN_EVASION_DOMAIN}}{{c.shortlink}}{% else %}{{c.permalink}}{% endif %}"><i class="fas fa-copy mr-2"></i>Copy link</button>
{% if v %}
<button type="button" data-bs-toggle="modal" data-bs-dismiss="modal" data-bs-target="#reportCommentModal" onclick="report_commentModal('{{c.id}}','{{c.author_name}}')" class="list-group-item"><i class="fas fa-flag mr-2"></i>Report</button>
{% if FEATURES['AWARDS'] and not c.wall_user_id -%}
{% if FEATURES['AWARDS'] -%}
<button type="button" class="list-group-item" data-bs-toggle="modal" data-bs-target="#awardModal" data-url="/award/comment/{{c.id}}" onclick="document.getElementById('giveaward').dataset.action = this.dataset.url"><i class="fas fa-gift mr-2" aria-hidden="true"></i>Give Award</button>
{%- endif %}