2021-03-02 16:46:48 -05:00
|
|
|
import * as irc from "../lib/irc.js";
|
2024-02-20 16:50:09 -05:00
|
|
|
import { strip as stripANSI } from "../lib/ansi.js";
|
2021-03-02 16:46:48 -05:00
|
|
|
import { html, Component } from "../lib/index.js";
|
2022-09-05 08:00:52 -04:00
|
|
|
import { BufferType, Unread, ServerStatus, getBufferURL, getServerName } from "../state.js";
|
2021-01-22 05:43:47 -05:00
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
function BufferItem(props) {
|
|
|
|
function handleClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
props.onClick();
|
|
|
|
}
|
2021-10-17 13:33:02 -04:00
|
|
|
function handleMouseDown(event) {
|
|
|
|
if (event.button === 1) { // middle click
|
|
|
|
event.preventDefault();
|
|
|
|
props.onClose();
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 08:23:08 -04:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let name = props.buffer.name;
|
2020-06-26 04:35:38 -04:00
|
|
|
if (props.buffer.type == BufferType.SERVER) {
|
2021-12-07 07:16:07 -05:00
|
|
|
name = getServerName(props.server, props.bouncerNetwork);
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|
|
|
|
|
2024-02-20 16:50:09 -05:00
|
|
|
let title;
|
2021-06-10 12:11:11 -04:00
|
|
|
let classes = ["type-" + props.buffer.type];
|
2021-01-23 06:04:58 -05:00
|
|
|
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
|
|
|
}
|
2024-02-20 16:50:09 -05:00
|
|
|
switch (props.buffer.type) {
|
|
|
|
case BufferType.SERVER:
|
2022-09-05 08:00:52 -04:00
|
|
|
let isError = props.server.status === ServerStatus.DISCONNECTED;
|
|
|
|
if (props.bouncerNetwork && props.bouncerNetwork.error) {
|
|
|
|
isError = true;
|
|
|
|
}
|
|
|
|
if (isError) {
|
|
|
|
classes.push("error");
|
|
|
|
}
|
2024-02-20 16:50:09 -05:00
|
|
|
break;
|
|
|
|
case BufferType.NICK:
|
|
|
|
let user = props.server.users.get(name);
|
|
|
|
if (user && irc.isMeaningfulRealname(user.realname, name)) {
|
|
|
|
title = stripANSI(user.realname);
|
|
|
|
}
|
|
|
|
break;
|
2022-09-05 08:00:52 -04:00
|
|
|
}
|
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(" ")}">
|
2021-10-17 13:33:02 -04:00
|
|
|
<a
|
|
|
|
href=${getBufferURL(props.buffer)}
|
2024-02-20 16:50:09 -05:00
|
|
|
title=${title}
|
2021-10-17 13:33:02 -04:00
|
|
|
onClick=${handleClick}
|
|
|
|
onMouseDown=${handleMouseDown}
|
|
|
|
>${name}</a>
|
2020-06-18 08:23:08 -04:00
|
|
|
</li>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function BufferList(props) {
|
2021-06-10 12:11:11 -04:00
|
|
|
let items = Array.from(props.buffers.values()).map((buf) => {
|
|
|
|
let server = props.servers.get(buf.server);
|
2021-01-22 15:01:03 -05:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let bouncerNetwork = null;
|
2022-02-04 08:32:29 -05:00
|
|
|
if (server.bouncerNetID) {
|
|
|
|
bouncerNetwork = props.bouncerNetworks.get(server.bouncerNetID);
|
2021-01-22 15:01:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return html`
|
2021-05-31 11:34:36 -04:00
|
|
|
<${BufferItem}
|
|
|
|
key=${buf.id}
|
|
|
|
buffer=${buf}
|
2021-06-03 05:46:50 -04:00
|
|
|
server=${server}
|
2021-05-31 11:34:36 -04:00
|
|
|
bouncerNetwork=${bouncerNetwork}
|
|
|
|
onClick=${() => props.onBufferClick(buf)}
|
2021-10-17 13:33:02 -04:00
|
|
|
onClose=${() => props.onBufferClose(buf)}
|
2021-05-31 11:34:36 -04:00
|
|
|
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
|
|
|
}
|