Introduce a RoomScrollStateStore
to keep the place we're scrolled to in rooms. This mainly eleimates the extra, superfluous onRoomViewStoreUpdate callback that happened when the previous room saved back its scroll state. Moving the scroll state to a separate store means we can have this not emit events because nothing needs to know when the scroll state changes.
This commit is contained in:
parent
d71f15adf4
commit
408b8c18ea
3 changed files with 59 additions and 50 deletions
|
@ -30,8 +30,6 @@ const INITIAL_STATE = {
|
|||
|
||||
// The event to scroll to when the room is first viewed
|
||||
initialEventId: null,
|
||||
// The offset to display the initial event at (see scrollStateMap)
|
||||
initialEventPixelOffset: null,
|
||||
// Whether to highlight the initial event
|
||||
isInitialEventHighlighted: false,
|
||||
|
||||
|
@ -41,20 +39,6 @@ const INITIAL_STATE = {
|
|||
roomLoading: false,
|
||||
// Any error that has occurred during loading
|
||||
roomLoadError: null,
|
||||
// A map from room id to scroll state.
|
||||
//
|
||||
// If there is no special scroll state (ie, we are following the live
|
||||
// timeline), the scroll state is null. Otherwise, it is an object with
|
||||
// the following properties:
|
||||
//
|
||||
// focussedEvent: the ID of the 'focussed' event. Typically this is
|
||||
// the last event fully visible in the viewport, though if we
|
||||
// have done an explicit scroll to an explicit event, it will be
|
||||
// that event.
|
||||
//
|
||||
// pixelOffset: the number of pixels the window is scrolled down
|
||||
// from the focussedEvent.
|
||||
scrollStateMap: {},
|
||||
|
||||
forwardingEvent: null,
|
||||
};
|
||||
|
@ -115,9 +99,6 @@ class RoomViewStore extends Store {
|
|||
case 'on_logged_out':
|
||||
this.reset();
|
||||
break;
|
||||
case 'update_scroll_state':
|
||||
this._updateScrollState(payload);
|
||||
break;
|
||||
case 'forward_event':
|
||||
this._setState({
|
||||
forwardingEvent: payload.event,
|
||||
|
@ -132,7 +113,6 @@ class RoomViewStore extends Store {
|
|||
roomId: payload.room_id,
|
||||
roomAlias: payload.room_alias,
|
||||
initialEventId: payload.event_id,
|
||||
initialEventPixelOffset: undefined,
|
||||
isInitialEventHighlighted: payload.highlighted,
|
||||
forwardingEvent: null,
|
||||
roomLoading: false,
|
||||
|
@ -145,16 +125,6 @@ class RoomViewStore extends Store {
|
|||
newState.joining = false;
|
||||
}
|
||||
|
||||
// If an event ID wasn't specified, default to the one saved for this room
|
||||
// via update_scroll_state. Assume initialEventPixelOffset should be set.
|
||||
if (!newState.initialEventId) {
|
||||
const roomScrollState = this._state.scrollStateMap[payload.room_id];
|
||||
if (roomScrollState) {
|
||||
newState.initialEventId = roomScrollState.focussedEvent;
|
||||
newState.initialEventPixelOffset = roomScrollState.pixelOffset;
|
||||
}
|
||||
}
|
||||
|
||||
if (this._state.forwardingEvent) {
|
||||
dis.dispatch({
|
||||
action: 'send_event',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue