const THREAD_REPLY_REGEX = /\[THREAD_REPLY:([^:\]]+):([^\]]*)\]/g;
const THREAD_RESOLVE_REGEX = /\[THREAD_RESOLVE:([^\]]+)\]/g;
const POST_COMMENT_REGEX = /\[POST_COMMENT:([^\]]+)\]/g;
const FETCH_THREADS_REGEX = /\[FETCH_THREADS\]/g;
function unescapeNewlines(message) {
    return message.replace(/\\n/g, '\n');
}
export function parseThreadActions(stdout) {
    const matches = [];
    let match;
    while ((match = THREAD_REPLY_REGEX.exec(stdout)) !== null) {
        matches.push({
            index: match.index,
            action: {
                type: 'THREAD_REPLY',
                threadId: match[1],
                message: match[2],
            },
        });
    }
    while ((match = THREAD_RESOLVE_REGEX.exec(stdout)) !== null) {
        matches.push({
            index: match.index,
            action: {
                type: 'THREAD_RESOLVE',
                threadId: match[1],
            },
        });
    }
    while ((match = POST_COMMENT_REGEX.exec(stdout)) !== null) {
        matches.push({
            index: match.index,
            action: {
                type: 'POST_COMMENT',
                body: unescapeNewlines(match[1]),
            },
        });
    }
    while ((match = FETCH_THREADS_REGEX.exec(stdout)) !== null) {
        matches.push({
            index: match.index,
            action: {
                type: 'FETCH_THREADS',
            },
        });
    }
    matches.sort((a, b) => a.index - b.index);
    return matches.map(m => m.action);
}
//# sourceMappingURL=threadActionsParser.js.map