mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 01:43:01 +01:00
make friend add fail if friend is in the block list
This commit is contained in:
parent
4b5a9abbd4
commit
127f9462e0
@ -1240,6 +1240,26 @@ Tox_Connection get_friend_connection_status(uint32_t friendnumber)
|
|||||||
return Friends.list[friendnumber].connection_status;
|
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 *new_friendlist(void)
|
||||||
{
|
{
|
||||||
ToxWindow *ret = calloc(1, sizeof(ToxWindow));
|
ToxWindow *ret = calloc(1, sizeof(ToxWindow));
|
||||||
|
@ -93,4 +93,11 @@ Tox_Connection get_friend_connection_status(uint32_t friendnumber);
|
|||||||
/* sorts friendlist_index first by connection status then alphabetically */
|
/* sorts friendlist_index first by connection status then alphabetically */
|
||||||
void sort_friendlist_index(void);
|
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 */
|
#endif /* end of include guard: FRIENDLIST_H */
|
||||||
|
@ -133,7 +133,7 @@ void cmd_add_helper(ToxWindow *self, Tox *m, const char *id_bin, const char *msg
|
|||||||
|
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
default:
|
default:
|
||||||
errmsg = "Faile to add friend: Unknown error.";
|
errmsg = "Failed to add friend: Unknown error.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +193,11 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
|||||||
id_bin[i] = x;
|
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);
|
cmd_add_helper(self, m, id_bin, msg);
|
||||||
} else { /* assume id is a username@domain address and do http name server lookup */
|
} else { /* assume id is a username@domain address and do http name server lookup */
|
||||||
name_lookup(self, m, id_bin, id, msg);
|
name_lookup(self, m, id_bin, id, msg);
|
||||||
|
Loading…
Reference in New Issue
Block a user