~emersion/gamja

5507b3253b8b2a25ff437f1e4c95c41798fd33a4 — Simon Ser 10 days ago 61e35dd
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
1 files changed, 16 insertions(+), 1 deletions(-)

M commands.js
M commands.js => commands.js +16 -1
@@ 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: "<name>",
	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);
		},
	},
};