Skip to content

Commit

Permalink
misc (#1431)
Browse files Browse the repository at this point in the history
  • Loading branch information
charmander authored Oct 3, 2024
2 parents 3a4b5f5 + c2db7b6 commit 88c8630
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 44 deletions.
2 changes: 1 addition & 1 deletion assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@
var currentTab = homeTabs.getElementsByClassName('current')[0];
var currentPane = homePanes.getElementsByClassName('current')[0];

$(homeTabs).on('click touchstart', '.home-pane-link', function (e) {
$(homeTabs).on('click', '.home-pane-link', function (e) {
e.preventDefault();

var paneId = this.getAttribute('href').substring(1);
Expand Down
3 changes: 1 addition & 2 deletions weasyl/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def can_notify(other):
return commentid


def remove(userid, feature=None, commentid=None):
def remove(userid, *, feature, commentid):
if feature not in ["submit", "char", "journal", "siteupdate"]:
raise WeasylError("Unexpected")

Expand Down Expand Up @@ -298,7 +298,6 @@ def remove(userid, feature=None, commentid=None):

# remove notifications
welcome.comment_remove(commentid, feature)
d._page_header_info.invalidate(userid)

# mark comments as hidden
if feature == 'submit':
Expand Down
28 changes: 3 additions & 25 deletions weasyl/controllers/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ def submit_report_(request):
@login_required
@token_checked
def submit_tags_(request):
# TODO: remove preferred/opt-out tag handling here when corresponding changes to `/control/editcommissionsettings` have been deployed for a while
if not define.is_vouched_for(request.userid):
raise WeasylError("vouchRequired")

target_key, targetid = only(
(key, expect_id(request.POST[key]))
for key in (
"preferred_tags_userid",
"optout_tags_userid",
"submitid",
"charid",
"journalid",
Expand All @@ -375,28 +375,6 @@ def submit_tags_(request):
)
tags = searchtag.parse_tags(request.POST["tags"])

match target_key:
case "preferred_tags_userid":
if targetid != request.userid:
raise WeasylError("Unexpected")
searchtag.set_commission_preferred_tags(
userid=request.userid,
tag_names=tags,
)
raise HTTPSeeOther(location="/control/editcommissionsettings")

case "optout_tags_userid":
if targetid != request.userid:
raise WeasylError("Unexpected")
searchtag.set_commission_optout_tags(
userid=request.userid,
tag_names=tags,
)
raise HTTPSeeOther(location="/control/editcommissionsettings")

if not define.is_vouched_for(request.userid):
raise WeasylError("vouchRequired")

match target_key:
case "submitid":
target = searchtag.SubmissionTarget(targetid)
Expand Down
6 changes: 6 additions & 0 deletions weasyl/define.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ def _page_header_info(userid):
return result


def page_header_info_invalidate_multi(userids):
namespace = None
cache_keys = [*map(region.function_key_generator(namespace, _page_header_info), userids)]
region.delete_multi(cache_keys)


def get_max_post_rating(userid):
return max((key.rating for key, count in posts_count(userid, friends=True).items() if count), default=ratings.GENERAL.code)

Expand Down
2 changes: 1 addition & 1 deletion weasyl/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def manageuser(userid, form):
"profile_text": query[3],
"catchphrase": query[4],
"user_media": media.get_user_media(query[0]),
"staff_notes": shout.count(query[0], staffnotes=True),
"staff_notes": shout.count_staff_notes(query[0]),
}


Expand Down
2 changes: 1 addition & 1 deletion weasyl/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def select_manage(userid):
"gender": query[9],
"country": query[10],
"config": query[11],
"staff_notes": shout.count(userid, staffnotes=True),
"staff_notes": shout.count_staff_notes(userid),
"sorted_user_links": sort_user_links(user_link_rows),
"user_sessions": active_user_sessions,
}
Expand Down
8 changes: 3 additions & 5 deletions weasyl/shout.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ def select(userid, ownerid, limit=None, staffnotes=False):
return result


def count(ownerid, staffnotes=False):
def count_staff_notes(ownerid):
db = d.connect()
sh = d.meta.tables['comments']
op = '~' if staffnotes else '!~'
q = (
sa.select([sa.func.count()])
.select_from(sh)
.where(sh.c.settings.op(op)('s'))
.where(sh.c.settings.op('~')('s'))
.where(sh.c.target_user == ownerid))
(ret,), = db.execute(q)
return ret
Expand Down Expand Up @@ -113,7 +112,7 @@ def insert(userid, target_user, parentid, content, staffnotes):
return commentid


def remove(userid, commentid=None):
def remove(userid, *, commentid):
query = d.engine.execute(
"SELECT userid, target_user, settings FROM comments WHERE commentid = %(id)s AND settings !~ 'h'",
id=commentid,
Expand All @@ -135,7 +134,6 @@ def remove(userid, commentid=None):

# remove notifications
welcome.comment_remove(commentid, 'shout')
d._page_header_info.invalidate(userid)

# hide comment
d.execute("UPDATE comments SET settings = settings || 'h', hidden_by = %i WHERE commentid = %i", [userid, commentid])
Expand Down
2 changes: 1 addition & 1 deletion weasyl/templates/common/page_start.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ <h2><i>Welcome,</i> <a id="username" class="username" href="/~${LOGIN(query['use
<li><a href="/messages/notifications#notifications" title="Notifications"><span class="icon icon-20 icon-notes">Notifications:</span> ${query['welcome'][2]}</a></li>
$if query['welcome'][4]:
<li><a href="/messages/notifications#journals" title="Journals"><span class="icon icon-20 icon-journals">Journals:</span> ${query['welcome'][4]}</a></li>
<li><a class="${'messages-none' if query['welcome'][0] == 0 else ''}" href="/notes" title="Private Messages"><svg class="icon icon-svg-20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 90 60" alt="Private Messages"><path d="M 0.45,2.94 C 0.16,3.56 0,4.26 0,5 v 50 c 0,0.23 0.02,0.46 0.05,0.68 L 29.38,27.18 Z M 3.8,59.85 C 4.18,59.95 4.58,60 5,60 h 80 c 0.33,0 0.65,-0.03 0.96,-0.09 L 56.35,31.14 45.23,40.46 33.7,30.8 Z M 89.91,55.93 C 89.97,55.63 90,55.32 90,55 V 5 C 90,4.37 89.88,3.77 89.67,3.22 l -29,24.3 z M 85.41,0.02 C 85.28,0.01 85.14,0 85,0 H 5.03 l 40.2,33.68 z" /></svg>
<li><a class="${'messages-none' if query['welcome'][0] == 0 else ''}" href="/notes" title="Private Messages"><svg class="icon icon-svg-20" viewBox="0 0 90 60" alt="Private Messages"><path d="M 0.45,2.94 C 0.16,3.56 0,4.26 0,5 v 50 c 0,0.23 0.02,0.46 0.05,0.68 L 29.38,27.18 Z M 3.8,59.85 C 4.18,59.95 4.58,60 5,60 h 80 c 0.33,0 0.65,-0.03 0.96,-0.09 L 56.35,31.14 45.23,40.46 33.7,30.8 Z M 89.91,55.93 C 89.97,55.63 90,55.32 90,55 V 5 C 90,4.37 89.88,3.77 89.67,3.22 l -29,24.3 z M 85.41,0.02 C 85.28,0.01 85.14,0 85,0 H 5.03 l 40.2,33.68 z" /></svg>
${query['welcome'][0]}</a></li>
</ul>

Expand Down
17 changes: 9 additions & 8 deletions weasyl/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,9 @@ def collectrequest_remove(userid, otherid, submitid):
# 3100 user favorited character
# 3110 user favorited journal

def favorite_insert(db, userid, submitid=None, charid=None, journalid=None, otherid=None):
ownerid = d.get_ownerid(submitid, charid, journalid)
if not otherid:
otherid = ownerid

def favorite_insert(db, userid, *, submitid, charid, journalid, otherid):
if submitid:
ownerid = d.get_ownerid(submitid, charid, journalid)
notiftype = 3020 if ownerid == otherid else 3050
elif charid:
notiftype = 3100
Expand Down Expand Up @@ -375,11 +372,15 @@ def comment_remove(commentid, feature):
) SELECT commentid FROM rc""" % {'feature': feature}, comment=commentid)

recursive_ids = [x['commentid'] for x in recursive_ids]
d.engine.execute(

# `targetid` is the notification comment id, and `referid` is the post id for a top-level comment or the parent comment id for a reply
result = d.engine.execute(
"""
DELETE FROM welcome WHERE (type = %(comment_code)s OR type = %(reply_code)s) AND
(targetid = ANY (%(ids)s) OR referid = ANY (%(ids)s))
DELETE FROM welcome WHERE type IN (%(comment_code)s, %(reply_code)s) AND
targetid = ANY (%(ids)s)
RETURNING userid
""", comment_code=comment_code, reply_code=reply_code, ids=recursive_ids)
d.page_header_info_invalidate_multi({row.userid for row in result})


# notifications
Expand Down

0 comments on commit 88c8630

Please sign in to comment.