basically refactored the email viewer
This commit is contained in:
@@ -1,41 +1,41 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from textual import work
|
||||
from textual.widgets import ListView
|
||||
from apis.himalaya import client as himalaya_client
|
||||
|
||||
|
||||
@work(exclusive=False)
|
||||
async def delete_current(app) -> None:
|
||||
app.show_status(f"Deleting message {app.current_message_id}...")
|
||||
try:
|
||||
index = app.current_message_index
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
f"himalaya message delete {app.current_message_id}",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
app.show_status(f"{stdout.decode()}", "info")
|
||||
if process.returncode == 0:
|
||||
# Remove the item from the ListView
|
||||
await app.query_one(ListView).pop(index)
|
||||
@work(exclusive=True)
|
||||
async def delete_current(app):
|
||||
"""Delete the current message."""
|
||||
if not app.current_message_id:
|
||||
app.show_status("No message selected to delete.", "error")
|
||||
return
|
||||
|
||||
# Find the next message to display using the MessageStore
|
||||
next_id, next_idx = app.message_store.find_next_valid_id(index)
|
||||
# Store the current message ID and index
|
||||
current_message_id = app.current_message_id
|
||||
current_index = app.current_message_index
|
||||
|
||||
# Show the next available message
|
||||
if next_id is not None and next_idx is not None:
|
||||
# Set ListView index first to ensure UI is synchronized
|
||||
app.query_one(ListView).index = next_idx
|
||||
# Now update the current_message_id to trigger content update
|
||||
app.current_message_id = next_id
|
||||
else:
|
||||
# No messages left, just update ListView
|
||||
app.query_one(ListView).index = 0
|
||||
app.reload_needed = True
|
||||
# Find the next message to display after deletion
|
||||
next_id, next_idx = app.message_store.find_next_valid_id(current_index)
|
||||
if next_id is None or next_idx is None:
|
||||
# If there's no next message, try to find a previous one
|
||||
next_id, next_idx = app.message_store.find_prev_valid_id(current_index)
|
||||
|
||||
# Delete the message using our Himalaya client module
|
||||
success = await himalaya_client.delete_message(current_message_id)
|
||||
|
||||
if success:
|
||||
app.show_status(f"Message {current_message_id} deleted.", "success")
|
||||
app.message_store.remove_envelope(current_message_id)
|
||||
app.refresh_list_view()
|
||||
|
||||
# Select the next available message if it exists
|
||||
if next_id is not None and next_idx is not None:
|
||||
app.current_message_id = next_id
|
||||
app.current_message_index = next_idx
|
||||
else:
|
||||
app.show_status(
|
||||
f"Failed to delete message {app.current_message_id}. {stderr.decode()}",
|
||||
"error",
|
||||
)
|
||||
except Exception as e:
|
||||
app.show_status(f"Error: {e}", "error")
|
||||
# If there are no other messages, reset the UI
|
||||
app.current_message_id = 0
|
||||
app.show_status("No more messages available.", "warning")
|
||||
else:
|
||||
app.show_status(f"Failed to delete message {current_message_id}.", "error")
|
||||
|
||||
Reference in New Issue
Block a user