Clean duplicate dashboard status messages
Clean duplicate Status dashboard messages by marker, preserve the tracked message, and avoid full-channel purge on startup.
This commit is contained in:
@@ -41,6 +41,10 @@ import {
|
||||
type DashboardRoomLine,
|
||||
renderCategorizedRoomSections,
|
||||
} from './dashboard-render.js';
|
||||
import {
|
||||
cleanupDashboardDuplicateMessages,
|
||||
purgeDashboardMessages,
|
||||
} from './dashboard-message-cleanup.js';
|
||||
import {
|
||||
buildClaudeUsageRows,
|
||||
extractCodexUsageRows,
|
||||
@@ -157,25 +161,14 @@ function findDiscordChannel(channels: Channel[]): Channel | undefined {
|
||||
export async function purgeDashboardChannel(
|
||||
opts: Pick<UnifiedDashboardOptions, 'channels' | 'statusChannelId'>,
|
||||
): Promise<void> {
|
||||
if (!opts.statusChannelId) return;
|
||||
|
||||
const statusJid = `dc:${opts.statusChannelId}`;
|
||||
const channel = opts.channels.find(
|
||||
(item) =>
|
||||
item.name.startsWith('discord') &&
|
||||
item.isConnected() &&
|
||||
item.purgeChannel,
|
||||
);
|
||||
if (channel?.purgeChannel) {
|
||||
await channel.purgeChannel(statusJid);
|
||||
}
|
||||
await purgeDashboardMessages(opts);
|
||||
}
|
||||
|
||||
export function shouldPurgeDashboardChannelOnStart(args: {
|
||||
purgeOnStart?: boolean;
|
||||
storedMessageId: string | null;
|
||||
}): boolean {
|
||||
return args.purgeOnStart === true && !args.storedMessageId;
|
||||
return args.purgeOnStart === true;
|
||||
}
|
||||
|
||||
async function refreshChannelMeta(
|
||||
@@ -729,6 +722,7 @@ export async function startUnifiedDashboard(
|
||||
})
|
||||
) {
|
||||
await purgeDashboardChannel(opts);
|
||||
statusMessageId = null;
|
||||
}
|
||||
|
||||
if (isRenderer) {
|
||||
@@ -787,6 +781,9 @@ export async function startUnifiedDashboard(
|
||||
writeDashboardStatusMessageId(opts.statusChannelId, id);
|
||||
}
|
||||
}
|
||||
if (statusMessageId) {
|
||||
await cleanupDashboardDuplicateMessages(opts, statusMessageId);
|
||||
}
|
||||
if (!dashboardUpdateLogged) {
|
||||
logger.info(
|
||||
{ messageId: statusMessageId, contentLength: content.length },
|
||||
|
||||
Reference in New Issue
Block a user