Number friend requests from zero like friend numbers.

This commit is contained in:
Håvard Pettersson 2014-09-13 22:19:28 +02:00
parent c0a54dee82
commit 6b24f3a0b9
2 changed files with 7 additions and 6 deletions

View file

@ -206,7 +206,7 @@ tox_weechat_cmd_friend(void *data, struct t_gui_buffer *buffer,
if (weechat_strcasecmp(argv[2], "all") == 0) if (weechat_strcasecmp(argv[2], "all") == 0)
{ {
int count = 0; int count = 0;
while ((request = tox_weechat_friend_request_with_num(identity, 1)) != NULL) while ((request = tox_weechat_friend_request_with_num(identity, 0)) != NULL)
{ {
if (accept) if (accept)
tox_weechat_accept_friend_request(request); tox_weechat_accept_friend_request(request);
@ -226,8 +226,9 @@ tox_weechat_cmd_friend(void *data, struct t_gui_buffer *buffer,
} }
else else
{ {
unsigned int num = atoi(argv[2]); char *endptr;
if (num == 0 || (request = tox_weechat_friend_request_with_num(identity, num)) == NULL) unsigned long num = strtoul(argv[2], &endptr, 10);
if (endptr == argv[2] || (request = tox_weechat_friend_request_with_num(identity, num)) == NULL)
{ {
weechat_printf(identity->buffer, weechat_printf(identity->buffer,
"%sInvalid friend request ID.", "%sInvalid friend request ID.",
@ -270,7 +271,7 @@ tox_weechat_cmd_friend(void *data, struct t_gui_buffer *buffer,
"%sPending friend requests:", "%sPending friend requests:",
weechat_prefix("network")); weechat_prefix("network"));
unsigned int num = 1; int num = 0;
for (struct t_tox_weechat_friend_request *request = identity->friend_requests; for (struct t_tox_weechat_friend_request *request = identity->friend_requests;
request; request;
request = request->next_request) request = request->next_request)

View file

@ -69,9 +69,9 @@ struct t_tox_weechat_friend_request *
tox_weechat_friend_request_with_num(struct t_tox_weechat_identity *identity, tox_weechat_friend_request_with_num(struct t_tox_weechat_identity *identity,
unsigned int num) unsigned int num)
{ {
if (num < 1 || num > identity->friend_request_count) return NULL; if (num >= identity->friend_request_count) return NULL;
unsigned int i = 1; unsigned int i = 0;
struct t_tox_weechat_friend_request *request = identity->friend_requests; struct t_tox_weechat_friend_request *request = identity->friend_requests;
while (i != num && request->next_request) while (i != num && request->next_request)
{ {