You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
Fix predecessor types, nowhere does the spec say it can be null
(#3159)
* Fix predecessor types, nowhere does the spec say it can be `null` * Iterate * Update comment * update test
This commit is contained in:
committed by
GitHub
parent
ad98706db4
commit
89df43a975
@ -3392,7 +3392,7 @@ describe("Room", function () {
|
|||||||
const useMsc3946 = true;
|
const useMsc3946 = true;
|
||||||
expect(room.findPredecessor(useMsc3946)).toEqual({
|
expect(room.findPredecessor(useMsc3946)).toEqual({
|
||||||
roomId: "otherreplacedroomid",
|
roomId: "otherreplacedroomid",
|
||||||
eventId: null, // m.predecessor did not include an event_id
|
eventId: undefined, // m.predecessor did not include an event_id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -973,22 +973,24 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
|
|||||||
* the roomId and last eventId of the predecessor room.
|
* the roomId and last eventId of the predecessor room.
|
||||||
* If msc3946ProcessDynamicPredecessor is true, use m.predecessor events
|
* If msc3946ProcessDynamicPredecessor is true, use m.predecessor events
|
||||||
* as well as m.room.create events to find predecessors.
|
* as well as m.room.create events to find predecessors.
|
||||||
* Note: if an m.predecessor event is used, eventId is null since those
|
* Note: if an m.predecessor event is used, eventId may be undefined
|
||||||
* events do not include an event_id property.
|
* since last_known_event_id is optional.
|
||||||
*/
|
*/
|
||||||
public findPredecessor(
|
public findPredecessor(msc3946ProcessDynamicPredecessor = false): { roomId: string; eventId?: string } | null {
|
||||||
msc3946ProcessDynamicPredecessor = false,
|
|
||||||
): { roomId: string; eventId: string | null } | null {
|
|
||||||
// Note: the tests for this function are against Room.findPredecessor,
|
// Note: the tests for this function are against Room.findPredecessor,
|
||||||
// which just calls through to here.
|
// which just calls through to here.
|
||||||
|
|
||||||
if (msc3946ProcessDynamicPredecessor) {
|
if (msc3946ProcessDynamicPredecessor) {
|
||||||
const predecessorEvent = this.getStateEvents(EventType.RoomPredecessor, "");
|
const predecessorEvent = this.getStateEvents(EventType.RoomPredecessor, "");
|
||||||
if (predecessorEvent) {
|
if (predecessorEvent) {
|
||||||
const roomId = predecessorEvent.getContent()["predecessor_room_id"];
|
const content = predecessorEvent.getContent<{
|
||||||
let eventId = predecessorEvent.getContent()["last_known_event_id"];
|
predecessor_room_id: string;
|
||||||
|
last_known_event_id?: string;
|
||||||
|
}>();
|
||||||
|
const roomId = content.predecessor_room_id;
|
||||||
|
let eventId = content.last_known_event_id;
|
||||||
if (typeof eventId !== "string") {
|
if (typeof eventId !== "string") {
|
||||||
eventId = null;
|
eventId = undefined;
|
||||||
}
|
}
|
||||||
if (typeof roomId === "string") {
|
if (typeof roomId === "string") {
|
||||||
return { roomId, eventId };
|
return { roomId, eventId };
|
||||||
@ -998,13 +1000,18 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
|
|||||||
|
|
||||||
const createEvent = this.getStateEvents(EventType.RoomCreate, "");
|
const createEvent = this.getStateEvents(EventType.RoomCreate, "");
|
||||||
if (createEvent) {
|
if (createEvent) {
|
||||||
const predecessor = createEvent.getContent()["predecessor"];
|
const predecessor = createEvent.getContent<{
|
||||||
|
predecessor?: Partial<{
|
||||||
|
room_id: string;
|
||||||
|
event_id: string;
|
||||||
|
}>;
|
||||||
|
}>()["predecessor"];
|
||||||
if (predecessor) {
|
if (predecessor) {
|
||||||
const roomId = predecessor["room_id"];
|
const roomId = predecessor["room_id"];
|
||||||
if (typeof roomId === "string") {
|
if (typeof roomId === "string") {
|
||||||
let eventId = predecessor["event_id"];
|
let eventId = predecessor["event_id"];
|
||||||
if (typeof eventId !== "string" || eventId === "") {
|
if (typeof eventId !== "string" || eventId === "") {
|
||||||
eventId = null;
|
eventId = undefined;
|
||||||
}
|
}
|
||||||
return { roomId, eventId };
|
return { roomId, eventId };
|
||||||
}
|
}
|
||||||
|
@ -3052,12 +3052,10 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
|||||||
* the roomId and last eventId of the predecessor room.
|
* the roomId and last eventId of the predecessor room.
|
||||||
* If msc3946ProcessDynamicPredecessor is true, use m.predecessor events
|
* If msc3946ProcessDynamicPredecessor is true, use m.predecessor events
|
||||||
* as well as m.room.create events to find predecessors.
|
* as well as m.room.create events to find predecessors.
|
||||||
* Note: if an m.predecessor event is used, eventId is null since those
|
* Note: if an m.predecessor event is used, eventId may be undefined
|
||||||
* events do not include an event_id property.
|
* since last_known_event_id is optional.
|
||||||
*/
|
*/
|
||||||
public findPredecessor(
|
public findPredecessor(msc3946ProcessDynamicPredecessor = false): { roomId: string; eventId?: string } | null {
|
||||||
msc3946ProcessDynamicPredecessor = false,
|
|
||||||
): { roomId: string; eventId: string | null } | null {
|
|
||||||
const currentState = this.getLiveTimeline().getState(EventTimeline.FORWARDS);
|
const currentState = this.getLiveTimeline().getState(EventTimeline.FORWARDS);
|
||||||
if (!currentState) {
|
if (!currentState) {
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user