merge: branch 'master' into production

This commit is contained in:
Paul Makles 2022-09-20 19:12:25 +01:00
commit 40d3356c1b

View file

@ -1,5 +1,5 @@
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { Channel, Member } from "revolt.js"; import { Channel } from "revolt.js";
import styled from "styled-components/macro"; import styled from "styled-components/macro";
import { Text } from "preact-i18n"; import { Text } from "preact-i18n";
@ -60,8 +60,6 @@ const Base = styled.div`
`; `;
export default observer(({ channel }: Props) => { export default observer(({ channel }: Props) => {
const client = channel.client;
const users = channel.typing.filter( const users = channel.typing.filter(
(x) => (x) =>
typeof x !== "undefined" && typeof x !== "undefined" &&
@ -69,47 +67,24 @@ export default observer(({ channel }: Props) => {
x.relationship !== "Blocked", x.relationship !== "Blocked",
); );
const members = users.map((user) => { if (users.length > 0) {
return client.members.getKey({ users.sort((a, b) =>
server: channel.server_id!, a!._id.toUpperCase().localeCompare(b!._id.toUpperCase()),
user: user!._id,
});
});
const getName = (member: Member) => {
return member.nickname === null
? member.user?.username
: member.nickname;
};
const getAvatar = (member: Member) => {
const memberAvatarURL = member.generateAvatarURL({
max_side: 256,
});
return memberAvatarURL === undefined
? member.user?.generateAvatarURL({ max_side: 256 })
: memberAvatarURL;
};
if (members.length > 0) {
members.sort((a, b) =>
a!._id.user.toUpperCase().localeCompare(b!._id.user.toUpperCase()),
); );
let text; let text;
if (members.length >= 5) { if (users.length >= 5) {
text = <Text id="app.main.channel.typing.several" />; text = <Text id="app.main.channel.typing.several" />;
} else if (members.length > 1) { } else if (users.length > 1) {
const memberlist = [...members].map((x) => getName(x!)); const userlist = [...users].map((x) => x!.username);
const member = memberlist.pop(); const user = userlist.pop();
text = ( text = (
<Text <Text
id="app.main.channel.typing.multiple" id="app.main.channel.typing.multiple"
fields={{ fields={{
user: member, user,
userlist: memberlist.join(", "), userlist: userlist.join(", "),
}} }}
/> />
); );
@ -117,7 +92,7 @@ export default observer(({ channel }: Props) => {
text = ( text = (
<Text <Text
id="app.main.channel.typing.single" id="app.main.channel.typing.single"
fields={{ user: getName(members[0]!) }} fields={{ user: users[0]!.username }}
/> />
); );
} }
@ -126,11 +101,11 @@ export default observer(({ channel }: Props) => {
<Base> <Base>
<div> <div>
<div className="avatars"> <div className="avatars">
{members.map((member) => ( {users.map((user) => (
<img <img
key={member!._id.user} key={user!._id}
loading="eager" loading="eager"
src={getAvatar(member!)} src={user!.generateAvatarURL({ max_side: 256 })}
/> />
))} ))}
</div> </div>