diff --git a/services/contact_service.py b/services/contact_service.py index 360e4ac..07eaa56 100644 --- a/services/contact_service.py +++ b/services/contact_service.py @@ -19,11 +19,14 @@ def get_by_telegram_id(db: Session, telegram_id: str) -> Contact | None: def get_by_phone(db: Session, phone: str) -> Contact | None: - return ( - db.query(Contact) - .filter((Contact.phone == phone) | (Contact.whatsapp_phone == phone)) - .first() - ) + # Normalisierung: mit und ohne führendes + suchen + variants = {phone, "+" + phone.lstrip("+"), phone.lstrip("+")} + from sqlalchemy import or_ + conditions = or_(*( + (Contact.phone == v) | (Contact.whatsapp_phone == v) + for v in variants + )) + return db.query(Contact).filter(conditions).first() def create(db: Session, data: ContactCreate) -> Contact: diff --git a/tui/screens/main_screen.py b/tui/screens/main_screen.py index 7d503c4..2b49626 100644 --- a/tui/screens/main_screen.py +++ b/tui/screens/main_screen.py @@ -143,11 +143,11 @@ class MainScreen(Screen): direction = msg.get("direction", "outbound") direction_prefix = "▶ " if direction == "outbound" else "◀ " status_suffix = " ✗" if msg.get("status") == "failed" else "" - style = "dim" if direction == "outbound" else "" - text = msg.get("text", "") - log.write( - f"[dim]{ts}[/dim] [{style}]{direction_prefix}{text}{status_suffix}[/{style}]" - ) + text = msg.get("text", "").replace("[", "\\[") + if direction == "outbound": + log.write(f"[dim]{ts}[/dim] [dim]{direction_prefix}{text}{status_suffix}[/dim]") + else: + log.write(f"[dim]{ts}[/dim] {direction_prefix}{text}{status_suffix}") # ── Background-Polling ─────────────────────────────────────────────────────