adjusted message handler

This commit is contained in:
DJ2LS 2024-02-07 23:03:55 +01:00
parent c33d23f326
commit ff624a4c9a

View file

@ -24,13 +24,16 @@ class DatabaseManagerAttachments(DatabaseManager):
) )
session.add(attachment) session.add(attachment)
session.flush() # Ensure the attachment is persisted and has an ID session.flush() # Ensure the attachment is persisted and has an ID
self.log(f"Added attachment to database: {attachment.name}")
else: else:
attachment = existing_attachment attachment = existing_attachment
self.log(f"Attachment {attachment.name} already exists in database")
# Link the message and the attachment through MessageAttachment # Link the message and the attachment through MessageAttachment
link = MessageAttachment(message=message, attachment=attachment) link = MessageAttachment(message=message, attachment=attachment)
self.log(f"Added attachment to database: {attachment.name}")
session.add(link) session.add(link)
self.log(f"Linked message with attachment: {attachment.name}")
return attachment return attachment
def get_attachments_by_message_id(self, message_id): def get_attachments_by_message_id(self, message_id):