2828#endif /* TOXAV_ENABLED */
2929
3030#include "twc-chat.h"
31+ #include "twc-config.h"
3132#include "twc-friend-request.h"
3233#include "twc-group-invite.h"
3334#include "twc-message-queue.h"
@@ -412,6 +413,9 @@ twc_handle_group_message(Tox *tox, int32_t group_number, int32_t peer_number,
412413
413414 char * myname = twc_get_self_name_nt (profile -> tox );
414415 char * name = twc_get_peer_name_nt (profile -> tox , group_number , peer_number );
416+ char * short_id =
417+ twc_get_peer_id_short (profile -> tox , group_number , peer_number );
418+ char * full_name = twc_get_peer_name_prefixed (short_id , name );
415419 char * tags = "notify_message" ;
416420 char * message_nt = twc_null_terminate (message , length );
417421
@@ -425,10 +429,14 @@ twc_handle_group_message(Tox *tox, int32_t group_number, int32_t peer_number,
425429
426430 if (weechat_string_has_highlight (message_nt , myname ))
427431 tags = "notify_highlight" ;
428- twc_chat_print_message (chat , tags , nick_color , name , message_nt ,
429- message_type );
432+ twc_chat_print_message (
433+ chat , tags , nick_color ,
434+ weechat_config_boolean (twc_config_show_id ) ? full_name : name ,
435+ message_nt , message_type );
430436
431437 free (name );
438+ free (short_id );
439+ free (full_name );
432440 free (myname );
433441 free (message_nt );
434442}
@@ -456,58 +464,88 @@ twc_group_peer_list_changed_callback(Tox *tox, uint32_t group_number,
456464
457465 struct t_weelist * new_nicks ;
458466 struct t_weelist_item * n ;
467+ struct t_weelist * new_ids ;
468+ struct t_weelist_item * id ;
459469
460470 npeers = tox_conference_peer_count (profile -> tox , group_number , & err );
461471
462472 if (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK )
463473 {
464474 new_nicks = weechat_list_new ();
475+ new_ids = weechat_list_new ();
465476 for (i = 0 ; i < npeers ; i ++ )
466477 {
467478 char * name = twc_get_peer_name_nt (profile -> tox , group_number , i );
479+ char * id = twc_get_peer_id_short (profile -> tox , group_number , i );
468480 weechat_list_add (new_nicks , name , WEECHAT_LIST_POS_END , NULL );
481+ weechat_list_add (new_ids , id , WEECHAT_LIST_POS_END , NULL );
469482 free (name );
483+ free (id );
470484 }
471485 }
472486 else
473487 return ;
474488
489+ bool changed = false;
490+
475491 /* searching for exits */
476492 n = weechat_list_get (chat -> nicks , 0 );
493+ id = weechat_list_get (chat -> ids , 0 );
477494
478- while (n )
495+ while (id && n )
479496 {
497+ const char * short_id = weechat_list_string (id );
480498 const char * name = weechat_list_string (n );
481- if (!weechat_list_search (new_nicks , name ))
499+ if (!weechat_list_search (new_ids , short_id ))
482500 {
483- weechat_printf (chat -> buffer , "%s%s just left the group chat" ,
484- weechat_prefix ("quit" ), name );
485- nick = weechat_nicklist_search_nick (chat -> buffer ,
486- chat -> nicklist_group , name );
501+ char * full_name = twc_get_peer_name_prefixed (short_id , name );
502+ nick = weechat_nicklist_search_nick (
503+ chat -> buffer , chat -> nicklist_group , full_name );
487504 weechat_nicklist_remove_nick (chat -> buffer , nick );
505+ weechat_printf (
506+ chat -> buffer , "%s%s just left the group chat" ,
507+ weechat_prefix ("quit" ),
508+ weechat_config_boolean (twc_config_show_id ) ? full_name : name );
509+ changed = true;
510+ free (full_name );
488511 }
489512 n = weechat_list_next (n );
513+ id = weechat_list_next (id );
490514 }
491515
492516 /* searching for joins */
493517 n = weechat_list_get (new_nicks , 0 );
518+ id = weechat_list_get (new_ids , 0 );
494519
495- while (n )
520+ while (id && n )
496521 {
522+ const char * short_id = weechat_list_string (id );
497523 const char * name = weechat_list_string (n );
498- if (!weechat_list_search (chat -> nicks , name ))
524+ if (!weechat_list_search (chat -> ids , short_id ))
499525 {
500- weechat_printf (chat -> buffer , "%s%s just joined the group chat" ,
501- weechat_prefix ("join" ), name );
502- weechat_nicklist_add_nick (chat -> buffer , chat -> nicklist_group , name ,
503- NULL , NULL , NULL , 1 );
526+ char * full_name = twc_get_peer_name_prefixed (short_id , name );
527+ weechat_nicklist_add_nick (chat -> buffer , chat -> nicklist_group ,
528+ full_name , NULL , NULL , NULL , 1 );
529+ weechat_printf (
530+ chat -> buffer , "%s%s just joined the group chat" ,
531+ weechat_prefix ("join" ),
532+ weechat_config_boolean (twc_config_show_id ) ? full_name : name );
533+ changed = true;
534+ free (full_name );
504535 }
505536 n = weechat_list_next (n );
537+ id = weechat_list_next (id );
506538 }
507539
508- weechat_list_remove_all (chat -> nicks );
509- weechat_list_free (chat -> nicks );
510- chat -> nicks = new_nicks ;
540+ if (changed )
541+ {
542+ weechat_list_remove_all (chat -> nicks );
543+ weechat_list_free (chat -> nicks );
544+ weechat_list_remove_all (chat -> ids );
545+ weechat_list_free (chat -> ids );
546+ chat -> nicks = new_nicks ;
547+ chat -> ids = new_ids ;
548+ }
511549}
512550
513551void
@@ -523,10 +561,13 @@ twc_group_peer_name_callback(Tox *tox, uint32_t group_number,
523561 struct t_gui_nick * nick = NULL ;
524562 const char * prev_name ;
525563 char * name ;
564+ const char * short_id ;
565+ char * prev_full_name ;
566+ char * full_name ;
526567 bool rc ;
527568 TOX_ERR_CONFERENCE_PEER_QUERY err = TOX_ERR_CONFERENCE_PEER_QUERY_OK ;
528569
529- struct t_weelist_item * n ;
570+ struct t_weelist_item * n , * id ;
530571
531572 npeers = tox_conference_peer_count (profile -> tox , group_number , & err );
532573
@@ -550,27 +591,40 @@ twc_group_peer_name_callback(Tox *tox, uint32_t group_number,
550591 twc_group_peer_list_changed_callback (tox , group_number , data );
551592 return ;
552593 }
553-
594+ id = weechat_list_get (chat -> ids , peer_number );
595+ short_id = weechat_list_string (id );
554596 prev_name = weechat_list_string (n );
597+ prev_full_name = twc_get_peer_name_prefixed (short_id , prev_name );
598+
555599 name = twc_null_terminate (pname , pname_len );
600+ full_name = twc_get_peer_name_prefixed (short_id , name );
556601
557602 nick = weechat_nicklist_search_nick (chat -> buffer , chat -> nicklist_group ,
558- prev_name );
559-
603+ prev_full_name );
560604 weechat_nicklist_remove_nick (chat -> buffer , nick );
605+ if (!twc_get_peer_name_count (chat -> nicks , prev_name ))
606+ {
607+ nick = weechat_nicklist_search_nick (chat -> buffer , chat -> nicklist_group ,
608+ prev_name );
609+ weechat_nicklist_remove_nick (chat -> buffer , nick );
610+ }
561611
562612 err = TOX_ERR_CONFERENCE_PEER_QUERY_OK ;
563613 rc = tox_conference_peer_number_is_ours (tox , group_number , peer_number ,
564614 & err );
615+ bool show_id = weechat_config_boolean (twc_config_show_id );
565616 if ((err == TOX_ERR_CONFERENCE_PEER_QUERY_OK ) && (!rc ))
566- weechat_printf (chat -> buffer , "%s%s is now known as %s" ,
567- weechat_prefix ("network" ), prev_name , name );
568-
617+ weechat_printf (
618+ chat -> buffer , "%s%s is now known as %s" , weechat_prefix ("network" ),
619+ show_id ? prev_full_name : prev_name , show_id ? full_name : name );
569620 weechat_list_set (n , name );
570-
621+ weechat_nicklist_add_nick (chat -> buffer , chat -> nicklist_group , full_name ,
622+ NULL , NULL , NULL , 1 );
571623 weechat_nicklist_add_nick (chat -> buffer , chat -> nicklist_group , name , NULL ,
572- NULL , NULL , 1 );
624+ NULL , NULL , 0 );
573625
626+ free (prev_full_name );
627+ free (full_name );
574628 free (name );
575629}
576630
0 commit comments