matrix-react-sdk
Version:
SDK for matrix.org using React
137 lines (136 loc) • 6.56 kB
TypeScript
import { MockedObject } from "jest-mock";
import { MatrixEvent, Room, User, IContent, RoomMember, MatrixClient, EventType, IEventRelation, IUnsigned, IPusher, OidcClientConfig } from "matrix-js-sdk/src/matrix";
import { KnownMembership } from "matrix-js-sdk/src/types";
import { MatrixRTCSessionManager } from "matrix-js-sdk/src/matrixrtc";
import type { Membership } from "matrix-js-sdk/src/types";
import { ValidatedServerConfig } from "../../src/utils/ValidatedServerConfig";
import { AsyncStoreWithClient } from "../../src/stores/AsyncStoreWithClient";
/**
* Stub out the MatrixClient, and configure the MatrixClientPeg object to
* return it when get() is called.
*
* TODO: once the components are updated to get their MatrixClients from
* the react context, we can get rid of this and just inject a test client
* via the context instead.
*
* See also {@link getMockClientWithEventEmitter} which does something similar but different.
*/
export declare function stubClient(): MatrixClient;
/**
* Create a stubbed-out MatrixClient
*
* @returns {object} MatrixClient stub
*/
export declare function createTestClient(): MatrixClient;
export declare function createStubMatrixRTC(): MatrixRTCSessionManager;
type MakeEventPassThruProps = {
user: User["userId"];
relatesTo?: IEventRelation;
event?: boolean;
ts?: number;
skey?: string;
};
type MakeEventProps = MakeEventPassThruProps & {
/** If provided will be used as event Id. Else an Id is generated. */
id?: string;
type: string;
redacts?: string;
content: IContent;
room?: Room["roomId"];
prev_content?: IContent;
unsigned?: IUnsigned;
};
export declare const mkRoomCreateEvent: (userId: string, roomId: string, content?: IContent) => MatrixEvent;
/**
* Create an Event.
* @param {Object} opts Values for the event.
* @param {string} opts.type The event.type
* @param {string} opts.room The event.room_id
* @param {string} opts.user The event.user_id
* @param {string=} opts.skey Optional. The state key (auto inserts empty string)
* @param {number=} opts.ts Optional. Timestamp for the event
* @param {Object} opts.content The event.content
* @param {boolean} opts.event True to make a MatrixEvent.
* @param {unsigned=} opts.unsigned
* @return {Object} a JSON object representing this event.
*/
export declare function mkEvent(opts: MakeEventProps): MatrixEvent;
/**
* Create an m.room.member event.
* @param {Object} opts Values for the membership.
* @param {string} opts.room The room ID for the event.
* @param {string} opts.mship The content.membership for the event.
* @param {string} opts.prevMship The prev_content.membership for the event.
* @param {number=} opts.ts Optional. Timestamp for the event
* @param {string} opts.user The user ID for the event.
* @param {RoomMember} opts.target The target of the event.
* @param {string=} opts.skey The other user ID for the event if applicable
* e.g. for invites/bans.
* @param {string} opts.name The content.displayname for the event.
* @param {string=} opts.url The content.avatar_url for the event.
* @param {boolean} opts.event True to make a MatrixEvent.
* @return {Object|MatrixEvent} The event
*/
export declare function mkMembership(opts: MakeEventPassThruProps & {
room: Room["roomId"];
mship: Membership;
prevMship?: Membership;
name?: string;
url?: string;
skey?: string;
target?: RoomMember;
}): MatrixEvent;
export declare function mkRoomMember(roomId: string, userId: string, membership?: KnownMembership, isKicked?: boolean, prevMemberContent?: Partial<IContent>): RoomMember;
export type MessageEventProps = MakeEventPassThruProps & {
room: Room["roomId"];
relatesTo?: IEventRelation;
msg?: string;
};
/**
* Creates a "🙃" reaction for the given event.
* Uses the same room and user as for the event.
*
* @returns The reaction event
*/
export declare const mkReaction: (event: MatrixEvent, opts?: Partial<MakeEventProps>) => MatrixEvent;
/**
* Create an m.room.message event.
* @param {Object} opts Values for the message
* @param {string} opts.room The room ID for the event.
* @param {string} opts.user The user ID for the event.
* @param {number} opts.ts The timestamp for the event.
* @param {boolean} opts.event True to make a MatrixEvent.
* @param {string=} opts.msg Optional. The content.body for the event.
* @param {string=} opts.format Optional. The content.format for the event.
* @param {string=} opts.formattedMsg Optional. The content.formatted_body for the event.
* @return {Object|MatrixEvent} The event
*/
export declare function mkMessage({ msg, format, formattedMsg, relatesTo, ...opts }: MakeEventPassThruProps & Pick<MakeEventProps, "id"> & {
room: Room["roomId"];
msg?: string;
format?: string;
formattedMsg?: string;
}): MatrixEvent;
export declare function mkStubRoom(roomId: string | null | undefined, name: string | undefined, client: MatrixClient | undefined): Room;
export declare function mkServerConfig(hsUrl: string, isUrl: string, delegatedAuthentication?: OidcClientConfig): ValidatedServerConfig;
export declare const setupAsyncStoreWithClient: <T extends Object = any>(store: AsyncStoreWithClient<T>, client: MatrixClient) => Promise<void>;
export declare const resetAsyncStoreWithClient: <T extends Object = any>(store: AsyncStoreWithClient<T>) => Promise<void>;
export declare const mockStateEventImplementation: (events: MatrixEvent[]) => {
(eventType: EventType | string): MatrixEvent[];
(eventType: EventType | string, stateKey: string): MatrixEvent;
};
export declare const mkRoom: (client: MatrixClient, roomId: string, rooms?: ReturnType<typeof mkStubRoom>[]) => MockedObject<Room>;
/**
* Upserts given events into room.currentState
* @param room
* @param events
*/
export declare const upsertRoomStateEvents: (room: Room, events: MatrixEvent[]) => void;
export declare const mkSpace: (client: MatrixClient, spaceId: string, rooms?: ReturnType<typeof mkStubRoom>[], children?: string[]) => MockedObject<Room>;
export declare const mkRoomMemberJoinEvent: (user: string, room: string, content?: IContent) => MatrixEvent;
export declare const mkRoomCanonicalAliasEvent: (userId: string, roomId: string, alias: string) => MatrixEvent;
export declare const mkThirdPartyInviteEvent: (user: string, displayName: string, room: string) => MatrixEvent;
export declare const mkPusher: (extra?: Partial<IPusher>) => IPusher;
/** Add a mute rule for a room. */
export declare function muteRoom(room: Room): void;
export {};