Create icons for users without an avatar in desktop notifications (#305)

* Add notifications icon for users without an avatar

* Render icon at higher resolution

* Use scale to render at higher resolution
This commit is contained in:
ginnyTheCat 2022-02-15 12:48:25 +01:00 committed by GitHub
parent fe674ef2ea
commit 8d3f0a9f4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 15 deletions

View file

@ -1,4 +1,6 @@
import EventEmitter from 'events';
import renderAvatar from '../../app/atoms/avatar/render';
import { cssColorMXID } from '../../util/colorMXID';
import { selectRoom } from '../action/navigation';
import cons from './cons';
import navigation from './navigation';
@ -183,9 +185,19 @@ class Notifications extends EventEmitter {
title = `${mEvent.sender.name} (${room.name})`;
}
const iconSize = 36;
const icon = await renderAvatar({
text: mEvent.sender.name,
bgColor: cssColorMXID(mEvent.getSender()),
imageSrc: mEvent.sender?.getAvatarUrl(this.matrixClient.baseUrl, iconSize, iconSize, 'crop'),
size: iconSize,
borderRadius: 8,
scale: 8,
});
const noti = new window.Notification(title, {
body: mEvent.getContent().body,
icon: mEvent.sender?.getAvatarUrl(this.matrixClient.baseUrl, 36, 36, 'crop'),
icon,
});
noti.onclick = () => selectRoom(room.roomId, mEvent.getId());
}