# retoor <retoor@molodetz.nl>
from __future__ import annotations
from devplacepy.database import (
get_attachments_by_type,
get_comment_counts_by_post_uids,
get_follow_counts,
get_following_among,
get_leaderboard,
get_muted_uids,
get_blocked_uids,
get_user_relations,
get_notification_prefs,
get_online_users,
get_polls_by_post_uids,
get_prominent_award,
get_reactions_by_targets,
get_recent_comments_by_post_uids,
get_seo_metadata_batch,
get_site_stats,
get_top_authors,
get_user_awards,
get_user_bookmarks,
get_user_media,
get_user_rank,
get_users_by_uids,
get_vote_counts,
load_comments,
)
def users_by_uids(uids: list[str]) -> dict:
return get_users_by_uids(uids)
def comment_counts(post_uids: list[str]) -> dict:
return get_comment_counts_by_post_uids(post_uids)
def vote_counts(target_uids: list[str]) -> dict:
ups, downs = get_vote_counts(target_uids)
return {"ups": ups, "downs": downs}
def reactions(target_type: str, target_uids: list[str], user: dict | None = None) -> dict:
return get_reactions_by_targets(target_type, target_uids, user)
def bookmarks(user_uid: str, target_type: str, target_uids: list[str]) -> list[str]:
result = get_user_bookmarks(user_uid, target_type, target_uids)
return sorted(result)
def polls(post_uids: list[str], user: dict | None = None) -> dict:
return get_polls_by_post_uids(post_uids, user)
def recent_comments(
post_uids: list[str], limit: int = 3, user: dict | None = None
) -> dict:
return get_recent_comments_by_post_uids(post_uids, limit, user)
def comments(target_type: str, target_uid: str, user: dict | None = None) -> list:
return load_comments(target_type, target_uid, user)
def follow_bundle(user_uid: str, target_uids: list[str] | None = None) -> dict:
payload = {
"counts": get_follow_counts(user_uid),
"following_among": sorted(get_following_among(user_uid, target_uids or [])),
}
return payload
def relations_bundle(viewer_uid: str | None) -> dict:
relations = get_user_relations(viewer_uid)
return {
"relations": {
"block": sorted(relations["block"]),
"mute": sorted(relations["mute"]),
},
"blocked_uids": sorted(get_blocked_uids(viewer_uid)),
"muted_uids": sorted(get_muted_uids(viewer_uid)),
}
def online_users_bundle(cutoff_iso: str, limit: int = 30) -> list:
return get_online_users(cutoff_iso, limit)
def notification_prefs_bundle(user_uid: str) -> list:
return get_notification_prefs(user_uid)
def leaderboard_bundle(
limit: int = 50, offset: int = 0, viewer_uid: str | None = None
) -> dict:
return {
"leaderboard": get_leaderboard(limit, offset),
"viewer_rank": get_user_rank(viewer_uid) if viewer_uid else None,
}
def site_sidebar(authors_limit: int = 5) -> dict:
return {
"stats": get_site_stats(),
"top_authors": get_top_authors(authors_limit),
}
def awards_bundle(
receiver_uid: str,
page: int = 1,
per_page: int = 12,
profile_user: dict | None = None,
) -> dict:
items, pagination = get_user_awards(receiver_uid, page, per_page)
prominent = get_prominent_award(profile_user) if profile_user else None
return {
"items": items,
"pagination": pagination,
"prominent": prominent,
}
def attachments_batch(resource_type: str, resource_uids: list[str]) -> dict:
return get_attachments_by_type(resource_type, resource_uids)
def user_media_bundle(user_uid: str, page: int = 1, per_page: int = 24) -> dict:
items, pagination = get_user_media(user_uid, page, per_page)
return {"items": items, "pagination": pagination}
def seo_meta_batch(target_type: str, uids: list[str]) -> dict:
return get_seo_metadata_batch(target_type, uids)