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
Set user widgets on application data.
This commit is contained in:
@@ -291,6 +291,7 @@ function setWidget(event, roomId) {
|
|||||||
const widgetUrl = event.data.url;
|
const widgetUrl = event.data.url;
|
||||||
const widgetName = event.data.name; // optional
|
const widgetName = event.data.name; // optional
|
||||||
const widgetData = event.data.data; // optional
|
const widgetData = event.data.data; // optional
|
||||||
|
const userWidget = event.data.userWidget;
|
||||||
|
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
if (!client) {
|
if (!client) {
|
||||||
@@ -330,10 +331,24 @@ function setWidget(event, roomId) {
|
|||||||
name: widgetName,
|
name: widgetName,
|
||||||
data: widgetData,
|
data: widgetData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (userWidget) {
|
||||||
|
const client = MatrixClientPeg.get();
|
||||||
|
let userWidgets = client.getAccountData('m.widgets');
|
||||||
|
|
||||||
|
// Delete existing widget with ID
|
||||||
|
userWidgets = userWidgets.filter((widget) => widget.data.id === widgetId ? false : true);
|
||||||
|
|
||||||
|
// Add new widget / update
|
||||||
|
if (widgetUrl !== null) {
|
||||||
|
userWidgets.push(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.setAccountData('m.widgets', userWidgets);
|
||||||
|
} else { // Room widget
|
||||||
if (widgetUrl === null) { // widget is being deleted
|
if (widgetUrl === null) { // widget is being deleted
|
||||||
content = {};
|
content = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
client.sendStateEvent(roomId, "im.vector.modular.widgets", content, widgetId).done(() => {
|
client.sendStateEvent(roomId, "im.vector.modular.widgets", content, widgetId).done(() => {
|
||||||
sendResponse(event, {
|
sendResponse(event, {
|
||||||
success: true,
|
success: true,
|
||||||
@@ -341,6 +356,7 @@ function setWidget(event, roomId) {
|
|||||||
}, (err) => {
|
}, (err) => {
|
||||||
sendError(event, _t('Failed to send request.'), err);
|
sendError(event, _t('Failed to send request.'), err);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWidgets(event, roomId) {
|
function getWidgets(event, roomId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user