You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-08 21:42:24 +03:00
Use getUserWidgets where possible.
This commit is contained in:
@@ -335,10 +335,7 @@ function setWidget(event, roomId) {
|
|||||||
|
|
||||||
if (userWidget) {
|
if (userWidget) {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
let userWidgets = {};
|
const userWidgets = Widgets.getUserWidgets();
|
||||||
if (client.getAccountData('m.widgets')) {
|
|
||||||
userWidgets = client.getAccountData('m.widgets').getContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete existing widget with ID
|
// Delete existing widget with ID
|
||||||
try {
|
try {
|
||||||
@@ -408,7 +405,7 @@ function getWidgets(event, roomId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add user widgets (not linked to a specific room)
|
// Add user widgets (not linked to a specific room)
|
||||||
const userWidgets = Widgets.getUserWidgets();
|
const userWidgets = Widgets.getUserWidgetsArray();
|
||||||
widgetStateEvents = widgetStateEvents.concat(userWidgets);
|
widgetStateEvents = widgetStateEvents.concat(userWidgets);
|
||||||
|
|
||||||
sendResponse(event, widgetStateEvents);
|
sendResponse(event, widgetStateEvents);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import MatrixClientPeg from '../MatrixClientPeg';
|
|||||||
*/
|
*/
|
||||||
function getWidgets(room) {
|
function getWidgets(room) {
|
||||||
const widgets = getRoomWidgets(room);
|
const widgets = getRoomWidgets(room);
|
||||||
widgets.concat(getUserWidgets());
|
widgets.concat(getUserWidgetsArray());
|
||||||
return widgets;
|
return widgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ function getRoomWidgets(room) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user specific widgets (not linked to a specific 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() {
|
function getUserWidgets() {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
@@ -41,7 +41,16 @@ function getUserWidgets() {
|
|||||||
if (userWidgets && userWidgets.getContent()) {
|
if (userWidgets && userWidgets.getContent()) {
|
||||||
userWidgetContent = 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
|
* @return {[object]} Array containing current / active stickerpicker widgets
|
||||||
*/
|
*/
|
||||||
function getStickerpickerWidgets() {
|
function getStickerpickerWidgets() {
|
||||||
const widgets = getUserWidgets();
|
const widgets = getUserWidgetsArray();
|
||||||
const stickerpickerWidgets = widgets.filter((widget) => widget.type='m.stickerpicker');
|
const stickerpickerWidgets = widgets.filter((widget) => widget.type='m.stickerpicker');
|
||||||
return stickerpickerWidgets;
|
return stickerpickerWidgets;
|
||||||
}
|
}
|
||||||
@@ -76,6 +85,7 @@ export default {
|
|||||||
getWidgets,
|
getWidgets,
|
||||||
getRoomWidgets,
|
getRoomWidgets,
|
||||||
getUserWidgets,
|
getUserWidgets,
|
||||||
|
getUserWidgetsArray,
|
||||||
getStickerpickerWidgets,
|
getStickerpickerWidgets,
|
||||||
removeStickerpickerWidgets,
|
removeStickerpickerWidgets,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user