Skip to content

Commit

Permalink
core: add unique "id" in nicklist group and nick (issue #2081)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
flashcode committed Apr 7, 2024
1 parent 40a6854 commit 89fe540
Show file tree
Hide file tree
Showing 23 changed files with 725 additions and 81 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.adoc
Expand Up @@ -21,7 +21,7 @@ New features::
* core: add variable `${highlight}` in option weechat.look.buffer_time_format (issue #2079)
* core: convert option weechat.look.hotlist_sort to a list of fields (issue #2097)
* core: rename variables with creation time in hdata "hotlist": "creation_time.tv_sec" to "time" and "creation_time.tv_usec" to "time_usec"
* core: add unique identifier "id" in buffer (issue #2081)
* core: add unique identifier "id" in buffer and nicklist (group and nick) (issue #2081)
* core: add option `malloc_trim` in command `/sys`
* core: add support of SGR mouse events (issue #2082)
* core: reintroduce help on the variables and operators in `/help eval` (issue #2005)
Expand Down
1 change: 1 addition & 0 deletions doc/en/weechat_dev.en.adoc
Expand Up @@ -448,6 +448,7 @@ WeeChat "core" is located in following directories:
|          test-gui-key.cpp | Tests: keys.
|          test-gui-line.cpp | Tests: lines.
|          test-gui-nick.cpp | Tests: nicks.
|          test-gui-nicklist.cpp | Tests: nicklist functions.
|          curses/ | Root of unit tests for Curses interface.
|             test-gui-curses-mouse.cpp | Tests: mouse (Curses interface).
|       plugins/ | Root of unit tests for plugins.
Expand Down
3 changes: 3 additions & 0 deletions doc/en/weechat_plugin_api.en.adoc
Expand Up @@ -14699,6 +14699,7 @@ Arguments:
** _short_name_: short name of buffer (note: used for display only and can be changed by user, this must not be used to find name of buffer, use instead _name_, _full_name_ or local variable _channel_)
** _type_: type of buffer: "formatted" or "free" _(WeeChat ≥ 4.2.0)_
** _title_: title of buffer
** _nicklist_last_id_assigned_: last unique identifier used in this buffer for a group or nick _(WeeChat ≥ 4.3.0)_
** _input_: input text
** _text_search_input_: input saved before text search
** _highlight_words_: list of words to highlight
Expand Down Expand Up @@ -15870,6 +15871,7 @@ Arguments:
* _buffer_: buffer pointer
* _group_: group pointer
* _property_: property name:
** _id_: unique identifier _(WeeChat ≥ 4.3.0)_
** _name_: name of group
** _color_: group color in nicklist

Expand Down Expand Up @@ -16072,6 +16074,7 @@ Arguments:
* _buffer_: buffer pointer
* _nick_: nick pointer
* _property_: property name:
** _id_: unique identifier _(WeeChat ≥ 4.3.0)_
** _name_: name of nick
** _color_: nick color in nicklist
** _prefix_: prefix of nick
Expand Down
1 change: 1 addition & 0 deletions doc/fr/weechat_dev.fr.adoc
Expand Up @@ -450,6 +450,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants :
|          test-gui-key.cpp | Tests : touches.
|          test-gui-line.cpp | Tests : lignes.
|          test-gui-nick.cpp | Tests : pseudos.
|          test-gui-nicklist.cpp | Tests : fonctions de liste de pseudos.
|          curses/ | Racine des tests unitaires pour l'interface Curses.
|             test-gui-curses-mouse.cpp | Tests : souris (interface Curses).
|       plugins/ | Racine des tests unitaires pour les extensions.
Expand Down
3 changes: 3 additions & 0 deletions doc/fr/weechat_plugin_api.fr.adoc
Expand Up @@ -15016,6 +15016,7 @@ Paramètres :
** _short_name_ : nom court du tampon (note : utilisé pour l'affichage seulement et peut être changé par l'utilisateur, il ne doit pas être utilisé pour trouver le nom du tampon, utilisez à la place _name_, _full_name_ ou bien la variable locale _channel_)
** _type_ : type de tampon : "formatted" (formaté) ou "free" (contenu libre) _(WeeChat ≥ 4.2.0)_
** _title_ : titre du tampon
** _nicklist_last_id_assigned_ : dernier identifiant unique utilisé dans ce tampon pour un groupe ou un pseudo _(WeeChat ≥ 4.3.0)_
** _input_ : texte saisi
** _text_search_input_ : texte saisi sauvegardé avant la recherche de texte
** _highlight_words_ : liste des mots pour le highlight
Expand Down Expand Up @@ -16213,6 +16214,7 @@ Paramètres :
* _buffer_ : pointeur vers le tampon
* _group_ : pointeur vers le groupe
* _property_ : nom de la propriété :
** _id_ : identifiant unique _(WeeChat ≥ 4.3.0)_
** _name_ : nom du groupe
** _color_ : couleur du groupe dans la liste des pseudos

Expand Down Expand Up @@ -16416,6 +16418,7 @@ Paramètres :
* _buffer_ : pointeur vers le tampon
* _nick_ : pointeur vers le pseudo
* _property_ : nom de la propriété :
** _id_ : identifiant unique _(WeeChat ≥ 4.3.0)_
** _name_ : nom du pseudo
** _color_ : couleur du pseudo dans la liste des pseudos
** _prefix_ : préfixe du pseudo
Expand Down
6 changes: 6 additions & 0 deletions doc/it/weechat_plugin_api.it.adoc
Expand Up @@ -15398,6 +15398,8 @@ Argomenti:
// TRANSLATION MISSING
** _type_: type of buffer: "formatted" or "free" _(WeeChat ≥ 4.2.0)_
** _title_: titolo del buffer
// TRANSLATION MISSING
** _nicklist_last_id_assigned_: last unique identifier used in this buffer for a group or nick _(WeeChat ≥ 4.3.0)_
** _input_: testo in ingresso
** _text_search_input_: input salvato prima della ricerca nel testo
** _highlight_words_: elenco di parole da evidenziare
Expand Down Expand Up @@ -16620,6 +16622,8 @@ Argomenti:
* _buffer_: puntatore al buffer
* _group_: puntatore al gruppo
* _property_: nome della proprietà:
// TRANSLATION MISSING
** _id_: unique identifier _(WeeChat ≥ 4.3.0)_
** _name_: nome del gruppo
** _color_: colore del gruppo nella lista nick

Expand Down Expand Up @@ -16826,6 +16830,8 @@ Argomenti:
* _buffer_: puntatore al buffer
* _nick_: puntatore al nick
* _property_: nome della proprietà:
// TRANSLATION MISSING
** _id_: unique identifier _(WeeChat ≥ 4.3.0)_
** _name_: nome del nick
** _color_: colore del nick nella lista nick
** _prefix_: prefisso del nick
Expand Down
2 changes: 2 additions & 0 deletions doc/ja/weechat_dev.ja.adoc
Expand Up @@ -508,6 +508,8 @@ WeeChat "core" は以下のディレクトリに配置されています:
// TRANSLATION MISSING
|          test-gui-nick.cpp | テスト: nicks
// TRANSLATION MISSING
|          test-gui-nicklist.cpp | Tests: nicklist functions.
// TRANSLATION MISSING
|          curses/ | Root of unit tests for Curses interface.
// TRANSLATION MISSING
|             test-gui-curses-mouse.cpp | Tests: mouse (Curses interface).
Expand Down
6 changes: 6 additions & 0 deletions doc/ja/weechat_plugin_api.ja.adoc
Expand Up @@ -14933,6 +14933,8 @@ const char *weechat_buffer_get_string (struct t_gui_buffer *buffer,
// TRANSLATION MISSING
** _type_: type of buffer: "formatted" or "free" _(WeeChat ≥ 4.2.0)_
** _title_: バッファのタイトル
// TRANSLATION MISSING
** _nicklist_last_id_assigned_: last unique identifier used in this buffer for a group or nick _(WeeChat ≥ 4.3.0)_
** _input_: 入力テキスト
** _text_search_input_: テキスト検索前に保存した入力テキスト
** _highlight_words_: ハイライトする単語のリスト
Expand Down Expand Up @@ -16112,6 +16114,8 @@ const char *weechat_nicklist_group_get_string (struct t_gui_buffer *buffer,
* _buffer_: バッファへのポインタ
* _group_: グループへのポインタ
* _property_: プロパティ名:
// TRANSLATION MISSING
** _id_: unique identifier _(WeeChat ≥ 4.3.0)_
** _name_: グループの名前
** _color_: ニックネームリストのグループ色

Expand Down Expand Up @@ -16315,6 +16319,8 @@ const char *weechat_nicklist_nick_get_string (struct t_gui_buffer *buffer,
* _buffer_: バッファへのプロパティ
* _nick_: ニックネームへのポインタ
* _property_: プロパティ名:
// TRANSLATION MISSING
** _id_: unique identifier _(WeeChat ≥ 4.3.0)_
** _name_: ニックネームの名前
** _color_: ニックネームリスト内でのニックネームの色
** _prefix_: ニックネームのプレフィックス
Expand Down
2 changes: 2 additions & 0 deletions doc/sr/weechat_dev.sr.adoc
Expand Up @@ -456,6 +456,8 @@ WeeChat „језгро” се налази у следећим директо
|          test-gui-line.cpp | Тестови: линије.
|          test-gui-nick.cpp | Тестови: надимци.
// TRANSLATION MISSING
|          test-gui-nicklist.cpp | Tests: nicklist functions.
// TRANSLATION MISSING
|          curses/ | Root of unit tests for Curses interface.
// TRANSLATION MISSING
|             test-gui-curses-mouse.cpp | Tests: mouse (Curses interface).
Expand Down
6 changes: 6 additions & 0 deletions doc/sr/weechat_plugin_api.sr.adoc
Expand Up @@ -14292,6 +14292,8 @@ const char *weechat_buffer_get_string (struct t_gui_buffer *buffer,
** _short_name_: кратко име бафера (напомена: користи се само за приказ и корисник може да га промени, ово не сме да се употребљава за проналажење имена бафера, уместо њега употребите _name_, _full_name_ или локалну променљиву _channel_)
** _type_: тип бафера: „formatted” или „free” _(WeeChat ≥ 4.2.0)_
** _title_: наслов бафера
// TRANSLATION MISSING
** _nicklist_last_id_assigned_: last unique identifier used in this buffer for a group or nick _(WeeChat ≥ 4.3.0)_
** _input_: текст уноса
** _text_search_input_: сачувани унос пре претраге текста
** _highlight_words_: листа речи које се истичу
Expand Down Expand Up @@ -15450,6 +15452,8 @@ const char *weechat_nicklist_group_get_string (struct t_gui_buffer *buffer,
* _buffer_: показивач на бафер
* _group_: показивач на групу
* _property_: име особине:
// TRANSLATION MISSING
** _id_: unique identifier _(WeeChat ≥ 4.3.0)_
** _name_: име групе
** _color_: боја групе у листи надимака

Expand Down Expand Up @@ -15652,6 +15656,8 @@ const char *weechat_nicklist_nick_get_string (struct t_gui_buffer *buffer,
* _buffer_: показивач на бафер
* _nick_: показивач на надимак
* _property_: име особине:
// TRANSLATION MISSING
** _id_: unique identifier _(WeeChat ≥ 4.3.0)_
** _name_: име надимка
** _color_: боја надимка у листи надимака
** _prefix_: префикс надимка
Expand Down
81 changes: 52 additions & 29 deletions src/core/core-upgrade.c
Expand Up @@ -711,49 +711,72 @@ void
upgrade_weechat_read_nicklist (struct t_infolist *infolist)
{
struct t_gui_nick_group *ptr_group;
const char *type, *name, *group_name;
const char *type, *name, *group_name, *ptr_id;
char *error;
long long id;

if (!upgrade_current_buffer)
return;

upgrade_current_buffer->nicklist = 1;
ptr_group = NULL;
type = infolist_string (infolist, "type");
if (type)
if (!type)
return;

/* "id" is new in WeeChat 4.3.0 */
id = -1;
if (infolist_search_var (infolist, "id"))
{
if (strcmp (type, "group") == 0)
ptr_id = infolist_string (infolist, "id");
if (ptr_id)
{
name = infolist_string (infolist, "name");
if (name && (strcmp (name, "root") != 0))
error = NULL;
id = strtoll (ptr_id, &error, 10);
if (!error || error[0])
id = -1;
}
}
if (id < 0)
id = gui_nicklist_generate_id (upgrade_current_buffer);

if (strcmp (type, "group") == 0)
{
name = infolist_string (infolist, "name");
if (name && (strcmp (name, "root") != 0))
{
group_name = infolist_string (infolist, "parent_name");
if (group_name)
{
group_name = infolist_string (infolist, "parent_name");
if (group_name)
{
ptr_group = gui_nicklist_search_group (
upgrade_current_buffer, NULL, group_name);
}
gui_nicklist_add_group (upgrade_current_buffer,
ptr_group,
name,
infolist_string (infolist, "color"),
infolist_integer (infolist, "visible"));
ptr_group = gui_nicklist_search_group (
upgrade_current_buffer, NULL, group_name);
}
gui_nicklist_add_group_with_id (
upgrade_current_buffer,
id,
ptr_group,
name,
infolist_string (infolist, "color"),
infolist_integer (infolist, "visible"));
}
else if (strcmp (type, "nick") == 0)
}
else if (strcmp (type, "nick") == 0)
{
group_name = infolist_string (infolist, "group_name");
if (group_name)
{
group_name = infolist_string (infolist, "group_name");
if (group_name)
ptr_group = gui_nicklist_search_group (upgrade_current_buffer,
NULL,
group_name);
gui_nicklist_add_nick (upgrade_current_buffer,
ptr_group,
infolist_string (infolist, "name"),
infolist_string (infolist, "color"),
infolist_string (infolist, "prefix"),
infolist_string (infolist, "prefix_color"),
infolist_integer (infolist, "visible"));
ptr_group = gui_nicklist_search_group (
upgrade_current_buffer, NULL, group_name);
}
gui_nicklist_add_nick_with_id (
upgrade_current_buffer,
id,
ptr_group,
infolist_string (infolist, "name"),
infolist_string (infolist, "color"),
infolist_string (infolist, "prefix"),
infolist_string (infolist, "prefix_color"),
infolist_integer (infolist, "visible"));
}
}

Expand Down
20 changes: 16 additions & 4 deletions src/gui/gui-buffer.c
Expand Up @@ -110,9 +110,9 @@ char *gui_buffer_properties_get_integer[] =
};
char *gui_buffer_properties_get_string[] =
{ "id", "plugin", "name", "full_name", "old_full_name", "short_name", "title",
"input", "text_search_input", "highlight_words", "highlight_disable_regex",
"highlight_regex", "highlight_tags_restrict", "highlight_tags",
"hotlist_max_level_nicks",
"nicklist_last_id_assigned", "input", "text_search_input", "highlight_words",
"highlight_disable_regex", "highlight_regex", "highlight_tags_restrict",
"highlight_tags", "hotlist_max_level_nicks",
NULL
};
char *gui_buffer_properties_get_pointer[] =
Expand Down Expand Up @@ -888,10 +888,11 @@ gui_buffer_new_props_with_id (long long id,
new_buffer->nicklist_groups_visible_count = 0;
new_buffer->nicklist_nicks_count = 0;
new_buffer->nicklist_nicks_visible_count = 0;
new_buffer->nicklist_last_id_assigned = -1;
new_buffer->nickcmp_callback = NULL;
new_buffer->nickcmp_callback_pointer = NULL;
new_buffer->nickcmp_callback_data = NULL;
gui_nicklist_add_group (new_buffer, NULL, "root", NULL, 0);
gui_nicklist_add_group_with_id (new_buffer, 0, NULL, "root", NULL, 0);

/* input */
new_buffer->input = 1;
Expand Down Expand Up @@ -1539,6 +1540,12 @@ gui_buffer_get_string (struct t_gui_buffer *buffer, const char *property)
return gui_buffer_type_string[buffer->type];
else if (strcmp (property, "title") == 0)
return buffer->title;
else if (strcmp (property, "nicklist_last_id_assigned") == 0)
{
snprintf (str_value, sizeof (str_value),
"%lld", buffer->nicklist_last_id_assigned);
return str_value;
}
else if (strcmp (property, "input") == 0)
return buffer->input_buffer;
else if (strcmp (property, "text_search_input") == 0)
Expand Down Expand Up @@ -5188,6 +5195,7 @@ gui_buffer_hdata_buffer_cb (const void *pointer, void *data,
HDATA_VAR(struct t_gui_buffer, nicklist_groups_visible_count, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, nicklist_nicks_count, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, nicklist_nicks_visible_count, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, nicklist_last_id_assigned, LONGLONG, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, nickcmp_callback, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, nickcmp_callback_pointer, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, nickcmp_callback_data, POINTER, 0, NULL, NULL);
Expand Down Expand Up @@ -5407,6 +5415,9 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!infolist_new_var_integer (ptr_item, "nicklist_nicks_visible_count", buffer->nicklist_nicks_visible_count))
return 0;
snprintf (str_value, sizeof (str_value), "%lld", buffer->nicklist_last_id_assigned);
if (!infolist_new_var_string (ptr_item, "nicklist_last_id_assigned", str_value))
return 0;
if (!infolist_new_var_string (ptr_item, "title", buffer->title))
return 0;
if (!infolist_new_var_integer (ptr_item, "input", buffer->input))
Expand Down Expand Up @@ -5643,6 +5654,7 @@ gui_buffer_print_log ()
log_printf (" nicklist_groups_vis_cnt : %d", ptr_buffer->nicklist_groups_visible_count);
log_printf (" nicklist_nicks_count. . : %d", ptr_buffer->nicklist_nicks_count);
log_printf (" nicklist_nicks_vis_cnt. : %d", ptr_buffer->nicklist_nicks_visible_count);
log_printf (" nicklist_last_id_assigned: %lld", ptr_buffer->nicklist_last_id_assigned);
log_printf (" nickcmp_callback. . . . : %p", ptr_buffer->nickcmp_callback);
log_printf (" nickcmp_callback_pointer: %p", ptr_buffer->nickcmp_callback_pointer);
log_printf (" nickcmp_callback_data . : %p", ptr_buffer->nickcmp_callback_data);
Expand Down
1 change: 1 addition & 0 deletions src/gui/gui-buffer.h
Expand Up @@ -169,6 +169,7 @@ struct t_gui_buffer
int nicklist_groups_visible_count; /* number of groups displayed */
int nicklist_nicks_count; /* number of nicks */
int nicklist_nicks_visible_count; /* number of nicks displayed */
long long nicklist_last_id_assigned; /* last id assigned for a grp/nick */
int (*nickcmp_callback)(const void *pointer, /* called to compare nicks */
void *data, /* (search in nicklist) */
struct t_gui_buffer *buffer,
Expand Down

0 comments on commit 89fe540

Please sign in to comment.