|
28 | 28 |
|
29 | 29 | #include "twc-bootstrap.h" |
30 | 30 | #include "twc-tfer.h" |
| 31 | +#include "twc-ignore.h" |
31 | 32 | #include "twc-chat.h" |
32 | 33 | #include "twc-config.h" |
33 | 34 | #include "twc-friend-request.h" |
@@ -973,6 +974,10 @@ twc_cmd_save(const void *pointer, void *data, struct t_gui_buffer *buffer, |
973 | 974 | weechat_prefix("error"), weechat_plugin->name, |
974 | 975 | item->profile->name); |
975 | 976 | } |
| 977 | + twc_ignore_dump(item->profile); |
| 978 | + weechat_printf(NULL, "%s: ignore list for profile '%s' saved", |
| 979 | + weechat_plugin->name, |
| 980 | + item->profile->name); |
976 | 981 | } |
977 | 982 |
|
978 | 983 | weechat_printf(NULL, "%s: profile data saved", weechat_plugin->name); |
@@ -1238,7 +1243,7 @@ twc_cmd_send(const void *pointer, void *data, struct t_gui_buffer *buffer, |
1238 | 1243 | /* /send <number>|<name>|<Tox ID> <file> */ |
1239 | 1244 | if (argc >= 3) |
1240 | 1245 | { |
1241 | | - /* do a shell split in case a friend has spaces in his name |
| 1246 | + /* do a shell split in case a friend has spaces in his name |
1242 | 1247 | * and join the name */ |
1243 | 1248 | int shell_argc; |
1244 | 1249 | char **shell_argv = weechat_string_split_shell(argv_eol[1], &shell_argc); |
@@ -1314,6 +1319,81 @@ twc_cmd_send(const void *pointer, void *data, struct t_gui_buffer *buffer, |
1314 | 1319 | return WEECHAT_RC_OK; |
1315 | 1320 | } |
1316 | 1321 |
|
| 1322 | +void |
| 1323 | +twc_name_prefix_in_groupchats(struct t_twc_profile *profile, |
| 1324 | + const char *name, const char *prefix, const char *prefix_color) |
| 1325 | +{ |
| 1326 | + struct t_twc_list_item *item; |
| 1327 | + struct t_twc_chat *chat; |
| 1328 | + size_t index; |
| 1329 | + twc_list_foreach(profile->chats , index, item) |
| 1330 | + { |
| 1331 | + chat = (struct t_twc_chat *)(item->chat); |
| 1332 | + if ((chat->group_number) >= 0) |
| 1333 | + { |
| 1334 | + twc_chat_update_prefix(chat, name, prefix, prefix_color); |
| 1335 | + } |
| 1336 | + } |
| 1337 | +} |
| 1338 | +/** |
| 1339 | + * Command /ignore callback. |
| 1340 | + */ |
| 1341 | +int |
| 1342 | +twc_cmd_ignore(const void *pointer, void *data, struct t_gui_buffer *buffer, |
| 1343 | + int argc, char **argv, char **argv_eol) |
| 1344 | +{ |
| 1345 | + struct t_twc_profile *profile = twc_profile_search_buffer(buffer); |
| 1346 | + TWC_CHECK_PROFILE(profile); |
| 1347 | + TWC_CHECK_PROFILE_LOADED(profile); |
| 1348 | + |
| 1349 | + /* list ignores */ |
| 1350 | + if ((argc == 1) |
| 1351 | + || ((argc == 2) && (weechat_strcasecmp (argv[1], "list") == 0))) |
| 1352 | + { |
| 1353 | + twc_ignore_print(profile); |
| 1354 | + return WEECHAT_RC_OK; |
| 1355 | + } |
| 1356 | + |
| 1357 | + const char *nick = argv_eol[2]; |
| 1358 | + struct t_weelist_item *item; |
| 1359 | + item = weechat_list_search(profile->ignore_list, nick); |
| 1360 | + |
| 1361 | + /* add ignore */ |
| 1362 | + if (weechat_strcasecmp (argv[1], "add") == 0) |
| 1363 | + { |
| 1364 | + WEECHAT_COMMAND_MIN_ARGS(3, "add"); |
| 1365 | + if (!item) |
| 1366 | + { |
| 1367 | + weechat_list_add(profile->ignore_list, nick, WEECHAT_LIST_POS_SORT, NULL); |
| 1368 | + weechat_printf(profile->buffer, "%snickname '%s' has been added to the ignore list", |
| 1369 | + weechat_prefix("action"), nick); |
| 1370 | + twc_name_prefix_in_groupchats(profile, nick, "-", "yellow"); |
| 1371 | + } |
| 1372 | + else |
| 1373 | + weechat_printf(profile->buffer, "%snickname '%s' is already in the ignore list", |
| 1374 | + weechat_prefix("error"), nick); |
| 1375 | + return WEECHAT_RC_OK; |
| 1376 | + } |
| 1377 | + |
| 1378 | + /* delete ignore */ |
| 1379 | + if (weechat_strcasecmp (argv[1], "del") == 0) |
| 1380 | + { |
| 1381 | + WEECHAT_COMMAND_MIN_ARGS(3, "del"); |
| 1382 | + if (item) |
| 1383 | + { |
| 1384 | + weechat_list_remove(profile->ignore_list, item); |
| 1385 | + weechat_printf(profile->buffer, "%snickname '%s' has been deleted from the ignore list", |
| 1386 | + weechat_prefix("action"), nick); |
| 1387 | + twc_name_prefix_in_groupchats(profile, nick, " ", "default"); |
| 1388 | + } |
| 1389 | + else |
| 1390 | + weechat_printf(profile->buffer, "%sthere's no nickname '%s' in the ignore list", |
| 1391 | + weechat_prefix("error"), nick); |
| 1392 | + return WEECHAT_RC_OK; |
| 1393 | + } |
| 1394 | + WEECHAT_COMMAND_ERROR |
| 1395 | +} |
| 1396 | + |
1317 | 1397 | /** |
1318 | 1398 | * Register Tox-WeeChat commands. |
1319 | 1399 | */ |
@@ -1445,4 +1525,15 @@ twc_commands_init() |
1445 | 1525 | "%(filename)" |
1446 | 1526 | " || %(tox_friend_name)|%(tox_friend_tox_id) %(filename)", |
1447 | 1527 | twc_cmd_send, NULL, NULL); |
| 1528 | + weechat_hook_command("ignore", "ommit messages from people with certain nicks", |
| 1529 | + "list" |
| 1530 | + " || add <name>" |
| 1531 | + " || del <name>", |
| 1532 | + "list: show the list of ignores\n" |
| 1533 | + "add: add a nick to the list\n" |
| 1534 | + "del: delete a nick from the list\n", |
| 1535 | + "list" |
| 1536 | + " || add %*" |
| 1537 | + " || del %*", |
| 1538 | + twc_cmd_ignore, NULL, NULL); |
1448 | 1539 | } |
0 commit comments