feat: QR-Code für alle Kanäle (contact_id in ConversationResponse)

This commit is contained in:
2026-03-17 15:19:40 +01:00
parent 7c237836e8
commit 28d3b36b78
3 changed files with 9 additions and 10 deletions

View File

@@ -20,14 +20,13 @@ def list_conversations(
result = [] result = []
for conv in convs: for conv in convs:
last_msg = conv.messages[-1] if conv.messages else None last_msg = conv.messages[-1] if conv.messages else None
contact_id = conv.participants[0].id if conv.participants else None
result.append( result.append(
ConversationResponse( 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, last_message=MessageResponse.model_validate(last_msg) if last_msg else None,
unread_count=conversation_service.unread_count(db, conv.id), unread_count=conversation_service.unread_count(db, conv.id),
contact_id=contact_id,
) )
) )
return result return result
@@ -43,10 +42,12 @@ def get_conversation(
if not conv: if not conv:
raise HTTPException(status_code=404, detail="Conversation not found") raise HTTPException(status_code=404, detail="Conversation not found")
last_msg = conv.messages[-1] if conv.messages else None last_msg = conv.messages[-1] if conv.messages else None
contact_id = conv.participants[0].id if conv.participants else None
return ConversationResponse( return 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, last_message=MessageResponse.model_validate(last_msg) if last_msg else None,
unread_count=conversation_service.unread_count(db, conv.id), unread_count=conversation_service.unread_count(db, conv.id),
contact_id=contact_id,
) )

View File

@@ -111,6 +111,7 @@ class ConversationResponse(BaseModel):
created_at: datetime created_at: datetime
last_message: Optional[MessageResponse] = None last_message: Optional[MessageResponse] = None
unread_count: int = 0 unread_count: int = 0
contact_id: Optional[str] = None
# ── Channel Status ───────────────────────────────────────────────────────────── # ── Channel Status ─────────────────────────────────────────────────────────────

View File

@@ -289,17 +289,14 @@ class MainScreen(Screen):
asyncio.create_task(self._generate_telegram_qr()) asyncio.create_task(self._generate_telegram_qr())
async def _generate_telegram_qr(self) -> None: 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") self.notify("Bitte erst eine Konversation auswählen.", severity="warning")
return return
conv = self._current_conv conv = self._current_conv or {}
if conv.get("channel") != "telegram":
self.notify("QR-Code nur für Telegram-Konversationen.", severity="warning")
return
contact_id = conv.get("contact_id") contact_id = conv.get("contact_id")
if not contact_id: if not contact_id:
try: 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") contact_id = (details or {}).get("contact_id")
except Exception: except Exception:
pass pass