Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Support avatar_url in the scalar client API #8550

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/ScalarMessaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Request:
can configure/lay out the widget in different ways. All widgets must have a type.
- `name` (String) is an optional human-readable string about the widget.
- `data` (Object) is some optional data about the widget, and can contain arbitrary key/value pairs.
- `avatar_url` (String) is some optional mxc: URI pointing to the avatar of the widget.
Response:
{
success: true
Expand Down Expand Up @@ -319,6 +320,7 @@ function setWidget(event: MessageEvent<any>, roomId: string): void {
const widgetUrl = event.data.url;
const widgetName = event.data.name; // optional
const widgetData = event.data.data; // optional
const widgetAvatarUrl = event.data.avatar_url; // optional
const userWidget = event.data.userWidget;

// both adding/removing widgets need these checks
Expand All @@ -337,6 +339,14 @@ function setWidget(event: MessageEvent<any>, roomId: string): void {
sendError(event, _t("Unable to create widget."), new Error("Optional field 'data' must be an Object."));
return;
}
if (widgetAvatarUrl !== undefined && typeof widgetAvatarUrl !== 'string') {
sendError(
event,
_t("Unable to create widget."),
new Error("Optional field 'avatar_url' must be a string."),
);
return;
}
if (typeof widgetType !== 'string') {
sendError(event, _t("Unable to create widget."), new Error("Field 'type' must be a string."));
return;
Expand Down Expand Up @@ -364,13 +374,14 @@ function setWidget(event: MessageEvent<any>, roomId: string): void {
if (!roomId) {
sendError(event, _t('Missing roomId.'), null);
}
WidgetUtils.setRoomWidget(roomId, widgetId, widgetType, widgetUrl, widgetName, widgetData).then(() => {
sendResponse(event, {
success: true,
WidgetUtils.setRoomWidget(roomId, widgetId, widgetType, widgetUrl, widgetName, widgetData, widgetAvatarUrl)
.then(() => {
sendResponse(event, {
success: true,
});
}, (err) => {
sendError(event, _t('Failed to send request.'), err);
});
}, (err) => {
sendError(event, _t('Failed to send request.'), err);
});
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/utils/WidgetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export default class WidgetUtils {
widgetUrl?: string,
widgetName?: string,
widgetData?: object,
widgetAvatarUrl?: string,
turt2live marked this conversation as resolved.
Show resolved Hide resolved
) {
let content;

Expand All @@ -299,6 +300,7 @@ export default class WidgetUtils {
url: widgetUrl,
name: widgetName,
data: widgetData,
avatar_url: widgetAvatarUrl,
};
} else {
content = {};
Expand Down