From 96fc12bc4c852f1343a120126f1f46ac7cca447d Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sun, 11 Sep 2022 20:46:35 +0200 Subject: xC/xP: send buffer type and server state Also make PM highlighting behaviour consistent. --- xP/public/xP.css | 9 ++++----- xP/public/xP.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 9 deletions(-) (limited to 'xP') diff --git a/xP/public/xP.css b/xP/public/xP.css index 71bf602..b4ce13c 100644 --- a/xP/public/xP.css +++ b/xP/public/xP.css @@ -17,6 +17,10 @@ body { padding: .05em .3em; background: #eee; + display: flex; + justify-content: space-between; + align-items: baseline; + position: relative; border-top: 3px solid #ccc; border-bottom: 2px solid #888; @@ -39,11 +43,6 @@ body { bottom: -1px; background: #ccc; } -.title { - display: flex; - justify-content: space-between; - align-items: baseline; -} .middle { flex: auto; diff --git a/xP/public/xP.js b/xP/public/xP.js index ea4b288..ced93e9 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -193,6 +193,8 @@ let bufferCurrent = undefined let bufferLog = undefined let bufferAutoscroll = true +let servers = new Map() + function bufferResetStats(b) { b.newMessages = 0 b.newUnimportantMessages = 0 @@ -234,6 +236,8 @@ rpc.connect().then(result => { bufferLog = undefined bufferAutoscroll = true + servers.clear() + rpc.send({command: 'Hello', version: 1}) connecting = false m.redraw() @@ -250,6 +254,8 @@ rpc.addEventListener('Ping', event => { rpc.send({command: 'PingResponse', eventSeq: event.detail.eventSeq}) }) +// ~~~ Buffer events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + rpc.addEventListener('BufferUpdate', event => { let e = event.detail, b = buffers.get(e.bufferName) if (b === undefined) { @@ -260,7 +266,10 @@ rpc.addEventListener('BufferUpdate', event => { })) bufferResetStats(b) } + b.hideUnimportant = e.hideUnimportant + b.kind = e.context.kind + b.server = servers.get(e.context.serverName) }) rpc.addEventListener('BufferStats', event => { @@ -354,8 +363,8 @@ rpc.addEventListener('BufferLine', event => { } } - // TODO: Also highlight on unseen private messages, like xC does. - if (line.isHighlight) { + if (line.isHighlight || + (!visible && b.kind === 'PrivateMessage' && !line.isUnimportant)) { beep() if (!visible) b.highlighted = true @@ -368,6 +377,26 @@ rpc.addEventListener('BufferClear', event => { b.lines.length = 0 }) +// ~~~ Server events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +rpc.addEventListener('ServerUpdate', event => { + let e = event.detail, s = servers.get(e.serverName) + if (s === undefined) + servers.set(e.serverName, (s = {})) + s.state = e.state +}) + +rpc.addEventListener('ServerRename', event => { + let e = event.detail + servers.set(e.new, servers.get(e.serverName)) + servers.delete(e.serverName) +}) + +rpc.addEventListener('ServerRemove', event => { + let e = event.detail + servers.delete(e.serverName) +}) + // --- Colours ----------------------------------------------------------------- let palette = [ @@ -614,6 +643,21 @@ let BufferContainer = { }, } +let Status = { + view: vnode => { + let b = buffers.get(bufferCurrent) + if (b === undefined) + return m('.status', {}, 'Synchronizing...') + + let status = `${bufferCurrent}` + if (b.hideUnimportant) + status += `` + if (b.server !== undefined) + status += ` (${b.server.state})` + return m('.status', {}, status) + }, +} + let Input = { counter: 0, stamp: textarea => { @@ -749,8 +793,7 @@ let Main = { return m('.xP', {}, [ m('.title', {}, [`xP (${state})`, m(Toolbar)]), m('.middle', {}, [m(BufferList), m(BufferContainer)]), - // TODO: Indicate hideUnimportant. - m('.status', {}, bufferCurrent), + m(Status), m(Input), ]) }, -- cgit v1.2.3-70-g09d2