feat: v5.14.0 Synced blocks - block created once, edited everywhere
- Table synced_blocks (source of truth) + page_synced_blocks (references) - Migration 15 + service app/services/synced_blocks.py - API endpoints: CRUD synced blocks, add/remove page references - Editor: /synced slash command, synced block rendering with badge - Realtime: _propagate_synced broadcasts updates to all referencing rooms - Export: synced blocks resolved in Markdown/HTML/PDF - 18 tests in tests/test_v514_synced_blocks.py Co-authored-by: FlowDeck <[email protected]>
This commit is contained in:
@@ -304,10 +304,33 @@ class RealtimeManager:
|
||||
return
|
||||
|
||||
async def room_state(self, page_id: int) -> dict:
|
||||
room = self.room(page_id)
|
||||
room = self._rooms.get(page_id)
|
||||
if not room.conns and not room.blocks:
|
||||
await self.load_room(room)
|
||||
return {"blocks": room.blocks, "title": room.title, "version": room.version}
|
||||
|
||||
async def _propagate_synced(self, synced_id: int) -> None:
|
||||
"""Broadcast a synced-block update to all rooms that reference it."""
|
||||
from app.db import get_conn as _get_conn
|
||||
# Find all pages that reference this synced block
|
||||
pages: list[int] = []
|
||||
try:
|
||||
with _get_conn() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT page_id FROM page_synced_blocks WHERE synced_block_id=?",
|
||||
(synced_id,),
|
||||
).fetchall()
|
||||
pages = [r["page_id"] for r in rows]
|
||||
except Exception:
|
||||
return
|
||||
for pid in pages:
|
||||
room = self._rooms.get(pid)
|
||||
if room and room.conns:
|
||||
# Re-load the page content from DB to get fresh synced blocks
|
||||
await self.load_room(room)
|
||||
await self._broadcast(room, {"t": "synced_update",
|
||||
"synced_id": synced_id,
|
||||
"version": room.version})
|
||||
|
||||
|
||||
manager = RealtimeManager()
|
||||
|
||||
Reference in New Issue
Block a user