1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 23:06:38 +02:00

irc: properly rename private buffer on nick changes or private message when new nick is the same with different case

This commit is contained in:
Sébastien Helleu
2023-01-02 14:17:20 +01:00
parent c739026c87
commit 7baef6396d
4 changed files with 65 additions and 25 deletions
+1
View File
@@ -50,6 +50,7 @@ Bug fixes::
* api: send NULL values to config section callbacks in scripting API (issue #1843)
* api: fix function string_cut when there are non printable chars in suffix
* api: do not expect any return value in callbacks "callback_change" and "callback_delete" of function config_new_option (scripting API)
* irc: properly rename private buffer on nick changes or private message when new nick is the same with different case
* irc: do not join channels in server autojoin option after reconnection to the server (issue #560, bug #21529)
* irc: escape backslashes in raw buffer (issue #1838)
* trigger: fix variables sent to focus callback (issue #1858)
+34
View File
@@ -536,6 +536,40 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
return new_channel;
}
/*
* Renames a private buffer.
*/
void
irc_channel_pv_rename (struct t_irc_server *server,
struct t_irc_channel *channel,
const char *new_name)
{
char *buffer_name;
if (!server || !channel || (channel->type != IRC_CHANNEL_TYPE_PRIVATE)
|| !new_name)
{
return;
}
free (channel->name);
channel->name = strdup (new_name);
if (channel->pv_remote_nick_color)
{
free (channel->pv_remote_nick_color);
channel->pv_remote_nick_color = NULL;
}
buffer_name = irc_buffer_build_name (server->name, channel->name);
if (buffer_name)
{
weechat_buffer_set (channel->buffer, "name", buffer_name);
weechat_buffer_set (channel->buffer, "short_name", channel->name);
weechat_buffer_set (channel->buffer, "localvar_set_channel", channel->name);
free (buffer_name);
}
}
/*
* Adds groups in nicklist for a channel.
*/
+3
View File
@@ -111,6 +111,9 @@ extern struct t_irc_channel *irc_channel_new (struct t_irc_server *server,
const char *channel_name,
int switch_to_channel,
int auto_switch);
extern void irc_channel_pv_rename (struct t_irc_server *server,
struct t_irc_channel *channel,
const char *new_name);
extern void irc_channel_add_nicklist_groups (struct t_irc_server *server,
struct t_irc_channel *channel);
extern void irc_channel_set_buffer_title (struct t_irc_channel *channel);
+27 -25
View File
@@ -2010,9 +2010,9 @@ IRC_PROTOCOL_CALLBACK(mode)
IRC_PROTOCOL_CALLBACK(nick)
{
struct t_irc_channel *ptr_channel;
struct t_irc_channel *ptr_channel, *ptr_channel_new_nick;
struct t_irc_nick *ptr_nick, *ptr_nick_found;
char *old_color, *new_color, str_tags[512], *buffer_name;
char *old_color, *new_color, str_tags[512];
int local_nick, smart_filter;
struct t_irc_channel_speaking *ptr_nick_speaking;
@@ -2057,35 +2057,31 @@ IRC_PROTOCOL_CALLBACK(nick)
weechat_buffer_set (NULL, "hotlist", "+");
}
ptr_channel_new_nick = irc_channel_search (server, params[0]);
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
switch (ptr_channel->type)
{
case IRC_CHANNEL_TYPE_PRIVATE:
/* rename private buffer if this is with "old nick" */
if ((irc_server_strcasecmp (server,
ptr_channel->name, nick) == 0)
&& !irc_channel_search (server, params[0]))
/*
* rename private buffer if this is with "old nick"
* or if it's with "new nick" but different case
* (only if another buffer for the nick doesn't exist)
*/
if ((!ptr_channel_new_nick
|| (ptr_channel_new_nick == ptr_channel))
&& ((irc_server_strcasecmp (server,
ptr_channel->name, nick) == 0)
|| ((irc_server_strcasecmp (server,
ptr_channel->name, params[0]) == 0)
&& (strcmp (ptr_channel->name, params[0]) != 0))))
{
free (ptr_channel->name);
ptr_channel->name = strdup (params[0]);
if (ptr_channel->pv_remote_nick_color)
{
free (ptr_channel->pv_remote_nick_color);
ptr_channel->pv_remote_nick_color = NULL;
}
buffer_name = irc_buffer_build_name (server->name,
ptr_channel->name);
weechat_buffer_set (ptr_channel->buffer,
"name", buffer_name);
weechat_buffer_set (ptr_channel->buffer,
"short_name", ptr_channel->name);
weechat_buffer_set (ptr_channel->buffer,
"localvar_set_channel",
ptr_channel->name);
if (buffer_name)
free (buffer_name);
/* rename private buffer */
irc_channel_pv_rename (server, ptr_channel, params[0]);
/* display message */
if (weechat_config_boolean (irc_config_look_display_pv_nick_change))
{
if (weechat_config_boolean (irc_config_look_color_nicks_in_server_messages))
@@ -2916,7 +2912,13 @@ IRC_PROTOCOL_CALLBACK(privmsg)
/* private message received => display it */
ptr_channel = irc_channel_search (server, remote_nick);
if (!ptr_channel)
if (ptr_channel)
{
/* rename buffer if open with nick case not matching */
if (strcmp (ptr_channel->name, remote_nick) != 0)
irc_channel_pv_rename (server, ptr_channel, remote_nick);
}
else
{
ptr_channel = irc_channel_new (server,
IRC_CHANNEL_TYPE_PRIVATE,