diff --git a/src/ScalarMessaging.js b/src/ScalarMessaging.js index 0fa342e69f..3d585108dd 100644 --- a/src/ScalarMessaging.js +++ b/src/ScalarMessaging.js @@ -362,6 +362,8 @@ function setWidget(event, roomId) { sendResponse(event, { success: true, }); + + dis.dispatch({ action: "user_widget_updated" }); } else { // Room widget if (!roomId) { sendError(event, _t('Missing roomId.'), null); diff --git a/src/components/views/rooms/Stickerpack.js b/src/components/views/rooms/Stickerpack.js index 77e188198a..a61ca84fbd 100644 --- a/src/components/views/rooms/Stickerpack.js +++ b/src/components/views/rooms/Stickerpack.js @@ -24,7 +24,7 @@ import Modal from '../../../Modal'; import sdk from '../../../index'; import SdkConfig from '../../../SdkConfig'; import ScalarAuthClient from '../../../ScalarAuthClient'; - +import dis from '../../../dispatcher'; export default class Stickerpack extends React.Component { constructor(props) { @@ -34,11 +34,12 @@ export default class Stickerpack extends React.Component { this.onFinished = this.onFinished.bind(this); this._launchManageIntegrations = this._launchManageIntegrations.bind(this); this._removeStickerpackWidgets = this._removeStickerpackWidgets.bind(this); + this._onWidgetAction = this._onWidgetAction.bind(this); this.defaultStickersContent = (
-

{_t("You don't currently have any stickerpacks enabled")}

-

{_t("Click")} { _t("here") } {_t("to add some!")}

+

{ _t("You don't currently have any stickerpacks enabled") }

+

{ _t("Click") } { _t("here") } { _t("to add some!") }

{_t('Add
); @@ -53,7 +54,9 @@ export default class Stickerpack extends React.Component { _removeStickerpackWidgets() { console.warn('Removing stickerpack widgets'); - Widgets.removeStickerpackWidgets() + Widgets.removeStickerpackWidgets(); + this._getStickerPickerWidget(); + this.onFinished(); } componentDidMount() { @@ -70,16 +73,36 @@ export default class Stickerpack extends React.Component { // }); }); } + this._getStickerPickerWidget(); + this.dispatcherRef = dis.register(this._onWidgetAction); + } + componentWillUnmount() { + dis.unregister(this.dispatcherRef); + } + + _onWidgetAction(payload) { + if (payload.action === "user_widget_updated") { + console.warn("user widget updated"); + this._getStickerPickerWidget(); + return; + } + console.error("Unhandled widget action"); + } + + _getStickerPickerWidget() { // Stickers // TODO - Add support for stickerpacks from multiple app stores. // Render content from multiple stickerpack sources, each within their own iframe, within the stickerpack UI element. + console.warn("Checking for sticker picker widgets"); const stickerpackWidget = Widgets.getStickerpackWidgets()[0]; - console.warn('Stickerpack widget', stickerpackWidget); let stickersContent; // Load stickerpack content if (stickerpackWidget && stickerpackWidget.content && stickerpackWidget.content.url) { + // Set default name + stickerpackWidget.content.name = stickerpackWidget.name || "Stickerpack"; + console.warn('Stickerpack widget', stickerpackWidget); this.widgetId = stickerpackWidget.id; stickersContent = (
X
widget.type='stickerpack'); + const widgets = getUserWidgets(); + console.warn("widgets", widgets); + const stickerpackWidgets = widgets.filter((widget) => widget.type='stickerpack'); console.warn('Stickerpack widgets', stickerpackWidgets); return stickerpackWidgets; }