You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-09 10:22:46 +03:00
Add authenticated media to getAvatarURL in room and room-member models (#4616)
This commit is contained in:
@@ -368,6 +368,11 @@ export class RoomMember extends TypedEventEmitter<RoomMemberEvent, RoomMemberEve
|
||||
* If false, any non-matrix content URLs will be ignored. Setting this option to
|
||||
* true will expose URLs that, if fetched, will leak information about the user
|
||||
* to anyone who they share a room with.
|
||||
* @param useAuthentication - (optional) If true, the caller supports authenticated
|
||||
* media and wants an authentication-required URL. Note that server support for
|
||||
* authenticated media will not be checked - it is the caller's responsibility
|
||||
* to do so before calling this function. Note also that useAuthentication
|
||||
* implies allowRedirects. Defaults to false (unauthenticated endpoints).
|
||||
* @returns the avatar URL or null.
|
||||
*/
|
||||
public getAvatarUrl(
|
||||
@@ -377,13 +382,23 @@ export class RoomMember extends TypedEventEmitter<RoomMemberEvent, RoomMemberEve
|
||||
resizeMethod: string,
|
||||
allowDefault = true,
|
||||
allowDirectLinks: boolean,
|
||||
useAuthentication: boolean = false,
|
||||
): string | null {
|
||||
const rawUrl = this.getMxcAvatarUrl();
|
||||
|
||||
if (!rawUrl && !allowDefault) {
|
||||
return null;
|
||||
}
|
||||
const httpUrl = getHttpUriForMxc(baseUrl, rawUrl, width, height, resizeMethod, allowDirectLinks);
|
||||
const httpUrl = getHttpUriForMxc(
|
||||
baseUrl,
|
||||
rawUrl,
|
||||
width,
|
||||
height,
|
||||
resizeMethod,
|
||||
allowDirectLinks,
|
||||
undefined,
|
||||
useAuthentication,
|
||||
);
|
||||
if (httpUrl) {
|
||||
return httpUrl;
|
||||
}
|
||||
|
@@ -1661,6 +1661,11 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
* "crop" or "scale".
|
||||
* @param allowDefault - True to allow an identicon for this room if an
|
||||
* avatar URL wasn't explicitly set. Default: true. (Deprecated)
|
||||
* @param useAuthentication - (optional) If true, the caller supports authenticated
|
||||
* media and wants an authentication-required URL. Note that server support for
|
||||
* authenticated media will not be checked - it is the caller's responsibility
|
||||
* to do so before calling this function. Note also that useAuthentication
|
||||
* implies allowRedirects. Defaults to false (unauthenticated endpoints).
|
||||
* @returns the avatar URL or null.
|
||||
*/
|
||||
public getAvatarUrl(
|
||||
@@ -1669,6 +1674,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
height: number,
|
||||
resizeMethod: ResizeMethod,
|
||||
allowDefault = true,
|
||||
useAuthentication: boolean = false,
|
||||
): string | null {
|
||||
const roomAvatarEvent = this.currentState.getStateEvents(EventType.RoomAvatar, "");
|
||||
if (!roomAvatarEvent && !allowDefault) {
|
||||
@@ -1677,7 +1683,16 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
|
||||
const mainUrl = roomAvatarEvent ? roomAvatarEvent.getContent().url : null;
|
||||
if (mainUrl) {
|
||||
return getHttpUriForMxc(baseUrl, mainUrl, width, height, resizeMethod);
|
||||
return getHttpUriForMxc(
|
||||
baseUrl,
|
||||
mainUrl,
|
||||
width,
|
||||
height,
|
||||
resizeMethod,
|
||||
undefined,
|
||||
undefined,
|
||||
useAuthentication,
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user