Add method to remove all stickerpacks.

This commit is contained in:
Richard Lewis 2018-02-05 11:49:26 +00:00
parent 29962ed89d
commit 34de3729fe

View File

@ -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,
};