| | |
| | | |
| | | class AddFriendsRequest(BaseModel): |
| | | """添加好友到忽略列表请求模型""" |
| | | |
| | | friends: List[str] |
| | | |
| | | |
| | | class RemoveFriendRequest(BaseModel): |
| | | """从忽略列表移除好友请求模型""" |
| | | |
| | | w_id: str |
| | | |
| | | |
| | | class IgnoreListResponse(BaseModel): |
| | | """忽略列表响应模型""" |
| | | |
| | | success: bool |
| | | message: str |
| | | data: Set[str] = None |
| | |
| | | async def get_ignore_list(): |
| | | """ |
| | | 获取当前的好友忽略列表 |
| | | |
| | | |
| | | Returns: |
| | | 忽略列表响应 |
| | | """ |
| | | try: |
| | | ignore_list = friend_ignore_service.get_ignore_list() |
| | | count = friend_ignore_service.get_ignore_list_count() |
| | | |
| | | |
| | | return IgnoreListResponse( |
| | | success=True, |
| | | message="获取忽略列表成功", |
| | | data=ignore_list, |
| | | count=count |
| | | success=True, message="获取忽略列表成功", data=ignore_list, count=count |
| | | ) |
| | | except Exception as e: |
| | | logger.error(f"获取忽略列表失败: {str(e)}") |
| | |
| | | async def add_friends_to_ignore_list(request: AddFriendsRequest): |
| | | """ |
| | | 添加好友到忽略列表 |
| | | |
| | | |
| | | Args: |
| | | request: 添加好友请求 |
| | | |
| | | |
| | | Returns: |
| | | 操作结果 |
| | | """ |
| | | try: |
| | | success = friend_ignore_service.add_friends_to_ignore_list(request.friends) |
| | | |
| | | |
| | | if success: |
| | | count = friend_ignore_service.get_ignore_list_count() |
| | | return IgnoreListResponse( |
| | | success=True, |
| | | message=f"成功添加 {len(request.friends)} 个好友到忽略列表", |
| | | count=count |
| | | count=count, |
| | | ) |
| | | else: |
| | | raise HTTPException(status_code=400, detail="添加好友到忽略列表失败") |
| | | |
| | | |
| | | except Exception as e: |
| | | logger.error(f"添加好友到忽略列表失败: {str(e)}") |
| | | raise HTTPException(status_code=500, detail=f"添加好友到忽略列表失败: {str(e)}") |
| | |
| | | async def remove_friend_from_ignore_list(request: RemoveFriendRequest): |
| | | """ |
| | | 从忽略列表中移除好友 |
| | | |
| | | |
| | | Args: |
| | | request: 移除好友请求 |
| | | |
| | | |
| | | Returns: |
| | | 操作结果 |
| | | """ |
| | | try: |
| | | success = friend_ignore_service.remove_friend_from_ignore_list(request.w_id) |
| | | |
| | | |
| | | if success: |
| | | count = friend_ignore_service.get_ignore_list_count() |
| | | return IgnoreListResponse( |
| | | success=True, |
| | | message=f"成功从忽略列表中移除好友: {request.w_id}", |
| | | count=count |
| | | count=count, |
| | | ) |
| | | else: |
| | | raise HTTPException(status_code=400, detail="从忽略列表移除好友失败") |
| | | |
| | | |
| | | except Exception as e: |
| | | logger.error(f"从忽略列表移除好友失败: {str(e)}") |
| | | raise HTTPException(status_code=500, detail=f"从忽略列表移除好友失败: {str(e)}") |
| | |
| | | async def clear_ignore_list(): |
| | | """ |
| | | 清空忽略列表 |
| | | |
| | | |
| | | Returns: |
| | | 操作结果 |
| | | """ |
| | | try: |
| | | success = friend_ignore_service.clear_ignore_list() |
| | | |
| | | |
| | | if success: |
| | | return IgnoreListResponse( |
| | | success=True, |
| | | message="成功清空忽略列表", |
| | | count=0 |
| | | ) |
| | | return IgnoreListResponse(success=True, message="成功清空忽略列表", count=0) |
| | | else: |
| | | raise HTTPException(status_code=400, detail="清空忽略列表失败") |
| | | |
| | | |
| | | except Exception as e: |
| | | logger.error(f"清空忽略列表失败: {str(e)}") |
| | | raise HTTPException(status_code=500, detail=f"清空忽略列表失败: {str(e)}") |
| | |
| | | async def sync_contacts_and_rebuild_ignore_list(): |
| | | """ |
| | | 重新同步联系人并重建忽略列表 |
| | | |
| | | |
| | | Returns: |
| | | 操作结果 |
| | | """ |
| | | try: |
| | | if not settings.ecloud_w_id: |
| | | raise HTTPException(status_code=400, detail="未配置ecloud_w_id") |
| | | |
| | | |
| | | success = contact_sync_service.sync_contacts_on_startup(settings.ecloud_w_id) |
| | | |
| | | |
| | | if success: |
| | | count = friend_ignore_service.get_ignore_list_count() |
| | | return IgnoreListResponse( |
| | | success=True, |
| | | message="联系人同步完成,忽略列表已重建", |
| | | count=count |
| | | success=True, message="联系人同步完成,忽略列表已重建", count=count |
| | | ) |
| | | else: |
| | | raise HTTPException(status_code=400, detail="联系人同步失败") |
| | | |
| | | |
| | | except Exception as e: |
| | | logger.error(f"联系人同步失败: {str(e)}") |
| | | raise HTTPException(status_code=500, detail=f"联系人同步失败: {str(e)}") |
| | |
| | | return { |
| | | "success": True, |
| | | "data": status_info, |
| | | "message": f"w_id {w_id} 状态检查完成" |
| | | "message": f"w_id {w_id} 状态检查完成", |
| | | } |
| | | |
| | | except Exception as e: |
| | |
| | | "success": True, |
| | | "data": whitelist, |
| | | "count": len(whitelist), |
| | | "message": "获取白名单成功" |
| | | "message": "获取白名单成功", |
| | | } |
| | | |
| | | except Exception as e: |
| | |
| | | "ignore_enabled": settings.friend_ignore_enabled, |
| | | "whitelist": settings.friend_ignore_whitelist, |
| | | "whitelist_count": len(settings.friend_ignore_whitelist), |
| | | "ignore_list_count": friend_ignore_service.get_ignore_list_count() |
| | | "ignore_list_count": friend_ignore_service.get_ignore_list_count(), |
| | | }, |
| | | "message": "获取配置信息成功" |
| | | "message": "获取配置信息成功", |
| | | } |
| | | |
| | | except Exception as e: |