//#region src/gateway/service/session-chat-ids.ts
async function getDistinctSessionChatIds(sessionIndex, channel) {
	const result = await sessionIndex.listSessions({
		limit: 1e3,
		sortBy: "lastAccessedAt",
		sortOrder: "desc",
		...channel ? { channel } : {}
	});
	const seen = /* @__PURE__ */ new Set();
	const chatIds = [];
	for (const session of result.items) {
		const key = `${session.sourceChannel}:${session.sourceChatId}`;
		if (!seen.has(key) && session.sourceChannel && session.sourceChatId) {
			seen.add(key);
			const r = session.routing;
			chatIds.push({
				channel: session.sourceChannel,
				chatId: session.sourceChatId,
				lastActive: session.lastAccessedAt,
				...r ? {
					accountId: r.accountId,
					peerKind: r.peerKind,
					peerId: r.peerId
				} : {}
			});
		}
	}
	return chatIds;
}
//#endregion
export { getDistinctSessionChatIds };

//# sourceMappingURL=session-chat-ids.js.map