feat: complete Ancestor quote bot with production-ready Docker support

This commit is contained in:
unfunny
2026-09-13 14:14:38 -04:00
parent f2016da05a
commit fe7351a7dc
1145 changed files with 30890 additions and 97684 deletions

View File

@@ -2,26 +2,23 @@
* This is an internal module. See {@link MatrixEvent} and {@link RoomEvent} for
* the public classes.
*/
import { type ExtensibleEvent } from "matrix-events-sdk";
import { EventType, type MsgType, RelationType, UNSIGNED_THREAD_ID_FIELD } from "../@types/event.ts";
import { type RoomMember } from "./room-member.ts";
import { type Thread, ThreadEvent, type ThreadEventHandlerMap } from "./thread.ts";
import { type IActionsObject } from "../pushprocessor.ts";
import { type MatrixError } from "../http-api/index.ts";
import { TypedEventEmitter } from "./typed-event-emitter.ts";
import { type EventStatus } from "./event-status.ts";
import { type CryptoBackend } from "../common-crypto/CryptoBackend.ts";
import { type IAnnotatedPushRule } from "../@types/PushRules.ts";
import { type Room } from "./room.ts";
import { type Membership } from "../@types/membership.ts";
import { DecryptionFailureCode } from "../crypto-api/index.ts";
import { type RoomState } from "./room-state.ts";
import { type EmptyObject } from "../@types/common.ts";
export { EventStatus } from "./event-status.ts";
import { ExtensibleEvent, Optional } from "matrix-events-sdk";
import { VerificationRequest } from "../crypto/verification/request/VerificationRequest";
import { EventType, MsgType, RelationType, UNSIGNED_THREAD_ID_FIELD } from "../@types/event";
import { Crypto } from "../crypto";
import { RoomMember } from "./room-member";
import { Thread, ThreadEvent, ThreadEventHandlerMap } from "./thread";
import { IActionsObject } from "../pushprocessor";
import { MatrixError } from "../http-api";
import { TypedEventEmitter } from "./typed-event-emitter";
import { EventStatus } from "./event-status";
import { CryptoBackend } from "../common-crypto/CryptoBackend";
import { IAnnotatedPushRule } from "../@types/PushRules";
export { EventStatus } from "./event-status";
export interface IContent {
[key: string]: any;
"msgtype"?: MsgType | string;
"membership"?: Membership;
"membership"?: string;
"avatar_url"?: string;
"displayname"?: string;
"m.relates_to"?: IEventRelation;
@@ -38,10 +35,7 @@ export interface IUnsigned {
"transaction_id"?: string;
"invite_room_state"?: StrippedState[];
"m.relations"?: Record<RelationType | string, any>;
"msc4354_sticky_duration_ttl_ms"?: number;
[UNSIGNED_THREAD_ID_FIELD.name]?: string;
"membership"?: Membership;
"io.element.msc4115.membership"?: Membership;
}
export interface IThreadBundledRelationship {
latest_event: IEvent;
@@ -57,12 +51,21 @@ export interface IEvent {
origin_server_ts: number;
txn_id?: string;
state_key?: string;
membership?: Membership;
membership?: string;
unsigned: IUnsigned;
redacts?: string;
msc4354_sticky?: {
duration_ms: number;
};
/**
* @deprecated in favour of `sender`
*/
user_id?: string;
/**
* @deprecated in favour of `unsigned.prev_content`
*/
prev_content?: IContent;
/**
* @deprecated in favour of `origin_server_ts`
*/
age?: number;
}
export interface IAggregatedRelation {
origin_server_ts: number;
@@ -110,13 +113,9 @@ export interface IVisibilityChange {
*/
reason: string | null;
}
export interface IMarkedUnreadEvent {
unread: boolean;
}
export interface IClearEvent {
room_id?: string;
type: string;
state_key?: string;
content: Omit<IContent, "membership" | "avatar_url" | "displayname" | "m.relates_to">;
unsigned?: IUnsigned;
}
@@ -125,20 +124,8 @@ interface IKeyRequestRecipient {
deviceId: "*" | string;
}
export interface IDecryptOptions {
/** Whether to emit {@link MatrixEventEvent.Decrypted} events on successful decryption. Defaults to true.
*/
emit?: boolean;
/**
* True if this is a retry, after receiving an update to the session key. (Enables more logging.)
*
* This is only intended for use within the js-sdk.
*
* @internal
*/
isRetry?: boolean;
/**
* @deprecated does nothing
*/
forceRedecryptIfUntrusted?: boolean;
}
/**
@@ -162,29 +149,23 @@ export interface IMessageVisibilityHidden {
*/
readonly reason: string | null;
}
export declare const MAX_STICKY_DURATION_MS = 3600000;
export declare enum MatrixEventEvent {
/**
* An event has been decrypted, or we have failed to decrypt it.
*
* The payload consists of:
*
* * `event` - The {@link MatrixEvent} which we attempted to decrypt.
*
* * `err` - The error that occurred during decryption, or `undefined` if no error occurred.
* Avoid use of this: {@link MatrixEvent.decryptionFailureReason} is more useful.
*/
Decrypted = "Event.decrypted",
BeforeRedaction = "Event.beforeRedaction",
VisibilityChange = "Event.visibilityChange",
LocalEventIdReplaced = "Event.localEventIdReplaced",
Status = "Event.status",
Replaced = "Event.replaced",
RelationsCreated = "Event.relationsCreated",
SentinelUpdated = "Event.sentinelUpdated"
RelationsCreated = "Event.relationsCreated"
}
export type MatrixEventEmittedEvents = MatrixEventEvent | ThreadEvent.Update;
export type MatrixEventHandlerMap = {
/**
* Fires when an event is decrypted
*
* @param event - The matrix event which has been decrypted
* @param err - The error that occurred during decryption, or `undefined` if no error occurred.
*/
[MatrixEventEvent.Decrypted]: (event: MatrixEvent, err?: Error) => void;
[MatrixEventEvent.BeforeRedaction]: (event: MatrixEvent, redactionEvent: MatrixEvent) => void;
[MatrixEventEvent.VisibilityChange]: (event: MatrixEvent, visible: boolean) => void;
@@ -192,7 +173,6 @@ export type MatrixEventHandlerMap = {
[MatrixEventEvent.Status]: (event: MatrixEvent, status: EventStatus | null) => void;
[MatrixEventEvent.Replaced]: (event: MatrixEvent) => void;
[MatrixEventEvent.RelationsCreated]: (relationType: string, eventType: string) => void;
[MatrixEventEvent.SentinelUpdated]: () => void;
} & Pick<ThreadEventHandlerMap, ThreadEvent.Update>;
export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, MatrixEventHandlerMap> {
event: Partial<IEvent>;
@@ -203,17 +183,11 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
private clearEvent?;
private visibility;
private _hasCachedExtEv;
private _cachedExtEv?;
/** If we failed to decrypt this event, the reason for the failure. Otherwise, `null`. */
private _decryptionFailureReason;
private _cachedExtEv;
private senderCurve25519Key;
private claimedEd25519Key;
/**
* If another user forwarded the key to this message
* (eg via [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268)),
* the ID of that user.
*/
private keyForwardedBy?;
private forwardingCurve25519KeyChain;
private untrusted;
private decryptionPromise;
private retryDecryption;
private txnId?;
@@ -222,6 +196,7 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
*/
private thread?;
private threadId?;
private encryptedDisabledForUnverifiedDevices;
localTimestamp: number;
/**
* The room member who sent this event, or null e.g.
@@ -239,13 +214,6 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* Should be read-only
*/
target: RoomMember | null;
/**
* Update the sentinels and forwardLooking flag for this event.
* @param stateContext - the room state to be queried
* @param toStartOfTimeline - if true the event's forwardLooking flag is set false
* @internal
*/
setMetadata(stateContext: RoomState, toStartOfTimeline: boolean): void;
/**
* The sending status of the event.
* @privateRemarks
@@ -255,7 +223,7 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
/**
* most recent error associated with sending the event, if any
* @privateRemarks
* Should be read-only. May not be a MatrixError.
* Should be read-only
*/
error: MatrixError | null;
/**
@@ -267,17 +235,8 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* Should be read-only
*/
forwardLooking: boolean;
verificationRequest?: VerificationRequest;
private readonly reEmitter;
/**
* The timestamp for when this event should expire, in milliseconds.
* Prefers using the server-provided value, but will fall back to local calculation.
*
* This value is **safe** to use, as malicious start time and duration are appropriately capped.
*
* If the event is not a sticky event (or not supported by the server),
* then this returns `undefined`.
*/
readonly unstableStickyExpiresAt: number | undefined;
/**
* Construct a Matrix Event object
*
@@ -294,15 +253,12 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
*
* @deprecated Use stable functions where possible.
*/
get unstableExtensibleEvent(): ExtensibleEvent | undefined;
get unstableExtensibleEvent(): Optional<ExtensibleEvent>;
private invalidateExtensibleEvent;
/**
* Gets the event as it would appear if it had been sent unencrypted.
*
* If the event is encrypted, we attempt to mock up an event as it would have looked had the sender not encrypted it.
* If the event is not encrypted, a copy of it is simply returned as-is.
*
* @returns A shallow copy of the event, in wire format, as it would have been had it not been encrypted.
* Gets the event as though it would appear unencrypted. If the event is already not
* encrypted, it is simply returned as-is.
* @returns The event in wire format.
*/
getEffectiveEvent(): IEvent;
/**
@@ -422,32 +378,16 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
*/
getLocalAge(): number;
/**
* Get the event state_key if it has one. If necessary, this will perform
* string-unpacking on the state key, as per MSC4362. This will return
* <code>undefined</code> for message events.
* @returns The event's `state_key`.
*/
getStateKey(): string | undefined;
/**
* Get the raw event state_key if it has one. This may be string-packed as per
* MSC4362 if the state event is encrypted. This will return <code>undefined
* Get the event state_key if it has one. This will return <code>undefined
* </code> for message events.
* @returns The event's `state_key`.
*/
getWireStateKey(): string | undefined;
getStateKey(): string | undefined;
/**
* Check if this event is a state event.
* @returns True if this is a state event.
*/
isState(): boolean;
/**
* Get the user's room membership at the time the event was sent, as reported
* by the server. This uses MSC4115.
*
* @returns The user's room membership, or `undefined` if the server does
* not report it.
*/
getMembershipAtEvent(): Membership | string | undefined;
/**
* Replace the content of this event with encrypted versions.
* (This is used when sending an event; it should not be used by applications).
@@ -484,8 +424,7 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* couldn't decrypt.
*/
isDecryptionFailure(): boolean;
/** If we failed to decrypt this event, the reason for the failure. Otherwise, `null`. */
get decryptionFailureReason(): DecryptionFailureCode | null;
get isEncryptedDisabledForUnverifiedDevices(): boolean;
shouldAttemptDecryption(): boolean;
/**
* Start the process of trying to decrypt this event.
@@ -500,6 +439,15 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* attempt is completed.
*/
attemptDecryption(crypto: CryptoBackend, options?: IDecryptOptions): Promise<void>;
/**
* Cancel any room key request for this event and resend another.
*
* @param crypto - crypto module
* @param userId - the user who received this event
*
* @returns a promise that resolves when the request is queued
*/
cancelAndResendKeyRequest(crypto: Crypto, userId: string): Promise<void>;
/**
* Calculate the recipients for keyshare requests.
*
@@ -509,6 +457,7 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
*/
getKeyRequestRecipients(userId: string): IKeyRequestRecipient[];
private decryptionLoop;
private badEncryptedMessage;
/**
* Update the cleartext data on this event.
*
@@ -517,14 +466,11 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* @internal
*
* @param decryptionResult - the decryption result, including the plaintext and some key info
*
* @remarks
* Fires {@link MatrixEventEvent.Decrypted}
*/
private setClearData;
/**
* Update the cleartext data on this event after a decryption failure.
*
* @param reason - the textual reason for the failure
*/
private setClearDataForDecryptionFailure;
/**
* Gets the cleartext content for this event. If the event is not encrypted,
* or encryption has not been completed, this will return null.
@@ -568,31 +514,29 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* signing the public curve25519 key with the ed25519 key.
*
* In general, applications should not use this method directly, but should
* instead use {@link crypto-api!CryptoApi#getEncryptionInfoForEvent}.
* instead use MatrixClient.getEventSenderDeviceInfo.
*/
getClaimedEd25519Key(): string | null;
/**
* Returns an empty array.
* Get the curve25519 keys of the devices which were involved in telling us
* about the claimedEd25519Key and sender curve25519 key.
*
* Previously, this returned the chain of Curve25519 keys through which
* this session was forwarded, via `m.forwarded_room_key` events.
* However, that is not cryptographically reliable, and clients should not
* be using it.
* Normally this will be empty, but in the case of a forwarded megolm
* session, the sender keys are sent to us by another device (the forwarding
* device), which we need to trust to do this. In that case, the result will
* be a list consisting of one entry.
*
* @see https://github.com/matrix-org/matrix-spec/issues/1089
* @deprecated
* If the device that sent us the key (A) got it from another device which
* it wasn't prepared to vouch for (B), the result will be [A, B]. And so on.
*
* @returns base64-encoded curve25519 keys, from oldest to newest.
*/
getForwardingCurve25519KeyChain(): string[];
/**
* @deprecated always returns false
* Whether the decryption key was obtained from an untrusted source. If so,
* we cannot verify the authenticity of the message.
*/
isKeySourceUntrusted(): false;
/**
* If another user forwarded the key to this message
* (eg via [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268)),
* get the ID of that user.
*/
getKeyForwardingUser(): string | undefined;
isKeySourceUntrusted(): boolean | undefined;
getUnsigned(): IUnsigned;
setUnsigned(unsigned: IUnsigned): void;
unmarkLocallyRedacted(): boolean;
@@ -623,11 +567,8 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* if it were redacted before it was sent to us
*
* @param redactionEvent - event causing the redaction
* @param room - the room in which the event exists
*/
makeRedacted(redactionEvent: MatrixEvent, room: Room): void;
private moveAllRelatedToMainTimeline;
private moveToMainTimeline;
makeRedacted(redactionEvent: MatrixEvent): void;
/**
* Check if this event has been redacted
*
@@ -662,7 +603,7 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
*
* @returns The redaction event JSON, or an empty object
*/
getRedactionEvent(): IEvent | EmptyObject | null;
getRedactionEvent(): IEvent | {} | null;
/**
* Get the push actions, if known, for this event
*
@@ -675,6 +616,14 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* @returns push actions
*/
getPushDetails(): PushDetails;
/**
* Set the push actions for this event.
* Clears rule from push details if present
* @deprecated use `setPushDetails`
*
* @param pushActions - push actions
*/
setPushActions(pushActions: IActionsObject | null): void;
/**
* Set the push details for this event.
*
@@ -750,6 +699,11 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* For relations and redactions, returns the event_id this event is referring to.
*/
getAssociatedId(): string | undefined;
/**
* Checks if this event is associated with another event. See `getAssociatedId`.
* @deprecated use hasAssociation instead.
*/
hasAssocation(): boolean;
/**
* Checks if this event is associated with another event. See `getAssociatedId`.
*/
@@ -798,25 +752,20 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
* @param otherEvent - The other event to check against.
* @returns True if the events are the same, false otherwise.
*/
isEquivalentTo(otherEvent?: MatrixEvent): boolean;
isEquivalentTo(otherEvent: MatrixEvent): boolean;
/**
* Summarise the event as JSON.
* Summarise the event as JSON. This is currently used by React SDK's view
* event source feature and Seshat's event indexing, so take care when
* adjusting the output here.
*
* If encrypted, include both the decrypted and encrypted view of the event.
*
* This is named `toJSON` for use with `JSON.stringify` which checks objects
* for functions named `toJSON` and will call them to customise the output
* if they are defined.
*
* **WARNING** Do not log the result of this method; otherwise, it will end up
* in rageshakes, leading to a privacy violation.
*
* @deprecated Prefer to use {@link MatrixEvent#getEffectiveEvent} or similar.
* This method will be removed soon; it is too easy to use it accidentally
* and cause a privacy violation (cf https://github.com/vector-im/element-web/issues/26380).
* In any case, the value it returns is not a faithful serialization of the object.
*/
toJSON(): object;
setVerificationRequest(request: VerificationRequest): void;
setTxnId(txnId: string): void;
getTxnId(): string | undefined;
/**
@@ -829,16 +778,5 @@ export declare class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEve
*/
getThread(): Thread | undefined;
setThreadId(threadId?: string): void;
/**
* Unstable getter to try and get the sticky information for the event.
* If the event is not a sticky event (or not supported by the server),
* then this returns `undefined`.
*
* `duration_ms` is safely bounded to a hour.
*/
get unstableStickyInfo(): {
duration_ms: number;
duration_ttl_ms?: number;
} | undefined;
}
//# sourceMappingURL=event.d.ts.map