Update widget state when account data changes
							parent
							
								
									d90292c6f1
								
							
						
					
					
						commit
						98c06315cf
					
				| 
						 | 
					@ -34,6 +34,7 @@ export default class Stickerpicker extends React.Component {
 | 
				
			||||||
        this._onHideStickersClick = this._onHideStickersClick.bind(this);
 | 
					        this._onHideStickersClick = this._onHideStickersClick.bind(this);
 | 
				
			||||||
        this._launchManageIntegrations = this._launchManageIntegrations.bind(this);
 | 
					        this._launchManageIntegrations = this._launchManageIntegrations.bind(this);
 | 
				
			||||||
        this._removeStickerpickerWidgets = this._removeStickerpickerWidgets.bind(this);
 | 
					        this._removeStickerpickerWidgets = this._removeStickerpickerWidgets.bind(this);
 | 
				
			||||||
 | 
					        this._updateWidget = this._updateWidget.bind(this);
 | 
				
			||||||
        this._onWidgetAction = this._onWidgetAction.bind(this);
 | 
					        this._onWidgetAction = this._onWidgetAction.bind(this);
 | 
				
			||||||
        this._onResize = this._onResize.bind(this);
 | 
					        this._onResize = this._onResize.bind(this);
 | 
				
			||||||
        this._onFinished = this._onFinished.bind(this);
 | 
					        this._onFinished = this._onFinished.bind(this);
 | 
				
			||||||
| 
						 | 
					@ -90,11 +91,12 @@ export default class Stickerpicker extends React.Component {
 | 
				
			||||||
        if (!this.state.imError) {
 | 
					        if (!this.state.imError) {
 | 
				
			||||||
            this.dispatcherRef = dis.register(this._onWidgetAction);
 | 
					            this.dispatcherRef = dis.register(this._onWidgetAction);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        const stickerpickerWidget = Widgets.getStickerpickerWidgets()[0];
 | 
					
 | 
				
			||||||
        this.setState({
 | 
					        // Track updates to widget state in account data
 | 
				
			||||||
            stickerpickerWidget,
 | 
					        MatrixClientPeg.get().on('accountData', this._updateWidget);
 | 
				
			||||||
            widgetId: stickerpickerWidget ? stickerpickerWidget.id : null,
 | 
					
 | 
				
			||||||
        });
 | 
					        // Initialise widget state from current account data
 | 
				
			||||||
 | 
					        this._updateWidget();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    componentWillUnmount() {
 | 
					    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) {
 | 
					    _onWidgetAction(payload) {
 | 
				
			||||||
        if (payload.action === "user_widget_updated") {
 | 
					        if (payload.action === "user_widget_updated") {
 | 
				
			||||||
            this.forceUpdate();
 | 
					            this.forceUpdate();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue