implement delete session on persistence services
This commit is contained in:
parent
76f5540f19
commit
76c967ce17
2 changed files with 17 additions and 1 deletions
|
|
@ -86,12 +86,14 @@ class ConversationPersistenceService:
|
|||
user_conversations = self.get_user_conversations(user_id)
|
||||
return user_conversations.get(response_id, {})
|
||||
|
||||
def delete_conversation_thread(self, user_id: str, response_id: str):
|
||||
def delete_conversation_thread(self, user_id: str, response_id: str) -> bool:
|
||||
"""Delete a specific conversation thread"""
|
||||
if user_id in self._conversations and response_id in self._conversations[user_id]:
|
||||
del self._conversations[user_id][response_id]
|
||||
self._save_conversations()
|
||||
logger.debug(f"Deleted conversation {response_id} for user {user_id}")
|
||||
return True
|
||||
return False
|
||||
|
||||
def clear_user_conversations(self, user_id: str):
|
||||
"""Clear all conversations for a user"""
|
||||
|
|
|
|||
|
|
@ -74,6 +74,20 @@ class SessionOwnershipService:
|
|||
"""Filter a list of sessions to only include those owned by the user"""
|
||||
user_sessions = self.get_user_sessions(user_id)
|
||||
return [session for session in session_ids if session in user_sessions]
|
||||
|
||||
def release_session(self, user_id: str, session_id: str) -> bool:
|
||||
"""Release a session from a user (delete ownership record)"""
|
||||
if session_id in self.ownership_data:
|
||||
# Verify the user owns this session before deleting
|
||||
if self.ownership_data[session_id].get("user_id") == user_id:
|
||||
del self.ownership_data[session_id]
|
||||
self._save_ownership_data()
|
||||
logger.debug(f"Released session {session_id} from user {user_id}")
|
||||
return True
|
||||
else:
|
||||
logger.warning(f"User {user_id} tried to release session {session_id} they don't own")
|
||||
return False
|
||||
return False
|
||||
|
||||
def get_ownership_stats(self) -> Dict[str, any]:
|
||||
"""Get statistics about session ownership"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue