Support m.jitsi-typed widgets as Jitsi widgets
Fixes https://github.com/vector-im/riot-web/issues/9268
This commit is contained in:
parent
4d461c6d87
commit
dc92f557fd
5 changed files with 54 additions and 16 deletions
|
@ -29,6 +29,8 @@ import SettingsStore from "../settings/SettingsStore";
|
|||
import ActiveWidgetStore from "../stores/ActiveWidgetStore";
|
||||
import {IntegrationManagers} from "../integrations/IntegrationManagers";
|
||||
import {Capability} from "../widgets/WidgetApi";
|
||||
import {Room} from "matrix-js-sdk/src/models/room";
|
||||
import {WidgetType} from "../widgets/WidgetType";
|
||||
|
||||
export default class WidgetUtils {
|
||||
/* Returns true if user is able to send state events to modify widgets in this room
|
||||
|
@ -249,14 +251,16 @@ export default class WidgetUtils {
|
|||
});
|
||||
}
|
||||
|
||||
static setRoomWidget(roomId, widgetId, widgetType, widgetUrl, widgetName, widgetData) {
|
||||
static setRoomWidget(roomId, widgetId, widgetType: WidgetType, widgetUrl, widgetName, widgetData) {
|
||||
let content;
|
||||
|
||||
const addingWidget = Boolean(widgetUrl);
|
||||
|
||||
if (addingWidget) {
|
||||
content = {
|
||||
type: widgetType,
|
||||
// TODO: Enable support for m.widget event type (https://github.com/vector-im/riot-web/issues/13111)
|
||||
// For now we'll send the legacy event type for compatibility with older apps/riots
|
||||
type: widgetType.legacy,
|
||||
url: widgetUrl,
|
||||
name: widgetName,
|
||||
data: widgetData,
|
||||
|
@ -279,10 +283,10 @@ export default class WidgetUtils {
|
|||
|
||||
/**
|
||||
* Get room specific widgets
|
||||
* @param {object} room The room to get widgets force
|
||||
* @param {Room} room The room to get widgets force
|
||||
* @return {[object]} Array containing current / active room widgets
|
||||
*/
|
||||
static getRoomWidgets(room) {
|
||||
static getRoomWidgets(room: Room) {
|
||||
const appsStateEvents = room.currentState.getStateEvents('im.vector.modular.widgets');
|
||||
if (!appsStateEvents) {
|
||||
return [];
|
||||
|
@ -335,6 +339,14 @@ export default class WidgetUtils {
|
|||
return widgets.filter(w => w.content && w.content.type === "m.integration_manager");
|
||||
}
|
||||
|
||||
static getRoomWidgetsOfType(room: Room, type: WidgetType) {
|
||||
const widgets = WidgetUtils.getRoomWidgets(room);
|
||||
return (widgets || []).filter(w => {
|
||||
const content = w.getContent();
|
||||
return content.url && type.matches(content.type);
|
||||
});
|
||||
}
|
||||
|
||||
static removeIntegrationManagerWidgets() {
|
||||
const client = MatrixClientPeg.get();
|
||||
if (!client) {
|
||||
|
@ -402,7 +414,7 @@ export default class WidgetUtils {
|
|||
// Obviously anyone that can add a widget can claim it's a jitsi widget,
|
||||
// so this doesn't really offer much over the set of domains we load
|
||||
// widgets from at all, but it probably makes sense for sanity.
|
||||
if (appType === 'jitsi') {
|
||||
if (WidgetType.JITSI.matches(appType)) {
|
||||
capWhitelist.push(Capability.AlwaysOnScreen);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue