From 60e7646f928e10845816b38810702f369ae15937 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 8 Jan 2018 16:47:49 +0000 Subject: [PATCH] Save user widgets in accountData --- src/ScalarMessaging.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ScalarMessaging.js b/src/ScalarMessaging.js index 7befee217a..41c667be25 100644 --- a/src/ScalarMessaging.js +++ b/src/ScalarMessaging.js @@ -333,18 +333,27 @@ function setWidget(event, roomId) { }; if (userWidget) { + console.warn('Adding user widget'); const client = MatrixClientPeg.get(); - let userWidgets = client.getAccountData('m.widgets'); + let userWidgets = client.getAccountData('m.widgets') || {}; // Delete existing widget with ID - userWidgets = userWidgets.filter((widget) => widget.data.id === widgetId ? false : true); + delete userWidgets[widgetId]; // Add new widget / update if (widgetUrl !== null) { - userWidgets.push(content); + userWidgets[widgetId] = { + content: content, + sender: client.getUserId(), + stateKey: widgetId, + type: 'm.widget', + }; } - client.setAccountData('m.widgets', userWidgets); + client.setAccountData('m.widgets', {widgets: userWidgets}); + sendResponse(event, { + success: true, + }); } else { // Room widget if (widgetUrl === null) { // widget is being deleted content = {};