Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openclaw/extensions/matrix/src/matrix/   (KI Agentensystem Version 22©)  Datei vom 26.3.2026 mit Größe 2 kB image not shown  

Quelle  poll-summary.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

import type { MatrixMessageSummary } from "./actions/types.js";
import {
  buildPollResultsSummary,
  formatPollAsText,
  formatPollResultsAsText,
  isPollEventType,
  isPollStartType,
  parsePollStartContent,
  resolvePollReferenceEventId,
  type PollStartContent,
} from "./poll-types.js";
import type { MatrixClient, MatrixRawEvent } from "./sdk.js";

export type MatrixPollSnapshot = {
  pollEventId: string;
  triggerEvent: MatrixRawEvent;
  rootEvent: MatrixRawEvent;
  text: string;
};

export function resolveMatrixPollRootEventId(
  event: Pick<MatrixRawEvent, "event_id" | "type" | "content">,
): string | null {
  if (isPollStartType(event.type)) {
    const eventId = event.event_id?.trim();
    return eventId ? eventId : null;
  }
  return resolvePollReferenceEventId(event.content);
}

async function readAllPollRelations(
  client: MatrixClient,
  roomId: string,
  pollEventId: string,
): Promise<MatrixRawEvent[]> {
  const relationEvents: MatrixRawEvent[] = [];
  let nextBatch: string | undefined;
  do {
    const page = await client.getRelations(roomId, pollEventId, "m.reference", undefined, {
      from: nextBatch,
    });
    relationEvents.push(...page.events);
    nextBatch = page.nextBatch ?? undefined;
  } while (nextBatch);
  return relationEvents;
}

export async function fetchMatrixPollSnapshot(
  client: MatrixClient,
  roomId: string,
  event: MatrixRawEvent,
): Promise<MatrixPollSnapshot | null> {
  if (!isPollEventType(event.type)) {
    return null;
  }

  const pollEventId = resolveMatrixPollRootEventId(event);
  if (!pollEventId) {
    return null;
  }

  const rootEvent = isPollStartType(event.type)
    ? event
    : ((await client.getEvent(roomId, pollEventId)) as MatrixRawEvent);
  if (!isPollStartType(rootEvent.type)) {
    return null;
  }

  const pollStartContent = rootEvent.content as PollStartContent;
  const pollSummary = parsePollStartContent(pollStartContent);
  if (!pollSummary) {
    return null;
  }

  const relationEvents = await readAllPollRelations(client, roomId, pollEventId);
  const pollResults = buildPollResultsSummary({
    pollEventId,
    roomId,
    sender: rootEvent.sender,
    senderName: rootEvent.sender,
    content: pollStartContent,
    relationEvents,
  });

  return {
    pollEventId,
    triggerEvent: event,
    rootEvent,
    text: pollResults ? formatPollResultsAsText(pollResults) : formatPollAsText(pollSummary),
  };
}

export async function fetchMatrixPollMessageSummary(
  client: MatrixClient,
  roomId: string,
  event: MatrixRawEvent,
): Promise<MatrixMessageSummary | null> {
  const snapshot = await fetchMatrixPollSnapshot(client, roomId, event);
  if (!snapshot) {
    return null;
  }

  return {
    eventId: snapshot.pollEventId,
    sender: snapshot.rootEvent.sender,
    body: snapshot.text,
    msgtype: "m.text",
    timestamp: snapshot.triggerEvent.origin_server_ts || snapshot.rootEvent.origin_server_ts,
  };
}

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.