Skip to content

Commit

Permalink
Add widget ID to template per MSC2774
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Oct 2, 2020
1 parent dd5aca9 commit 3fdfe4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/models/Widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ export class Widget {
* @returns {string} A templated URL.
*/
public getCompleteUrl(params: ITemplateParams): string {
return runTemplate(this.templateUrl, this.rawData, params);
return runTemplate(this.templateUrl, this.definition, params);
}
}
7 changes: 4 additions & 3 deletions src/templating/url-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { IWidgetData } from "..";
import { IWidget } from "..";

export interface ITemplateParams {
currentRoomId?: string;
Expand All @@ -23,13 +23,14 @@ export interface ITemplateParams {
userHttpAvatarUrl?: string;
}

export function runTemplate(url: string, data: IWidgetData, params: ITemplateParams): string {
export function runTemplate(url: string, widget: IWidget, params: ITemplateParams): string {
// Always apply the supplied params over top of data to ensure the data can't lie about them.
const variables = Object.assign({}, data, {
const variables = Object.assign({}, widget.data, {
matrix_room_id: params.currentRoomId || "",
matrix_user_id: params.currentUserId,
matrix_display_name: params.userDisplayName || params.currentUserId,
matrix_avatar_url: params.userHttpAvatarUrl || "",
matrix_widget_id: widget.id,
});
let result = url;
for (const key of Object.keys(variables)) {
Expand Down

0 comments on commit 3fdfe4f

Please sign in to comment.