From 5507b3253b8b2a25ff437f1e4c95c41798fd33a4 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 10 Jun 2021 19:32:00 +0200 Subject: [PATCH] Mark server buffer as unread after server query command When a command will print its reply in the server buffer, mark it as unread to make it more obvious where to look. Closes: https://todo.sr.ht/~emersion/gamja/53 --- commands.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/commands.js b/commands.js index 8a3b84f..b6d52e4 100644 --- a/commands.js +++ b/commands.js @@ -1,5 +1,5 @@ import * as irc from "./lib/irc.js"; -import { SERVER_BUFFER, BufferType } from "./state.js"; +import { SERVER_BUFFER, BufferType, Unread } from "./state.js"; function getActiveClient(app) { let buf = app.state.buffers.get(app.state.activeBuffer); @@ -43,6 +43,16 @@ function setUserHostMode(app, args, mode) { }); } +function markServerBufferUnread(app) { + var activeBuffer = app.state.buffers.get(app.state.activeBuffer); + if (!activeBuffer || activeBuffer.type === BufferType.SERVER) { + return; + } + app.setBufferState({ server: activeBuffer.server }, (buf) => { + return { unread: Unread.union(buf.unread, Unread.MESSAGE) }; + }); +} + const join = { usage: "", description: "Join a channel", @@ -174,6 +184,7 @@ export default { description: "Request user statistics about the network", execute: (app, args) => { getActiveClient(app).send({ command: "LUSERS", params: args }); + markServerBufferUnread(app); }, }, "me": { @@ -203,6 +214,7 @@ export default { description: "Get the Message Of The Day", execute: (app, args) => { getActiveClient(app).send({ command: "MOTD", params: args }); + markServerBufferUnread(app); }, }, "msg": { @@ -310,6 +322,7 @@ export default { params.push(args.slice(1).join(" ")); } getActiveClient(app).send({ command: "STATS", params }); + markServerBufferUnread(app); }, }, "topic": { @@ -341,6 +354,7 @@ export default { description: "Retrieve a list of users", execute: (app, args) => { getActiveClient(app).send({ command: "WHO", params: args }); + markServerBufferUnread(app); }, }, "whois": { @@ -352,6 +366,7 @@ export default { throw new Error("Missing nick"); } getActiveClient(app).send({ command: "WHOIS", params: [nick] }); + markServerBufferUnread(app); }, }, };