2020-06-25 12:30:21 -04:00
|
|
|
import { html, Component } from "/lib/index.js";
|
2020-07-13 07:00:49 -04:00
|
|
|
import linkify from "/lib/linkify.js";
|
2020-08-04 08:25:05 -04:00
|
|
|
import { strip as stripANSI } from "/lib/ansi.js";
|
2021-01-22 12:29:22 -05:00
|
|
|
import { BufferType, NetworkStatus } from "/state.js";
|
2020-06-25 12:30:21 -04:00
|
|
|
|
2021-01-22 05:53:17 -05:00
|
|
|
const UserStatus = {
|
2020-07-13 06:51:09 -04:00
|
|
|
HERE: "here",
|
|
|
|
GONE: "gone",
|
|
|
|
OFFLINE: "offline",
|
|
|
|
};
|
|
|
|
|
|
|
|
function NickStatus(props) {
|
|
|
|
var textMap = {
|
2021-01-22 05:53:17 -05:00
|
|
|
[UserStatus.HERE]: "User is online",
|
|
|
|
[UserStatus.GONE]: "User is away",
|
|
|
|
[UserStatus.OFFLINE]: "User is offline",
|
2020-07-13 06:51:09 -04:00
|
|
|
};
|
|
|
|
var text = textMap[props.status];
|
|
|
|
return html`<span class="status status-${props.status}" title=${text}>●</span>`;
|
|
|
|
}
|
|
|
|
|
2020-06-25 12:30:21 -04:00
|
|
|
export default function BufferHeader(props) {
|
|
|
|
function handlePartClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
props.onClose();
|
|
|
|
}
|
2021-03-02 10:13:49 -05:00
|
|
|
function handleJoinClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
props.onJoin();
|
|
|
|
}
|
2020-06-25 12:30:21 -04:00
|
|
|
|
2020-06-26 06:00:10 -04:00
|
|
|
var description = null;
|
2020-06-26 06:08:14 -04:00
|
|
|
if (props.buffer.serverInfo) {
|
2021-01-22 05:53:17 -05:00
|
|
|
switch (props.network.status) {
|
2021-01-22 12:29:22 -05:00
|
|
|
case NetworkStatus.DISCONNECTED:
|
2021-01-22 05:53:17 -05:00
|
|
|
description = "Disconnected";
|
|
|
|
break;
|
2021-01-22 12:29:22 -05:00
|
|
|
case NetworkStatus.CONNECTING:
|
2021-01-22 05:53:17 -05:00
|
|
|
description = "Connecting...";
|
|
|
|
break;
|
2021-01-22 12:29:22 -05:00
|
|
|
case NetworkStatus.REGISTERING:
|
|
|
|
description = "Logging in...";
|
|
|
|
break;
|
|
|
|
case NetworkStatus.REGISTERED:
|
2021-01-22 05:53:17 -05:00
|
|
|
var serverInfo = props.buffer.serverInfo;
|
|
|
|
description = `Connected to ${serverInfo.name}`;
|
|
|
|
break;
|
|
|
|
}
|
2020-06-26 06:08:14 -04:00
|
|
|
} else if (props.buffer.topic) {
|
2020-08-04 08:25:05 -04:00
|
|
|
description = linkify(stripANSI(props.buffer.topic));
|
2020-06-26 06:00:10 -04:00
|
|
|
} else if (props.buffer.who) {
|
|
|
|
var who = props.buffer.who;
|
2020-06-26 06:45:27 -04:00
|
|
|
|
2020-08-04 08:25:05 -04:00
|
|
|
var realname = stripANSI(who.realname || "");
|
|
|
|
|
2021-01-22 05:53:17 -05:00
|
|
|
var status = UserStatus.HERE;
|
2020-06-26 06:45:27 -04:00
|
|
|
if (who.away) {
|
2021-01-22 05:53:17 -05:00
|
|
|
status = UserStatus.GONE;
|
2020-07-13 06:51:09 -04:00
|
|
|
}
|
|
|
|
if (props.buffer.offline) {
|
2021-01-22 05:53:17 -05:00
|
|
|
status = UserStatus.OFFLINE;
|
2020-06-26 06:45:27 -04:00
|
|
|
}
|
|
|
|
|
2020-08-04 08:25:05 -04:00
|
|
|
description = html`<${NickStatus} status=${status}/> ${realname} (${who.username}@${who.hostname})`;
|
2020-07-13 06:51:09 -04:00
|
|
|
} else if (props.buffer.offline) {
|
|
|
|
// User is offline, but we don't have WHO information
|
2021-01-22 05:53:17 -05:00
|
|
|
description = html`<${NickStatus} status=${UserStatus.OFFLINE}/> ${props.buffer.name}`;
|
2020-06-26 06:00:10 -04:00
|
|
|
}
|
|
|
|
|
2021-03-02 10:13:49 -05:00
|
|
|
var actions = null;
|
2020-06-26 06:00:10 -04:00
|
|
|
var closeText = "Close";
|
|
|
|
switch (props.buffer.type) {
|
|
|
|
case BufferType.SERVER:
|
2021-03-02 10:13:49 -05:00
|
|
|
actions = html`<a href="#" onClick=${handleJoinClick}>Join</a>`;
|
2020-06-26 06:00:10 -04:00
|
|
|
closeText = "Disconnect";
|
|
|
|
break;
|
|
|
|
case BufferType.CHANNEL:
|
|
|
|
closeText = "Part";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-25 12:30:21 -04:00
|
|
|
return html`
|
2020-06-26 06:08:14 -04:00
|
|
|
<span class="description">${description}</span>
|
2020-06-25 12:30:21 -04:00
|
|
|
<span class="actions">
|
2021-03-02 10:13:49 -05:00
|
|
|
${actions}
|
|
|
|
${" "}
|
2020-06-26 06:00:10 -04:00
|
|
|
<a href="#" onClick=${handlePartClick}>${closeText}</a>
|
2020-06-25 12:30:21 -04:00
|
|
|
</span>
|
|
|
|
`;
|
|
|
|
}
|