show live message preview during migration
This commit is contained in:
parent
5738e4dd00
commit
ad2dca7f0a
3 changed files with 25 additions and 2 deletions
|
|
@ -98,7 +98,13 @@ async def analyze_migration(context: MigrationContext, source_channel_id: int, a
|
|||
|
||||
async def migrate_messages(context: MigrationContext, source_channel_id: int, target_channel_id: str, after_message_id: int | None = None, progress_callback: Callable[[Dict[str, Any]], Awaitable[None]] | None = None) -> Dict[str, Any]:
|
||||
"""Migrate messages for a specific channel and returns detailed statistics."""
|
||||
stats = {"messages": 0, "threads": 0, "attachments": 0}
|
||||
stats = {
|
||||
"messages": 0,
|
||||
"threads": 0,
|
||||
"attachments": 0,
|
||||
"last_message_content": "",
|
||||
"last_message_author": ""
|
||||
}
|
||||
|
||||
logger.info(f"Starting message migration: Discord #{source_channel_id} -> Fluxer #{target_channel_id}")
|
||||
if after_message_id:
|
||||
|
|
@ -211,6 +217,8 @@ async def migrate_messages(context: MigrationContext, source_channel_id: int, ta
|
|||
context.state.update_last_message_timestamp(target_channel_id, str(msg.created_at))
|
||||
context.state.update_last_message_id(target_channel_id, str(msg.id))
|
||||
stats["messages"] += 1
|
||||
stats["last_message_content"] = content
|
||||
stats["last_message_author"] = msg.author.display_name
|
||||
context.state.increment_stats(target_channel_id, messages=1, files=len(files) if files else 0)
|
||||
|
||||
# Periodic log
|
||||
|
|
|
|||
|
|
@ -108,7 +108,9 @@ async def migrate_messages(context: MigrationContext, source_channel_id: int, ta
|
|||
"threads": 0,
|
||||
"attachments": 0,
|
||||
"first_message_url": "",
|
||||
"last_message_url": ""
|
||||
"last_message_url": "",
|
||||
"last_message_content": "",
|
||||
"last_message_author": ""
|
||||
}
|
||||
|
||||
logger.info(f"Starting message migration: Discord #{source_channel_id} -> Stoat #{target_channel_id}")
|
||||
|
|
@ -220,6 +222,8 @@ async def migrate_messages(context: MigrationContext, source_channel_id: int, ta
|
|||
context.state.update_last_message_timestamp(target_channel_id, str(msg.created_at))
|
||||
context.state.update_last_message_id(target_channel_id, str(msg.id))
|
||||
stats["messages"] += 1
|
||||
stats["last_message_content"] = content
|
||||
stats["last_message_author"] = msg.author.display_name
|
||||
context.state.increment_stats(target_channel_id, messages=1, files=len(files) if files else 0)
|
||||
|
||||
# Periodic log
|
||||
|
|
|
|||
|
|
@ -790,6 +790,10 @@ class ShuttlePane(Container):
|
|||
total_threads = stats_analysis["threads"]
|
||||
total_attachments = stats_analysis["attachments"]
|
||||
|
||||
modal.set_status(f"Migrating: [cyan]#{source_channel.name}[/cyan] → [green]#{target_channel.get('name')}[/green]")
|
||||
modal.write(f"[bold cyan]Migration Started:[/bold cyan] Discord [cyan]#{source_channel.name}[/cyan] → {platform_name} [green]#{target_channel.get('name')}[/green]")
|
||||
modal.write(f"[dim]Stats: {total_messages} messages, {total_threads} threads, {total_attachments} files[/dim]\n")
|
||||
|
||||
logger.info(f"Execution started for #{source_channel.name} -> {platform_name} @ {target_channel.get('name')}")
|
||||
self.engine.is_running = True
|
||||
|
||||
|
|
@ -810,6 +814,13 @@ class ShuttlePane(Container):
|
|||
# optionally show a scrolling trace if the backend provided it
|
||||
modal.write_live(f"Migrated message #{c_msgs}")
|
||||
|
||||
content = current_stats.get("last_message_content", "")
|
||||
author = current_stats.get("last_message_author", "Unknown")
|
||||
if content:
|
||||
# Clean up content for display (truncate long messages)
|
||||
disp_content = (content[:100] + '...') if len(content) > 100 else content
|
||||
modal.write(f"[bold]{author}:[/bold] {disp_content}")
|
||||
|
||||
result = await migrate_mod.migrate_messages(
|
||||
self.engine,
|
||||
source_channel_id=source_channel.id,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue