@@ -1381,6 +1381,102 @@ twc_input_complete(const void *pointer, void *data, struct t_gui_buffer *buffer,
13811381 }
13821382 return WEECHAT_RC_OK ;
13831383}
1384+ /**
1385+ * Update a certain nick's prefix in all opened group chats
1386+ */
1387+ void
1388+ twc_name_prefix_in_groupchats (struct t_twc_profile * profile , const char * id ,
1389+ const char * prefix , const char * prefix_color )
1390+ {
1391+ struct t_twc_list_item * item ;
1392+ struct t_twc_chat * chat ;
1393+ size_t index ;
1394+ twc_list_foreach (profile -> chats , index , item )
1395+ {
1396+ chat = (struct t_twc_chat * )(item -> chat );
1397+ if ((chat -> group_number ) >= 0 )
1398+ {
1399+ twc_chat_update_prefix (chat , id , prefix , prefix_color );
1400+ }
1401+ }
1402+ }
1403+
1404+ /**
1405+ * Command /ignore callback.
1406+ */
1407+ int
1408+ twc_cmd_ignore (const void * pointer , void * data , struct t_gui_buffer * buffer ,
1409+ int argc , char * * argv , char * * argv_eol )
1410+ {
1411+ struct t_twc_profile * profile = twc_profile_search_buffer (buffer );
1412+ TWC_CHECK_PROFILE (profile );
1413+ TWC_CHECK_PROFILE_LOADED (profile );
1414+
1415+ /* list ignores */
1416+ if ((argc == 1 ) ||
1417+ ((argc == 2 ) && (weechat_strcasecmp (argv [1 ], "list" ) == 0 )))
1418+ {
1419+ if (!weechat_list_size (profile -> ignores ))
1420+ {
1421+ weechat_printf (profile -> buffer , "ignore list is empty" );
1422+ return WEECHAT_RC_OK ;
1423+ }
1424+ weechat_printf (profile -> buffer , "ignore list:" );
1425+ size_t i = 0 ;
1426+ struct t_weelist_item * item ;
1427+ for (item = weechat_list_get (profile -> ignores , 0 ); item ;
1428+ item = weechat_list_next (item ))
1429+ {
1430+ weechat_printf (profile -> buffer , " [%d] %s" , i ,
1431+ weechat_list_string (item ));
1432+ i ++ ;
1433+ }
1434+ return WEECHAT_RC_OK ;
1435+ }
1436+ /* add ignore */
1437+
1438+ const char * id = argv_eol [2 ];
1439+ struct t_weelist_item * item ;
1440+ item = weechat_list_casesearch (profile -> ignores , id );
1441+
1442+ if (weechat_strcasecmp (argv [1 ], "add" ) == 0 )
1443+ {
1444+ WEECHAT_COMMAND_MIN_ARGS (3 , "add" );
1445+ if (!item )
1446+ {
1447+ weechat_list_add (profile -> ignores , id , WEECHAT_LIST_POS_END , NULL );
1448+ weechat_printf (profile -> buffer ,
1449+ "%sID '%s' has been added to the ignore list" ,
1450+ weechat_prefix ("action" ), id );
1451+ twc_name_prefix_in_groupchats (profile , id , "-" , "yellow" );
1452+ }
1453+ else
1454+ weechat_printf (profile -> buffer ,
1455+ "%sID '%s' is already in the ignore list" ,
1456+ weechat_prefix ("error" ), id );
1457+ return WEECHAT_RC_OK ;
1458+ }
1459+
1460+ /* delete ignore */
1461+ if (weechat_strcasecmp (argv [1 ], "del" ) == 0 )
1462+ {
1463+ WEECHAT_COMMAND_MIN_ARGS (3 , "del" );
1464+ if (item )
1465+ {
1466+ weechat_list_remove (profile -> ignores , item );
1467+ weechat_printf (profile -> buffer ,
1468+ "%sID '%s' has been deleted from the ignore list" ,
1469+ weechat_prefix ("action" ), id );
1470+ twc_name_prefix_in_groupchats (profile , id , " " , "default" );
1471+ }
1472+ else
1473+ weechat_printf (profile -> buffer ,
1474+ "%sthere's no ID '%s' in the ignore list" ,
1475+ weechat_prefix ("error" ), id );
1476+ return WEECHAT_RC_OK ;
1477+ }
1478+ return WEECHAT_RC_ERROR ;
1479+ }
13841480
13851481/**
13861482 * Register Tox-WeeChat commands.
@@ -1519,4 +1615,16 @@ twc_commands_init()
15191615 "%(filename)"
15201616 " || %(tox_friend_name)|%(tox_friend_tox_id) %(filename)" ,
15211617 twc_cmd_send , NULL , NULL );
1618+ weechat_hook_command ("ignore" ,
1619+ "ommit messages from people with certain Tox IDs" ,
1620+ "list"
1621+ " || add <ID part>"
1622+ " || del <ID part>" ,
1623+ "list: show the list of ignores\n"
1624+ "add: add an ID to the list\n"
1625+ "del: delete an ID from the list\n" ,
1626+ "list"
1627+ " || add %*"
1628+ " || del %*" ,
1629+ twc_cmd_ignore , NULL , NULL );
15221630}
0 commit comments