Add support for incoming INVITE messages

This commit is contained in:
Simon Ser 2021-06-03 11:04:32 +02:00
parent 55882776b0
commit 63a71e5f5d
4 changed files with 75 additions and 5 deletions

View File

@ -443,6 +443,7 @@ export default class App extends Component {
if (this.hasReceipt(target, type, msg)) { if (this.hasReceipt(target, type, msg)) {
return; return;
} }
// TODO: this doesn't trigger a redraw
this.receipts.set(target, { this.receipts.set(target, {
...this.receipts.get(target), ...this.receipts.get(target),
[type]: { time: msg.tags.time }, [type]: { time: msg.tags.time },
@ -514,6 +515,30 @@ export default class App extends Component {
}); });
} }
} }
if (msg.command === "INVITE" && client.isMyNick(msg.params[0])) {
msgUnread = Unread.HIGHLIGHT;
var channel = msg.params[1];
if (window.Notification && Notification.permission === "granted") {
var notif = new Notification("Invitation to " + channel, {
body: msg.prefix.name + " has invited you to " + channel,
requireInteraction: true,
actions: [{
action: "accept",
title: "Accept",
}],
});
notif.addEventListener("click", (event) => {
if (event.action === "accept") {
this.setReceipt(bufName, ReceiptType.READ, msg);
this.open(channel, netID);
} else {
// TODO: scroll to message
this.switchBuffer({ network: netID, name: bufName });
}
});
}
}
if (!client.isMyNick(msg.prefix.name) && (msg.command != "PART" && msg.comand != "QUIT")) { if (!client.isMyNick(msg.prefix.name) && (msg.command != "PART" && msg.comand != "QUIT")) {
this.createBuffer(netID, bufName); this.createBuffer(netID, bufName);
@ -847,6 +872,17 @@ export default class App extends Component {
this.setBufferState({ network: netID, name: channel }, { topic }); this.setBufferState({ network: netID, name: channel }, { topic });
this.addMessage(netID, channel, msg); this.addMessage(netID, channel, msg);
break; break;
case "INVITE":
var channel = msg.params[1];
// TODO: find a more reliable way to do this
var bufName = channel;
if (!getBuffer(this.state, { network: netID, name: channel })) {
bufName = SERVER_BUFFER;
}
this.addMessage(netID, bufName, msg);
break;
case "AWAY": case "AWAY":
var awayMessage = msg.params[0]; var awayMessage = msg.params[0];
@ -960,8 +996,11 @@ export default class App extends Component {
}); });
} }
open(target) { open(target, netID) {
var netID = getActiveNetworkID(this.state); if (!netID) {
netID = getActiveNetworkID(this.state);
}
var client = this.clients.get(netID); var client = this.clients.get(netID);
if (this.isChannel(target)) { if (this.isChannel(target)) {

View File

@ -2,7 +2,7 @@ import { html, Component } from "../lib/index.js";
import linkify from "../lib/linkify.js"; import linkify from "../lib/linkify.js";
import * as irc from "../lib/irc.js"; import * as irc from "../lib/irc.js";
import { strip as stripANSI } from "../lib/ansi.js"; import { strip as stripANSI } from "../lib/ansi.js";
import { BufferType, getNickURL, getMessageURL } from "../state.js"; import { BufferType, getNickURL, getChannelURL, getMessageURL } from "../state.js";
function djb2(s) { function djb2(s) {
var hash = 5381; var hash = 5381;
@ -64,13 +64,24 @@ class LogLine extends Component {
render() { render() {
var msg = this.props.message; var msg = this.props.message;
var onChannelClick = this.props.onChannelClick;
var onNickClick = this.props.onNickClick; var onNickClick = this.props.onNickClick;
var onChannelClick = this.props.onChannelClick;
function createNick(nick) { function createNick(nick) {
return html` return html`
<${Nick} nick=${nick} onClick=${() => onNickClick(nick)}/> <${Nick} nick=${nick} onClick=${() => onNickClick(nick)}/>
`; `;
} }
function createChannel(channel) {
function onClick(event) {
event.preventDefault();
onChannelClick(channel);
}
return html`
<a href=${getChannelURL(channel)} onClick=${onClick}>
${channel}
</a>
`;
}
var lineClass = ""; var lineClass = "";
var content; var content;
@ -139,6 +150,21 @@ class LogLine extends Component {
${createNick(msg.prefix.name)} changed the topic to: ${linkify(stripANSI(topic), onChannelClick)} ${createNick(msg.prefix.name)} changed the topic to: ${linkify(stripANSI(topic), onChannelClick)}
`; `;
break; break;
case "INVITE":
var invitee = msg.params[0];
var channel = msg.params[1];
// TODO: instead of checking buffer type, check if invitee is our nick
if (this.props.buffer.type === BufferType.SERVER) {
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;
case irc.RPL_MOTD: case irc.RPL_MOTD:
lineClass = "motd"; lineClass = "motd";
content = msg.params[1]; content = msg.params[1];

View File

@ -6,6 +6,7 @@ const permanentCaps = [
"away-notify", "away-notify",
"batch", "batch",
"echo-message", "echo-message",
"invite-notify",
"message-tags", "message-tags",
"multi-prefix", "multi-prefix",
"server-time", "server-time",

View File

@ -37,12 +37,16 @@ export function getNickURL(nick) {
return "irc:///" + encodeURIComponent(nick) + ",isuser"; return "irc:///" + encodeURIComponent(nick) + ",isuser";
} }
export function getChannelURL(channel) {
return "irc:///" + encodeURIComponent(channel);
}
export function getBufferURL(buf) { export function getBufferURL(buf) {
switch (buf.type) { switch (buf.type) {
case BufferType.SERVER: case BufferType.SERVER:
return "irc:///"; return "irc:///";
case BufferType.CHANNEL: case BufferType.CHANNEL:
return "irc:///" + encodeURIComponent(buf.name); return getChannelURL(buf.name);
case BufferType.NICK: case BufferType.NICK:
return getNickURL(buf.name); return getNickURL(buf.name);
} }