1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-14 05:33:03 +01:00

make friend add fail if friend is in the block list

This commit is contained in:
jfreegman 2019-11-16 01:55:47 -05:00
parent 4b5a9abbd4
commit 127f9462e0
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
3 changed files with 33 additions and 1 deletions

View File

@ -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));

View File

@ -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 */

View File

@ -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);