2021-03-02 16:46:48 -05:00
|
|
|
import * as irc from "../lib/irc.js";
|
|
|
|
import { html, Component } from "../lib/index.js";
|
|
|
|
import { BufferType, Unread, getBufferURL } from "../state.js";
|
2020-06-18 08:23:08 -04:00
|
|
|
|
2021-01-22 15:01:03 -05:00
|
|
|
function getNetworkName(network, bouncerNetwork, bouncer) {
|
|
|
|
if (bouncerNetwork && bouncerNetwork.name) {
|
|
|
|
return bouncerNetwork.name;
|
|
|
|
}
|
|
|
|
if (bouncer) {
|
|
|
|
return "bouncer";
|
2021-01-22 05:43:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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-03-08 12:15:04 -05:00
|
|
|
name = getNetworkName(props.network, props.bouncerNetwork, props.isBouncer);
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|
|
|
|
|
2021-01-23 06:04:58 -05:00
|
|
|
var classes = ["type-" + props.buffer.type];
|
|
|
|
if (props.active) {
|
|
|
|
classes.push("active");
|
|
|
|
}
|
2020-06-24 10:56:28 -04:00
|
|
|
if (props.buffer.unread != Unread.NONE) {
|
2021-01-23 06:04:58 -05:00
|
|
|
classes.push("unread-" + props.buffer.unread);
|
2020-06-24 10:56:28 -04:00
|
|
|
}
|
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
return html`
|
2021-01-23 06:04:58 -05:00
|
|
|
<li class="${classes.join(" ")}">
|
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) {
|
2021-01-22 15:01:03 -05:00
|
|
|
var items = Array.from(props.buffers.values()).map((buf) => {
|
|
|
|
var network = props.networks.get(buf.network);
|
|
|
|
|
|
|
|
var bouncerNetwork = null;
|
|
|
|
var bouncerNetID = network.isupport.get("BOUNCER_NETID");
|
|
|
|
if (bouncerNetID) {
|
|
|
|
bouncerNetwork = props.bouncerNetworks.get(bouncerNetID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return html`
|
2021-03-08 12:15:04 -05:00
|
|
|
<${BufferItem} key=${buf.id} buffer=${buf} network=${network} isBouncer=${props.isBouncer} bouncerNetwork=${bouncerNetwork} onClick=${() => props.onBufferClick(buf)} active=${props.activeBuffer == buf.id}/>
|
2021-01-22 15:01:03 -05:00
|
|
|
`;
|
|
|
|
});
|
|
|
|
|
|
|
|
return html`<ul>${items}</ul>`;
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|