5
0
mirror of https://codeberg.org/emersion/gamja synced 2025-03-13 07:48:37 +01:00

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

@ -443,6 +443,7 @@ export default class App extends Component {
if (this.hasReceipt(target, type, msg)) {
return;
}
// TODO: this doesn't trigger a redraw
this.receipts.set(target, {
...this.receipts.get(target),
[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")) {
this.createBuffer(netID, bufName);
@ -847,6 +872,17 @@ export default class App extends Component {
this.setBufferState({ network: netID, name: channel }, { topic });
this.addMessage(netID, channel, msg);
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":
var awayMessage = msg.params[0];
@ -960,8 +996,11 @@ export default class App extends Component {
});
}
open(target) {
var netID = getActiveNetworkID(this.state);
open(target, netID) {
if (!netID) {
netID = getActiveNetworkID(this.state);
}
var client = this.clients.get(netID);
if (this.isChannel(target)) {

@ -2,7 +2,7 @@ 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";
import { BufferType, getNickURL, getMessageURL } from "../state.js";
import { BufferType, getNickURL, getChannelURL, getMessageURL } from "../state.js";
function djb2(s) {
var hash = 5381;
@ -64,13 +64,24 @@ class LogLine extends Component {
render() {
var msg = this.props.message;
var onChannelClick = this.props.onChannelClick;
var onNickClick = this.props.onNickClick;
var onChannelClick = this.props.onChannelClick;
function createNick(nick) {
return html`
<${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 content;
@ -139,6 +150,21 @@ class LogLine extends Component {
${createNick(msg.prefix.name)} changed the topic to: ${linkify(stripANSI(topic), onChannelClick)}
`;
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:
lineClass = "motd";
content = msg.params[1];

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

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