improve: circumvention of the short ID collisions
Even though it's a pretty rare case to happen, it's still possible to occure that there are two+ peers in a group chat with the same first 2 bytes of the ID. Since we're using 2 (that means 4 character length) as a minimal possible value for the shortened ID form, I've changed the ignore list storage in the way that you can now store as many bytes as you want regardless of the option `tox.look.short_id_size`. If the ID collision happens, you can increase the value of that option and you don't have to change your ignore list.
This commit is contained in:
parent
5c8f9bc239
commit
dd8f1f58a8
@ -24,6 +24,7 @@
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc-config.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-message-queue.h"
|
||||
#include "twc-profile.h"
|
||||
@ -297,10 +298,13 @@ twc_chat_update_prefix(struct t_twc_chat *chat, const char *id,
|
||||
{
|
||||
const char *name_field = weechat_nicklist_nick_get_string(
|
||||
chat->buffer, ptr_nick, "name");
|
||||
if (!weechat_strncasecmp(id, name_field + sizeof(char), strlen(id)))
|
||||
size_t short_id_length =
|
||||
weechat_config_integer(twc_config_short_id_size);
|
||||
if (!weechat_strncasecmp(id, name_field + sizeof(char),
|
||||
short_id_length))
|
||||
{
|
||||
weechat_nicklist_nick_set(chat->buffer, ptr_nick,
|
||||
"prefix", prefix);
|
||||
weechat_nicklist_nick_set(chat->buffer, ptr_nick, "prefix",
|
||||
prefix);
|
||||
weechat_nicklist_nick_set(chat->buffer, ptr_nick,
|
||||
"prefix_color", prefix_color);
|
||||
weechat_nicklist_nick_set(chat->buffer, ptr_nick, "color",
|
||||
|
@ -1437,7 +1437,7 @@ twc_cmd_ignore(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
|
||||
const char *id = argv_eol[2];
|
||||
struct t_weelist_item *item;
|
||||
item = weechat_list_casesearch(profile->ignores, id);
|
||||
item = twc_is_id_ignored(profile, id);
|
||||
|
||||
if (weechat_strcasecmp(argv[1], "add") == 0)
|
||||
{
|
||||
|
@ -533,7 +533,8 @@ twc_group_peer_list_changed_callback(Tox *tox, uint32_t group_number,
|
||||
full_name, NULL, NULL, NULL, 1);
|
||||
nick = weechat_nicklist_search_nick(
|
||||
chat->buffer, chat->nicklist_group, full_name);
|
||||
bool ignored = twc_is_id_ignored(profile, short_id);
|
||||
struct t_weelist_item *ignored =
|
||||
twc_is_id_ignored(profile, short_id);
|
||||
twc_chat_update_prefix_by_nick(chat->buffer, nick,
|
||||
ignored ? "-" : " ",
|
||||
ignored ? "yellow" : "default");
|
||||
@ -625,10 +626,10 @@ twc_group_peer_name_callback(Tox *tox, uint32_t group_number,
|
||||
weechat_list_set(n, name);
|
||||
weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group, full_name,
|
||||
NULL, NULL, NULL, 1);
|
||||
bool ignored = twc_is_id_ignored(profile, short_id);
|
||||
nick = weechat_nicklist_search_nick(chat->buffer, chat->nicklist_group, full_name);
|
||||
twc_chat_update_prefix_by_nick(chat->buffer, nick,
|
||||
ignored ? "-" : " ",
|
||||
struct t_weelist_item *ignored = twc_is_id_ignored(profile, short_id);
|
||||
nick = weechat_nicklist_search_nick(chat->buffer, chat->nicklist_group,
|
||||
full_name);
|
||||
twc_chat_update_prefix_by_nick(chat->buffer, nick, ignored ? "-" : " ",
|
||||
ignored ? "yellow" : "default");
|
||||
free(prev_full_name);
|
||||
free(full_name);
|
||||
|
@ -277,9 +277,10 @@ twc_get_next_completion(struct t_weelist *completion_list,
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an ID is ignored.
|
||||
* Checks if an ID is ignored. Returns the item from the ignore list if so, NULL
|
||||
* otherwise.
|
||||
*/
|
||||
bool
|
||||
struct t_weelist_item *
|
||||
twc_is_id_ignored(struct t_twc_profile *profile, const char *short_id)
|
||||
{
|
||||
struct t_weelist_item *ignore_item;
|
||||
@ -287,10 +288,10 @@ twc_is_id_ignored(struct t_twc_profile *profile, const char *short_id)
|
||||
ignore_item = weechat_list_next(ignore_item))
|
||||
{
|
||||
if (!weechat_strncasecmp(short_id, weechat_list_string(ignore_item),
|
||||
strlen(weechat_list_string(ignore_item))))
|
||||
return true;
|
||||
strlen(short_id)))
|
||||
return ignore_item;
|
||||
}
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,8 @@ twc_starts_with(struct t_weelist *list, const char *search,
|
||||
const char *
|
||||
twc_get_next_completion(struct t_weelist *completion_list,
|
||||
const char *prev_comp);
|
||||
bool
|
||||
|
||||
struct t_weelist_item *
|
||||
twc_is_id_ignored(struct t_twc_profile *profile, const char *short_id);
|
||||
|
||||
uint32_t
|
||||
|
Loading…
Reference in New Issue
Block a user