Separate network info from self

weechat-hashes
C. McEnroe 2020-02-15 04:54:53 -05:00
parent 91fa136672
commit 42d106260b
4 changed files with 19 additions and 15 deletions

7
chat.c
View File

@ -65,6 +65,7 @@ enum Color idColors[IDCap] = {
size_t idNext = Network + 1;
struct Network network;
struct Self self = { .color = Default };
static const char *save;
@ -187,10 +188,10 @@ int main(int argc, char *argv[]) {
if (!user) user = nick;
if (!real) real = nick;
set(&network.name, host);
set(&network.chanTypes, "#&");
set(&network.prefixes, "@+");
set(&self.nick, "*");
set(&self.network, host);
set(&self.chanTypes, "#&");
set(&self.prefixes, "@+");
commandComplete();
FILE *certFile = NULL;

9
chat.h
View File

@ -82,15 +82,18 @@ enum Cap {
#undef X
};
extern struct Network {
char *name;
char *chanTypes;
char *prefixes;
} network;
extern struct Self {
bool debug;
bool restricted;
char *plain;
const char *join;
enum Cap caps;
char *network;
char *chanTypes;
char *prefixes;
char *nick;
char *user;
enum Color color;

View File

@ -212,17 +212,17 @@ static void handleReplyISupport(struct Message *msg) {
char *key = strsep(&msg->params[i], "=");
if (!msg->params[i]) continue;
if (!strcmp(key, "NETWORK")) {
set(&self.network, msg->params[i]);
set(&network.name, msg->params[i]);
uiFormat(
Network, Cold, tagTime(msg),
"You arrive in %s", msg->params[i]
);
} else if (!strcmp(key, "CHANTYPES")) {
set(&self.chanTypes, msg->params[i]);
set(&network.chanTypes, msg->params[i]);
} else if (!strcmp(key, "PREFIX")) {
strsep(&msg->params[i], ")");
if (!msg->params[i]) continue;
set(&self.prefixes, msg->params[i]);
set(&network.prefixes, msg->params[i]);
}
}
}
@ -348,7 +348,7 @@ static void handleReplyNames(struct Message *msg) {
size_t len = 0;
while (msg->params[3]) {
char *name = strsep(&msg->params[3], " ");
name += strspn(name, self.prefixes);
name += strspn(name, network.prefixes);
char *nick = strsep(&name, "!");
char *user = strsep(&name, "@");
enum Color color = (user ? hash(user) : Default);
@ -510,7 +510,7 @@ static void handleReplyWhoisChannels(struct Message *msg) {
size_t len = 0;
while (msg->params[2]) {
char *channel = strsep(&msg->params[2], " ");
channel += strspn(channel, self.prefixes);
channel += strspn(channel, network.prefixes);
int n = snprintf(
&buf[len], sizeof(buf) - len,
"%s\3%02d%s\3", (len ? ", " : ""), hash(channel), channel
@ -642,11 +642,11 @@ static const char *colorMentions(size_t id, struct Message *msg) {
static void handlePrivmsg(struct Message *msg) {
require(msg, true, 2);
bool query = !strchr(self.chanTypes, msg->params[0][0]);
bool network = strchr(msg->nick, '.');
bool query = !strchr(network.chanTypes, msg->params[0][0]);
bool server = strchr(msg->nick, '.');
bool mine = !strcmp(msg->nick, self.nick);
size_t id;
if (query && network) {
if (query && server) {
id = Network;
} else if (query && !mine) {
id = idFor(msg->nick);

2
ui.c
View File

@ -426,7 +426,7 @@ static void statusUpdate(void) {
wclrtoeol(status);
const struct Window *window = windows.ptrs[windows.show];
snprintf(title, sizeof(title), "%s %s", self.network, idNames[window->id]);
snprintf(title, sizeof(title), "%s %s", network.name, idNames[window->id]);
if (window->mark && window->unreadWarm) {
snprintf(
&title[strlen(title)], sizeof(title) - strlen(title),