2021-03-02 16:46:48 -05:00
|
|
|
import { html, Component } from "../lib/index.js";
|
|
|
|
import linkify from "../lib/linkify.js";
|
|
|
|
import * as irc from "../lib/irc.js";
|
|
|
|
import { strip as stripANSI } from "../lib/ansi.js";
|
2022-02-11 10:37:58 -05:00
|
|
|
import { BufferType, ServerStatus, getNickURL, getChannelURL, getMessageURL, isMessageBeforeReceipt } from "../state.js";
|
2021-11-07 11:53:10 -05:00
|
|
|
import * as store from "../store.js";
|
2021-06-11 05:18:29 -04:00
|
|
|
import Membership from "./membership.js";
|
2020-06-18 08:23:08 -04:00
|
|
|
|
|
|
|
function djb2(s) {
|
2021-06-10 12:11:11 -04:00
|
|
|
let hash = 5381;
|
|
|
|
for (let i = 0; i < s.length; i++) {
|
2020-06-18 08:23:08 -04:00
|
|
|
hash = (hash << 5) + hash + s.charCodeAt(i);
|
|
|
|
hash = hash >>> 0; // convert to uint32
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Nick(props) {
|
|
|
|
function handleClick(event) {
|
|
|
|
event.preventDefault();
|
2020-06-25 12:45:41 -04:00
|
|
|
props.onClick();
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let colorIndex = djb2(props.nick) % 16 + 1;
|
2020-06-18 08:23:08 -04:00
|
|
|
return html`
|
2020-07-15 12:47:33 -04:00
|
|
|
<a href=${getNickURL(props.nick)} class="nick nick-${colorIndex}" onClick=${handleClick}>${props.nick}</a>
|
2020-06-18 08:23:08 -04:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2020-07-15 12:47:33 -04:00
|
|
|
function Timestamp({ date, url }) {
|
2020-07-09 17:33:34 -04:00
|
|
|
if (!date) {
|
|
|
|
return html`<spam class="timestamp">--:--:--</span>`;
|
2020-06-25 12:45:41 -04:00
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let hh = date.getHours().toString().padStart(2, "0");
|
|
|
|
let mm = date.getMinutes().toString().padStart(2, "0");
|
|
|
|
let ss = date.getSeconds().toString().padStart(2, "0");
|
|
|
|
let timestamp = `${hh}:${mm}:${ss}`;
|
2020-07-09 17:33:34 -04:00
|
|
|
return html`
|
2021-09-21 08:34:30 -04:00
|
|
|
<a
|
|
|
|
href=${url}
|
|
|
|
class="timestamp"
|
|
|
|
title=${date.toLocaleString()}
|
|
|
|
onClick=${(event) => event.preventDefault()}
|
|
|
|
>
|
|
|
|
${timestamp}
|
|
|
|
</a>
|
2020-06-18 08:23:08 -04:00
|
|
|
`;
|
2020-07-09 17:33:34 -04:00
|
|
|
}
|
|
|
|
|
2021-05-28 08:52:31 -04:00
|
|
|
/**
|
|
|
|
* Check whether a message can be folded.
|
|
|
|
*
|
|
|
|
* Unimportant and noisy messages that may clutter the discussion should be
|
|
|
|
* folded.
|
|
|
|
*/
|
|
|
|
function canFoldMessage(msg) {
|
|
|
|
switch (msg.command) {
|
|
|
|
case "JOIN":
|
|
|
|
case "PART":
|
|
|
|
case "QUIT":
|
|
|
|
case "NICK":
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-09 17:33:34 -04:00
|
|
|
class LogLine extends Component {
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2020-07-13 05:03:34 -04:00
|
|
|
return this.props.message !== nextProps.message;
|
2020-07-09 17:33:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-06-10 12:11:11 -04:00
|
|
|
let msg = this.props.message;
|
2021-06-11 05:18:29 -04:00
|
|
|
let buf = this.props.buffer;
|
|
|
|
let server = this.props.server;
|
2020-06-18 08:23:08 -04:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let onNickClick = this.props.onNickClick;
|
|
|
|
let onChannelClick = this.props.onChannelClick;
|
2021-11-30 09:13:34 -05:00
|
|
|
let onVerifyClick = this.props.onVerifyClick;
|
|
|
|
|
2020-07-09 17:33:34 -04:00
|
|
|
function createNick(nick) {
|
|
|
|
return html`
|
2021-03-03 03:41:19 -05:00
|
|
|
<${Nick} nick=${nick} onClick=${() => onNickClick(nick)}/>
|
2020-07-09 17:33:34 -04:00
|
|
|
`;
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|
2021-06-03 05:04:32 -04:00
|
|
|
function createChannel(channel) {
|
|
|
|
return html`
|
2022-01-10 04:32:37 -05:00
|
|
|
<a href=${getChannelURL(channel)} onClick=${onChannelClick}>
|
2021-06-03 05:04:32 -04:00
|
|
|
${channel}
|
|
|
|
</a>
|
|
|
|
`;
|
|
|
|
}
|
2020-07-09 17:33:34 -04:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let lineClass = "";
|
|
|
|
let content;
|
2021-11-16 07:32:54 -05:00
|
|
|
let invitee, target, account;
|
2020-07-09 17:33:34 -04:00
|
|
|
switch (msg.command) {
|
|
|
|
case "NOTICE":
|
|
|
|
case "PRIVMSG":
|
2021-11-03 16:58:26 -04:00
|
|
|
target = msg.params[0];
|
2021-06-10 12:11:11 -04:00
|
|
|
let text = msg.params[1];
|
2020-07-09 17:33:34 -04:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let ctcp = irc.parseCTCP(msg);
|
2020-08-13 10:04:39 -04:00
|
|
|
if (ctcp) {
|
|
|
|
if (ctcp.command == "ACTION") {
|
|
|
|
lineClass = "me-tell";
|
2021-05-31 22:39:35 -04:00
|
|
|
content = html`* ${createNick(msg.prefix.name)} ${linkify(stripANSI(ctcp.param), onChannelClick)}`;
|
2020-08-13 10:04:39 -04:00
|
|
|
} else {
|
|
|
|
content = html`
|
|
|
|
${createNick(msg.prefix.name)} has sent a CTCP command: ${ctcp.command} ${ctcp.param}
|
|
|
|
`;
|
|
|
|
}
|
2020-07-09 17:33:34 -04:00
|
|
|
} else {
|
|
|
|
lineClass = "talk";
|
2021-06-10 12:11:11 -04:00
|
|
|
let prefix = "<", suffix = ">";
|
2020-08-17 09:08:37 -04:00
|
|
|
if (msg.command == "NOTICE") {
|
|
|
|
prefix = suffix = "-";
|
|
|
|
}
|
2021-05-31 22:39:35 -04:00
|
|
|
content = html`${prefix}${createNick(msg.prefix.name)}${suffix} ${linkify(stripANSI(text), onChannelClick)}`;
|
2020-07-09 17:33:34 -04:00
|
|
|
}
|
2020-08-13 05:58:36 -04:00
|
|
|
|
2021-06-11 05:18:29 -04:00
|
|
|
let status = null;
|
2021-12-07 06:09:10 -05:00
|
|
|
let allowedPrefixes = server.statusMsg;
|
2021-06-11 05:18:29 -04:00
|
|
|
if (target !== buf.name && allowedPrefixes) {
|
|
|
|
let parts = irc.parseTargetPrefix(target, allowedPrefixes);
|
|
|
|
if (parts.name === buf.name) {
|
|
|
|
content = [html`(<${Membership} value=${parts.prefix}/>)`, " ", content];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 05:58:36 -04:00
|
|
|
if (msg.isHighlight) {
|
|
|
|
lineClass += " highlight";
|
|
|
|
}
|
2020-07-09 17:33:34 -04:00
|
|
|
break;
|
2021-05-28 12:47:40 -04:00
|
|
|
case "JOIN":
|
|
|
|
content = html`
|
|
|
|
${createNick(msg.prefix.name)} has joined
|
|
|
|
`;
|
|
|
|
break;
|
|
|
|
case "PART":
|
|
|
|
content = html`
|
|
|
|
${createNick(msg.prefix.name)} has left
|
|
|
|
`;
|
|
|
|
break;
|
|
|
|
case "QUIT":
|
|
|
|
content = html`
|
|
|
|
${createNick(msg.prefix.name)} has quit
|
|
|
|
`;
|
|
|
|
break;
|
|
|
|
case "NICK":
|
2021-06-10 12:11:11 -04:00
|
|
|
let newNick = msg.params[0];
|
2021-05-28 12:47:40 -04:00
|
|
|
content = html`
|
|
|
|
${createNick(msg.prefix.name)} is now known as ${createNick(newNick)}
|
|
|
|
`;
|
|
|
|
break;
|
2021-05-26 19:28:24 -04:00
|
|
|
case "KICK":
|
|
|
|
content = html`
|
|
|
|
${createNick(msg.params[1])} was kicked by ${createNick(msg.prefix.name)} (${msg.params.slice(2)})
|
|
|
|
`;
|
|
|
|
break;
|
2021-05-27 09:34:43 -04:00
|
|
|
case "MODE":
|
2021-11-03 16:58:26 -04:00
|
|
|
target = msg.params[0];
|
2021-05-27 09:34:43 -04:00
|
|
|
content = html`
|
|
|
|
* ${createNick(msg.prefix.name)} sets mode ${msg.params.slice(1).join(" ")}
|
|
|
|
`;
|
2021-11-03 16:58:26 -04:00
|
|
|
// TODO: case-mapping
|
|
|
|
if (buf.name !== target) {
|
|
|
|
content = html`${content} on ${target}`;
|
|
|
|
}
|
2021-05-27 09:34:43 -04:00
|
|
|
break;
|
2020-07-09 17:33:34 -04:00
|
|
|
case "TOPIC":
|
2021-06-10 12:11:11 -04:00
|
|
|
let topic = msg.params[1];
|
2020-07-09 17:33:34 -04:00
|
|
|
content = html`
|
2021-05-31 22:39:35 -04:00
|
|
|
${createNick(msg.prefix.name)} changed the topic to: ${linkify(stripANSI(topic), onChannelClick)}
|
2020-07-09 17:33:34 -04:00
|
|
|
`;
|
|
|
|
break;
|
2021-06-03 05:04:32 -04:00
|
|
|
case "INVITE":
|
2021-06-24 12:01:24 -04:00
|
|
|
invitee = msg.params[0];
|
2021-06-10 12:11:11 -04:00
|
|
|
let channel = msg.params[1];
|
2021-06-03 05:04:32 -04:00
|
|
|
// TODO: instead of checking buffer type, check if invitee is our nick
|
2021-06-11 05:18:29 -04:00
|
|
|
if (buf.type === BufferType.SERVER) {
|
2021-06-03 05:04:32 -04:00
|
|
|
lineClass = "talk";
|
|
|
|
content = html`
|
|
|
|
You have been invited to ${createChannel(channel)} by ${createNick(msg.prefix.name)}
|
|
|
|
`;
|
|
|
|
} else {
|
|
|
|
content = html`
|
|
|
|
${createNick(msg.prefix.name)} has invited ${createNick(invitee)} to the channel
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
break;
|
2021-11-02 10:27:24 -04:00
|
|
|
case irc.RPL_WELCOME:
|
|
|
|
let nick = msg.params[0];
|
|
|
|
content = html`Connected to server, your nickname is ${nick}`;
|
|
|
|
break;
|
2021-06-24 12:01:24 -04:00
|
|
|
case irc.RPL_INVITING:
|
|
|
|
invitee = msg.params[1];
|
|
|
|
content = html`${createNick(invitee)} has been invited to the channel`;
|
|
|
|
break;
|
2021-05-28 04:46:32 -04:00
|
|
|
case irc.RPL_MOTD:
|
|
|
|
lineClass = "motd";
|
2021-06-10 06:09:07 -04:00
|
|
|
content = linkify(stripANSI(msg.params[1]), onChannelClick);
|
2021-05-28 04:46:32 -04:00
|
|
|
break;
|
2021-10-18 16:11:14 -04:00
|
|
|
case irc.RPL_LOGGEDIN:
|
2021-11-16 07:32:54 -05:00
|
|
|
account = msg.params[2];
|
2021-10-18 16:11:14 -04:00
|
|
|
content = html`You are now authenticated as ${account}`;
|
|
|
|
break;
|
|
|
|
case irc.RPL_LOGGEDOUT:
|
|
|
|
content = html`You are now unauthenticated`;
|
|
|
|
break;
|
2021-11-16 07:32:54 -05:00
|
|
|
case "REGISTER":
|
|
|
|
account = msg.params[1];
|
2021-11-30 09:13:34 -05:00
|
|
|
let reason = msg.params[2];
|
|
|
|
|
|
|
|
function handleVerifyClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
onVerifyClick(account, reason);
|
|
|
|
}
|
|
|
|
|
2021-11-16 07:32:54 -05:00
|
|
|
switch (msg.params[0]) {
|
|
|
|
case "SUCCESS":
|
|
|
|
content = html`A new account has been created, you are now authenticated as ${account}`;
|
|
|
|
break;
|
|
|
|
case "VERIFICATION_REQUIRED":
|
2021-11-30 09:13:34 -05:00
|
|
|
content = html`A new account has been created, but you need to <a href="#" onClick=${handleVerifyClick}>verify it</a>: ${linkify(reason)}`;
|
2021-11-16 07:32:54 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "VERIFY":
|
|
|
|
account = msg.params[1];
|
|
|
|
content = html`The new account has been verified, you are now authenticated as ${account}`;
|
|
|
|
break;
|
2021-10-05 05:22:20 -04:00
|
|
|
case irc.RPL_UMODEIS:
|
|
|
|
let mode = msg.params[1];
|
|
|
|
if (mode) {
|
|
|
|
content = html`Your user mode is ${mode}`;
|
|
|
|
} else {
|
|
|
|
content = html`You have no user mode`;
|
|
|
|
}
|
|
|
|
break;
|
2021-10-06 06:12:49 -04:00
|
|
|
case irc.RPL_CHANNELMODEIS:
|
|
|
|
content = html`Channel mode is ${msg.params.slice(2).join(" ")}`;
|
|
|
|
break;
|
|
|
|
case irc.RPL_CREATIONTIME:
|
|
|
|
let date = new Date(parseInt(msg.params[2], 10) * 1000);
|
|
|
|
content = html`Channel was created on ${date.toLocaleString()}`;
|
|
|
|
break;
|
2020-07-09 17:33:34 -04:00
|
|
|
default:
|
|
|
|
if (irc.isError(msg.command) && msg.command != irc.ERR_NOMOTD) {
|
|
|
|
lineClass = "error";
|
|
|
|
}
|
2021-11-29 07:38:07 -05:00
|
|
|
content = html`${msg.command} ${linkify(msg.params.join(" "))}`;
|
2020-06-29 08:29:31 -04:00
|
|
|
}
|
2020-06-18 08:23:08 -04:00
|
|
|
|
2021-11-16 07:32:54 -05:00
|
|
|
if (!content) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-07-09 17:33:34 -04:00
|
|
|
return html`
|
2021-03-02 14:48:49 -05:00
|
|
|
<div class="logline ${lineClass}" data-key=${msg.key}>
|
2021-06-11 05:18:29 -04:00
|
|
|
<${Timestamp} date=${new Date(msg.tags.time)} url=${getMessageURL(buf, msg)}/>
|
2020-07-09 17:33:34 -04:00
|
|
|
${" "}
|
|
|
|
${content}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|
|
|
|
|
2021-05-28 12:47:40 -04:00
|
|
|
function createNickList(nicks, createNick) {
|
|
|
|
if (nicks.length === 0) {
|
|
|
|
return null;
|
|
|
|
} else if (nicks.length === 1) {
|
|
|
|
return createNick(nicks[0]);
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let l = nicks.slice(0, nicks.length - 1).map((nick, i) => {
|
2021-05-28 12:47:40 -04:00
|
|
|
if (i === 0) {
|
|
|
|
return createNick(nick);
|
|
|
|
} else {
|
|
|
|
return [", ", createNick(nick)];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
l.push(" and ");
|
|
|
|
l.push(createNick(nicks[nicks.length - 1]));
|
|
|
|
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2021-05-28 08:52:31 -04:00
|
|
|
class FoldGroup extends Component {
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2021-05-28 12:36:25 -04:00
|
|
|
return this.props.messages[0] !== nextProps.messages[0] ||
|
|
|
|
this.props.messages[this.props.messages.length - 1] !== nextProps.messages[nextProps.messages.length - 1];
|
2021-05-28 08:52:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-06-10 12:11:11 -04:00
|
|
|
let msgs = this.props.messages;
|
|
|
|
let buf = this.props.buffer;
|
2021-05-28 08:52:31 -04:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let onNickClick = this.props.onNickClick;
|
2021-05-28 08:52:31 -04:00
|
|
|
function createNick(nick) {
|
|
|
|
return html`
|
|
|
|
<${Nick} nick=${nick} onClick=${() => onNickClick(nick)}/>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let byCommand = {
|
2021-05-28 12:47:40 -04:00
|
|
|
"JOIN": [],
|
|
|
|
"PART": [],
|
|
|
|
"QUIT": [],
|
|
|
|
"NICK": [],
|
|
|
|
};
|
|
|
|
msgs.forEach((msg) => {
|
|
|
|
byCommand[msg.command].push(msg);
|
|
|
|
});
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let first = true;
|
|
|
|
let content = [];
|
2021-05-28 12:47:40 -04:00
|
|
|
["JOIN", "PART", "QUIT"].forEach((cmd) => {
|
|
|
|
if (byCommand[cmd].length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-05 10:00:08 -04:00
|
|
|
let nicks = new Set(byCommand[cmd].map((msg) => msg.prefix.name));
|
|
|
|
|
|
|
|
let plural = nicks.size > 1;
|
2021-06-10 12:11:11 -04:00
|
|
|
let action;
|
2021-05-28 12:47:40 -04:00
|
|
|
switch (cmd) {
|
|
|
|
case "JOIN":
|
|
|
|
action = plural ? "have joined" : "has joined";
|
|
|
|
break;
|
|
|
|
case "PART":
|
|
|
|
action = plural ? "have left" : "has left";
|
|
|
|
break;
|
|
|
|
case "QUIT":
|
|
|
|
action = plural ? "have quit" : "has quit";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
content.push(", ");
|
|
|
|
}
|
|
|
|
|
2021-11-05 10:00:08 -04:00
|
|
|
content.push(createNickList([...nicks], createNick));
|
2021-05-28 12:47:40 -04:00
|
|
|
content.push(" " + action);
|
|
|
|
});
|
|
|
|
|
|
|
|
byCommand["NICK"].forEach((msg) => {
|
|
|
|
if (first) {
|
2021-05-31 08:08:30 -04:00
|
|
|
first = false;
|
2021-05-28 08:52:31 -04:00
|
|
|
} else {
|
2021-05-28 12:47:40 -04:00
|
|
|
content.push(", ");
|
2021-05-28 08:52:31 -04:00
|
|
|
}
|
2021-05-28 12:47:40 -04:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let newNick = msg.params[0];
|
2021-05-28 12:47:40 -04:00
|
|
|
content.push(html`
|
|
|
|
${createNick(msg.prefix.name)} is now known as ${createNick(newNick)}
|
|
|
|
`);
|
2021-05-28 08:52:31 -04:00
|
|
|
});
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let lastMsg = msgs[msgs.length - 1];
|
|
|
|
let firstDate = new Date(msgs[0].tags.time);
|
|
|
|
let lastDate = new Date(lastMsg.tags.time);
|
|
|
|
let timestamp = html`
|
2021-05-28 10:01:34 -04:00
|
|
|
<${Timestamp} date=${firstDate} url=${getMessageURL(buf, msgs[0])}/>
|
|
|
|
`;
|
|
|
|
if (lastDate - firstDate > 60 * 100) {
|
|
|
|
timestamp = [
|
|
|
|
timestamp,
|
|
|
|
" — ",
|
|
|
|
html`
|
|
|
|
<${Timestamp} date=${lastDate} url=${getMessageURL(buf, lastMsg)}/>
|
|
|
|
`,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-05-28 08:52:31 -04:00
|
|
|
return html`
|
|
|
|
<div class="logline" data-key=${msgs[0].key}>
|
2021-05-28 10:01:34 -04:00
|
|
|
${timestamp}
|
2021-05-28 08:52:31 -04:00
|
|
|
${" "}
|
|
|
|
${content}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-10 11:01:26 -04:00
|
|
|
// Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=481856
|
2021-06-10 12:11:11 -04:00
|
|
|
let notificationsSupported = false;
|
2021-06-10 11:01:26 -04:00
|
|
|
if (window.Notification) {
|
|
|
|
notificationsSupported = true;
|
|
|
|
if (Notification.permission === "default") {
|
|
|
|
try {
|
|
|
|
new Notification("");
|
|
|
|
} catch (err) {
|
|
|
|
if (err.name === "TypeError") {
|
|
|
|
notificationsSupported = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 05:50:42 -04:00
|
|
|
class NotificationNagger extends Component {
|
|
|
|
state = { nag: false };
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
|
|
|
|
this.state.nag = this.shouldNag();
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldNag() {
|
2021-06-10 11:01:26 -04:00
|
|
|
return notificationsSupported && Notification.permission === "default";
|
2020-06-29 05:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
handleClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
Notification.requestPermission((permission) => {
|
|
|
|
this.setState({ nag: this.shouldNag() });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (!this.state.nag) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return html`
|
|
|
|
<div class="logline">
|
2020-07-09 17:33:34 -04:00
|
|
|
<${Timestamp}/>
|
2020-06-29 05:50:42 -04:00
|
|
|
${" "}
|
|
|
|
<a href="#" onClick=${this.handleClick}>Turn on desktop notifications</a> to get notified about new messages
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 11:53:10 -05:00
|
|
|
class ProtocolHandlerNagger extends Component {
|
|
|
|
state = { nag: true };
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
|
|
|
|
this.state.nag = !store.naggedProtocolHandler.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
let url = window.location.origin + window.location.pathname + "?open=%s";
|
|
|
|
try {
|
|
|
|
navigator.registerProtocolHandler("irc", url);
|
|
|
|
navigator.registerProtocolHandler("ircs", url);
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Failed to register protocol handler: ", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
store.naggedProtocolHandler.put(true);
|
|
|
|
this.setState({ nag: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (!navigator.registerProtocolHandler || !this.state.nag) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-16 05:30:33 -05:00
|
|
|
let name = this.props.bouncerName || "this bouncer";
|
2021-11-07 11:53:10 -05:00
|
|
|
return html`
|
|
|
|
<div class="logline">
|
|
|
|
<${Timestamp}/>
|
|
|
|
${" "}
|
2021-11-16 05:30:33 -05:00
|
|
|
<a href="#" onClick=${this.handleClick}>Register our protocol handler</a> to open IRC links with ${name}
|
2021-11-07 11:53:10 -05:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 07:32:54 -05:00
|
|
|
function AccountNagger({ server, onAuthClick, onRegisterClick }) {
|
2021-11-21 10:40:46 -05:00
|
|
|
let accDesc = "an account on this server";
|
2021-12-07 06:09:10 -05:00
|
|
|
if (server.name) {
|
|
|
|
accDesc = "a " + server.name + " account";
|
2021-11-21 10:40:46 -05:00
|
|
|
}
|
|
|
|
|
2021-11-16 07:32:54 -05:00
|
|
|
function handleAuthClick(event) {
|
2021-11-21 10:40:46 -05:00
|
|
|
event.preventDefault();
|
2021-11-16 07:32:54 -05:00
|
|
|
onAuthClick();
|
|
|
|
}
|
|
|
|
function handleRegisterClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
onRegisterClick();
|
|
|
|
}
|
|
|
|
|
|
|
|
let msg = [html`
|
|
|
|
You are unauthenticated on this server,
|
|
|
|
${" "}
|
|
|
|
<a href="#" onClick=${handleAuthClick}>login</a>
|
|
|
|
${" "}
|
|
|
|
`];
|
|
|
|
|
|
|
|
if (server.supportsAccountRegistration) {
|
|
|
|
msg.push(html`or <a href="#" onClick=${handleRegisterClick}>register</a> ${accDesc}`);
|
|
|
|
} else {
|
|
|
|
msg.push(html`if you have ${accDesc}`);
|
2021-11-21 10:40:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return html`
|
|
|
|
<div class="logline">
|
2021-11-16 07:32:54 -05:00
|
|
|
<${Timestamp}/> ${msg}
|
2021-11-21 10:40:46 -05:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2020-08-13 13:00:56 -04:00
|
|
|
class DateSeparator extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
return this.props.date.getTime() !== nextProps.date.getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-06-10 12:11:11 -04:00
|
|
|
let date = this.props.date;
|
2022-01-13 15:00:45 -05:00
|
|
|
let text = date.toLocaleDateString([], { year: "numeric", month: "2-digit", day: "2-digit" });
|
2020-08-13 13:00:56 -04:00
|
|
|
return html`
|
2020-09-03 05:51:52 -04:00
|
|
|
<div class="separator date-separator">
|
2020-08-13 13:00:56 -04:00
|
|
|
${text}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 05:51:52 -04:00
|
|
|
function UnreadSeparator(props) {
|
|
|
|
return html`<div class="separator unread-separator">New messages</div>`;
|
|
|
|
}
|
|
|
|
|
2020-08-13 13:00:56 -04:00
|
|
|
function sameDate(d1, d2) {
|
|
|
|
return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate();
|
|
|
|
}
|
|
|
|
|
2020-07-09 17:33:34 -04:00
|
|
|
export default class Buffer extends Component {
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2020-07-13 05:03:34 -04:00
|
|
|
return this.props.buffer !== nextProps.buffer;
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|
|
|
|
|
2020-07-09 17:33:34 -04:00
|
|
|
render() {
|
2021-06-10 12:11:11 -04:00
|
|
|
let buf = this.props.buffer;
|
2020-09-03 05:51:52 -04:00
|
|
|
if (!buf) {
|
2020-07-09 17:33:34 -04:00
|
|
|
return null;
|
|
|
|
}
|
2020-07-01 05:58:30 -04:00
|
|
|
|
2021-11-16 07:32:54 -05:00
|
|
|
let server = this.props.server;
|
|
|
|
let bouncerNetwork = this.props.bouncerNetwork;
|
2021-12-07 06:09:10 -05:00
|
|
|
let serverName = server.name;
|
2021-11-16 07:32:54 -05:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let children = [];
|
2020-09-03 05:51:52 -04:00
|
|
|
if (buf.type == BufferType.SERVER) {
|
2020-08-13 13:00:56 -04:00
|
|
|
children.push(html`<${NotificationNagger}/>`);
|
2020-07-09 17:33:34 -04:00
|
|
|
}
|
2021-12-07 07:16:07 -05:00
|
|
|
if (buf.type == BufferType.SERVER && server.isBouncer && !server.bouncerNetID) {
|
2021-11-16 07:32:54 -05:00
|
|
|
children.push(html`<${ProtocolHandlerNagger} bouncerName=${serverName}/>`);
|
2021-11-07 11:53:10 -05:00
|
|
|
}
|
2021-11-21 10:40:46 -05:00
|
|
|
if (buf.type == BufferType.SERVER && server.status == ServerStatus.REGISTERED && server.supportsSASLPlain && !server.account) {
|
2021-11-16 07:32:54 -05:00
|
|
|
children.push(html`
|
|
|
|
<${AccountNagger}
|
|
|
|
server=${server}
|
|
|
|
onAuthClick=${this.props.onAuthClick}
|
|
|
|
onRegisterClick=${this.props.onRegisterClick}
|
|
|
|
/>
|
|
|
|
`);
|
2021-11-21 10:40:46 -05:00
|
|
|
}
|
2020-07-09 17:33:34 -04:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let onChannelClick = this.props.onChannelClick;
|
|
|
|
let onNickClick = this.props.onNickClick;
|
2021-11-30 09:13:34 -05:00
|
|
|
let onVerifyClick = this.props.onVerifyClick;
|
|
|
|
|
2021-05-28 08:52:31 -04:00
|
|
|
function createLogLine(msg) {
|
|
|
|
return html`
|
|
|
|
<${LogLine}
|
|
|
|
key=${"msg-" + msg.key}
|
|
|
|
message=${msg}
|
|
|
|
buffer=${buf}
|
2021-06-11 05:18:29 -04:00
|
|
|
server=${server}
|
2021-05-31 22:39:35 -04:00
|
|
|
onChannelClick=${onChannelClick}
|
2021-05-28 08:52:31 -04:00
|
|
|
onNickClick=${onNickClick}
|
2021-11-30 09:13:34 -05:00
|
|
|
onVerifyClick=${onVerifyClick}
|
2021-05-28 08:52:31 -04:00
|
|
|
/>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
function createFoldGroup(msgs) {
|
2021-05-28 09:51:39 -04:00
|
|
|
// Filter out PART → JOIN pairs
|
2021-06-10 12:11:11 -04:00
|
|
|
let partIndexes = new Map();
|
|
|
|
let keep = [];
|
2021-05-28 09:51:39 -04:00
|
|
|
msgs.forEach((msg, i) => {
|
|
|
|
if (msg.command === "PART" || msg.command === "QUIT") {
|
|
|
|
partIndexes.set(msg.prefix.name, i);
|
|
|
|
}
|
|
|
|
if (msg.command === "JOIN" && partIndexes.has(msg.prefix.name)) {
|
|
|
|
keep[partIndexes.get(msg.prefix.name)] = false;
|
|
|
|
partIndexes.delete(msg.prefix.name);
|
|
|
|
keep.push(false);
|
|
|
|
} else {
|
|
|
|
keep.push(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
msgs = msgs.filter((msg, i) => keep[i]);
|
|
|
|
|
2021-05-28 08:52:31 -04:00
|
|
|
if (msgs.length === 0) {
|
|
|
|
return null;
|
|
|
|
} else if (msgs.length === 1) {
|
|
|
|
return createLogLine(msgs[0]);
|
|
|
|
}
|
|
|
|
return html`
|
|
|
|
<${FoldGroup}
|
2021-05-28 12:36:25 -04:00
|
|
|
key=${"fold-" + msgs[0].key + "-" + msgs[msgs.length - 1].key}
|
2021-05-28 08:52:31 -04:00
|
|
|
messages=${msgs}
|
|
|
|
buffer=${buf}
|
2021-06-11 05:18:29 -04:00
|
|
|
server=${server}
|
2021-05-28 08:52:31 -04:00
|
|
|
onNickClick=${onNickClick}
|
|
|
|
/>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let hasUnreadSeparator = false;
|
|
|
|
let prevDate = new Date();
|
|
|
|
let foldMessages = [];
|
2020-09-03 05:51:52 -04:00
|
|
|
buf.messages.forEach((msg) => {
|
2021-06-10 12:11:11 -04:00
|
|
|
let sep = [];
|
2021-05-28 08:52:31 -04:00
|
|
|
|
2022-02-11 10:37:58 -05:00
|
|
|
if (!hasUnreadSeparator && buf.type != BufferType.SERVER && !isMessageBeforeReceipt(msg, buf.prevReadReceipt)) {
|
2021-05-28 08:52:31 -04:00
|
|
|
sep.push(html`<${UnreadSeparator} key="unread"/>`);
|
2020-09-03 05:51:52 -04:00
|
|
|
hasUnreadSeparator = true;
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let date = new Date(msg.tags.time);
|
2020-08-13 13:00:56 -04:00
|
|
|
if (!sameDate(prevDate, date)) {
|
2021-05-28 08:52:31 -04:00
|
|
|
sep.push(html`<${DateSeparator} key=${"date-" + date} date=${date}/>`);
|
2020-08-13 13:00:56 -04:00
|
|
|
}
|
|
|
|
prevDate = date;
|
|
|
|
|
2021-05-28 08:52:31 -04:00
|
|
|
if (sep.length > 0) {
|
|
|
|
children.push(createFoldGroup(foldMessages));
|
|
|
|
children.push(sep);
|
|
|
|
foldMessages = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: consider checking the time difference too
|
|
|
|
if (canFoldMessage(msg)) {
|
|
|
|
foldMessages.push(msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foldMessages.length > 0) {
|
|
|
|
children.push(createFoldGroup(foldMessages));
|
|
|
|
foldMessages = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
children.push(createLogLine(msg));
|
2020-08-13 13:00:56 -04:00
|
|
|
});
|
2021-05-28 08:52:31 -04:00
|
|
|
children.push(createFoldGroup(foldMessages));
|
2020-08-13 13:00:56 -04:00
|
|
|
|
2020-07-09 17:33:34 -04:00
|
|
|
return html`
|
|
|
|
<div class="logline-list">
|
2020-08-13 13:00:56 -04:00
|
|
|
${children}
|
2020-07-09 17:33:34 -04:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|