Updated to new tox API. Fixed profile loading.
This commit is contained in:
parent
ed96d36711
commit
b376432f04
9 changed files with 248 additions and 216 deletions
|
@ -142,14 +142,14 @@ enum TWC_FRIEND_MATCH
|
|||
enum TWC_FRIEND_MATCH
|
||||
twc_match_friend(struct t_twc_profile *profile, const char *search_string)
|
||||
{
|
||||
uint32_t friend_count = tox_count_friendlist(profile->tox);
|
||||
int32_t *friend_numbers = malloc(sizeof(int32_t) * friend_count);
|
||||
tox_get_friendlist(profile->tox, friend_numbers, friend_count);
|
||||
uint32_t friend_count = tox_self_get_friend_list_size(profile->tox);
|
||||
uint32_t *friend_numbers = malloc(sizeof(uint32_t) * friend_count);
|
||||
tox_self_get_friend_list(profile->tox, friend_numbers);
|
||||
|
||||
int32_t match = TWC_FRIEND_MATCH_NOMATCH;
|
||||
|
||||
char *endptr;
|
||||
unsigned long friend_number = strtoul(search_string, &endptr, 10);
|
||||
uint32_t friend_number = (uint32_t)strtoul(search_string, &endptr, 10);
|
||||
if (endptr == search_string + strlen(search_string)
|
||||
&& tox_friend_exists(profile->tox, friend_number))
|
||||
return friend_number;
|
||||
|
@ -162,7 +162,7 @@ twc_match_friend(struct t_twc_profile *profile, const char *search_string)
|
|||
uint8_t tox_id[TOX_PUBLIC_KEY_SIZE];
|
||||
char hex_id[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
||||
|
||||
tox_get_client_id(profile->tox, friend_numbers[i], tox_id);
|
||||
tox_friend_get_public_key(profile->tox, friend_numbers[i], tox_id, NULL); // do error handling
|
||||
twc_bin2hex(tox_id, TOX_PUBLIC_KEY_SIZE, hex_id);
|
||||
|
||||
if (weechat_strcasecmp(hex_id, search_string) == 0)
|
||||
|
@ -227,9 +227,9 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
|
|||
// /friend or /friend list
|
||||
if (argc == 1 || (argc == 2 && weechat_strcasecmp(argv[1], "list") == 0))
|
||||
{
|
||||
size_t friend_count = tox_count_friendlist(profile->tox);
|
||||
int32_t friend_numbers[friend_count];
|
||||
tox_get_friendlist(profile->tox, friend_numbers, friend_count);
|
||||
size_t friend_count = tox_self_get_friend_list_size(profile->tox);
|
||||
uint32_t friend_numbers[friend_count];
|
||||
tox_self_get_friend_list(profile->tox, friend_numbers);
|
||||
|
||||
if (friend_count == 0)
|
||||
{
|
||||
|
@ -245,7 +245,7 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
|
|||
|
||||
for (size_t i = 0; i < friend_count; ++i)
|
||||
{
|
||||
int32_t friend_number = friend_numbers[i];
|
||||
uint32_t friend_number = friend_numbers[i];
|
||||
char *name = twc_get_name_nt(profile->tox, friend_number);
|
||||
char *hex_address = twc_get_friend_id_short(profile->tox,
|
||||
friend_number);
|
||||
|
@ -306,7 +306,7 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
|
|||
if (friend_number == TWC_FRIEND_MATCH_AMBIGUOUS)
|
||||
fail = true;
|
||||
else if (friend_number != TWC_FRIEND_MATCH_NOMATCH)
|
||||
fail = tox_del_friend(profile->tox, friend_number) != 0;
|
||||
fail = !tox_friend_delete(profile->tox, friend_number, NULL);
|
||||
|
||||
if (fail)
|
||||
{
|
||||
|
@ -318,12 +318,13 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
|
|||
}
|
||||
}
|
||||
|
||||
TOX_ERR_FRIEND_ADD result = tox_add_friend(profile->tox,
|
||||
(uint8_t *)address,
|
||||
(uint8_t *)message,
|
||||
strlen(message));
|
||||
TOX_ERR_FRIEND_ADD err;
|
||||
(void)tox_friend_add(profile->tox,
|
||||
(uint8_t *)address,
|
||||
(uint8_t *)message,
|
||||
strlen(message), &err);
|
||||
|
||||
switch (result)
|
||||
switch (err)
|
||||
{
|
||||
case TOX_ERR_FRIEND_ADD_OK:
|
||||
weechat_printf(profile->buffer,
|
||||
|
@ -363,7 +364,7 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
|
|||
default:
|
||||
weechat_printf(profile->buffer,
|
||||
"%sCould not add friend (unknown error %d).",
|
||||
weechat_prefix("error"), result);
|
||||
weechat_prefix("error"), err);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -377,7 +378,7 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
|
|||
TWC_CHECK_FRIEND_NUMBER(profile, friend_number, argv[2]);
|
||||
|
||||
char *name = twc_get_name_nt(profile->tox, friend_number);
|
||||
if (tox_del_friend(profile->tox, friend_number) == 0)
|
||||
if (tox_friend_delete(profile->tox, friend_number, NULL) == 0)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sRemoved %s from friend list.",
|
||||
|
@ -693,7 +694,7 @@ twc_cmd_myid(void *data, struct t_gui_buffer *buffer,
|
|||
TWC_CHECK_PROFILE_LOADED(profile);
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
tox_get_address(profile->tox, address);
|
||||
tox_self_get_address(profile->tox, address);
|
||||
|
||||
char address_str[TOX_ADDRESS_SIZE * 2 + 1];
|
||||
twc_bin2hex(address, TOX_ADDRESS_SIZE, address_str);
|
||||
|
@ -722,8 +723,8 @@ twc_cmd_name(void *data, struct t_gui_buffer *buffer,
|
|||
|
||||
char *name = argv_eol[1];
|
||||
|
||||
int result = tox_set_name(profile->tox, (uint8_t *)name, strlen(name));
|
||||
if (result == -1)
|
||||
int result = tox_self_set_name(profile->tox, (uint8_t *)name, strlen(name), NULL);
|
||||
if (!result)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s",
|
||||
|
@ -789,8 +790,8 @@ twc_cmd_nospam(void *data, struct t_gui_buffer *buffer,
|
|||
new_nospam = random();
|
||||
}
|
||||
|
||||
uint32_t old_nospam = tox_get_nospam(profile->tox);
|
||||
tox_set_nospam(profile->tox, new_nospam);
|
||||
uint32_t old_nospam = tox_self_get_nospam(profile->tox);
|
||||
tox_self_set_nospam(profile->tox, new_nospam);
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%snew nospam has been set; this changes your Tox ID! To "
|
||||
|
@ -887,7 +888,7 @@ twc_cmd_status(void *data, struct t_gui_buffer *buffer,
|
|||
else
|
||||
return WEECHAT_RC_ERROR;
|
||||
|
||||
tox_set_user_status(profile->tox, status);
|
||||
tox_self_set_status(profile->tox, status);
|
||||
weechat_bar_item_update("away");
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
|
@ -906,10 +907,10 @@ twc_cmd_statusmsg(void *data, struct t_gui_buffer *buffer,
|
|||
|
||||
char *message = argc > 1 ? argv_eol[1] : " ";
|
||||
|
||||
int result = tox_set_status_message(profile->tox,
|
||||
(uint8_t *)message,
|
||||
strlen(message));
|
||||
if (result == -1)
|
||||
bool result = tox_self_set_status_message(profile->tox,
|
||||
(uint8_t *)message,
|
||||
strlen(message), NULL);
|
||||
if (!result)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue