Use getUserWidgets where possible.

This commit is contained in:
Richard Lewis 2018-03-09 09:15:16 +00:00
parent e7c19fd83b
commit a33859326e
2 changed files with 16 additions and 9 deletions

View file

@ -335,10 +335,7 @@ function setWidget(event, roomId) {
if (userWidget) {
const client = MatrixClientPeg.get();
let userWidgets = {};
if (client.getAccountData('m.widgets')) {
userWidgets = client.getAccountData('m.widgets').getContent();
}
const userWidgets = Widgets.getUserWidgets();
// Delete existing widget with ID
try {
@ -408,7 +405,7 @@ function getWidgets(event, roomId) {
}
// Add user widgets (not linked to a specific room)
const userWidgets = Widgets.getUserWidgets();
const userWidgets = Widgets.getUserWidgetsArray();
widgetStateEvents = widgetStateEvents.concat(userWidgets);
sendResponse(event, widgetStateEvents);

View file

@ -7,7 +7,7 @@ import MatrixClientPeg from '../MatrixClientPeg';
*/
function getWidgets(room) {
const widgets = getRoomWidgets(room);
widgets.concat(getUserWidgets());
widgets.concat(getUserWidgetsArray());
return widgets;
}
@ -29,7 +29,7 @@ function getRoomWidgets(room) {
/**
* Get user specific widgets (not linked to a specific room)
* @return {[object]} Array containing current / active user widgets
* @return {object} Event content object containing current / active user widgets
*/
function getUserWidgets() {
const client = MatrixClientPeg.get();
@ -41,7 +41,16 @@ function getUserWidgets() {
if (userWidgets && userWidgets.getContent()) {
userWidgetContent = userWidgets.getContent();
}
return Object.keys(userWidgetContent).map((key) => userWidgetContent[key]);
return userWidgetContent;
}
/**
* Get user specific widgets (not linked to a specific room) as an array
* @return {[object]} Array containing current / active user widgets
*/
function getUserWidgetsArray() {
const userWidgetContent = getUserWidgets();
return Object.keys(userWidgetContent).map((key) => userWidgetContent[key]);
}
/**
@ -49,7 +58,7 @@ function getUserWidgets() {
* @return {[object]} Array containing current / active stickerpicker widgets
*/
function getStickerpickerWidgets() {
const widgets = getUserWidgets();
const widgets = getUserWidgetsArray();
const stickerpickerWidgets = widgets.filter((widget) => widget.type='m.stickerpicker');
return stickerpickerWidgets;
}
@ -76,6 +85,7 @@ export default {
getWidgets,
getRoomWidgets,
getUserWidgets,
getUserWidgetsArray,
getStickerpickerWidgets,
removeStickerpickerWidgets,
};