feat: counts on lists of notes, reply cards link to the reply, fix class clash (v2.13.4)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
81c730813c
commit
647f6c723b
12 files changed
+181
-37
No files matched your search
@@ -465,5 +465,5 @@ def create_app(config=None):
|
||||
|
||||
# Package version (Semantic Versioning 2.0.0)
|
||||
# See docs/standards/versioning-strategy.md for details
|
||||
__version__ = "2.13.3"
|
||||
__version_info__ = (2, 13, 3)
|
||||
__version__ = "2.13.4"
|
||||
__version_info__ = (2, 13, 4)
|
||||
@@ -292,9 +292,23 @@ def index():
|
||||
object.__setattr__(note, '_cached_tags', tags)
|
||||
|
||||
attach_contexts(notes)
|
||||
attach_response_counts(notes)
|
||||
return render_template("index.html", notes=notes)
|
||||
|
||||
|
||||
def attach_response_counts(notes) -> None:
|
||||
"""Give listed notes their like, repost and reply counts (v2.13.4)"""
|
||||
counts = {}
|
||||
if current_app.config.get('WEBMENTION_ENABLED', False) and notes:
|
||||
try:
|
||||
from starpunk.webmention_queries import response_counts
|
||||
counts = response_counts([n.id for n in notes])
|
||||
except Exception as e:
|
||||
current_app.logger.warning(f"Could not count responses: {e}")
|
||||
for note in notes:
|
||||
object.__setattr__(note, 'response_counts', counts.get(note.id))
|
||||
|
||||
|
||||
def attach_contexts(notes) -> None:
|
||||
"""Give likes and reposts the fetched context of the post they point at"""
|
||||
from starpunk.webmention_queries import get_reply_context
|
||||
@@ -320,6 +334,7 @@ def likes():
|
||||
object.__setattr__(note, 'media', get_note_media(note.id))
|
||||
object.__setattr__(note, '_cached_tags', get_note_tags(note.id))
|
||||
attach_contexts(notes)
|
||||
attach_response_counts(notes)
|
||||
return render_template("likes.html", notes=notes)
|
||||
|
||||
|
||||
@@ -467,6 +482,7 @@ def tag(tag: str):
|
||||
media = get_note_media(note.id)
|
||||
object.__setattr__(note, 'media', media)
|
||||
attach_contexts(notes)
|
||||
attach_response_counts(notes)
|
||||
|
||||
return render_template(
|
||||
"tag.html",
|
||||
|
||||
@@ -110,6 +110,47 @@ def get_webmentions_for_note(note_id: int) -> Dict[str, List[Dict[str, Any]]]:
|
||||
return grouped
|
||||
|
||||
|
||||
def response_counts(note_ids: List[int]) -> Dict[int, Dict[str, int]]:
|
||||
"""
|
||||
Likes, reposts and replies per note, for lists of notes (v2.13.4).
|
||||
|
||||
Shown responses (valid and approved) plus the counts silos give without
|
||||
names (Threads; people who opted out of backfeed) on synced crossposts.
|
||||
Notes with none are left out.
|
||||
"""
|
||||
if not note_ids:
|
||||
return {}
|
||||
db = get_db()
|
||||
marks = ','.join('?' * len(note_ids))
|
||||
counts: Dict[int, Dict[str, int]] = {}
|
||||
|
||||
def add(note_id, key, n):
|
||||
if n:
|
||||
counts.setdefault(note_id, {'likes': 0, 'reposts': 0, 'replies': 0})[key] += n
|
||||
|
||||
for row in db.execute(
|
||||
f"""
|
||||
SELECT target_note_id, mention_type, COUNT(*) FROM webmentions
|
||||
WHERE target_note_id IN ({marks}) AND validation_status = 'valid'
|
||||
AND moderation_status = 'approved' AND mention_type IN ('like', 'repost', 'reply')
|
||||
GROUP BY target_note_id, mention_type
|
||||
""",
|
||||
note_ids,
|
||||
):
|
||||
add(row[0], {'like': 'likes', 'repost': 'reposts', 'reply': 'replies'}[row[1]], row[2])
|
||||
for row in db.execute(
|
||||
f"""
|
||||
SELECT note_id, SUM(COALESCE(likes_count, 0)), SUM(COALESCE(reposts_count, 0))
|
||||
FROM syndications WHERE note_id IN ({marks}) AND state = 'synced'
|
||||
GROUP BY note_id
|
||||
""",
|
||||
note_ids,
|
||||
):
|
||||
add(row[0], 'likes', row[1])
|
||||
add(row[0], 'reposts', row[2])
|
||||
return counts
|
||||
|
||||
|
||||
def list_webmentions(
|
||||
status_filter: Optional[str] = None,
|
||||
page: int = 1,
|
||||
|
||||
Reference in new issue
Block a user