From 98c06315cf44121779125a98f7025436c72f11af Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 14 May 2018 11:14:49 +0100 Subject: [PATCH] Update widget state when account data changes --- src/components/views/rooms/Stickerpicker.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/Stickerpicker.js b/src/components/views/rooms/Stickerpicker.js index 40ce6e6b39..51d4816e59 100644 --- a/src/components/views/rooms/Stickerpicker.js +++ b/src/components/views/rooms/Stickerpicker.js @@ -34,6 +34,7 @@ export default class Stickerpicker extends React.Component { this._onHideStickersClick = this._onHideStickersClick.bind(this); this._launchManageIntegrations = this._launchManageIntegrations.bind(this); this._removeStickerpickerWidgets = this._removeStickerpickerWidgets.bind(this); + this._updateWidget = this._updateWidget.bind(this); this._onWidgetAction = this._onWidgetAction.bind(this); this._onResize = this._onResize.bind(this); this._onFinished = this._onFinished.bind(this); @@ -90,11 +91,12 @@ export default class Stickerpicker extends React.Component { if (!this.state.imError) { this.dispatcherRef = dis.register(this._onWidgetAction); } - const stickerpickerWidget = Widgets.getStickerpickerWidgets()[0]; - this.setState({ - stickerpickerWidget, - widgetId: stickerpickerWidget ? stickerpickerWidget.id : null, - }); + + // Track updates to widget state in account data + MatrixClientPeg.get().on('accountData', this._updateWidget); + + // Initialise widget state from current account data + this._updateWidget(); } componentWillUnmount() { @@ -116,6 +118,14 @@ export default class Stickerpicker extends React.Component { }); } + _updateWidget() { + const stickerpickerWidget = Widgets.getStickerpickerWidgets()[0]; + this.setState({ + stickerpickerWidget, + widgetId: stickerpickerWidget ? stickerpickerWidget.id : null, + }); + } + _onWidgetAction(payload) { if (payload.action === "user_widget_updated") { this.forceUpdate();