diff --git a/plugin/adapter.py b/plugin/adapter.py index 6ab6ee1..ce87c21 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -483,16 +483,18 @@ class RocketChatAdapter(BasePlatformAdapter): attachments = msg_obj.get("attachments", []) if file_info or attachments: file_details = [] + seen_ids = set() base_url = self.base_url.rstrip("/") - # Process file object if present + # Process file object if present (has precise MIME type) if file_info and isinstance(file_info, dict): filename = file_info.get("name", "unknown") filetype = file_info.get("type", "unknown") file_id = file_info.get("_id") if file_id and filename: + seen_ids.add(file_id) download_url = f"{base_url}/file-upload/{file_id}/{filename}" file_details.append(f"[FILE] {filename} ({filetype})\nDownload: {download_url}") - # Process attachments if present + # Process attachments if present (skip duplicates already covered by file_info) if attachments and isinstance(attachments, list): for attachment in attachments: if isinstance(attachment, dict) and attachment.get("type") == "file": @@ -503,6 +505,10 @@ class RocketChatAdapter(BasePlatformAdapter): download_url = f"{base_url}{title_link}" else: download_url = f"{base_url}/{title_link}" + # Extract file_id from title_link to detect duplicates + link_id = title_link.split("/")[2] if title_link.startswith("/file-upload/") else None + if link_id and link_id in seen_ids: + continue # Already covered by precise file_info file_details.append(f"[FILE] {title} (file)\nDownload: {download_url}") # Add file information to message text if file_details: