From 19b7d18e7a7f9226d8ae0b0c2222fe390ba3ce52 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 21 Aug 2019 18:43:29 -0600 Subject: [PATCH] No-op removals of widgets that don't exist An example of this is setting your very first widget: there's nothing to remove, so you end up with "cannot call .getContent() of undefined" instead. --- src/utils/WidgetUtils.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/WidgetUtils.js b/src/utils/WidgetUtils.js index 12c1578474..06b4eed55b 100644 --- a/src/utils/WidgetUtils.js +++ b/src/utils/WidgetUtils.js @@ -354,7 +354,9 @@ export default class WidgetUtils { if (!client) { throw new Error('User not logged in'); } - const userWidgets = client.getAccountData('m.widgets').getContent() || {}; + const widgets = client.getAccountData('m.widgets'); + if (!widgets) return; + const userWidgets = widgets.getContent() || {}; Object.entries(userWidgets).forEach(([key, widget]) => { if (widget.content && widget.content.type === "m.integration_manager") { delete userWidgets[key]; @@ -382,7 +384,9 @@ export default class WidgetUtils { if (!client) { throw new Error('User not logged in'); } - const userWidgets = client.getAccountData('m.widgets').getContent() || {}; + const widgets = client.getAccountData('m.widgets'); + if (!widgets) return; + const userWidgets = widgets.getContent() || {}; Object.entries(userWidgets).forEach(([key, widget]) => { if (widget.content && widget.content.type === 'm.stickerpicker') { delete userWidgets[key];