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

Commit f7ba3f0

Browse files
authored
Support avatar_url in the scalar client API (#8550)
* Support avatar_url in the scalar client API Signed-off-by: Oliver Sand <oliver.sand@nordeck.net> * Fix return type * Remove automatic upload * Remove return type * Fix indention
1 parent efc36ac commit f7ba3f0

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/ScalarMessaging.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Request:
148148
can configure/lay out the widget in different ways. All widgets must have a type.
149149
- `name` (String) is an optional human-readable string about the widget.
150150
- `data` (Object) is some optional data about the widget, and can contain arbitrary key/value pairs.
151+
- `avatar_url` (String) is some optional mxc: URI pointing to the avatar of the widget.
151152
Response:
152153
{
153154
success: true
@@ -319,6 +320,7 @@ function setWidget(event: MessageEvent<any>, roomId: string): void {
319320
const widgetUrl = event.data.url;
320321
const widgetName = event.data.name; // optional
321322
const widgetData = event.data.data; // optional
323+
const widgetAvatarUrl = event.data.avatar_url; // optional
322324
const userWidget = event.data.userWidget;
323325

324326
// both adding/removing widgets need these checks
@@ -337,6 +339,14 @@ function setWidget(event: MessageEvent<any>, roomId: string): void {
337339
sendError(event, _t("Unable to create widget."), new Error("Optional field 'data' must be an Object."));
338340
return;
339341
}
342+
if (widgetAvatarUrl !== undefined && typeof widgetAvatarUrl !== 'string') {
343+
sendError(
344+
event,
345+
_t("Unable to create widget."),
346+
new Error("Optional field 'avatar_url' must be a string."),
347+
);
348+
return;
349+
}
340350
if (typeof widgetType !== 'string') {
341351
sendError(event, _t("Unable to create widget."), new Error("Field 'type' must be a string."));
342352
return;
@@ -364,13 +374,14 @@ function setWidget(event: MessageEvent<any>, roomId: string): void {
364374
if (!roomId) {
365375
sendError(event, _t('Missing roomId.'), null);
366376
}
367-
WidgetUtils.setRoomWidget(roomId, widgetId, widgetType, widgetUrl, widgetName, widgetData).then(() => {
368-
sendResponse(event, {
369-
success: true,
377+
WidgetUtils.setRoomWidget(roomId, widgetId, widgetType, widgetUrl, widgetName, widgetData, widgetAvatarUrl)
378+
.then(() => {
379+
sendResponse(event, {
380+
success: true,
381+
});
382+
}, (err) => {
383+
sendError(event, _t('Failed to send request.'), err);
370384
});
371-
}, (err) => {
372-
sendError(event, _t('Failed to send request.'), err);
373-
});
374385
}
375386
}
376387

src/utils/WidgetUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export default class WidgetUtils {
286286
widgetUrl?: string,
287287
widgetName?: string,
288288
widgetData?: object,
289+
widgetAvatarUrl?: string,
289290
) {
290291
let content;
291292

@@ -299,6 +300,7 @@ export default class WidgetUtils {
299300
url: widgetUrl,
300301
name: widgetName,
301302
data: widgetData,
303+
avatar_url: widgetAvatarUrl,
302304
};
303305
} else {
304306
content = {};

0 commit comments

Comments
 (0)