From 57ed3a13a3772c0465f67a5eb041b910bee2c0a2 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 26 Jun 2020 12:00:10 +0200 Subject: [PATCH] Send WHO query when opening nick buffer --- components/app.js | 22 ++++++++++++++++++++-- components/buffer-header.js | 28 +++++++++++++++++++++------- lib/irc.js | 2 ++ 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/components/app.js b/components/app.js index fb5ee84..52b2459 100644 --- a/components/app.js +++ b/components/app.js @@ -122,7 +122,8 @@ export default class App extends Component { buffers.set(name, { name, type, - topic: null, + topic: null, // if channel + who: null, // if nick members: new Map(), messages: [], unread: Unread.NONE, @@ -240,6 +241,21 @@ export default class App extends Component { break; case irc.RPL_ENDOFNAMES: break; + case irc.RPL_WHOREPLY: + var last = msg.params[msg.params.length - 1]; + var who = { + username: msg.params[2], + hostname: msg.params[3], + server: msg.params[4], + nick: msg.params[5], + away: msg.params[6] == 'G', // H for here, G for gone + realname: last.slice(last.indexOf(" ") + 1), + }; + + this.setBufferState(who.nick, { who }); + break; + case irc.RPL_ENDOFWHO: + break; case "NOTICE": case "PRIVMSG": var target = msg.params[0]; @@ -335,6 +351,8 @@ export default class App extends Component { open(target) { if (this.isChannel(target)) { this.client.send({ command: "JOIN", params: [target] }); + } else { + this.client.send({ command: "WHO", params: [target] }); } this.createBuffer(target); this.switchBuffer(target); @@ -470,7 +488,7 @@ export default class App extends Component { } var topbar = null; - if (activeBuffer && this.isChannel(activeBuffer.name)) { + if (activeBuffer && activeBuffer.type != BufferType.SERVER) { topbar = html`
<${BufferHeader} buffer=${activeBuffer} onClose=${() => this.close(activeBuffer.name)}/> diff --git a/components/buffer-header.js b/components/buffer-header.js index 215017e..1e8d762 100644 --- a/components/buffer-header.js +++ b/components/buffer-header.js @@ -1,20 +1,34 @@ import { html, Component } from "/lib/index.js"; +import { BufferType } from "/state.js"; export default function BufferHeader(props) { - var topic = null; - if (props.buffer.topic) { - topic = html`${props.buffer.topic}`; - } - function handlePartClick(event) { event.preventDefault(); props.onClose(); } + var description = null; + if (props.buffer.topic) { + description = html`${props.buffer.topic}`; + } else if (props.buffer.who) { + var who = props.buffer.who; + description = html`${who.realname} (${who.username}@${who.hostname})`; + } + + var closeText = "Close"; + switch (props.buffer.type) { + case BufferType.SERVER: + closeText = "Disconnect"; + break; + case BufferType.CHANNEL: + closeText = "Part"; + break; + } + return html` - ${topic} + ${description} - Part + ${closeText} `; } diff --git a/lib/irc.js b/lib/irc.js index b48f8dc..b9a5565 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -1,5 +1,7 @@ export const RPL_WELCOME = "001"; +export const RPL_ENDOFWHO = "315"; export const RPL_TOPIC = "332"; +export const RPL_WHOREPLY = "352"; export const RPL_NAMREPLY = "353"; export const RPL_ENDOFNAMES = "366"; export const ERR_PASSWDMISMATCH = "464";