commit ca67f24f12554332b738dc8ec79590643ea0feec
parent 50df7066fbc67c17067beef2e1b0884d3585c7d7
Author: hhvn <dev@hhvn.uk>
Date: Sun, 12 Dec 2021 16:03:41 +0000
s/chan.c s/ui.c s/config.c s/handle.c s/hirc.h s/struct.h: hide nicklist in privs
Diffstat:
6 files changed, 32 insertions(+), 18 deletions(-)
diff --git a/src/chan.c b/src/chan.c
@@ -29,7 +29,7 @@ chan_free_list(struct Channel **head) {
}
struct Channel *
-chan_create(struct Server *server, char *name) {
+chan_create(struct Server *server, char *name, int priv) {
struct Channel *channel;
channel = emalloc(sizeof(struct Channel));
@@ -38,6 +38,7 @@ chan_create(struct Server *server, char *name) {
channel->nicks = NULL;
channel->old = 0;
channel->mode = channel->topic = NULL;
+ channel->priv = priv;
channel->server = server;
channel->history = emalloc(sizeof(struct HistInfo));
channel->history->activity = Activity_ignore;
@@ -58,13 +59,13 @@ chan_selected(struct Channel *channel) {
}
struct Channel *
-chan_add(struct Server *server, struct Channel **head, char *name) {
+chan_add(struct Server *server, struct Channel **head, char *name, int priv) {
struct Channel *channel, *p;
if (!name)
return NULL;
- if ((channel = chan_create(server, name)) == NULL)
+ if ((channel = chan_create(server, name, priv)) == NULL)
return NULL;
if (!*head) {
diff --git a/src/config.c b/src/config.c
@@ -1203,6 +1203,9 @@ config_nicklist_location(long num) {
return 0;
}
+ if (!selected.hasnicks)
+ return;
+
if (num == windows[Win_buflist].location != HIDDEN)
windows[Win_buflist].location = num == LEFT ? RIGHT : LEFT;
windows[Win_nicklist].location = num;
diff --git a/src/handle.c b/src/handle.c
@@ -97,7 +97,7 @@ handle_JOIN(char *msg, char **params, struct Server *server, time_t timestamp) {
target = *(params+2);
if ((chan = chan_get(&server->channels, target, -1)) == NULL)
- chan = chan_add(server, &server->channels, target);
+ chan = chan_add(server, &server->channels, target, 0);
chan_setold(chan, 0);
nick = nick_create(*params, ' ', server);
@@ -131,7 +131,7 @@ handle_PART(char *msg, char **params, struct Server *server, time_t timestamp) {
target = *(params+2);
if ((chan = chan_get(&server->channels, target, -1)) == NULL)
- chan = chan_add(server, &server->channels, target);
+ chan = chan_add(server, &server->channels, target, 0);
nick = nick_create(*params, ' ', server);
if (nick_isself(nick)) {
@@ -164,7 +164,7 @@ handle_KICK(char *msg, char **params, struct Server *server, time_t timestamp) {
target = *(params+2);
if ((chan = chan_get(&server->channels, target, -1)) == NULL)
- chan = chan_add(server, &server->channels, target);
+ chan = chan_add(server, &server->channels, target, 0);
nick = nick_create(*(params+3), ' ', server);
if (nick_isself(nick)) {
@@ -220,7 +220,7 @@ handle_MODE(char *msg, char **params, struct Server *server, time_t timestamp) {
if (strchr(support_get(server, "CHANTYPES"), **(params+2))) {
if ((chan = chan_get(&server->channels, *(params+2), -1)) == NULL)
- chan = chan_add(server, &server->channels, *(params+2));
+ chan = chan_add(server, &server->channels, *(params+2), 0);
hist_add(chan->history, NULL, msg, params, Activity_status, timestamp, HIST_DFL);
ircprintf(server, "MODE %s\r\n", chan->name); /* Get full mode via RPL_CHANNELMODEIS
@@ -253,21 +253,21 @@ handle_PRIVMSG(char *msg, char **params, struct Server *server, time_t timestamp
} else if (strcmp(target, server->self->nick) == 0) {
/* it's messaging me */
if ((priv = chan_get(&server->privs, nick->nick, -1)) == NULL)
- priv = chan_add(server, &server->privs, nick->nick);
+ priv = chan_add(server, &server->privs, nick->nick, 1);
chan_setold(priv, 0);
hist_add(priv->history, nick, msg, params, act_direct, timestamp, HIST_DFL);
} else if (nick_isself(nick) && !chrcmp(*target, "#&!+")) {
/* i'm messaging someone */
if ((priv = chan_get(&server->privs, target, -1)) == NULL)
- priv = chan_add(server, &server->privs, target);
+ priv = chan_add(server, &server->privs, target, 1);
chan_setold(priv, 0);
hist_add(priv->history, nick, msg, params, act_regular, timestamp, HIST_DFL);
} else {
/* message to a channel */
if ((chan = chan_get(&server->channels, target, -1)) == NULL)
- chan = chan_add(server, &server->channels, target);
+ chan = chan_add(server, &server->channels, target, 0);
hist_add(chan->history, nick, msg, params,
strstr(*(params+3), server->self->nick) ? act_direct : act_regular,
@@ -314,7 +314,7 @@ handle_RPL_CHANNELMODEIS(char *msg, char **params, struct Server *server, time_t
return;
if ((chan = chan_get(&server->channels, *(params+3), -1)) == NULL)
- chan = chan_add(server, &server->channels, *(params+3));
+ chan = chan_add(server, &server->channels, *(params+3), 0);
free(chan->mode);
chan->mode = strdup(*(params+4));
@@ -339,7 +339,7 @@ handle_RPL_NAMREPLY(char *msg, char **params, struct Server *server, time_t time
target = *params;
if ((chan = chan_get(&server->channels, target, -1)) == NULL)
- chan = chan_add(server, &server->channels, target);
+ chan = chan_add(server, &server->channels, target, 0);
if (strcmp_n(target, handle_expect_get(server, Expect_names)) == 0)
hist_add(chan->history, NULL, msg, bparams, Activity_status, timestamp, HIST_DFL);
diff --git a/src/hirc.h b/src/hirc.h
@@ -34,9 +34,9 @@ int strisnum(char *str);
/* chan.c */
void chan_free(struct Channel *channel);
void chan_free_list(struct Channel **head);
-struct Channel *chan_create(struct Server *server, char *name);
+struct Channel *chan_create(struct Server *server, char *name, int priv);
struct Channel *chan_get(struct Channel **head, char *name, int old);
-struct Channel *chan_add(struct Server *server, struct Channel **head, char *name);
+struct Channel *chan_add(struct Server *server, struct Channel **head, char *name, int priv);
int chan_isold(struct Channel *channel);
void chan_setold(struct Channel *channel, int old);
/* struct Channel *chan_dup(struct Channel *channel); */
diff --git a/src/struct.h b/src/struct.h
@@ -69,6 +69,7 @@ struct Channel {
char *name;
char *mode;
char *topic;
+ int priv;
struct Nick *nicks;
struct HistInfo *history;
struct Server *server;
@@ -210,6 +211,7 @@ struct Selected {
struct Server *server;
struct HistInfo *history;
char *name;
+ int hasnicks;
};
struct Keybind {
diff --git a/src/ui.c b/src/ui.c
@@ -1061,15 +1061,23 @@ ui_draw_main(void) {
void
ui_select(struct Server *server, struct Channel *channel) {
- selected.channel = channel;
- selected.server = server;
- selected.history = channel ? channel->history : server ? server->history : main_buf;
- selected.name = channel ? channel->name : server ? server->name : "hirc";
+ int oldhasnicks = selected.hasnicks;
+
+ selected.channel = channel;
+ selected.server = server;
+ selected.history = channel ? channel->history : server ? server->history : main_buf;
+ selected.name = channel ? channel->name : server ? server->name : "hirc";
+ selected.hasnicks = channel ? !channel->priv : 0;
selected.history->activity = Activity_none;
selected.history->unread = 0;
hist_purgeopt(selected.history, HIST_TMP);
+ if (!selected.hasnicks)
+ windows[Win_nicklist].location = HIDDEN;
+ else
+ windows[Win_nicklist].location = config_getl("nicklist.location");
+ ui_redraw();
}
static char *