diff --git a/src/friendlist.c b/src/friendlist.c index ada0d71..56802a4 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -1240,6 +1240,26 @@ Tox_Connection get_friend_connection_status(uint32_t friendnumber) return Friends.list[friendnumber].connection_status; } +/* + * Returns true if friend associated with `public_key` is in the block list. + * + * `public_key` must be at least TOX_PUBLIC_KEY_SIZE bytes. + */ +bool friend_is_blocked(const char *public_key) +{ + for (size_t i = 0; i < Blocked.max_idx; ++i) { + if (!Blocked.list[i].active) { + continue; + } + + if (memcmp(public_key, Blocked.list[i].pub_key, TOX_PUBLIC_KEY_SIZE) == 0) { + return true; + } + } + + return false; +} + ToxWindow *new_friendlist(void) { ToxWindow *ret = calloc(1, sizeof(ToxWindow)); diff --git a/src/friendlist.h b/src/friendlist.h index ee5667d..54171b3 100644 --- a/src/friendlist.h +++ b/src/friendlist.h @@ -93,4 +93,11 @@ Tox_Connection get_friend_connection_status(uint32_t friendnumber); /* sorts friendlist_index first by connection status then alphabetically */ void sort_friendlist_index(void); +/* + * Returns true if friend associated with `public_key` is in the block list. + * + * `public_key` must be at least TOX_PUBLIC_KEY_SIZE bytes. + */ +bool friend_is_blocked(const char *public_key); + #endif /* end of include guard: FRIENDLIST_H */ diff --git a/src/global_commands.c b/src/global_commands.c index 45fdec8..759719a 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -133,7 +133,7 @@ void cmd_add_helper(ToxWindow *self, Tox *m, const char *id_bin, const char *msg /* fallthrough */ default: - errmsg = "Faile to add friend: Unknown error."; + errmsg = "Failed to add friend: Unknown error."; break; } @@ -193,6 +193,11 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX id_bin[i] = x; } + if (friend_is_blocked(id_bin)) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Friend is in your block list."); + return; + } + cmd_add_helper(self, m, id_bin, msg); } else { /* assume id is a username@domain address and do http name server lookup */ name_lookup(self, m, id_bin, id, msg);