Extract network name from ISUPPORT

This commit is contained in:
Simon Ser 2021-01-22 11:43:47 +01:00
parent b3f8b0c97d
commit 51523f4014
3 changed files with 23 additions and 5 deletions

View file

@ -1020,7 +1020,7 @@ export default class App extends Component {
return html` return html`
<section id="buffer-list"> <section id="buffer-list">
<${BufferList} buffers=${this.state.buffers} activeBuffer=${this.state.activeBuffer} onBufferClick=${this.handleBufferListClick}/> <${BufferList} buffers=${this.state.buffers} networks=${this.state.networks} activeBuffer=${this.state.activeBuffer} onBufferClick=${this.handleBufferListClick}/>
<div class="actions"> <div class="actions">
<a href="#" onClick=${this.handleJoinClick}>Join channel</a> <a href="#" onClick=${this.handleJoinClick}>Join channel</a>
</div> </div>

View file

@ -1,6 +1,24 @@
import * as irc from "/lib/irc.js";
import { html, Component } from "/lib/index.js"; import { html, Component } from "/lib/index.js";
import { BufferType, Unread, getBufferURL } from "/state.js"; import { BufferType, Unread, getBufferURL } from "/state.js";
function getNetworkName(network) {
var bouncerStr = network.isupport.get("BOUNCER");
if (bouncerStr) {
var bouncerProps = irc.parseTags(bouncerStr);
if (bouncerProps["network"]) {
return bouncerProps["network"];
}
}
var netName = network.isupport.get("NETWORK");
if (netName) {
return netName;
}
return "server";
}
function BufferItem(props) { function BufferItem(props) {
function handleClick(event) { function handleClick(event) {
event.preventDefault(); event.preventDefault();
@ -9,7 +27,7 @@ function BufferItem(props) {
var name = props.buffer.name; var name = props.buffer.name;
if (props.buffer.type == BufferType.SERVER) { if (props.buffer.type == BufferType.SERVER) {
name = "server"; name = getNetworkName(props.network);
} }
var activeClass = props.active ? "active" : ""; var activeClass = props.active ? "active" : "";
@ -31,7 +49,7 @@ export default function BufferList(props) {
return html` return html`
<ul> <ul>
${Array.from(props.buffers.values()).map((buf) => html` ${Array.from(props.buffers.values()).map((buf) => html`
<${BufferItem} key=${buf.id} buffer=${buf} onClick=${() => props.onBufferClick(buf.name)} active=${props.activeBuffer == buf.id}/> <${BufferItem} key=${buf.id} buffer=${buf} network=${props.networks.get(buf.network)} onClick=${() => props.onBufferClick(buf.name)} active=${props.activeBuffer == buf.id}/>
`)} `)}
</ul> </ul>
`; `;

View file

@ -50,7 +50,7 @@ function unescapeTag(s) {
return s.replace(/\\[:s\\rn]/, (seq) => tagUnescapeMap[seq]); return s.replace(/\\[:s\\rn]/, (seq) => tagUnescapeMap[seq]);
} }
function parseTags(s) { export function parseTags(s) {
var tags = {}; var tags = {};
s.split(";").forEach(function(s) { s.split(";").forEach(function(s) {
if (!s) { if (!s) {
@ -70,7 +70,7 @@ function parseTags(s) {
return tags; return tags;
} }
function formatTags(tags) { export function formatTags(tags) {
var l = []; var l = [];
for (var k in tags) { for (var k in tags) {
var v = escapeTag(tags[k]); var v = escapeTag(tags[k]);