2021-01-22 05:43:47 -05:00
|
|
|
import * as irc from "/lib/irc.js";
|
2020-06-18 08:23:08 -04:00
|
|
|
import { html, Component } from "/lib/index.js";
|
2020-07-15 12:47:33 -04:00
|
|
|
import { BufferType, Unread, getBufferURL } from "/state.js";
|
2020-06-18 08:23:08 -04:00
|
|
|
|
2021-01-22 05:43:47 -05:00
|
|
|
function getNetworkName(network) {
|
|
|
|
var bouncerStr = network.isupport.get("BOUNCER");
|
|
|
|
if (bouncerStr) {
|
|
|
|
var bouncerProps = irc.parseTags(bouncerStr);
|
|
|
|
if (bouncerProps["network"]) {
|
|
|
|
return bouncerProps["network"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var netName = network.isupport.get("NETWORK");
|
|
|
|
if (netName) {
|
|
|
|
return netName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "server";
|
|
|
|
}
|
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
function BufferItem(props) {
|
|
|
|
function handleClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
props.onClick();
|
|
|
|
}
|
|
|
|
|
|
|
|
var name = props.buffer.name;
|
2020-06-26 04:35:38 -04:00
|
|
|
if (props.buffer.type == BufferType.SERVER) {
|
2021-01-22 05:43:47 -05:00
|
|
|
name = getNetworkName(props.network);
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|
|
|
|
|
2020-06-24 10:56:28 -04:00
|
|
|
var activeClass = props.active ? "active" : "";
|
|
|
|
|
|
|
|
var unreadClass = "";
|
|
|
|
if (props.buffer.unread != Unread.NONE) {
|
|
|
|
unreadClass = "unread-" + props.buffer.unread;
|
|
|
|
}
|
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
return html`
|
2020-06-24 10:56:28 -04:00
|
|
|
<li class="${activeClass} ${unreadClass}">
|
2020-07-15 12:47:33 -04:00
|
|
|
<a href=${getBufferURL(props.buffer)} onClick=${handleClick}>${name}</a>
|
2020-06-18 08:23:08 -04:00
|
|
|
</li>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2020-06-26 08:40:27 -04:00
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
export default function BufferList(props) {
|
|
|
|
return html`
|
2020-06-26 09:16:07 -04:00
|
|
|
<ul>
|
2020-08-03 09:43:20 -04:00
|
|
|
${Array.from(props.buffers.values()).map((buf) => html`
|
2021-01-22 05:43:47 -05:00
|
|
|
<${BufferItem} key=${buf.id} buffer=${buf} network=${props.networks.get(buf.network)} onClick=${() => props.onBufferClick(buf.name)} active=${props.activeBuffer == buf.id}/>
|
2020-06-18 08:23:08 -04:00
|
|
|
`)}
|
|
|
|
</ul>
|
|
|
|
`;
|
|
|
|
}
|