feat: 增强日历功能并集成 AgentScope 代理服务
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from typing import TYPE_CHECKING, Protocol
|
||||
from uuid import UUID
|
||||
|
||||
@@ -21,11 +22,20 @@ class FriendshipRepository(Protocol):
|
||||
"""Protocol defining the friendship repository interface."""
|
||||
|
||||
async def create_request(
|
||||
self, initiator_id: UUID, recipient_id: UUID
|
||||
self, initiator_id: UUID, recipient_id: UUID, content: str | None = None
|
||||
) -> tuple[Friendship, InboxMessage]:
|
||||
"""Create a friendship request and inbox message."""
|
||||
...
|
||||
|
||||
async def reactivate_request(
|
||||
self,
|
||||
friendship: Friendship,
|
||||
initiator_id: UUID,
|
||||
content: str | None = None,
|
||||
) -> tuple[Friendship, InboxMessage]:
|
||||
"""Reactivate a declined or canceled friendship request."""
|
||||
...
|
||||
|
||||
async def get_friendship_between_users(
|
||||
self, user_id_1: UUID, user_id_2: UUID
|
||||
) -> Friendship | None:
|
||||
@@ -70,18 +80,21 @@ class SQLAlchemyFriendshipRepository(BaseRepository[Friendship]):
|
||||
super().__init__(session, Friendship)
|
||||
|
||||
async def create_request(
|
||||
self, initiator_id: UUID, recipient_id: UUID
|
||||
self, initiator_id: UUID, recipient_id: UUID, content: str | None = None
|
||||
) -> tuple[Friendship, InboxMessage]:
|
||||
try:
|
||||
user_low_id = min(initiator_id, recipient_id)
|
||||
user_high_id = max(initiator_id, recipient_id)
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
friendship = Friendship(
|
||||
user_low_id=user_low_id,
|
||||
user_high_id=user_high_id,
|
||||
initiator_id=initiator_id,
|
||||
status=FriendshipStatus.PENDING,
|
||||
requested_at=UUID(int=0),
|
||||
requested_at=now,
|
||||
created_by=initiator_id,
|
||||
updated_by=initiator_id,
|
||||
)
|
||||
self._session.add(friendship)
|
||||
await self._session.flush()
|
||||
@@ -91,7 +104,9 @@ class SQLAlchemyFriendshipRepository(BaseRepository[Friendship]):
|
||||
sender_id=initiator_id,
|
||||
message_type=InboxMessageType.FRIEND_REQUEST,
|
||||
friendship_id=friendship.id,
|
||||
content=content,
|
||||
status=InboxMessageStatus.PENDING,
|
||||
created_by=initiator_id,
|
||||
)
|
||||
self._session.add(inbox)
|
||||
await self._session.flush()
|
||||
@@ -105,6 +120,44 @@ class SQLAlchemyFriendshipRepository(BaseRepository[Friendship]):
|
||||
)
|
||||
raise
|
||||
|
||||
async def reactivate_request(
|
||||
self,
|
||||
friendship: Friendship,
|
||||
initiator_id: UUID,
|
||||
content: str | None = None,
|
||||
) -> tuple[Friendship, InboxMessage]:
|
||||
try:
|
||||
now = datetime.now(timezone.utc)
|
||||
friendship.status = FriendshipStatus.PENDING
|
||||
friendship.requested_at = now
|
||||
friendship.initiator_id = initiator_id
|
||||
friendship.updated_by = initiator_id
|
||||
|
||||
inbox = InboxMessage(
|
||||
recipient_id=(
|
||||
friendship.user_low_id
|
||||
if initiator_id == friendship.user_high_id
|
||||
else friendship.user_high_id
|
||||
),
|
||||
sender_id=initiator_id,
|
||||
message_type=InboxMessageType.FRIEND_REQUEST,
|
||||
friendship_id=friendship.id,
|
||||
content=content,
|
||||
status=InboxMessageStatus.PENDING,
|
||||
created_by=initiator_id,
|
||||
)
|
||||
self._session.add(inbox)
|
||||
await self._session.flush()
|
||||
|
||||
return friendship, inbox
|
||||
except SQLAlchemyError:
|
||||
logger.exception(
|
||||
"Failed to reactivate friendship request",
|
||||
friendship_id=str(friendship.id),
|
||||
initiator_id=str(initiator_id),
|
||||
)
|
||||
raise
|
||||
|
||||
async def get_friendship_between_users(
|
||||
self, user_id_1: UUID, user_id_2: UUID
|
||||
) -> Friendship | None:
|
||||
|
||||
Reference in New Issue
Block a user