2021-03-02 16:46:48 -05:00
|
|
|
import { html, Component } from "../lib/index.js";
|
|
|
|
import { getNickURL } from "../state.js";
|
2021-06-11 05:18:29 -04:00
|
|
|
import Membership from "./membership.js";
|
2020-06-26 08:32:56 -04:00
|
|
|
|
2020-07-13 05:09:16 -04:00
|
|
|
class MemberItem extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2021-05-28 11:45:27 -04:00
|
|
|
return this.props.nick !== nextProps.nick
|
2021-06-11 05:18:29 -04:00
|
|
|
|| this.props.membership !== nextProps.membership;
|
2020-07-13 05:09:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
handleClick(event) {
|
2020-06-26 08:32:56 -04:00
|
|
|
event.preventDefault();
|
2020-07-13 05:09:16 -04:00
|
|
|
this.props.onClick();
|
2020-06-26 08:32:56 -04:00
|
|
|
}
|
|
|
|
|
2020-07-13 05:09:16 -04:00
|
|
|
render() {
|
2021-05-28 11:45:27 -04:00
|
|
|
// XXX: If we were feeling creative we could generate unique colors for
|
|
|
|
// each item in ISUPPORT CHANMODES. But I am not feeling creative.
|
|
|
|
const membmap = {
|
|
|
|
"~": "owner",
|
|
|
|
"&": "admin",
|
|
|
|
"@": "op",
|
|
|
|
"%": "halfop",
|
|
|
|
"+": "voice",
|
|
|
|
};
|
|
|
|
const membclass = membmap[this.props.membership[0]] || "";
|
|
|
|
let membership = "";
|
|
|
|
if (this.props.membership) {
|
|
|
|
membership = html`
|
|
|
|
<span class="membership ${membclass}" title=${membclass}>
|
|
|
|
${this.props.membership}
|
|
|
|
</span>
|
|
|
|
`;
|
|
|
|
};
|
2021-09-21 08:19:30 -04:00
|
|
|
|
|
|
|
let title = null;
|
|
|
|
let user = this.props.user;
|
|
|
|
if (user && user.username && user.hostname) {
|
|
|
|
title = `${user.username}@${user.hostname}`;
|
|
|
|
}
|
|
|
|
|
2020-07-13 05:09:16 -04:00
|
|
|
return html`
|
|
|
|
<li>
|
2021-05-28 11:45:27 -04:00
|
|
|
<a
|
|
|
|
href=${getNickURL(this.props.nick)}
|
|
|
|
class="nick"
|
2021-09-21 08:19:30 -04:00
|
|
|
title=${title}
|
2021-05-28 11:45:27 -04:00
|
|
|
onClick=${this.handleClick}
|
2021-06-11 05:18:29 -04:00
|
|
|
>
|
|
|
|
<${Membership} value=${this.props.membership}/>
|
|
|
|
${this.props.nick}
|
|
|
|
</a>
|
2020-07-13 05:09:16 -04:00
|
|
|
</li>
|
|
|
|
`;
|
|
|
|
}
|
2020-06-26 08:32:56 -04:00
|
|
|
}
|
|
|
|
|
2021-05-28 11:45:27 -04:00
|
|
|
function sortMembers(a, b) {
|
2021-06-10 12:11:11 -04:00
|
|
|
let [nickA, membA] = a, [nickB, membB] = b;
|
2021-05-28 11:45:27 -04:00
|
|
|
|
|
|
|
const prefixPrivs = ["~", "&", "@", "%", "+"]; // TODO: grab it from ISUPPORT PREFIX
|
2021-06-10 12:11:11 -04:00
|
|
|
let i = prefixPrivs.indexOf(membA[0]), j = prefixPrivs.indexOf(membB[0]);
|
2021-05-28 11:45:27 -04:00
|
|
|
if (i < 0) {
|
|
|
|
i = prefixPrivs.length;
|
|
|
|
}
|
|
|
|
if (j < 0) {
|
|
|
|
j = prefixPrivs.length;
|
|
|
|
}
|
|
|
|
if (i !== j) {
|
|
|
|
return i - j;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nickA < nickB ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
2020-07-13 05:09:16 -04:00
|
|
|
export default class MemberList extends Component {
|
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
return this.props.members !== nextProps.members;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return html`
|
|
|
|
<ul>
|
2021-05-28 11:45:27 -04:00
|
|
|
${Array.from(this.props.members).sort(sortMembers).map(([nick, membership]) => html`
|
|
|
|
<${MemberItem}
|
|
|
|
key=${nick}
|
|
|
|
nick=${nick}
|
|
|
|
membership=${membership}
|
2021-09-21 08:19:30 -04:00
|
|
|
user=${this.props.users.get(nick)}
|
2021-05-28 11:45:27 -04:00
|
|
|
onClick=${() => this.props.onNickClick(nick)}
|
|
|
|
/>
|
2020-07-13 05:09:16 -04:00
|
|
|
`)}
|
|
|
|
</ul>
|
|
|
|
`;
|
|
|
|
}
|
2020-06-26 08:32:56 -04:00
|
|
|
}
|