Better support for widgets overriding their URLs
Move the URL processing into AppTile so that the widget can have a URL used for embedding in the page and a separate one for popping out into a browser.
This commit is contained in:
parent
78fd8e4569
commit
538147f7fa
6 changed files with 135 additions and 131 deletions
|
@ -30,26 +30,6 @@ import ActiveWidgetStore from "../stores/ActiveWidgetStore";
|
|||
import {IntegrationManagers} from "../integrations/IntegrationManagers";
|
||||
import {Capability} from "../widgets/WidgetApi";
|
||||
|
||||
/**
|
||||
* Encodes a URI according to a set of template variables. Variables will be
|
||||
* passed through encodeURIComponent.
|
||||
* @param {string} pathTemplate The path with template variables e.g. '/foo/$bar'.
|
||||
* @param {Object} variables The key/value pairs to replace the template
|
||||
* variables with. E.g. { '$bar': 'baz' }.
|
||||
* @return {string} The result of replacing all template variables e.g. '/foo/baz'.
|
||||
*/
|
||||
function encodeUri(pathTemplate, variables) {
|
||||
for (const key in variables) {
|
||||
if (!variables.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
pathTemplate = pathTemplate.replace(
|
||||
key, encodeURIComponent(variables[key]),
|
||||
);
|
||||
}
|
||||
return pathTemplate;
|
||||
}
|
||||
|
||||
export default class WidgetUtils {
|
||||
/* Returns true if user is able to send state events to modify widgets in this room
|
||||
* (Does not apply to non-room-based / user widgets)
|
||||
|
@ -402,18 +382,6 @@ export default class WidgetUtils {
|
|||
}
|
||||
|
||||
static makeAppConfig(appId, app, senderUserId, roomId, eventId) {
|
||||
const myUserId = MatrixClientPeg.get().credentials.userId;
|
||||
const user = MatrixClientPeg.get().getUser(myUserId);
|
||||
const params = {
|
||||
'$matrix_user_id': myUserId,
|
||||
'$matrix_room_id': roomId,
|
||||
'$matrix_display_name': user ? user.displayName : myUserId,
|
||||
'$matrix_avatar_url': user ? MatrixClientPeg.get().mxcUrlToHttp(user.avatarUrl) : '',
|
||||
|
||||
// TODO: Namespace themes through some standard
|
||||
'$theme': SettingsStore.getValue("theme"),
|
||||
};
|
||||
|
||||
if (!senderUserId) {
|
||||
throw new Error("Widgets must be created by someone - provide a senderUserId");
|
||||
}
|
||||
|
@ -423,32 +391,6 @@ export default class WidgetUtils {
|
|||
app.eventId = eventId;
|
||||
app.name = app.name || app.type;
|
||||
|
||||
if (app.type === 'jitsi') {
|
||||
console.log("Replacing Jitsi widget URL with local wrapper");
|
||||
if (!app.data || !app.data.conferenceId) {
|
||||
// Assumed to be a v1 widget: add a data object for visibility on the wrapper
|
||||
// TODO: Remove this once mobile supports v2 widgets
|
||||
console.log("Replacing v1 Jitsi widget with v2 equivalent");
|
||||
const parsed = new URL(app.url);
|
||||
app.data = {
|
||||
conferenceId: parsed.searchParams.get("confId"),
|
||||
domain: "jitsi.riot.im", // v1 widgets have this hardcoded
|
||||
};
|
||||
}
|
||||
|
||||
app.url = WidgetUtils.getLocalJitsiWrapperUrl({forLocalRender: true});
|
||||
}
|
||||
|
||||
if (app.data) {
|
||||
Object.keys(app.data).forEach((key) => {
|
||||
params['$' + key] = app.data[key];
|
||||
});
|
||||
|
||||
app.waitForIframeLoad = (app.data.waitForIframeLoad === 'false' ? false : true);
|
||||
}
|
||||
|
||||
app.url = encodeUri(app.url, params);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue