Ensure message previews update when needed

In 9969b01c5f we stopped updating the sublist whenever we felt like it, which indirectly froze message previews for room tiles (badges, unread state, etc were unaffected because that is managed by a different store). To fix this, we simply have to listen for changes and perform an update.
This commit is contained in:
Travis Ralston 2020-07-23 22:24:07 -06:00
parent 7e50464eeb
commit fd15fc3984
2 changed files with 15 additions and 1 deletions

View file

@ -35,7 +35,7 @@ import {
MenuItem,
} from "../../structures/ContextMenu";
import { DefaultTagID, TagID } from "../../../stores/room-list/models";
import { MessagePreviewStore } from "../../../stores/room-list/MessagePreviewStore";
import { MessagePreviewStore, ROOM_PREVIEW_CHANGED } from "../../../stores/room-list/MessagePreviewStore";
import DecoratedRoomAvatar from "../avatars/DecoratedRoomAvatar";
import {
getRoomNotifsState,
@ -128,6 +128,7 @@ export default class RoomTile extends React.Component<IProps, IState> {
ActiveRoomObserver.addListener(this.props.room.roomId, this.onActiveRoomUpdate);
this.dispatcherRef = defaultDispatcher.register(this.onAction);
MessagePreviewStore.instance.on(ROOM_PREVIEW_CHANGED, this.onRoomPreviewChanged);
}
private get showContextMenu(): boolean {
@ -150,6 +151,7 @@ export default class RoomTile extends React.Component<IProps, IState> {
ActiveRoomObserver.removeListener(this.props.room.roomId, this.onActiveRoomUpdate);
}
defaultDispatcher.unregister(this.dispatcherRef);
MessagePreviewStore.instance.off(ROOM_PREVIEW_CHANGED, this.onRoomPreviewChanged);
}
private onAction = (payload: ActionPayload) => {
@ -160,6 +162,12 @@ export default class RoomTile extends React.Component<IProps, IState> {
}
};
private onRoomPreviewChanged = (room: Room) => {
if (this.props.room && room.roomId === this.props.room.roomId) {
this.forceUpdate(); // we don't have any state to set, so just complain that we need an update
}
};
private scrollIntoView = () => {
if (!this.roomTileRef.current) return;
this.roomTileRef.current.scrollIntoView({