diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-07 10:09:04 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-07 13:18:14 +0200 |
commit | 89fe540b531705d8455685173c692522e81cd134 (patch) | |
tree | 717a3b15ef5e7d254a2515371efac6d79329f527 /src/plugins/irc | |
parent | 40a68549b5d4d99c0083f15242aab7516a87871f (diff) | |
download | weechat-89fe540b531705d8455685173c692522e81cd134.zip |
core: add unique "id" in nicklist group and nick (issue #2081)
The id is a "long long" variable with the current time (microseconds
precision).
It is guaranteed to be unique for all groups and nicks inside the buffer, and
the same number is never used again in the same buffer, during the lifetime of
the process.
It persists and is unchanged after `/upgrade`.
Diffstat (limited to 'src/plugins/irc')
-rw-r--r-- | src/plugins/irc/irc-channel.c | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 81 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.h | 8 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.c | 20 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.h | 2 |
5 files changed, 80 insertions, 37 deletions
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 1b45f17df..6382fad1c 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -33,12 +33,13 @@ #include "irc-color.h" #include "irc-command.h" #include "irc-config.h" +#include "irc-input.h" #include "irc-join.h" #include "irc-modelist.h" #include "irc-nick.h" #include "irc-protocol.h" #include "irc-server.h" -#include "irc-input.h" +#include "irc-upgrade.h" char *irc_channel_typing_state_string[IRC_CHANNEL_NUM_TYPING_STATES] = @@ -241,7 +242,8 @@ irc_channel_create_buffer (struct t_irc_server *server, if (ptr_buffer) { - weechat_nicklist_remove_all (ptr_buffer); + if (!irc_upgrading) + weechat_nicklist_remove_all (ptr_buffer); weechat_hashtable_map (buffer_props, &irc_channel_apply_props, ptr_buffer); } else diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index f00bbc006..f3ee654d9 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -521,41 +521,25 @@ irc_nick_nicklist_set_color_all () } /* - * Adds a new nick in channel. + * Adds a new nick in channel, but do not update the buffer nicklist. + * This function is only called by the function `irc_nick_new` (below) and + * when restoring nicks after upgrade: in this case we want to just add nick + * in channel nicks without changing anything in the buffer nicklist, + * to preserve same identifiers). * * Returns pointer to new nick, NULL if error. */ struct t_irc_nick * -irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, - const char *nickname, const char *host, const char *prefixes, - int away, const char *account, const char *realname) +irc_nick_new_in_channel (struct t_irc_server *server, + struct t_irc_channel *channel, + const char *nickname, const char *host, + const char *prefixes, int away, const char *account, + const char *realname) { - struct t_irc_nick *new_nick, *ptr_nick; + struct t_irc_nick *new_nick; int length; - if (!nickname || !nickname[0]) - return NULL; - - if (!channel->nicks) - irc_channel_add_nicklist_groups (server, channel); - - /* nick already exists on this channel? */ - ptr_nick = irc_nick_search (server, channel, nickname); - if (ptr_nick) - { - /* remove old nick from nicklist */ - irc_nick_nicklist_remove (server, channel, ptr_nick); - - /* update nick prefixes */ - irc_nick_set_prefixes (server, ptr_nick, prefixes); - - /* add new nick in nicklist */ - irc_nick_nicklist_add (server, channel, ptr_nick); - - return ptr_nick; - } - /* alloc memory for new nick */ if ((new_nick = malloc (sizeof (*new_nick))) == NULL) return NULL; @@ -609,6 +593,49 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, channel->nick_completion_reset = 1; + return new_nick; +} + +/* + * Adds a new nick in channel. + * + * Returns pointer to new nick, NULL if error. + */ + +struct t_irc_nick * +irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, + const char *nickname, const char *host, const char *prefixes, + int away, const char *account, const char *realname) +{ + struct t_irc_nick *new_nick, *ptr_nick; + + if (!nickname || !nickname[0]) + return NULL; + + if (!channel->nicks) + irc_channel_add_nicklist_groups (server, channel); + + /* nick already exists on this channel? */ + ptr_nick = irc_nick_search (server, channel, nickname); + if (ptr_nick) + { + /* remove old nick from nicklist */ + irc_nick_nicklist_remove (server, channel, ptr_nick); + + /* update nick prefixes */ + irc_nick_set_prefixes (server, ptr_nick, prefixes); + + /* add new nick in nicklist */ + irc_nick_nicklist_add (server, channel, ptr_nick); + + return ptr_nick; + } + + new_nick = irc_nick_new_in_channel (server, channel, nickname, host, + prefixes, away, account, realname); + if (!new_nick) + return NULL; + /* add nick to buffer nicklist */ irc_nick_nicklist_add (server, channel, new_nick); diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index 4c3d07a9e..3a1cc80e2 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -61,6 +61,14 @@ extern const char *irc_nick_get_prefix_color_name (struct t_irc_server *server, char prefix); extern void irc_nick_nicklist_set_prefix_color_all (); extern void irc_nick_nicklist_set_color_all (); +extern struct t_irc_nick *irc_nick_new_in_channel (struct t_irc_server *server, + struct t_irc_channel *channel, + const char *nickname, + const char *host, + const char *prefixes, + int away, + const char *account, + const char *realname); extern struct t_irc_nick *irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, const char *nickname, diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index 402a225e4..4a82af10f 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -42,6 +42,7 @@ struct t_irc_server *irc_upgrade_current_server = NULL; struct t_irc_channel *irc_upgrade_current_channel = NULL; struct t_irc_modelist *irc_upgrade_current_modelist = NULL; +int irc_upgrading = 0; /* @@ -795,14 +796,15 @@ irc_upgrade_read_cb (const void *pointer, void *data, case IRC_UPGRADE_TYPE_NICK: if (irc_upgrade_current_server && irc_upgrade_current_channel) { - ptr_nick = irc_nick_new (irc_upgrade_current_server, - irc_upgrade_current_channel, - weechat_infolist_string (infolist, "name"), - weechat_infolist_string (infolist, "host"), - weechat_infolist_string (infolist, "prefixes"), - weechat_infolist_integer (infolist, "away"), - weechat_infolist_string (infolist, "account"), - weechat_infolist_string (infolist, "realname")); + ptr_nick = irc_nick_new_in_channel ( + irc_upgrade_current_server, + irc_upgrade_current_channel, + weechat_infolist_string (infolist, "name"), + weechat_infolist_string (infolist, "host"), + weechat_infolist_string (infolist, "prefixes"), + weechat_infolist_integer (infolist, "away"), + weechat_infolist_string (infolist, "account"), + weechat_infolist_string (infolist, "realname")); if (ptr_nick) { /* @@ -1005,7 +1007,9 @@ irc_upgrade_load () if (!upgrade_file) return 0; + irc_upgrading = 1; rc = weechat_upgrade_read (upgrade_file); + irc_upgrading = 0; weechat_upgrade_close (upgrade_file); diff --git a/src/plugins/irc/irc-upgrade.h b/src/plugins/irc/irc-upgrade.h index c33e44d07..af2008f15 100644 --- a/src/plugins/irc/irc-upgrade.h +++ b/src/plugins/irc/irc-upgrade.h @@ -37,6 +37,8 @@ enum t_irc_upgrade_type IRC_UPGRADE_TYPE_MODELIST_ITEM, }; +extern int irc_upgrading; + extern int irc_upgrade_save (int force_disconnected_state); extern int irc_upgrade_load (); |