1.9
This commit is contained in:
@@ -79,3 +79,60 @@ async def delete_message(
|
||||
return {"success": True}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=403, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/{conversation_id}/messages/{message_id}/recall")
|
||||
async def recall_message(
|
||||
conversation_id: str,
|
||||
message_id: str,
|
||||
user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""撤回消息(2 分钟内)"""
|
||||
service = MessageService(db)
|
||||
try:
|
||||
await service.recall_message(message_id, user.id)
|
||||
# 广播撤回事件
|
||||
from app.services.conversation_service import ConversationService
|
||||
conv_service = ConversationService(db)
|
||||
detail = await conv_service.get_conversation_detail(conversation_id, user.id)
|
||||
if detail and "members" in detail:
|
||||
from app.websocket.events import EventType
|
||||
from app.websocket.manager import manager
|
||||
member_ids = [m["user_id"] for m in detail["members"]]
|
||||
for uid in member_ids:
|
||||
await manager.send_to_user(uid, EventType.CHAT_MESSAGE_RECALLED, {
|
||||
"conversation_id": conversation_id, "message_id": message_id,
|
||||
"recalled_by": user.id,
|
||||
})
|
||||
return {"success": True}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/{conversation_id}/messages/{message_id}/reactions")
|
||||
async def add_reaction(
|
||||
conversation_id: str,
|
||||
message_id: str,
|
||||
body: dict,
|
||||
user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""添加/取消表情回应(toggle)"""
|
||||
service = MessageService(db)
|
||||
result = await service.react(message_id, user.id, body.get("emoji", ""))
|
||||
# 广播回应变化
|
||||
from app.services.conversation_service import ConversationService
|
||||
from app.websocket.events import EventType
|
||||
from app.websocket.manager import manager
|
||||
conv_service = ConversationService(db)
|
||||
detail = await conv_service.get_conversation_detail(conversation_id, user.id)
|
||||
if detail and "members" in detail:
|
||||
member_ids = [m["user_id"] for m in detail["members"]]
|
||||
etype = EventType.CHAT_REACTION_ADDED if result["action"] == "added" else EventType.CHAT_REACTION_REMOVED
|
||||
for uid in member_ids:
|
||||
await manager.send_to_user(uid, etype, {
|
||||
"conversation_id": conversation_id, "message_id": message_id,
|
||||
"emoji": result["emoji"], "user_id": user.id,
|
||||
})
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user