docs: add block/mute user relations, emoji-sync CLI, and uid indexes

- Add `/block`, `/mute` endpoints with block/unblock and mute/unmute functionality in `routers/relations.py`, hiding blocked users' content everywhere except their own profile while muting only suppresses notifications
- Introduce `devplace emoji-sync` CLI command to regenerate `static/js/emoji-shortcodes.js` from the emoji library, documented in `CLAUDE.md` and wired in `cli.py`
- Create `get_blocked_uids()` database helper and apply it in `content.py` `load_detail()` to filter blocked users' posts from detail views
- Implement `_uid_index()` and `_drop_index()` helpers in `database.py` for unique uid indexes across tables, with `user_relations` added to `SOFT_DELETE_TABLES`
- Document new routes in `AGENTS.md` and `README.md`, including emoji shortcodes rendering behavior distinct from the emoji picker
This commit is contained in:
2026-06-19 08:06:09 +00:00
parent f3a4667fce
commit 741d7aade6
136 changed files with 3025 additions and 564 deletions
+44 -8
View File
@@ -35,8 +35,10 @@ from devplacepy.database import (
interleave_by_author,
get_user_post_count,
get_user_stars,
get_blocked_uids,
)
from devplacepy.templating import templates
from devplacepy.cache import TTLCache
from devplacepy.responses import respond, wants_json, json_error
from devplacepy.schemas import LandingOut, ValidationErrorOut
from fastapi.responses import JSONResponse
@@ -54,6 +56,7 @@ from devplacepy.routers import (
votes,
avatar,
follow,
relations,
admin,
seo,
issues,
@@ -371,6 +374,7 @@ app.include_router(bookmarks.router, prefix="/bookmarks")
app.include_router(polls.router, prefix="/polls")
app.include_router(avatar.router, prefix="/avatar")
app.include_router(follow.router, prefix="/follow")
app.include_router(relations.router)
app.include_router(leaderboard.router, prefix="/leaderboard")
app.include_router(admin.router, prefix="/admin")
app.include_router(seo.router)
@@ -418,6 +422,10 @@ async def add_security_headers(request: Request, call_next):
response.headers["Referrer-Policy"] = "strict-origin-when-cross-origin"
if not request.url.path.startswith("/p/"):
response.headers["X-Frame-Options"] = "DENY"
response.headers["Content-Security-Policy"] = (
"object-src 'none'; base-uri 'self'; "
"frame-ancestors 'none'; form-action 'self'"
)
if request.url.path.startswith("/admin"):
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
response.headers["Pragma"] = "no-cache"
@@ -512,11 +520,14 @@ async def response_timing(request: Request, call_next):
return response
@app.get("/")
async def landing(request: Request):
user = get_current_user(request)
_home_cache = TTLCache(ttl=60, max_size=4)
landing_articles = []
def _landing_news():
cached = _home_cache.get("news")
if cached is not None:
return cached
articles = []
if "news" in db.tables:
news_table = get_table("news")
raw = list(
@@ -524,7 +535,7 @@ async def landing(request: Request):
)
images_by_news = get_news_images_by_uids([a["uid"] for a in raw])
for a in raw:
landing_articles.append(
articles.append(
{
"uid": a["uid"],
"slug": a.get("slug", ""),
@@ -539,12 +550,25 @@ async def landing(request: Request):
"image_url": a.get("image_url", "") or images_by_news.get(a["uid"], ""),
}
)
_home_cache.set("news", articles)
return articles
landing_posts = []
def _landing_recent_posts(blocked):
if not blocked:
cached = _home_cache.get("posts")
if cached is not None:
return cached
posts = []
if "posts" in db.tables:
posts_table = get_table("posts")
clauses = []
if blocked:
clauses.append(posts_table.table.columns.user_uid.notin_(blocked))
raw_posts = list(
posts_table.find(deleted_at=None, order_by=["-created_at"], _limit=6)
posts_table.find(
*clauses, deleted_at=None, order_by=["-created_at"], _limit=6
)
)
raw_posts = interleave_by_author(raw_posts)
if raw_posts:
@@ -554,7 +578,7 @@ async def landing(request: Request):
comment_counts = get_comment_counts_by_post_uids(post_uids)
upvotes, downvotes = get_vote_counts(post_uids)
for p in raw_posts:
landing_posts.append(
posts.append(
{
"post": p,
"author": authors.get(p["user_uid"]),
@@ -564,6 +588,18 @@ async def landing(request: Request):
"slug": p.get("slug", "") or p["uid"],
}
)
if not blocked:
_home_cache.set("posts", posts)
return posts
@app.get("/")
async def landing(request: Request):
user = get_current_user(request)
landing_articles = _landing_news()
blocked = get_blocked_uids(user["uid"]) if user else frozenset()
landing_posts = _landing_recent_posts(blocked)
base = site_url(request)
seo_ctx = base_seo_context(