fix: WhatsApp @c.us Doppel-Suffix + Chat löschen in TUI
- WhatsApp send: @c.us wird vor dem Anhängen entfernt (verhindert 4915..@c.us@c.us) - DELETE /api/v1/conversations/{id}: löscht Konversation + alle Nachrichten - TUI: Taste D öffnet Bestätigungsdialog zum Löschen des aktuellen Chats
This commit is contained in:
@@ -101,6 +101,14 @@ class MCMApiClient:
|
||||
async def get_contacts(self) -> list[dict[str, Any]]:
|
||||
return await self._get("/contacts")
|
||||
|
||||
async def delete_conversation(self, conv_id: str) -> None:
|
||||
async with httpx.AsyncClient(timeout=10.0, follow_redirects=True) as client:
|
||||
resp = await client.delete(
|
||||
self._base + f"/conversations/{conv_id}",
|
||||
headers=self._headers,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
|
||||
async def get_telegram_qr(self, contact_id: str) -> bytes:
|
||||
"""QR-Code PNG-Bytes für einen Kontakt abrufen."""
|
||||
async with httpx.AsyncClient(timeout=10.0, follow_redirects=True) as client:
|
||||
|
||||
@@ -25,6 +25,7 @@ class MainScreen(Screen):
|
||||
Binding("n", "new_message", "Neu"),
|
||||
Binding("r", "refresh", "Aktualisieren"),
|
||||
Binding("t", "telegram_qr", "Telegram QR"),
|
||||
Binding("d", "delete_conv", "Chat löschen"),
|
||||
Binding("q", "quit_app", "Beenden"),
|
||||
]
|
||||
|
||||
@@ -241,6 +242,35 @@ class MainScreen(Screen):
|
||||
if self._current_conv_id:
|
||||
await self._load_messages(self._current_conv_id)
|
||||
|
||||
def action_delete_conv(self) -> None:
|
||||
if not self._current_conv_id:
|
||||
self.notify("Kein Chat ausgewählt.", severity="warning")
|
||||
return
|
||||
title = (self._current_conv or {}).get("title") or self._current_conv_id[:8]
|
||||
self.app.push_screen(
|
||||
_ConfirmScreen(f"Chat löschen?\n\n{title}\n\nAlle Nachrichten werden entfernt."),
|
||||
self._delete_conv_callback,
|
||||
)
|
||||
|
||||
def _delete_conv_callback(self, confirmed: bool) -> None:
|
||||
if confirmed:
|
||||
asyncio.create_task(self._do_delete_conv())
|
||||
|
||||
async def _do_delete_conv(self) -> None:
|
||||
conv_id = self._current_conv_id
|
||||
if not conv_id:
|
||||
return
|
||||
try:
|
||||
await self._api.delete_conversation(conv_id)
|
||||
self._current_conv_id = None
|
||||
self._current_conv = None
|
||||
self.query_one("#chat-header", Static).update("Kein Chat geöffnet")
|
||||
self.query_one("#message-log", RichLog).clear()
|
||||
await self._load_conversations()
|
||||
self.notify("Chat gelöscht.")
|
||||
except Exception as exc:
|
||||
self.notify(f"Löschen fehlgeschlagen: {exc}", severity="error")
|
||||
|
||||
def action_telegram_qr(self) -> None:
|
||||
asyncio.create_task(self._generate_telegram_qr())
|
||||
|
||||
@@ -301,3 +331,22 @@ class MainScreen(Screen):
|
||||
|
||||
def action_quit_app(self) -> None:
|
||||
self.app.exit()
|
||||
|
||||
|
||||
class _ConfirmScreen(ModalScreen[bool]):
|
||||
"""Einfacher Ja/Nein-Dialog."""
|
||||
|
||||
def __init__(self, message: str) -> None:
|
||||
super().__init__()
|
||||
self._message = message
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
from textual.widgets import Label
|
||||
with Vertical(id="compose-dialog"):
|
||||
yield Label(self._message, id="confirm-msg")
|
||||
with Horizontal(id="compose-buttons"):
|
||||
yield Button("Abbrechen", variant="default", id="btn-no")
|
||||
yield Button("Löschen", variant="error", id="btn-yes")
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
self.dismiss(event.button.id == "btn-yes")
|
||||
|
||||
Reference in New Issue
Block a user