fix: shared chats can't open new files attached together with a file already in the chat (#31650)

When files were attached to a chat message and one of them was already attached to that chat (on the same message or another one), none of the new files were recorded as part of the chat, and nothing showed up in the logs. The sender still saw every file in their own chat, but anyone opening a shared copy of the chat could not open the new ones. Files already attached to the chat are now skipped and the new ones are recorded normally.

Fixes #31648
This commit is contained in:
Classic298 2026-09-30 19:03:32 +02:00 • committed by GitHub
parent 6c322941d1
commit 3d43a497b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2585,11 +2585,11 @@ class ChatTable:
if not file_ids:
return None
chat_message_file_ids = {
item.id for item in await self.get_chat_files_by_chat_id_and_message_id(chat_id, message_id, db=db)
}
async with get_async_db_context(db) as session:
result = await session.execute(select(ChatFile.file_id).filter_by(chat_id=chat_id))
chat_file_ids = set(result.scalars().all())
# Remove duplicates and existing file_ids
file_ids = list({file_id for file_id in file_ids if file_id and file_id not in chat_message_file_ids})
file_ids = list({file_id for file_id in file_ids if file_id and file_id not in chat_file_ids})
if not file_ids:
return None