From 5a630d6a235c1bd66487d5148c3c272adc6d96a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Pettersson?= Date: Tue, 2 Sep 2014 20:24:47 +0200 Subject: [PATCH] asd --- src/tox-weechat-chats.c | 11 ----------- src/tox-weechat-chats.h | 3 --- src/tox-weechat-commands.c | 10 +++++++++- src/tox-weechat-tox.c | 21 +++++++++++++-------- src/tox-weechat-utils.c | 9 +++++++++ 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/tox-weechat-chats.c b/src/tox-weechat-chats.c index bab68d6..7a8afb0 100644 --- a/src/tox-weechat-chats.c +++ b/src/tox-weechat-chats.c @@ -152,17 +152,6 @@ tox_weechat_chat_print_action(struct t_tox_chat *chat, sender, message); } -void -tox_weechat_chat_print_name_change(struct t_tox_chat *chat, - const char *old_name, - const char *new_name) -{ - weechat_printf(chat->buffer, - "%s%s is now known as %s", - weechat_prefix("network"), - old_name, new_name); -} - int tox_weechat_buffer_input_callback(void *data, struct t_gui_buffer *weechat_buffer, diff --git a/src/tox-weechat-chats.h b/src/tox-weechat-chats.h index 303dd13..bf09542 100644 --- a/src/tox-weechat-chats.h +++ b/src/tox-weechat-chats.h @@ -28,9 +28,6 @@ void tox_weechat_chat_print_message(struct t_tox_chat *chat, void tox_weechat_chat_print_action(struct t_tox_chat *chat, const char *sender, const char *message); -void tox_weechat_chat_print_name_change(struct t_tox_chat *chat, - const char *old_name, - const char *new_name); void tox_weechat_chat_refresh(struct t_tox_chat *chat); diff --git a/src/tox-weechat-commands.c b/src/tox-weechat-commands.c index 29287d6..b7331c2 100644 --- a/src/tox-weechat-commands.c +++ b/src/tox-weechat-commands.c @@ -305,11 +305,19 @@ tox_weechat_cmd_name(void *data, struct t_gui_buffer *buffer, weechat_bar_item_update("input_prompt"); + weechat_printf(tox_main_buffer, + "%sYou are now known as %s", + weechat_prefix("network"), + name); + for (struct t_tox_chat *chat = tox_weechat_get_first_chat(); chat; chat = chat->next) { - tox_weechat_chat_print_name_change(chat, "You", name); + weechat_printf(chat->buffer, + "%sYou are now known as %s", + weechat_prefix("network"), + name); } return WEECHAT_RC_OK; diff --git a/src/tox-weechat-tox.c b/src/tox-weechat-tox.c index 64d37f2..fc8672f 100644 --- a/src/tox-weechat-tox.c +++ b/src/tox-weechat-tox.c @@ -127,13 +127,6 @@ tox_weechat_connection_status_callback(Tox *tox, if (status == 1) { char *name = tox_weechat_get_name_nt(friend_number); - if (weechat_utf8_strlen(name) == 0) - { - free(name); - uint8_t client_id[TOX_CLIENT_ID_SIZE]; - tox_get_client_id(tox, friend_number, client_id); - name = tox_weechat_bin2hex(client_id, TOX_CLIENT_ID_SIZE); - } weechat_printf(tox_main_buffer, "%s%s just went online!", @@ -157,7 +150,19 @@ tox_weechat_name_change_callback(Tox *tox, char *old_name = tox_weechat_get_name_nt(friend_number); char *new_name = tox_weechat_null_terminate(name, length); - tox_weechat_chat_print_name_change(chat, old_name, new_name); + + if (strcmp(old_name, new_name) != 0) + { + weechat_printf(chat->buffer, + "%s%s is now known as %s", + weechat_prefix("network"), + old_name, new_name); + weechat_printf(tox_main_buffer, + "%s%s is now known as %s", + weechat_prefix("network"), + old_name, new_name); + } + free(old_name); free(new_name); } diff --git a/src/tox-weechat-utils.c b/src/tox-weechat-utils.c index 5d5807a..5a236c9 100644 --- a/src/tox-weechat-utils.c +++ b/src/tox-weechat-utils.c @@ -3,6 +3,7 @@ #include #include +#include #include #include "tox-weechat.h" @@ -58,6 +59,14 @@ tox_weechat_get_name_nt(int32_t friend_number) uint8_t name[length]; tox_get_name(tox, friend_number, name); + // if no name, return client ID instead + if (weechat_utf8_strlen((char *)name) == 0) + { + uint8_t client_id[TOX_CLIENT_ID_SIZE]; + tox_get_client_id(tox, friend_number, client_id); + return tox_weechat_bin2hex(client_id, TOX_CLIENT_ID_SIZE); + } + return tox_weechat_null_terminate(name, length); }