jcs
/wallops
/amendments
/80
*: Implement selective ignoring of certain events like joins and quits
On a small screen in a busy channel, having a screenful of nothing
but joins and quits is pretty annoying, so make it easy to turn them
off and on globally.
jcs made amendment 80 2 months ago
--- chatter.h Tue Sep 10 08:49:49 2024
+++ chatter.h Tue Sep 10 22:20:33 2024
@@ -47,12 +47,23 @@
#define VIEW_MENU_ID 131
#define VIEW_MENU_HIDE_ID 1
#define VIEW_MENU_CLOSE_ID 2
+#define VIEW_MENU_IGNORE_ID 3
+#define IGNORE_MENU_ID 132
+#define IGNORE_MENU_JOINS_ID 1
+#define IGNORE_MENU_QUITS_ID 2
+#define IGNORE_MENU_NICKS_ID 3
+
#define WAIT_TYPE_NONE (1 << 0)
#define WAIT_TYPE_BACKGROUND (1 << 1)
#define WAIT_TYPE_FOREGROUND (1 << 2)
#define WAIT_TYPE_URGENT (1 << 3)
+#define IGNORE_NONE (1 << 0)
+#define IGNORE_JOINS (1 << 1)
+#define IGNORE_QUITS (1 << 2)
+#define IGNORE_NICKS (1 << 3)
+
struct chatter_tab {
SLIST_ENTRY(chatter_tab) list;
struct irc_connection *conn;
@@ -80,7 +91,7 @@ struct chatter {
struct chatter_tab *current_tab;
};
-extern MenuHandle apple_menu, file_menu, edit_menu, view_menu;
+extern MenuHandle apple_menu, file_menu, edit_menu, view_menu, ignore_menu;
void notify(void);
void cancel_notification(void);
--- irc.c Tue Sep 10 21:55:38 2024
+++ irc.c Tue Sep 10 22:53:39 2024
@@ -20,6 +20,7 @@
#include "chatter.h"
#include "irc.h"
+#include "settings.h"
#include "strnatcmp.h"
short irc_verify_state(struct irc_connection *conn, short state);
@@ -539,9 +540,10 @@ irc_process_server(struct irc_connection *conn)
if (channel)
irc_add_nick_to_channel(channel, user->nick, 0, 0);
}
- chatter_printf(channel->chatter, conn, msg.arg[0],
- "$B*** %s ($0%s@%s$B)$0 has joined $B%s$0",
- user->nick, user->username, user->hostname, msg.arg[0]);
+ if (!(settings.ignores & IGNORE_JOINS))
+ chatter_printf(channel->chatter, conn, msg.arg[0],
+ "$B*** %s ($0%s@%s$B)$0 has joined $B%s$0",
+ user->nick, user->username, user->hostname, msg.arg[0]);
return true;
}
if (strcmp(msg.cmd, "KICK") == 0) {
@@ -553,9 +555,10 @@ irc_process_server(struct irc_connection *conn)
} else
irc_remove_nick_from_channel(channel, msg.arg[1]);
}
- chatter_printf(conn->chatter, conn, msg.arg[0],
- "$B*** %s$0 was kicked from $B%s$0 by $B%s%0:$/ %s",
- msg.arg[0], msg.arg[1], user->nick, msg.msg);
+ if (!(settings.ignores & IGNORE_QUITS))
+ chatter_printf(conn->chatter, conn, msg.arg[0],
+ "$B*** %s$0 was kicked from $B%s$0 by $B%s%0:$/ %s",
+ msg.arg[0], msg.arg[1], user->nick, msg.msg);
return true;
}
if (strcmp(msg.cmd, "KILL") == 0) {
@@ -617,10 +620,12 @@ irc_process_server(struct irc_connection *conn)
SLIST_FOREACH(channel, &conn->channels_list, list) {
if (!irc_nick_is_in_channel(channel, user->nick))
continue;
-
- chatter_printf(conn->chatter, conn, channel->name,
- "$B*** %s$0 is now known as $B%s$0",
- user->nick, msg.msg);
+
+ if (strcmp(msg.msg, conn->nick) == 0 ||
+ !(settings.ignores & IGNORE_NICKS))
+ chatter_printf(conn->chatter, conn, channel->name,
+ "$B*** %s$0 is now known as $B%s$0",
+ user->nick, msg.msg);
irc_change_user_nick(channel, user, msg.msg);
}
/* TODO: if any query windows for this nick, update them */
@@ -654,9 +659,11 @@ irc_process_server(struct irc_connection *conn)
/* we don't need to print anything */
} else {
irc_remove_nick_from_channel(channel, user->nick);
- chatter_printf(conn->chatter, conn, channel->name,
- "$B*** %s ($0%s@%s$B)$0 has left $B%s$0",
- user->nick, user->username, user->hostname, msg.arg[0]);
+ if (!(settings.ignores & IGNORE_QUITS))
+ chatter_printf(conn->chatter, conn, channel->name,
+ "$B*** %s ($0%s@%s$B)$0 has left $B%s$0",
+ user->nick, user->username, user->hostname,
+ msg.arg[0]);
}
}
return true;
@@ -669,9 +676,10 @@ irc_process_server(struct irc_connection *conn)
continue;
irc_remove_nick_from_channel(channel, user->nick);
- chatter_printf(conn->chatter, conn, channel->name,
- "$B*** %s ($0%s@%s$B)$0 has quit:$/ %s",
- user->nick, user->username, user->hostname, msg.msg);
+ if (!(settings.ignores & IGNORE_QUITS))
+ chatter_printf(conn->chatter, conn, channel->name,
+ "$B*** %s ($0%s@%s$B)$0 has quit:$/ %s",
+ user->nick, user->username, user->hostname, msg.msg);
}
if (strcmp(user->nick, conn->nick) == 0) {
--- main.c Tue Sep 10 09:29:25 2024
+++ main.c Tue Sep 10 22:46:53 2024
@@ -24,7 +24,7 @@
NMRec notification = { 0 };
struct settings settings;
-MenuHandle apple_menu, file_menu, edit_menu, view_menu;
+MenuHandle apple_menu, file_menu, edit_menu, view_menu, ignore_menu;
#ifdef MALLOC_DEBUG
MenuHandle debug_menu;
@@ -79,6 +79,9 @@ main(void)
panic("no edit menu");
if (!(view_menu = GetMHandle(VIEW_MENU_ID)))
panic("no view menu");
+ if (!(ignore_menu = GetMenu(IGNORE_MENU_ID)))
+ panic("no ignore menu");
+ InsertMenu(ignore_menu, -1);
update_menu();
#ifdef MALLOC_DEBUG
debug_menu = NewMenu(DEBUG_MENU_DUMP_ID, "\pDebug");
@@ -300,6 +303,36 @@ handle_menu(long menu_id)
}
}
break;
+ case IGNORE_MENU_ID: {
+ short current;
+
+ GetItemMark(ignore_menu, LoWord(menu_id), ¤t);
+
+ switch (LoWord(menu_id)) {
+ case IGNORE_MENU_JOINS_ID:
+ if (current)
+ settings.ignores &= ~(IGNORE_JOINS);
+ else
+ settings.ignores |= (IGNORE_JOINS);
+ break;
+ case IGNORE_MENU_QUITS_ID:
+ if (current)
+ settings.ignores &= ~(IGNORE_QUITS);
+ else
+ settings.ignores |= (IGNORE_QUITS);
+ break;
+ case IGNORE_MENU_NICKS_ID:
+ if (current)
+ settings.ignores &= ~(IGNORE_NICKS);
+ else
+ settings.ignores |= (IGNORE_NICKS);
+ break;
+ }
+ settings_save(&settings);
+ update_menu();
+ ret = true;
+ break;
+ }
#ifdef MALLOC_DEBUG
case DEBUG_MENU_DUMP_ID:
switch (LoWord(menu_id)) {
@@ -390,6 +423,13 @@ update_menu(void)
} else
SetItem(view_menu, VIEW_MENU_HIDE_ID, "\pHide Windows");
+ CheckItem(ignore_menu, IGNORE_MENU_JOINS_ID,
+ !!(settings.ignores & IGNORE_JOINS));
+ CheckItem(ignore_menu, IGNORE_MENU_QUITS_ID,
+ !!(settings.ignores & IGNORE_QUITS));
+ CheckItem(ignore_menu, IGNORE_MENU_NICKS_ID,
+ !!(settings.ignores & IGNORE_NICKS));
+
if (nfocusables && focusables[0]->visible &&
focusables[0]->update_menu) {
focusables[0]->update_menu(focusables[0]);
--- settings.h Thu Sep 5 10:16:05 2024
+++ settings.h Tue Sep 10 22:04:44 2024
@@ -50,6 +50,7 @@ struct settings {
char realname[32];
char channel[32];
unsigned char hide_motd;
+ unsigned long ignores;
};
extern struct settings settings;
--- wallops.π.r Tue Sep 10 09:36:37 2024
+++ wallops.π.r Wed Sep 11 08:17:13 2024
@@ -21,7 +21,15 @@ data 'MENU' (131) {
$"0083 0000 0000 0000 0000 FFFF FFFF 0456" /* .É.............V */
$"6965 770C 4869 6465 2057 696E 646F 7773" /* iew.Hide Windows */
$"0048 0000 0943 6C6F 7365 2054 6162 0057" /* .H..∆Close Tab.W */
- $"0000 00" /* ... */
+ $"0000 0649 676E 6F72 6500 1B84 0000" /* ...Ignore..Ñ.. */
+};
+
+data 'MENU' (132) {
+ $"0084 0000 0000 0000 0000 FFFF FFFF 0649" /* .Ñ.............I */
+ $"676E 6F72 6505 4A6F 696E 7300 0000 000B" /* gnore.Joins..... */
+ $"5061 7274 732F 5175 6974 7300 0000 000C" /* Parts/Quits..... */
+ $"4E69 636B 2043 6861 6E67 6573 0000 0000" /* Nick Changes.... */
+ $"00" /* . */
};
data 'MBAR' (128) {