Merge main: read state and tags meet per-agent votes and affinity
The per-agent migration becomes v6 behind main's v5. A vote still stamps the role's read_at, tag counts hide the agent's hidden companies, and /api/filters takes the agent like /api/roles. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
c69fb0b6c4
23 files changed
+2270
-717
No files matched your search
+52
-2
@@ -92,6 +92,24 @@ def unvote_role(uid: str, store: StoreDep, agent: int | None = None) -> Role:
|
||||
raise HTTPException(404, f"no such role: {uid}") from None
|
||||
|
||||
|
||||
@router.post("/roles/{uid}/read")
|
||||
def read_role(uid: str, store: StoreDep) -> Role:
|
||||
"""Mark a role read. Never hides it; a vote does this too, see `vote_role`."""
|
||||
try:
|
||||
return store.set_read(uid, True)
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such role: {uid}") from None
|
||||
|
||||
|
||||
@router.delete("/roles/{uid}/read")
|
||||
def unread_role(uid: str, store: StoreDep) -> Role:
|
||||
"""Unread again: what pressing the state a role already has does."""
|
||||
try:
|
||||
return store.set_read(uid, False)
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such role: {uid}") from None
|
||||
|
||||
|
||||
class RolesPage(BaseModel):
|
||||
"""One page of roles, and how many the same filters match in all."""
|
||||
|
||||
@@ -109,6 +127,9 @@ def list_roles(
|
||||
remote: str = "",
|
||||
days: int | None = None,
|
||||
show_muted: bool = False,
|
||||
include_read: bool = True,
|
||||
tags: list[str] = Query(default=[]),
|
||||
tag_mode: Literal["any", "all"] = "any",
|
||||
agent: int | None = None,
|
||||
order: Literal["score", "newest"] = "score",
|
||||
gated: bool = False,
|
||||
@@ -127,18 +148,47 @@ def list_roles(
|
||||
one only with `gated=1`; with `order=newest` every open role, newest
|
||||
first, with no score. Without `agent` the default agent's votes and
|
||||
hidden companies apply, the order is newest and there is no score; with
|
||||
no agent at all, every vote is None and nothing is hidden."""
|
||||
no agent at all, every vote is None and nothing is hidden.
|
||||
|
||||
`include_read` set false hides a role already marked read. `tags` is
|
||||
`?tags=a&tags=b`, kept to a role with any of them or, with
|
||||
`tag_mode=all`, every one."""
|
||||
agent_id = _agent_id(store, agent)
|
||||
by_score = agent is not None and order == "score"
|
||||
filters: dict[str, Any] = {
|
||||
"q": q or None, "company": company or None, "place": place or None,
|
||||
"function": function or None, "remote": remote or None, "days": days,
|
||||
"hide_muted": not show_muted, "agent": agent_id, "by_score": by_score,
|
||||
"hide_muted": not show_muted, "include_read": include_read, "tags": tags,
|
||||
"tag_mode": tag_mode, "agent": agent_id, "by_score": by_score,
|
||||
"gated": gated, "judged": judged or None}
|
||||
return RolesPage(items=store.roles(limit=limit, offset=offset, **filters),
|
||||
total=store.count_roles(**filters))
|
||||
|
||||
|
||||
class TagCount(BaseModel):
|
||||
"""One tag as the filter row offers it: how many open roles carry it and
|
||||
how many of those are unread."""
|
||||
|
||||
tag: str
|
||||
count: int
|
||||
unread: int
|
||||
|
||||
|
||||
class FiltersOut(BaseModel):
|
||||
tags: list[TagCount]
|
||||
|
||||
|
||||
@router.get("/filters")
|
||||
def list_filters(store: StoreDep, show_muted: bool = False,
|
||||
agent: int | None = None) -> FiltersOut:
|
||||
"""The tag vocabulary for the feed's filter row, most-used first. The
|
||||
companies `agent` hid (the default agent's without one) are left out
|
||||
unless `show_muted`, matching `/api/roles`."""
|
||||
hidden_for = _agent_id(store, agent)
|
||||
return FiltersOut(tags=[TagCount(tag=tag, count=count, unread=unread)
|
||||
for tag, count, unread in store.tag_counts(hidden_for, show_muted)])
|
||||
|
||||
|
||||
# ------------------------------------------------- roles: text and summary
|
||||
|
||||
#: What the read page toasts when a posting page gave nothing readable, by
|
||||
|
||||
Reference in new issue
Block a user