Skip to content

Commit ad4c783

Browse files
authored
Merge pull request #37 from matrix-org/travis/change-read
Replace read with receive as per MSC2762
2 parents d920671 + ced455a commit ad4c783

File tree

3 files changed

+2
-54
lines changed

3 files changed

+2
-54
lines changed

src/ClientWidgetApi.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,6 @@ export class ClientWidgetApi extends EventEmitter {
157157
e.matchesAsStateEvent(eventType, stateKey) && e.direction === EventDirection.Receive);
158158
}
159159

160-
public canReadRoomEvent(eventType: string, msgtype: string = null): boolean {
161-
return this.allowedEvents.some(e =>
162-
e.matchesAsRoomEvent(eventType, msgtype) && e.direction === EventDirection.Read);
163-
}
164-
165-
public canReadStateEvent(eventType: string, stateKey: string): boolean {
166-
return this.allowedEvents.some(e =>
167-
e.matchesAsStateEvent(eventType, stateKey) && e.direction === EventDirection.Read);
168-
}
169-
170160
public stop() {
171161
this.isStopped = true;
172162
this.transport.stop();
@@ -359,14 +349,14 @@ export class ClientWidgetApi extends EventEmitter {
359349
let events: Promise<unknown[]> = Promise.resolve([]);
360350
if (request.data.state_key !== undefined) {
361351
const stateKey = request.data.state_key === true ? undefined : request.data.state_key.toString();
362-
if (!this.canReadStateEvent(request.data.type, stateKey)) {
352+
if (!this.canReceiveStateEvent(request.data.type, stateKey)) {
363353
return this.transport.reply<IWidgetApiErrorResponseData>(request, {
364354
error: {message: "Cannot read state events of this type"},
365355
});
366356
}
367357
events = this.driver.readStateEvents(request.data.type, stateKey, limit);
368358
} else {
369-
if (!this.canReadRoomEvent(request.data.type, request.data.msgtype)) {
359+
if (!this.canReceiveRoomEvent(request.data.type, request.data.msgtype)) {
370360
return this.transport.reply<IWidgetApiErrorResponseData>(request, {
371361
error: {message: "Cannot read room events of this type"},
372362
});

src/WidgetApi.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,6 @@ export class WidgetApi extends EventEmitter {
167167
this.requestCapability(WidgetEventCapability.forStateEvent(EventDirection.Receive, eventType, stateKey).raw);
168168
}
169169

170-
/**
171-
* Requests the capability to read a given state event with optional explicit
172-
* state key. It is not guaranteed to be allowed, but will be asked for if the
173-
* negotiation has not already happened.
174-
* @param {string} eventType The state event type to ask for.
175-
* @param {string} stateKey If specified, the specific state key to request.
176-
* Otherwise all state keys will be requested.
177-
*/
178-
public requestCapabilityToReadState(eventType: string, stateKey?: string) {
179-
this.requestCapability(WidgetEventCapability.forStateEvent(EventDirection.Read, eventType, stateKey).raw);
180-
}
181-
182170
/**
183171
* Requests the capability to send a given room event. It is not guaranteed to be
184172
* allowed, but will be asked for if the negotiation has not already happened.
@@ -197,15 +185,6 @@ export class WidgetApi extends EventEmitter {
197185
this.requestCapability(WidgetEventCapability.forRoomEvent(EventDirection.Receive, eventType).raw);
198186
}
199187

200-
/**
201-
* Requests the capability to read a given room event. It is not guaranteed to be allowed,
202-
* but will be asked for if the negotiation has not already happened.
203-
* @param {string} eventType The room event type to ask for.
204-
*/
205-
public requestCapabilityToReadEvent(eventType: string) {
206-
this.requestCapability(WidgetEventCapability.forRoomEvent(EventDirection.Read, eventType).raw);
207-
}
208-
209188
/**
210189
* Requests the capability to send a given message event with optional explicit
211190
* `msgtype`. It is not guaranteed to be allowed, but will be asked for if the
@@ -228,17 +207,6 @@ export class WidgetApi extends EventEmitter {
228207
this.requestCapability(WidgetEventCapability.forRoomMessageEvent(EventDirection.Receive, msgtype).raw);
229208
}
230209

231-
/**
232-
* Requests the capability to read a given message event with optional explicit
233-
* `msgtype`. It is not guaranteed to be allowed, but will be asked for if the
234-
* negotiation has not already happened.
235-
* @param {string} msgtype If specified, the specific msgtype to request.
236-
* Otherwise all message types will be requested.
237-
*/
238-
public requestCapabilityToReadMessage(msgtype?: string) {
239-
this.requestCapability(WidgetEventCapability.forRoomMessageEvent(EventDirection.Read, msgtype).raw);
240-
}
241-
242210
/**
243211
* Requests an OpenID Connect token from the client for the currently logged in
244212
* user. This token can be validated server-side with the federation API. Note

src/models/WidgetEventCapability.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { Capability } from "..";
1919
export enum EventDirection {
2020
Send = "send",
2121
Receive = "receive",
22-
Read = "read",
2322
}
2423

2524
export class WidgetEventCapability {
@@ -124,15 +123,6 @@ export class WidgetEventCapability {
124123
isState = true;
125124
eventSegment = cap.substring("org.matrix.msc2762.receive.state_event:".length);
126125
}
127-
} else if (cap.startsWith("org.matrix.msc2762.read.")) {
128-
if (cap.startsWith("org.matrix.msc2762.read.event:")) {
129-
direction = EventDirection.Read;
130-
eventSegment = cap.substring("org.matrix.msc2762.read.event:".length);
131-
} else if (cap.startsWith("org.matrix.msc2762.read.state_event:")) {
132-
direction = EventDirection.Read;
133-
isState = true;
134-
eventSegment = cap.substring("org.matrix.msc2762.read.state_event:".length);
135-
}
136126
}
137127

138128
if (direction === null) continue;

0 commit comments

Comments
 (0)