Add type assertions where we know an event is a room event (has room_id) (#9498)
This commit is contained in:
parent
306a2449e5
commit
b7ff56a726
4 changed files with 13 additions and 12 deletions
|
@ -18,6 +18,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
|
|||
import {
|
||||
ClientWidgetApi,
|
||||
IModalWidgetOpenRequest,
|
||||
IRoomEvent,
|
||||
IStickerActionRequest,
|
||||
IStickyActionRequest,
|
||||
ITemplateParams,
|
||||
|
@ -465,7 +466,7 @@ export class StopGapWidget extends EventEmitter {
|
|||
private onToDeviceEvent = async (ev: MatrixEvent) => {
|
||||
await this.client.decryptEventIfNeeded(ev);
|
||||
if (ev.isDecryptionFailure()) return;
|
||||
await this.messaging.feedToDevice(ev.getEffectiveEvent(), ev.isEncrypted());
|
||||
await this.messaging.feedToDevice(ev.getEffectiveEvent() as IRoomEvent, ev.isEncrypted());
|
||||
};
|
||||
|
||||
private feedEvent(ev: MatrixEvent) {
|
||||
|
@ -509,7 +510,7 @@ export class StopGapWidget extends EventEmitter {
|
|||
this.readUpToMap[ev.getRoomId()] = ev.getId();
|
||||
|
||||
const raw = ev.getEffectiveEvent();
|
||||
this.messaging.feedEvent(raw, this.eventListenerRoomId).catch(e => {
|
||||
this.messaging.feedEvent(raw as IRoomEvent, this.eventListenerRoomId).catch(e => {
|
||||
logger.error("Error sending event to widget: ", e);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import {
|
|||
} from "matrix-widget-api";
|
||||
import { ClientEvent, ITurnServer as IClientTurnServer } from "matrix-js-sdk/src/client";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
import { IContent, IEvent, MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { IContent, MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
|
||||
|
@ -310,7 +310,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||
limitPerRoom = limitPerRoom > 0 ? Math.min(limitPerRoom, Number.MAX_SAFE_INTEGER) : Number.MAX_SAFE_INTEGER; // relatively arbitrary
|
||||
|
||||
const rooms = this.pickRooms(roomIds);
|
||||
const allResults: IEvent[] = [];
|
||||
const allResults: IRoomEvent[] = [];
|
||||
for (const room of rooms) {
|
||||
const results: MatrixEvent[] = [];
|
||||
const events = room.getLiveTimeline().getEvents(); // timelines are most recent last
|
||||
|
@ -323,7 +323,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||
results.push(ev);
|
||||
}
|
||||
|
||||
results.forEach(e => allResults.push(e.getEffectiveEvent()));
|
||||
results.forEach(e => allResults.push(e.getEffectiveEvent() as IRoomEvent));
|
||||
}
|
||||
return allResults;
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||
limitPerRoom = limitPerRoom > 0 ? Math.min(limitPerRoom, Number.MAX_SAFE_INTEGER) : Number.MAX_SAFE_INTEGER; // relatively arbitrary
|
||||
|
||||
const rooms = this.pickRooms(roomIds);
|
||||
const allResults: IEvent[] = [];
|
||||
const allResults: IRoomEvent[] = [];
|
||||
for (const room of rooms) {
|
||||
const results: MatrixEvent[] = [];
|
||||
const state: Map<string, MatrixEvent> = room.currentState.events.get(eventType);
|
||||
|
@ -350,7 +350,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||
}
|
||||
}
|
||||
|
||||
results.slice(0, limitPerRoom).forEach(e => allResults.push(e.getEffectiveEvent()));
|
||||
results.slice(0, limitPerRoom).forEach(e => allResults.push(e.getEffectiveEvent() as IRoomEvent));
|
||||
}
|
||||
return allResults;
|
||||
}
|
||||
|
@ -459,7 +459,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||
});
|
||||
|
||||
return {
|
||||
chunk: events.map(e => e.getEffectiveEvent()),
|
||||
chunk: events.map(e => e.getEffectiveEvent() as IRoomEvent),
|
||||
nextBatch,
|
||||
prevBatch,
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@ Array [
|
|||
Array [
|
||||
Object {
|
||||
"deviceInfo": DeviceInfo {
|
||||
"algorithms": undefined,
|
||||
"algorithms": Array [],
|
||||
"deviceId": "aliceWeb",
|
||||
"keys": Object {},
|
||||
"known": false,
|
||||
|
@ -18,7 +18,7 @@ Array [
|
|||
},
|
||||
Object {
|
||||
"deviceInfo": DeviceInfo {
|
||||
"algorithms": undefined,
|
||||
"algorithms": Array [],
|
||||
"deviceId": "aliceMobile",
|
||||
"keys": Object {},
|
||||
"known": false,
|
||||
|
@ -37,7 +37,7 @@ Array [
|
|||
Array [
|
||||
Object {
|
||||
"deviceInfo": DeviceInfo {
|
||||
"algorithms": undefined,
|
||||
"algorithms": Array [],
|
||||
"deviceId": "bobDesktop",
|
||||
"keys": Object {},
|
||||
"known": false,
|
||||
|
|
|
@ -28,7 +28,7 @@ import { isSelfLocation } from "../../../src/utils/location";
|
|||
|
||||
describe("isSelfLocation", () => {
|
||||
it("Returns true for a full m.asset event", () => {
|
||||
const content = makeLocationContent("", '0');
|
||||
const content = makeLocationContent("", '0', Date.now());
|
||||
expect(isSelfLocation(content)).toBe(true);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue