From 34de3729fe12c61f263f102131e2a3bf61761259 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 5 Feb 2018 11:49:26 +0000 Subject: [PATCH] Add method to remove all stickerpacks. --- src/utils/widgets.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/utils/widgets.js b/src/utils/widgets.js index 4e26fa6ceb..806906f072 100644 --- a/src/utils/widgets.js +++ b/src/utils/widgets.js @@ -45,12 +45,33 @@ function getUserWidgets() { * @return {[object]} Array containing current / active stickerpack widgets */ function getStickerpackWidgets() { - return getUserWidgets().filter((widget) => widget.type='stickerpack'); + const stickerpackWidgets = getUserWidgets().filter((widget) => widget.type='stickerpack'); + console.warn('Stickerpack widgets', stickerpackWidgets); + return stickerpackWidgets; } +/** + * Remove all stickerpack widgets (stickerpacks are user widgets by nature) + */ +function removeStickerpackWidgets() { + const client = MatrixClientPeg.get(); + if (!client) { + throw new Error('User not logged in'); + } + const userWidgets = client.getAccountData('m.widgets').getContent() || {}; + Object.entries(userWidgets).forEach(([key, widget]) => { + if (widget.type === 'stickerpack') { + delete userWidgets[key]; + } + }); + client.setAccountData('m.widgets', userWidgets); +} + + export default { getWidgets, getRoomWidgets, getUserWidgets, getStickerpackWidgets, + removeStickerpackWidgets, };