refactor: consolidate runtime helpers
This commit is contained in:
19
src/available-groups.ts
Normal file
19
src/available-groups.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { AvailableGroup } from './agent-runner.js';
|
||||
import { getAllChats } from './db.js';
|
||||
import type { RegisteredGroup } from './types.js';
|
||||
|
||||
export function listAvailableGroups(
|
||||
registeredGroups: Record<string, RegisteredGroup>,
|
||||
): AvailableGroup[] {
|
||||
const chats = getAllChats();
|
||||
const registeredJids = new Set(Object.keys(registeredGroups));
|
||||
|
||||
return chats
|
||||
.filter((chat) => chat.jid !== '__group_sync__' && chat.is_group)
|
||||
.map((chat) => ({
|
||||
jid: chat.jid,
|
||||
name: chat.name,
|
||||
lastActivity: chat.last_message_time,
|
||||
isRegistered: registeredJids.has(chat.jid),
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user