Re-use existing sticker picker widgets

There's a potential for a race condition by deleting then recreating the widget. Instead, we'll just re-use the widget and change the properties of it.

Fixes https://github.com/turt2live/matrix-dimension/issues/200

Note that the actual change may not be reflected due to https://github.com/vector-im/riot-web/issues/7547
This commit is contained in:
Travis Ralston 2018-10-24 00:27:57 -06:00
parent 9ae83f3dae
commit a103f3ca6b

View File

@ -59,16 +59,11 @@ export class StickerpickerComponent implements OnInit {
try {
const widgets = await this.scalarClient.getWidgets();
const stickerPicker = widgets.response.find(w => w.content && w.content.type === "m.stickerpicker");
if (stickerPicker && !stickerPicker.content.data.dimension) {
console.log("Deleting non-Dimension sticker picker");
await this.scalarClient.deleteUserWidget(stickerPicker);
}
const widgetId = stickerPicker ? ((<any>stickerPicker).id || stickerPicker.state_key) : "dimension-stickerpicker-" + (new Date().getTime());
if (stickerPicker) return; // already have a widget
console.log("Adding Dimension sticker picker");
console.log("Force-setting new widget of ID " + widgetId);
await this.scalarClient.setUserWidget({
id: "dimension-stickerpicker-" + (new Date().getTime()),
id: widgetId,
type: WIDGET_STICKER_PICKER[0],
url: this.window.location.origin + "/widgets/stickerpicker",
data: {