Add type assertions where we know an event is a room event (has room_id) (#9498)

This commit is contained in:
Michael Telatynski 2022-10-25 19:57:36 +01:00 committed by GitHub
parent 306a2449e5
commit b7ff56a726
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 12 deletions

View file

@ -18,6 +18,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { import {
ClientWidgetApi, ClientWidgetApi,
IModalWidgetOpenRequest, IModalWidgetOpenRequest,
IRoomEvent,
IStickerActionRequest, IStickerActionRequest,
IStickyActionRequest, IStickyActionRequest,
ITemplateParams, ITemplateParams,
@ -465,7 +466,7 @@ export class StopGapWidget extends EventEmitter {
private onToDeviceEvent = async (ev: MatrixEvent) => { private onToDeviceEvent = async (ev: MatrixEvent) => {
await this.client.decryptEventIfNeeded(ev); await this.client.decryptEventIfNeeded(ev);
if (ev.isDecryptionFailure()) return; 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) { private feedEvent(ev: MatrixEvent) {
@ -509,7 +510,7 @@ export class StopGapWidget extends EventEmitter {
this.readUpToMap[ev.getRoomId()] = ev.getId(); this.readUpToMap[ev.getRoomId()] = ev.getId();
const raw = ev.getEffectiveEvent(); 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); logger.error("Error sending event to widget: ", e);
}); });
} }

View file

@ -34,7 +34,7 @@ import {
} from "matrix-widget-api"; } from "matrix-widget-api";
import { ClientEvent, ITurnServer as IClientTurnServer } from "matrix-js-sdk/src/client"; import { ClientEvent, ITurnServer as IClientTurnServer } from "matrix-js-sdk/src/client";
import { EventType } from "matrix-js-sdk/src/@types/event"; 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 { Room } from "matrix-js-sdk/src/models/room";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; 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 limitPerRoom = limitPerRoom > 0 ? Math.min(limitPerRoom, Number.MAX_SAFE_INTEGER) : Number.MAX_SAFE_INTEGER; // relatively arbitrary
const rooms = this.pickRooms(roomIds); const rooms = this.pickRooms(roomIds);
const allResults: IEvent[] = []; const allResults: IRoomEvent[] = [];
for (const room of rooms) { for (const room of rooms) {
const results: MatrixEvent[] = []; const results: MatrixEvent[] = [];
const events = room.getLiveTimeline().getEvents(); // timelines are most recent last const events = room.getLiveTimeline().getEvents(); // timelines are most recent last
@ -323,7 +323,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
results.push(ev); results.push(ev);
} }
results.forEach(e => allResults.push(e.getEffectiveEvent())); results.forEach(e => allResults.push(e.getEffectiveEvent() as IRoomEvent));
} }
return allResults; 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 limitPerRoom = limitPerRoom > 0 ? Math.min(limitPerRoom, Number.MAX_SAFE_INTEGER) : Number.MAX_SAFE_INTEGER; // relatively arbitrary
const rooms = this.pickRooms(roomIds); const rooms = this.pickRooms(roomIds);
const allResults: IEvent[] = []; const allResults: IRoomEvent[] = [];
for (const room of rooms) { for (const room of rooms) {
const results: MatrixEvent[] = []; const results: MatrixEvent[] = [];
const state: Map<string, MatrixEvent> = room.currentState.events.get(eventType); 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; return allResults;
} }
@ -459,7 +459,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
}); });
return { return {
chunk: events.map(e => e.getEffectiveEvent()), chunk: events.map(e => e.getEffectiveEvent() as IRoomEvent),
nextBatch, nextBatch,
prevBatch, prevBatch,
}; };

View file

@ -6,7 +6,7 @@ Array [
Array [ Array [
Object { Object {
"deviceInfo": DeviceInfo { "deviceInfo": DeviceInfo {
"algorithms": undefined, "algorithms": Array [],
"deviceId": "aliceWeb", "deviceId": "aliceWeb",
"keys": Object {}, "keys": Object {},
"known": false, "known": false,
@ -18,7 +18,7 @@ Array [
}, },
Object { Object {
"deviceInfo": DeviceInfo { "deviceInfo": DeviceInfo {
"algorithms": undefined, "algorithms": Array [],
"deviceId": "aliceMobile", "deviceId": "aliceMobile",
"keys": Object {}, "keys": Object {},
"known": false, "known": false,
@ -37,7 +37,7 @@ Array [
Array [ Array [
Object { Object {
"deviceInfo": DeviceInfo { "deviceInfo": DeviceInfo {
"algorithms": undefined, "algorithms": Array [],
"deviceId": "bobDesktop", "deviceId": "bobDesktop",
"keys": Object {}, "keys": Object {},
"known": false, "known": false,

View file

@ -28,7 +28,7 @@ import { isSelfLocation } from "../../../src/utils/location";
describe("isSelfLocation", () => { describe("isSelfLocation", () => {
it("Returns true for a full m.asset event", () => { it("Returns true for a full m.asset event", () => {
const content = makeLocationContent("", '0'); const content = makeLocationContent("", '0', Date.now());
expect(isSelfLocation(content)).toBe(true); expect(isSelfLocation(content)).toBe(true);
}); });