From 8501d36ee9e888b26631332bab93a1cc3da7aed9 Mon Sep 17 00:00:00 2001 From: Gordon Quad Date: Mon, 5 Dec 2016 00:19:33 +0000 Subject: [PATCH] nicklist added to proflie buffer to show online friends --- src/twc-profile.c | 4 ++++ src/twc-profile.h | 1 + src/twc-tox-callbacks.c | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/twc-profile.c b/src/twc-profile.c index b1afe2c..75a08fb 100644 --- a/src/twc-profile.c +++ b/src/twc-profile.c @@ -285,6 +285,10 @@ twc_profile_load(struct t_twc_profile *profile) profile, NULL); if (!(profile->buffer)) return TWC_RC_ERROR; + + profile->nicklist_group = weechat_nicklist_add_group(profile->buffer, NULL, + NULL, NULL, true); + weechat_buffer_set(profile->buffer, "nicklist", "1"); } weechat_printf(profile->buffer, diff --git a/src/twc-profile.h b/src/twc-profile.h index 5bbd91f..6279681 100644 --- a/src/twc-profile.h +++ b/src/twc-profile.h @@ -51,6 +51,7 @@ struct t_twc_profile int tox_online; struct t_gui_buffer *buffer; + struct t_gui_nick_group *nicklist_group; struct t_hook *tox_do_timer; struct t_twc_list *chats; diff --git a/src/twc-tox-callbacks.c b/src/twc-tox-callbacks.c index 4250e6a..58bf5e8 100644 --- a/src/twc-tox-callbacks.c +++ b/src/twc-tox-callbacks.c @@ -84,6 +84,7 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number, { struct t_twc_profile *profile = data; char *name = twc_get_name_nt(profile->tox, friend_number); + struct t_gui_nick *nick = NULL; struct t_twc_chat *chat = twc_chat_search_friend(profile, friend_number, false); @@ -91,6 +92,11 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number, // TODO: print in friend's buffer if it exists if (status == 0) { + nick = weechat_nicklist_search_nick(profile->buffer, + profile->nicklist_group, name); + if (nick) + weechat_nicklist_remove_nick(profile->buffer, nick); + weechat_printf(profile->buffer, "%s%s just went offline.", weechat_prefix("network"), @@ -105,6 +111,9 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number, } else if (status == 1) { + weechat_nicklist_add_nick(profile->buffer, profile->nicklist_group, + name, NULL, NULL, NULL, 1); + weechat_printf(profile->buffer, "%s%s just came online.", weechat_prefix("network"), @@ -127,6 +136,7 @@ twc_name_change_callback(Tox *tox, uint32_t friend_number, void *data) { struct t_twc_profile *profile = data; + struct t_gui_nick *nick = NULL; struct t_twc_chat *chat = twc_chat_search_friend(profile, friend_number, false); @@ -146,6 +156,14 @@ twc_name_change_callback(Tox *tox, uint32_t friend_number, old_name, new_name); } + nick = weechat_nicklist_search_nick(profile->buffer, + profile->nicklist_group, old_name); + if (nick) + weechat_nicklist_remove_nick(profile->buffer, nick); + + weechat_nicklist_add_nick(profile->buffer, profile->nicklist_group, + new_name, NULL, NULL, NULL, 1); + weechat_printf(profile->buffer, "%s%s is now known as %s", weechat_prefix("network"),