mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-14 08:36:37 +03:00
Remove avatarForExport string
This commit is contained in:
parent
55ffb318e5
commit
685441baf5
2 changed files with 15 additions and 9 deletions
|
@ -67,8 +67,7 @@ export default class MemberAvatar extends React.Component<IProps, IState> {
|
||||||
private static getState(props: IProps): IState {
|
private static getState(props: IProps): IState {
|
||||||
if (props.member?.name) {
|
if (props.member?.name) {
|
||||||
let imageUrl = null;
|
let imageUrl = null;
|
||||||
if (props.forExport && props.member.getMxcAvatarUrl()) imageUrl = "avatarForExport";
|
if (props.member.getMxcAvatarUrl()) {
|
||||||
else if (props.member.getMxcAvatarUrl()) {
|
|
||||||
imageUrl = mediaFromMxc(props.member.getMxcAvatarUrl()).getThumbnailOfSourceHttp(
|
imageUrl = mediaFromMxc(props.member.getMxcAvatarUrl()).getThumbnailOfSourceHttp(
|
||||||
props.width,
|
props.width,
|
||||||
props.height,
|
props.height,
|
||||||
|
|
|
@ -190,19 +190,26 @@ export default class HTMLExporter extends Exporter {
|
||||||
</html>`
|
</html>`
|
||||||
}
|
}
|
||||||
|
|
||||||
protected hasAvatar(event: MatrixEvent): boolean {
|
protected getAvatarURL(event: MatrixEvent): string {
|
||||||
const member = event.sender;
|
const member = event.sender;
|
||||||
return !!member.getMxcAvatarUrl();
|
return (
|
||||||
|
member.getMxcAvatarUrl() &&
|
||||||
|
mediaFromMxc(member.getMxcAvatarUrl()).getThumbnailOfSourceHttp(
|
||||||
|
30,
|
||||||
|
30,
|
||||||
|
"crop",
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async saveAvatarIfNeeded(event: MatrixEvent) {
|
protected async saveAvatarIfNeeded(event: MatrixEvent) {
|
||||||
const member = event.sender;
|
const member = event.sender;
|
||||||
const avatarUrl = mediaFromMxc(member.getMxcAvatarUrl()).getThumbnailOfSourceHttp(30, 30, "crop");
|
|
||||||
if (!this.avatars.has(member.userId)) {
|
if (!this.avatars.has(member.userId)) {
|
||||||
|
const avatarUrl = this.getAvatarURL(event);
|
||||||
this.avatars.set(member.userId, true);
|
this.avatars.set(member.userId, true);
|
||||||
const image = await fetch(avatarUrl);
|
const image = await fetch(avatarUrl);
|
||||||
const blob = await image.blob();
|
const blob = await image.blob();
|
||||||
this.addFile(`users/${member.userId.replace(/:/g, '-')}`, blob);
|
this.addFile(`users/${member.userId.replace(/:/g, '-')}.png`, blob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +225,7 @@ export default class HTMLExporter extends Exporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getEventTile(mxEv: MatrixEvent, continuation: boolean, filePath?: string) {
|
protected async getEventTile(mxEv: MatrixEvent, continuation: boolean, filePath?: string) {
|
||||||
const hasAvatar = this.hasAvatar(mxEv);
|
const hasAvatar = !!this.getAvatarURL(mxEv);
|
||||||
if (hasAvatar) await this.saveAvatarIfNeeded(mxEv);
|
if (hasAvatar) await this.saveAvatarIfNeeded(mxEv);
|
||||||
|
|
||||||
const eventTile = <div className="mx_Export_EventWrapper" id={mxEv.getId()}>
|
const eventTile = <div className="mx_Export_EventWrapper" id={mxEv.getId()}>
|
||||||
|
@ -251,8 +258,8 @@ export default class HTMLExporter extends Exporter {
|
||||||
if (filePath) eventTileMarkup = eventTileMarkup.replace(/(src=|href=)"forExport"/g, `$1"${filePath}"`);
|
if (filePath) eventTileMarkup = eventTileMarkup.replace(/(src=|href=)"forExport"/g, `$1"${filePath}"`);
|
||||||
if (hasAvatar) {
|
if (hasAvatar) {
|
||||||
eventTileMarkup = eventTileMarkup.replace(
|
eventTileMarkup = eventTileMarkup.replace(
|
||||||
/src="avatarForExport"/g,
|
encodeURI(this.getAvatarURL(mxEv)).replace(/&/g, '&'),
|
||||||
`src="users/${mxEv.sender.userId.replace(/:/g, "-")}"`,
|
`users/${mxEv.sender.userId.replace(/:/g, "-")}.png`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return eventTileMarkup;
|
return eventTileMarkup;
|
||||||
|
|
Loading…
Reference in a new issue