diff --git a/api/routes/conversations.py b/api/routes/conversations.py index 2da7c7b..7f39928 100644 --- a/api/routes/conversations.py +++ b/api/routes/conversations.py @@ -20,14 +20,13 @@ def list_conversations( result = [] for conv in convs: last_msg = conv.messages[-1] if conv.messages else None + contact_id = conv.participants[0].id if conv.participants else None result.append( ConversationResponse( - **{ - c.key: getattr(conv, c.key) - for c in conv.__table__.columns - }, + **{c.key: getattr(conv, c.key) for c in conv.__table__.columns}, last_message=MessageResponse.model_validate(last_msg) if last_msg else None, unread_count=conversation_service.unread_count(db, conv.id), + contact_id=contact_id, ) ) return result @@ -43,10 +42,12 @@ def get_conversation( if not conv: raise HTTPException(status_code=404, detail="Conversation not found") last_msg = conv.messages[-1] if conv.messages else None + contact_id = conv.participants[0].id if conv.participants else None return ConversationResponse( **{c.key: getattr(conv, c.key) for c in conv.__table__.columns}, last_message=MessageResponse.model_validate(last_msg) if last_msg else None, unread_count=conversation_service.unread_count(db, conv.id), + contact_id=contact_id, ) diff --git a/schemas.py b/schemas.py index 6638a3f..fd38970 100644 --- a/schemas.py +++ b/schemas.py @@ -111,6 +111,7 @@ class ConversationResponse(BaseModel): created_at: datetime last_message: Optional[MessageResponse] = None unread_count: int = 0 + contact_id: Optional[str] = None # ── Channel Status ───────────────────────────────────────────────────────────── diff --git a/tui/screens/main_screen.py b/tui/screens/main_screen.py index 1849098..0cb511f 100644 --- a/tui/screens/main_screen.py +++ b/tui/screens/main_screen.py @@ -289,17 +289,14 @@ class MainScreen(Screen): asyncio.create_task(self._generate_telegram_qr()) async def _generate_telegram_qr(self) -> None: - if not self._current_conv: + if not self._current_conv_id: self.notify("Bitte erst eine Konversation auswählen.", severity="warning") return - conv = self._current_conv - if conv.get("channel") != "telegram": - self.notify("QR-Code nur für Telegram-Konversationen.", severity="warning") - return + conv = self._current_conv or {} contact_id = conv.get("contact_id") if not contact_id: try: - details = await self._api.get_conversation(conv["id"]) + details = await self._api.get_conversation(self._current_conv_id) contact_id = (details or {}).get("contact_id") except Exception: pass