Skip to content

Commit

Permalink
Improve types for reading events (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
robintown authored Jun 25, 2022
1 parent 65af255 commit 3922a2c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/ClientWidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export class ClientWidgetApi extends EventEmitter {

const limit = request.data.limit || 0;

let events: Promise<unknown[]> = Promise.resolve([]);
let events: Promise<IRoomEvent[]> = Promise.resolve([]);
if (request.data.state_key !== undefined) {
const stateKey = request.data.state_key === true ? undefined : request.data.state_key.toString();
if (!this.canReceiveStateEvent(request.data.type, stateKey)) {
Expand Down
5 changes: 3 additions & 2 deletions src/WidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { ISendEventFromWidgetRequestData, ISendEventFromWidgetResponseData } fro
import { EventDirection, WidgetEventCapability } from "./models/WidgetEventCapability";
import { INavigateActionRequestData } from "./interfaces/NavigateAction";
import { IReadEventFromWidgetRequestData, IReadEventFromWidgetResponseData } from "./interfaces/ReadEventAction";
import { IRoomEvent } from "./interfaces/IRoomEvent";
import { Symbols } from "./Symbols";

/**
Expand Down Expand Up @@ -366,7 +367,7 @@ export class WidgetApi extends EventEmitter {
limit = 25,
msgtype?: string,
roomIds?: (string | Symbols.AnyRoom)[],
): Promise<unknown> {
): Promise<IRoomEvent[]> {
const data: IReadEventFromWidgetRequestData = {type: eventType, msgtype: msgtype, limit};
if (roomIds) {
if (roomIds.includes(Symbols.AnyRoom)) {
Expand All @@ -386,7 +387,7 @@ export class WidgetApi extends EventEmitter {
limit = 25,
stateKey?: string,
roomIds?: (string | Symbols.AnyRoom)[],
): Promise<unknown> {
): Promise<IRoomEvent[]> {
const data: IReadEventFromWidgetRequestData = {
type: eventType,
state_key: stateKey === undefined ? true : stateKey,
Expand Down
10 changes: 5 additions & 5 deletions src/driver/WidgetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Capability, IOpenIDCredentials, OpenIDRequestState, SimpleObservable } from "..";
import { Capability, IOpenIDCredentials, OpenIDRequestState, SimpleObservable, IRoomEvent } from "..";

export interface ISendEventDetails {
roomId: string;
Expand Down Expand Up @@ -88,14 +88,14 @@ export abstract class WidgetDriver {
* as possible".
* @param roomIds When null, the user's currently viewed room. Otherwise, the list of room IDs
* to look within, possibly containing Symbols.AnyRoom to denote all known rooms.
* @returns {Promise<*[]>} Resolves to the room events, or an empty array.
* @returns {Promise<IRoomEvent[]>} Resolves to the room events, or an empty array.
*/
public readRoomEvents(
eventType: string,
msgtype: string | undefined,
limit: number,
roomIds: string[] = null,
): Promise<unknown[]> {
): Promise<IRoomEvent[]> {
return Promise.resolve([]);
}

Expand All @@ -112,14 +112,14 @@ export abstract class WidgetDriver {
* as possible".
* @param roomIds When null, the user's currently viewed room. Otherwise, the list of room IDs
* to look within, possibly containing Symbols.AnyRoom to denote all known rooms.
* @returns {Promise<*[]>} Resolves to the state events, or an empty array.
* @returns {Promise<IRoomEvent[]>} Resolves to the state events, or an empty array.
*/
public readStateEvents(
eventType: string,
stateKey: string | undefined,
limit: number,
roomIds: string[] = null,
): Promise<unknown[]> {
): Promise<IRoomEvent[]> {
return Promise.resolve([]);
}

Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/ReadEventAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { IWidgetApiRequest, IWidgetApiRequestData } from "./IWidgetApiRequest";
import { WidgetApiFromWidgetAction } from "./WidgetApiAction";
import { IWidgetApiResponseData } from "./IWidgetApiResponse";
import { IRoomEvent } from "./IRoomEvent";
import { Symbols } from "../Symbols";

export interface IReadEventFromWidgetRequestData extends IWidgetApiRequestData {
Expand All @@ -33,7 +34,7 @@ export interface IReadEventFromWidgetActionRequest extends IWidgetApiRequest {
}

export interface IReadEventFromWidgetResponseData extends IWidgetApiResponseData {
events: unknown[];
events: IRoomEvent[];
}

export interface IReadEventFromWidgetActionResponse extends IReadEventFromWidgetActionRequest {
Expand Down

0 comments on commit 3922a2c

Please sign in to comment.