Skip to content

Commit

Permalink
Update time when activating conversation
Browse files Browse the repository at this point in the history
- Fix sorting
  • Loading branch information
smathot committed Jan 20, 2024
1 parent 2cd1698 commit 352c3de
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions heymans/database/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,20 @@ def get_active_conversation(self) -> dict:

def set_active_conversation(self, conversation_id: int) -> bool:
try:
# We first get the active conversation
conversation = Conversation.query.filter_by(
conversation_id=conversation_id, user_id=self.user_id).one()
# And then update the current time for that conversation so that
# it ends on top
decrypted_data = self.encryption_manager.decrypt_data(
conversation.data)
conversation_data = json.loads(decrypted_data)
conversation_data['last_updated'] = time.time()
json_data = json.dumps(conversation_data)
encrypted_data = self.encryption_manager.encrypt_data(
json_data.encode('utf-8'))
conversation.data = encrypted_data
# Finally we change the active conversation for the user
user = User.query.filter_by(user_id=self.user_id).one()
user.active_conversation_id = conversation.conversation_id
db.session.commit()
Expand Down

0 comments on commit 352c3de

Please sign in to comment.