commit 6a10ea8690415396c61a1cde9ff56f91d9ca2b41
parent 62dae4a7d9d1f853308aafb14668e658f1dc12ca
Author: Carlosokumu <carlosokumu254@gmail.com>
Date: Mon, 1 Sep 2025 07:44:27 +0300
deduplicate poster and long attachments
Diffstat:
1 file changed, 15 insertions(+), 22 deletions(-)
diff --git a/ungana/ical/ical_manager.py b/ungana/ical/ical_manager.py
@@ -1,7 +1,7 @@
import os
import uuid
from zoneinfo import ZoneInfo
-from icalendar import Calendar, Event, vDatetime,prop
+from icalendar import Calendar, Event, vDatetime
from datetime import datetime, timedelta, timezone
from typing import Dict, Any
@@ -66,6 +66,7 @@ class ICalManager:
def update_event(self,cal: Calendar,updates: Dict[str, Any],attachments: list = None,filename: str = None) -> Calendar:
uid = cal.walk("VEVENT")[0].get("UID")
event_found = False
+
for component in cal.walk():
if component.name == "VEVENT" and str(component.get("UID")) == uid:
event_found = True
@@ -78,33 +79,25 @@ class ICalManager:
component.add(key, v, parameters=params)
else:
component[key] = value
+
+ # Deduplicate attachments
if attachments:
- existing = component.get("ATTACH")
- if not existing:
- existing = []
- elif not isinstance(existing, list):
- existing = [existing]
-
- preserved = []
- for e in existing:
- ctx = None
- if hasattr(e, "params"):
- ctx = e.params.get("CTX")
- if ctx not in ("poster", "long"):
- preserved.append(e)
-
- if "ATTACH" in component:
- component.pop("ATTACH")
-
- for e in preserved:
- component.add("ATTACH", e)
+ existing_attachments = {
+ str(a) for a in component.get("ATTACH", [])
+ }
for attachment in attachments:
if isinstance(attachment, tuple) and len(attachment) == 3:
prop, value, params = attachment
- component.add(prop, value, parameters=params)
+ if value not in existing_attachments:
+ component.add(prop, value, parameters=params)
+ existing_attachments.add(value)
else:
- component.add("ATTACH", str(attachment))
+ value = str(attachment)
+ if value not in existing_attachments:
+ component.add("ATTACH", value)
+ existing_attachments.add(value)
+
break
if not event_found: