Compare commits
3 Commits
30b5a1438b
...
6e438dbfdc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e438dbfdc | ||
|
|
7316dc6eac | ||
|
|
a3a41dbefd |
@@ -129,6 +129,11 @@ class CalendarService(Protocol):
|
||||
self, session: AsyncSession, content_type: str, content_id: int,
|
||||
) -> set[int]: ...
|
||||
|
||||
async def upcoming_entries_for_container(
|
||||
self, session: AsyncSession, container_type: str, container_id: int,
|
||||
*, page: int = 1, per_page: int = 20,
|
||||
) -> tuple[list[CalendarEntryDTO], bool]: ...
|
||||
|
||||
async def visible_entries_for_period(
|
||||
self, session: AsyncSession, calendar_id: int,
|
||||
period_start: datetime, period_end: datetime,
|
||||
|
||||
@@ -42,6 +42,9 @@ def _build_activity_json(activity: APActivity, actor: ActorProfile, domain: str)
|
||||
obj.setdefault("published", activity.published.isoformat() if activity.published else None)
|
||||
obj.setdefault("to", ["https://www.w3.org/ns/activitystreams#Public"])
|
||||
obj.setdefault("cc", [f"{actor_url}/followers"])
|
||||
if activity.activity_type == "Update":
|
||||
from datetime import datetime, timezone
|
||||
obj["updated"] = datetime.now(timezone.utc).isoformat()
|
||||
|
||||
return {
|
||||
"@context": [
|
||||
|
||||
@@ -239,6 +239,35 @@ class SqlCalendarService:
|
||||
merged = sorted(entries_by_id.values(), key=lambda e: e.start_at or period_start)
|
||||
return [_entry_to_dto(e) for e in merged]
|
||||
|
||||
async def upcoming_entries_for_container(
|
||||
self, session: AsyncSession, container_type: str, container_id: int,
|
||||
*, page: int = 1, per_page: int = 20,
|
||||
) -> tuple[list[CalendarEntryDTO], bool]:
|
||||
"""Upcoming confirmed entries across all calendars for a container."""
|
||||
cal_ids = select(Calendar.id).where(
|
||||
Calendar.container_type == container_type,
|
||||
Calendar.container_id == container_id,
|
||||
Calendar.deleted_at.is_(None),
|
||||
).scalar_subquery()
|
||||
|
||||
offset = (page - 1) * per_page
|
||||
result = await session.execute(
|
||||
select(CalendarEntry)
|
||||
.where(
|
||||
CalendarEntry.calendar_id.in_(cal_ids),
|
||||
CalendarEntry.state == "confirmed",
|
||||
CalendarEntry.deleted_at.is_(None),
|
||||
CalendarEntry.start_at >= func.now(),
|
||||
)
|
||||
.order_by(CalendarEntry.start_at.asc())
|
||||
.limit(per_page)
|
||||
.offset(offset)
|
||||
.options(selectinload(CalendarEntry.calendar))
|
||||
)
|
||||
entries = result.scalars().all()
|
||||
has_more = len(entries) == per_page
|
||||
return [_entry_to_dto(e) for e in entries], has_more
|
||||
|
||||
async def associated_entries(
|
||||
self, session: AsyncSession, content_type: str, content_id: int, page: int,
|
||||
) -> tuple[list[CalendarEntryDTO], bool]:
|
||||
|
||||
@@ -49,8 +49,6 @@ async def try_publish(
|
||||
if existing:
|
||||
if activity_type == "Create" and existing.activity_type != "Delete":
|
||||
return # already published (allow re-Create after Delete/unpublish)
|
||||
if activity_type == "Update" and existing.activity_type == "Update":
|
||||
return # already updated (Ghost fires duplicate webhooks)
|
||||
if activity_type == "Delete" and existing.activity_type == "Delete":
|
||||
return # already deleted
|
||||
elif activity_type in ("Delete", "Update"):
|
||||
|
||||
@@ -140,6 +140,9 @@ class StubCalendarService:
|
||||
) -> int:
|
||||
return 0
|
||||
|
||||
async def upcoming_entries_for_container(self, session, container_type, container_id, *, page=1, per_page=20):
|
||||
return [], False
|
||||
|
||||
async def entry_ids_for_content(self, session, content_type, content_id):
|
||||
return set()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user