-
-
Notifications
You must be signed in to change notification settings - Fork 827
Don't use deprecated room.currentState
in useRoomState.
#12408
Conversation
Signed-off-by: Timo K <toger5@hotmail.de>
Honestly with the advent of getters in modern JS I think we should undo the deprecation and just have it call the right thing for us, just like we did with Index: src/models/room.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/models/room.ts b/src/models/room.ts
--- a/src/models/room.ts (revision 8f8101bf8b16cb7f4ba0edb2521f87cc39b0e1bc)
+++ b/src/models/room.ts (date 1712597697947)
@@ -383,20 +383,7 @@
* The room summary.
*/
public summary: RoomSummary | null = null;
- /**
- * oldState The state of the room at the time of the oldest event in the live timeline.
- *
- * @deprecated Present for backwards compatibility.
- * Use getLiveTimeline().getState(EventTimeline.BACKWARDS) instead
- */
- public oldState!: RoomState;
- /**
- * currentState The state of the room at the time of the newest event in the timeline.
- *
- * @deprecated Present for backwards compatibility.
- * Use getLiveTimeline().getState(EventTimeline.FORWARDS) instead.
- */
- public currentState!: RoomState;
+
public readonly relations = new RelationsContainer(this.client, this);
/**
@@ -802,6 +789,28 @@
return this.getLiveTimeline().getEvents();
}
+ /**
+ * The state of the room at the time of the oldest event in the live timeline.
+ */
+ public get oldState(): RoomState {
+ const roomState = this.getLiveTimeline().getState(EventTimeline.BACKWARDS);
+ if (!roomState) {
+ throw new Error("No oldState");
+ }
+ return roomState;
+ }
+
+ /**
+ * The state of the room at the time of the newest event in the timeline.
+ */
+ public get currentState(): RoomState {
+ const roomState = this.getLiveTimeline().getState(EventTimeline.FORWARDS);
+ if (!roomState) {
+ throw new Error("No currentState");
+ }
+ return roomState;
+ }
+
/**
* Get the timestamp of the last message in the room
*
@@ -1267,12 +1276,6 @@
const previousOldState = this.oldState;
const previousCurrentState = this.currentState;
- // maintain this.oldState and this.currentState as references to the
- // state at the start and end of that timeline. These are more
- // for backwards-compatibility than anything else.
- this.oldState = this.getLiveTimeline().getState(EventTimeline.BACKWARDS)!;
- this.currentState = this.getLiveTimeline().getState(EventTimeline.FORWARDS)!;
-
// Let people know to register new listeners for the new state
// references. The reference won't necessarily change every time so only
// emit when we see a change. |
I did find the |
It is just a bodged patch, untested |
Adding the changes i am wondering how this would behave with event emitters?
|
Does it? Assuming the same LiveTimeline the same state object would be returned.
Yes that would need fixing via some other means as you need to know when the RoomState is changed out from under you |
Sure only if the oldState changed. Is it as simple that whenever there is a new state object both (current and old) get changed? |
No, the each EventTimeline has 2 RoomState objects, they never change. They are set in the c'tor only. So only when your EventTimeline changes would you need to update room states. Except whatever magic |
It seems we never use the |
I think the emitted events could possibly be deprecated, but we'd still need the logic for reEmitter.stopReEmitting, reEmit, etc so they might as well stay given they are in the same place |
Signed-off-by: Timo K toger5@hotmail.de
Checklist
public
/exported
symbols have accurate TSDoc documentation.