Skip to content

Commit

Permalink
Merge pull request #37 from matrix-org/travis/change-read
Browse files Browse the repository at this point in the history
Replace read with receive as per MSC2762
  • Loading branch information
turt2live authored May 17, 2021
2 parents d920671 + ced455a commit ad4c783
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 54 deletions.
14 changes: 2 additions & 12 deletions src/ClientWidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,6 @@ export class ClientWidgetApi extends EventEmitter {
e.matchesAsStateEvent(eventType, stateKey) && e.direction === EventDirection.Receive);
}

public canReadRoomEvent(eventType: string, msgtype: string = null): boolean {
return this.allowedEvents.some(e =>
e.matchesAsRoomEvent(eventType, msgtype) && e.direction === EventDirection.Read);
}

public canReadStateEvent(eventType: string, stateKey: string): boolean {
return this.allowedEvents.some(e =>
e.matchesAsStateEvent(eventType, stateKey) && e.direction === EventDirection.Read);
}

public stop() {
this.isStopped = true;
this.transport.stop();
Expand Down Expand Up @@ -359,14 +349,14 @@ export class ClientWidgetApi extends EventEmitter {
let events: Promise<unknown[]> = Promise.resolve([]);
if (request.data.state_key !== undefined) {
const stateKey = request.data.state_key === true ? undefined : request.data.state_key.toString();
if (!this.canReadStateEvent(request.data.type, stateKey)) {
if (!this.canReceiveStateEvent(request.data.type, stateKey)) {
return this.transport.reply<IWidgetApiErrorResponseData>(request, {
error: {message: "Cannot read state events of this type"},
});
}
events = this.driver.readStateEvents(request.data.type, stateKey, limit);
} else {
if (!this.canReadRoomEvent(request.data.type, request.data.msgtype)) {
if (!this.canReceiveRoomEvent(request.data.type, request.data.msgtype)) {
return this.transport.reply<IWidgetApiErrorResponseData>(request, {
error: {message: "Cannot read room events of this type"},
});
Expand Down
32 changes: 0 additions & 32 deletions src/WidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,6 @@ export class WidgetApi extends EventEmitter {
this.requestCapability(WidgetEventCapability.forStateEvent(EventDirection.Receive, eventType, stateKey).raw);
}

/**
* Requests the capability to read a given state event with optional explicit
* state key. It is not guaranteed to be allowed, but will be asked for if the
* negotiation has not already happened.
* @param {string} eventType The state event type to ask for.
* @param {string} stateKey If specified, the specific state key to request.
* Otherwise all state keys will be requested.
*/
public requestCapabilityToReadState(eventType: string, stateKey?: string) {
this.requestCapability(WidgetEventCapability.forStateEvent(EventDirection.Read, eventType, stateKey).raw);
}

/**
* Requests the capability to send a given room event. It is not guaranteed to be
* allowed, but will be asked for if the negotiation has not already happened.
Expand All @@ -197,15 +185,6 @@ export class WidgetApi extends EventEmitter {
this.requestCapability(WidgetEventCapability.forRoomEvent(EventDirection.Receive, eventType).raw);
}

/**
* Requests the capability to read a given room event. It is not guaranteed to be allowed,
* but will be asked for if the negotiation has not already happened.
* @param {string} eventType The room event type to ask for.
*/
public requestCapabilityToReadEvent(eventType: string) {
this.requestCapability(WidgetEventCapability.forRoomEvent(EventDirection.Read, eventType).raw);
}

/**
* Requests the capability to send a given message event with optional explicit
* `msgtype`. It is not guaranteed to be allowed, but will be asked for if the
Expand All @@ -228,17 +207,6 @@ export class WidgetApi extends EventEmitter {
this.requestCapability(WidgetEventCapability.forRoomMessageEvent(EventDirection.Receive, msgtype).raw);
}

/**
* Requests the capability to read a given message event with optional explicit
* `msgtype`. It is not guaranteed to be allowed, but will be asked for if the
* negotiation has not already happened.
* @param {string} msgtype If specified, the specific msgtype to request.
* Otherwise all message types will be requested.
*/
public requestCapabilityToReadMessage(msgtype?: string) {
this.requestCapability(WidgetEventCapability.forRoomMessageEvent(EventDirection.Read, msgtype).raw);
}

/**
* Requests an OpenID Connect token from the client for the currently logged in
* user. This token can be validated server-side with the federation API. Note
Expand Down
10 changes: 0 additions & 10 deletions src/models/WidgetEventCapability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Capability } from "..";
export enum EventDirection {
Send = "send",
Receive = "receive",
Read = "read",
}

export class WidgetEventCapability {
Expand Down Expand Up @@ -124,15 +123,6 @@ export class WidgetEventCapability {
isState = true;
eventSegment = cap.substring("org.matrix.msc2762.receive.state_event:".length);
}
} else if (cap.startsWith("org.matrix.msc2762.read.")) {
if (cap.startsWith("org.matrix.msc2762.read.event:")) {
direction = EventDirection.Read;
eventSegment = cap.substring("org.matrix.msc2762.read.event:".length);
} else if (cap.startsWith("org.matrix.msc2762.read.state_event:")) {
direction = EventDirection.Read;
isState = true;
eventSegment = cap.substring("org.matrix.msc2762.read.state_event:".length);
}
}

if (direction === null) continue;
Expand Down

0 comments on commit ad4c783

Please sign in to comment.