migration to TokTok c-toxcore

This commit is contained in:
Gordon Quad 2016-12-22 12:35:08 +00:00
parent 8d395d8011
commit cc9d370105
11 changed files with 141 additions and 154 deletions

View File

@ -80,6 +80,7 @@ twc_chat_new(struct t_twc_profile *profile, const char *name)
twc_chat_buffer_close_callback); twc_chat_buffer_close_callback);
weechat_buffer_set_pointer(chat->buffer, "close_callback_pointer", chat); weechat_buffer_set_pointer(chat->buffer, "close_callback_pointer", chat);
} }
free(full_name); free(full_name);
if (!(chat->buffer)) if (!(chat->buffer))
@ -152,6 +153,9 @@ twc_chat_refresh(const struct t_twc_chat *chat)
{ {
char *name = NULL; char *name = NULL;
char *title = NULL; char *title = NULL;
bool rc = false;
TOX_ERR_CONFERENCE_TITLE err = TOX_ERR_CONFERENCE_TITLE_OK;
if (chat->friend_number >= 0) if (chat->friend_number >= 0)
{ {
name = twc_get_name_nt(chat->profile->tox, name = twc_get_name_nt(chat->profile->tox,
@ -162,10 +166,12 @@ twc_chat_refresh(const struct t_twc_chat *chat)
else if (chat->group_number >= 0) else if (chat->group_number >= 0)
{ {
char group_name[TOX_MAX_NAME_LENGTH + 1] = {0}; char group_name[TOX_MAX_NAME_LENGTH + 1] = {0};
int len = tox_group_get_title(chat->profile->tox, chat->group_number, int len = tox_conference_get_title_size(chat->profile->tox, chat->group_number,
(uint8_t *)group_name, &err);
TOX_MAX_NAME_LENGTH); if ((err == TOX_ERR_CONFERENCE_TITLE_OK) && (len <= TOX_MAX_NAME_LENGTH))
if (len <= 0) rc = tox_conference_get_title(chat->profile->tox, chat->group_number,
(uint8_t *)group_name, &err);
if (!rc)
sprintf(group_name, "Group Chat %d", chat->group_number); sprintf(group_name, "Group Chat %d", chat->group_number);
name = title = strdup((char *)group_name); name = title = strdup((char *)group_name);
@ -278,17 +284,17 @@ twc_chat_print_message(struct t_twc_chat *chat,
const char *color, const char *color,
const char *sender, const char *sender,
const char *message, const char *message,
enum TWC_MESSAGE_TYPE message_type) TOX_MESSAGE_TYPE message_type)
{ {
switch (message_type) switch (message_type)
{ {
case TWC_MESSAGE_TYPE_MESSAGE: case TOX_MESSAGE_TYPE_NORMAL:
weechat_printf_date_tags(chat->buffer, 0, tags, weechat_printf_date_tags(chat->buffer, 0, tags,
"%s%s%s\t%s", "%s%s%s\t%s",
color, sender, color, sender,
weechat_color("reset"), message); weechat_color("reset"), message);
break; break;
case TWC_MESSAGE_TYPE_ACTION: case TOX_MESSAGE_TYPE_ACTION:
weechat_printf_date_tags(chat->buffer, 0, tags, weechat_printf_date_tags(chat->buffer, 0, tags,
"%s%s%s%s %s", "%s%s%s%s %s",
weechat_prefix("action"), weechat_prefix("action"),
@ -303,9 +309,9 @@ twc_chat_print_message(struct t_twc_chat *chat,
*/ */
void void
twc_chat_send_message(struct t_twc_chat *chat, const char *message, twc_chat_send_message(struct t_twc_chat *chat, const char *message,
enum TWC_MESSAGE_TYPE message_type) TOX_MESSAGE_TYPE message_type)
{ {
int64_t rc = 0; TOX_ERR_CONFERENCE_SEND_MESSAGE err = TOX_ERR_CONFERENCE_SEND_MESSAGE_OK;
if (chat->friend_number >= 0) if (chat->friend_number >= 0)
{ {
twc_message_queue_add_friend_message(chat->profile, twc_message_queue_add_friend_message(chat->profile,
@ -318,30 +324,27 @@ twc_chat_send_message(struct t_twc_chat *chat, const char *message,
free(name); free(name);
} }
else if (chat->group_number >= 0) else if (chat->group_number >= 0)
{
if (message_type == TWC_MESSAGE_TYPE_MESSAGE)
{ {
int len = strlen(message); int len = strlen(message);
while (len > 0) while (len > 0)
{ {
int fit_len = twc_fit_utf8(message, TWC_MAX_GROUP_MESSAGE_LENGTH); int fit_len = twc_fit_utf8(message, TWC_MAX_GROUP_MESSAGE_LENGTH);
rc = tox_group_message_send(chat->profile->tox, chat->group_number, err = TOX_ERR_CONFERENCE_SEND_MESSAGE_OK;
(uint8_t *)message, fit_len); tox_conference_send_message(chat->profile->tox, chat->group_number,
if (rc < 0) message_type, (uint8_t *)message, fit_len,
&err);
if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK)
break; break;
message += fit_len; message += fit_len;
len -= fit_len; len -= fit_len;
} }
} if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK)
else if (message_type == TWC_MESSAGE_TYPE_ACTION)
rc = tox_group_action_send(chat->profile->tox, chat->group_number,
(uint8_t *)message, strlen(message));
if (rc < 0)
{ {
weechat_printf(chat->buffer, weechat_printf(chat->buffer,
"%s%sFailed to send message%s", "%s%sFailed to send message with error %d%s",
weechat_prefix("error"), weechat_prefix("error"),
weechat_color("chat_highlight"), weechat_color("chat_highlight"),
err,
weechat_color("reset")); weechat_color("reset"));
} }
} }
@ -357,7 +360,7 @@ twc_chat_buffer_input_callback(const void *pointer, void *data,
{ {
/* TODO: don't strip the const */ /* TODO: don't strip the const */
struct t_twc_chat *chat = (void *)pointer; struct t_twc_chat *chat = (void *)pointer;
twc_chat_send_message(chat, input_data, TWC_MESSAGE_TYPE_MESSAGE); twc_chat_send_message(chat, input_data, TOX_MESSAGE_TYPE_NORMAL);
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
} }
@ -370,16 +373,17 @@ twc_chat_buffer_close_callback(const void *pointer, void *data,
struct t_gui_buffer *weechat_buffer) struct t_gui_buffer *weechat_buffer)
{ {
/* TODO: don't strip the const */ /* TODO: don't strip the const */
TOX_ERR_CONFERENCE_DELETE err = TOX_ERR_CONFERENCE_DELETE_OK;
struct t_twc_chat *chat = (void *)pointer; struct t_twc_chat *chat = (void *)pointer;
if (chat->profile->tox && chat->group_number >= 0) if (chat->profile->tox && chat->group_number >= 0)
{ {
int rc = tox_del_groupchat(chat->profile->tox, chat->group_number); tox_conference_delete(chat->profile->tox, chat->group_number, &err);
if (rc != 0) if (err != TOX_ERR_CONFERENCE_DELETE_OK)
{ {
weechat_printf(chat->profile->buffer, weechat_printf(chat->profile->buffer,
"%swarning: failed to leave group chat", "%swarning: failed to leave group chat with error %d",
weechat_prefix("error")); weechat_prefix("error"), err);
} }
} }

View File

@ -29,12 +29,6 @@ extern const char *twc_tag_unsent_message;
extern const char *twc_tag_sent_message; extern const char *twc_tag_sent_message;
extern const char *twc_tag_received_message; extern const char *twc_tag_received_message;
enum TWC_MESSAGE_TYPE
{
TWC_MESSAGE_TYPE_MESSAGE,
TWC_MESSAGE_TYPE_ACTION,
};
struct t_twc_chat struct t_twc_chat
{ {
struct t_twc_profile *profile; struct t_twc_profile *profile;
@ -64,11 +58,11 @@ twc_chat_print_message(struct t_twc_chat *chat,
const char *color, const char *color,
const char *sender, const char *sender,
const char *message, const char *message,
enum TWC_MESSAGE_TYPE message_type); TOX_MESSAGE_TYPE message_type);
void void
twc_chat_send_message(struct t_twc_chat *chat, const char *message, twc_chat_send_message(struct t_twc_chat *chat, const char *message,
enum TWC_MESSAGE_TYPE message_type); TOX_MESSAGE_TYPE message_type);
void void
twc_chat_queue_refresh(struct t_twc_chat *chat); twc_chat_queue_refresh(struct t_twc_chat *chat);

View File

@ -534,19 +534,20 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
struct t_twc_profile *profile = twc_profile_search_buffer(buffer); struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
TOX_ERR_CONFERENCE_NEW err = TOX_ERR_CONFERENCE_NEW_OK;
TWC_CHECK_PROFILE(profile); TWC_CHECK_PROFILE(profile);
TWC_CHECK_PROFILE_LOADED(profile); TWC_CHECK_PROFILE_LOADED(profile);
// /group create // /group create
if (argc == 2 && weechat_strcasecmp(argv[1], "create") == 0) if (argc == 2 && weechat_strcasecmp(argv[1], "create") == 0)
{ {
int rc = tox_add_groupchat(profile->tox); int rc = tox_conference_new(profile->tox, &err);
if (rc >= 0) if (err == TOX_ERR_CONFERENCE_NEW_OK)
twc_chat_search_group(profile, rc, true); twc_chat_search_group(profile, rc, true);
else else
weechat_printf(profile->buffer, weechat_printf(profile->buffer,
"%sCould not create group chat (unknown error)", "%sCould not create group chat with error %d",
weechat_prefix("error")); weechat_prefix("error"), err);
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
} }
@ -626,6 +627,7 @@ twc_cmd_invite(const void *pointer, void *data, struct t_gui_buffer *buffer,
if (argc == 1) if (argc == 1)
return WEECHAT_RC_ERROR; return WEECHAT_RC_ERROR;
TOX_ERR_CONFERENCE_INVITE err = TOX_ERR_CONFERENCE_INVITE_OK;
struct t_twc_chat *chat = twc_chat_search_buffer(buffer); struct t_twc_chat *chat = twc_chat_search_buffer(buffer);
TWC_CHECK_PROFILE_LOADED(chat->profile); TWC_CHECK_PROFILE_LOADED(chat->profile);
@ -634,10 +636,9 @@ twc_cmd_invite(const void *pointer, void *data, struct t_gui_buffer *buffer,
int32_t friend_number = twc_match_friend(chat->profile, argv_eol[1]); int32_t friend_number = twc_match_friend(chat->profile, argv_eol[1]);
TWC_CHECK_FRIEND_NUMBER(chat->profile, friend_number, argv_eol[1]); TWC_CHECK_FRIEND_NUMBER(chat->profile, friend_number, argv_eol[1]);
int rc = tox_invite_friend(chat->profile->tox, tox_conference_invite(chat->profile->tox, friend_number, chat->group_number, &err);
friend_number, chat->group_number);
if (rc == 0) if (err == TOX_ERR_CONFERENCE_INVITE_OK)
{ {
char *friend_name = twc_get_name_nt(chat->profile->tox, friend_number); char *friend_name = twc_get_name_nt(chat->profile->tox, friend_number);
weechat_printf(chat->buffer, "%sInvited %s to the group chat.", weechat_printf(chat->buffer, "%sInvited %s to the group chat.",
@ -647,8 +648,8 @@ twc_cmd_invite(const void *pointer, void *data, struct t_gui_buffer *buffer,
else else
{ {
weechat_printf(chat->buffer, weechat_printf(chat->buffer,
"%sFailed to send group chat invite (unknown error)", "%sFailed to send group chat invite with error %d",
weechat_prefix("error")); weechat_prefix("error"), err);
} }
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
@ -668,7 +669,7 @@ twc_cmd_me(const void *pointer, void *data, struct t_gui_buffer *buffer,
TWC_CHECK_CHAT(chat); TWC_CHECK_CHAT(chat);
TWC_CHECK_PROFILE_LOADED(chat->profile); TWC_CHECK_PROFILE_LOADED(chat->profile);
twc_chat_send_message(chat, argv_eol[1], TWC_MESSAGE_TYPE_ACTION); twc_chat_send_message(chat, argv_eol[1], TOX_MESSAGE_TYPE_ACTION);
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
} }
@ -714,7 +715,7 @@ twc_cmd_msg(const void *pointer, void *data, struct t_gui_buffer *buffer,
if (message) if (message)
twc_chat_send_message(chat, twc_chat_send_message(chat,
weechat_string_strip(message, 1, 1, " "), weechat_string_strip(message, 1, 1, " "),
TWC_MESSAGE_TYPE_MESSAGE); TOX_MESSAGE_TYPE_NORMAL);
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
} }
@ -860,11 +861,12 @@ twc_cmd_part(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
struct t_twc_chat *chat = twc_chat_search_buffer(buffer); struct t_twc_chat *chat = twc_chat_search_buffer(buffer);
TOX_ERR_CONFERENCE_DELETE err = TOX_ERR_CONFERENCE_DELETE_OK;
TWC_CHECK_PROFILE_LOADED(chat->profile); TWC_CHECK_PROFILE_LOADED(chat->profile);
TWC_CHECK_GROUP_CHAT(chat); TWC_CHECK_GROUP_CHAT(chat);
int rc = tox_del_groupchat(chat->profile->tox, chat->group_number); tox_conference_delete(chat->profile->tox, chat->group_number, &err);
if (rc == 0) if (err == TOX_ERR_CONFERENCE_DELETE_OK)
{ {
weechat_printf(chat->buffer, weechat_printf(chat->buffer,
"%sYou have left the group chat", "%sYou have left the group chat",
@ -873,8 +875,8 @@ twc_cmd_part(const void *pointer, void *data, struct t_gui_buffer *buffer,
else else
{ {
weechat_printf(chat->buffer, weechat_printf(chat->buffer,
"%sFailed to leave group chat", "%sFailed to leave group chat with error %d",
weechat_prefix("error")); weechat_prefix("error"), err);
} }
weechat_buffer_set_pointer(chat->buffer, "input_callback", NULL); weechat_buffer_set_pointer(chat->buffer, "input_callback", NULL);
@ -996,6 +998,8 @@ twc_cmd_topic(const void *pointer, void *data, struct t_gui_buffer *buffer,
if (argc == 1) if (argc == 1)
return WEECHAT_RC_ERROR; return WEECHAT_RC_ERROR;
TOX_ERR_CONFERENCE_TITLE err = TOX_ERR_CONFERENCE_TITLE_OK;
struct t_twc_chat *chat = twc_chat_search_buffer(buffer); struct t_twc_chat *chat = twc_chat_search_buffer(buffer);
TWC_CHECK_CHAT(chat); TWC_CHECK_CHAT(chat);
TWC_CHECK_PROFILE_LOADED(chat->profile); TWC_CHECK_PROFILE_LOADED(chat->profile);
@ -1011,9 +1015,9 @@ twc_cmd_topic(const void *pointer, void *data, struct t_gui_buffer *buffer,
char *topic = argv_eol[1]; char *topic = argv_eol[1];
int result = tox_group_set_title(chat->profile->tox, chat->group_number, tox_conference_set_title(chat->profile->tox, chat->group_number,
(uint8_t *)topic, strlen(topic)); (uint8_t *)topic, strlen(topic), &err);
if (result == -1) if (err != TOX_ERR_CONFERENCE_TITLE_OK)
{ {
weechat_printf(chat->buffer, "%s%s", weechat_printf(chat->buffer, "%s%s",
weechat_prefix("error"), "Could not set topic."); weechat_prefix("error"), "Could not set topic.");

View File

@ -71,15 +71,15 @@ int
twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite) twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite)
{ {
int rc; int rc;
TOX_ERR_CONFERENCE_JOIN err = TOX_ERR_CONFERENCE_JOIN_OK;
switch (invite->group_chat_type) switch (invite->group_chat_type)
{ {
case TOX_GROUPCHAT_TYPE_TEXT: case TOX_CONFERENCE_TYPE_TEXT:
rc = tox_join_groupchat(invite->profile->tox, rc = tox_conference_join(invite->profile->tox, invite->friend_number,
invite->friend_number, invite->data, invite->data_size, &err);
invite->data, invite->data_size);
break; break;
#ifdef TOXAV_ENABLED #ifdef TOXAV_ENABLED
case TOX_GROUPCHAT_TYPE_AV: case TOX_CONFERENCE_TYPE_AV:
rc = toxav_join_av_groupchat(invite->profile->tox, rc = toxav_join_av_groupchat(invite->profile->tox,
invite->friend_number, invite->friend_number,
invite->data, invite->data_size, invite->data, invite->data_size,
@ -93,6 +93,8 @@ twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite)
twc_group_chat_invite_remove(invite); twc_group_chat_invite_remove(invite);
if (err != TOX_ERR_CONFERENCE_JOIN_OK)
return -1;
return rc; return rc;
} }

View File

@ -33,7 +33,7 @@ struct t_twc_group_chat_invite
{ {
struct t_twc_profile *profile; struct t_twc_profile *profile;
int32_t friend_number; uint32_t friend_number;
uint8_t group_chat_type; uint8_t group_chat_type;
uint8_t *data; uint8_t *data;
size_t data_size; size_t data_size;

View File

@ -56,7 +56,7 @@ void
twc_message_queue_add_friend_message(struct t_twc_profile *profile, twc_message_queue_add_friend_message(struct t_twc_profile *profile,
int32_t friend_number, int32_t friend_number,
const char *message, const char *message,
enum TWC_MESSAGE_TYPE message_type) TOX_MESSAGE_TYPE message_type)
{ {
int len = strlen(message); int len = strlen(message);
while (len > 0) while (len > 0)
@ -107,9 +107,7 @@ twc_message_queue_flush_friend(struct t_twc_profile *profile,
TOX_ERR_FRIEND_SEND_MESSAGE err; TOX_ERR_FRIEND_SEND_MESSAGE err;
(void)tox_friend_send_message(profile->tox, (void)tox_friend_send_message(profile->tox,
friend_number, friend_number,
queued_message->message_type == TWC_MESSAGE_TYPE_MESSAGE? queued_message->message_type,
TOX_MESSAGE_TYPE_NORMAL:
TOX_MESSAGE_TYPE_ACTION,
(uint8_t *)queued_message->message, (uint8_t *)queued_message->message,
strlen(queued_message->message), strlen(queued_message->message),
&err); &err);

View File

@ -33,14 +33,14 @@ struct t_twc_queued_message
{ {
struct tm *time; struct tm *time;
char *message; char *message;
enum TWC_MESSAGE_TYPE message_type; TOX_MESSAGE_TYPE message_type;
}; };
void void
twc_message_queue_add_friend_message(struct t_twc_profile *profile, twc_message_queue_add_friend_message(struct t_twc_profile *profile,
int32_t friend_number, int32_t friend_number,
const char *message, const char *message,
enum TWC_MESSAGE_TYPE message_type); TOX_MESSAGE_TYPE message_type);
void void
twc_message_queue_flush_friend(struct t_twc_profile *profile, twc_message_queue_flush_friend(struct t_twc_profile *profile,

View File

@ -416,17 +416,16 @@ twc_profile_load(struct t_twc_profile *profile)
twc_do_timer_cb(profile, NULL, 0); twc_do_timer_cb(profile, NULL, 0);
// register Tox callbacks // register Tox callbacks
tox_callback_friend_message(profile->tox, twc_friend_message_callback, profile); tox_callback_friend_message(profile->tox, twc_friend_message_callback);
tox_callback_friend_connection_status(profile->tox, twc_connection_status_callback, profile); tox_callback_friend_connection_status(profile->tox, twc_connection_status_callback);
tox_callback_friend_name(profile->tox, twc_name_change_callback, profile); tox_callback_friend_name(profile->tox, twc_name_change_callback);
tox_callback_friend_status(profile->tox, twc_user_status_callback, profile); tox_callback_friend_status(profile->tox, twc_user_status_callback);
tox_callback_friend_status_message(profile->tox, twc_status_message_callback, profile); tox_callback_friend_status_message(profile->tox, twc_status_message_callback);
tox_callback_friend_request(profile->tox, twc_friend_request_callback, profile); tox_callback_friend_request(profile->tox, twc_friend_request_callback);
tox_callback_group_invite(profile->tox, twc_group_invite_callback, profile); tox_callback_conference_invite(profile->tox, twc_group_invite_callback);
tox_callback_group_message(profile->tox, twc_group_message_callback, profile); tox_callback_conference_message(profile->tox, twc_group_message_callback);
tox_callback_group_action(profile->tox, twc_group_action_callback, profile); tox_callback_conference_namelist_change(profile->tox, twc_group_namelist_change_callback);
tox_callback_group_namelist_change(profile->tox, twc_group_namelist_change_callback, profile); tox_callback_conference_title(profile->tox, twc_group_title_callback);
tox_callback_group_title(profile->tox, twc_group_title_callback, profile);
return TWC_RC_OK; return TWC_RC_OK;
} }

View File

@ -43,7 +43,7 @@ twc_do_timer_cb(const void *pointer, void *data,
/* TODO: don't strip the const */ /* TODO: don't strip the const */
struct t_twc_profile *profile = (void *)pointer; struct t_twc_profile *profile = (void *)pointer;
tox_iterate(profile->tox); tox_iterate(profile->tox, profile);
struct t_hook *hook = weechat_hook_timer(tox_iteration_interval(profile->tox), struct t_hook *hook = weechat_hook_timer(tox_iteration_interval(profile->tox),
0, 1, twc_do_timer_cb, profile, NULL); 0, 1, twc_do_timer_cb, profile, NULL);
profile->tox_do_timer = hook; profile->tox_do_timer = hook;
@ -240,10 +240,11 @@ twc_friend_request_callback(Tox *tox, const uint8_t *public_key,
void void
twc_group_invite_callback(Tox *tox, twc_group_invite_callback(Tox *tox,
int32_t friend_number, uint8_t type, uint32_t friend_number, TOX_CONFERENCE_TYPE type,
const uint8_t *invite_data, uint16_t length, const uint8_t *invite_data, size_t length,
void *data) void *data)
{ {
TOX_ERR_CONFERENCE_JOIN err = TOX_ERR_CONFERENCE_JOIN_OK;
struct t_twc_profile *profile = data; struct t_twc_profile *profile = data;
char *friend_name = twc_get_name_nt(profile->tox, friend_number); char *friend_name = twc_get_name_nt(profile->tox, friend_number);
struct t_twc_chat *friend_chat struct t_twc_chat *friend_chat
@ -254,10 +255,10 @@ twc_group_invite_callback(Tox *tox,
char *type_str; char *type_str;
switch (type) switch (type)
{ {
case TOX_GROUPCHAT_TYPE_TEXT: case TOX_CONFERENCE_TYPE_TEXT:
type_str = "a text-only group chat"; break; type_str = "a text-only group chat"; break;
case TOX_GROUPCHAT_TYPE_AV: case TOX_CONFERENCE_TYPE_AV:
type_str = "an audio/video group chat"; break; type_str = "an audio/vikdeo group chat"; break;
default: default:
type_str = "a group chat"; break; type_str = "a group chat"; break;
} }
@ -266,12 +267,12 @@ twc_group_invite_callback(Tox *tox,
{ {
switch (type) switch (type)
{ {
case TOX_GROUPCHAT_TYPE_TEXT: case TOX_CONFERENCE_TYPE_TEXT:
rc = tox_join_groupchat(tox, friend_number, rc = tox_conference_join(tox, friend_number,
invite_data, length); invite_data, length, &err);
break; break;
#ifdef TOXAV_ENABLED #ifdef TOXAV_ENABLED
case TOX_GROUPCHAT_TYPE_AV: case TOX_CONFERENCE_TYPE_AV:
rc = toxav_join_av_groupchat(tox, friend_number, rc = toxav_join_av_groupchat(tox, friend_number,
invite_data, length, invite_data, length,
NULL, NULL); NULL, NULL);
@ -282,7 +283,7 @@ twc_group_invite_callback(Tox *tox,
break; break;
} }
if (rc >= 0) if (rc >= 0 && err == TOX_ERR_CONFERENCE_JOIN_OK)
{ {
tags = "notify_private"; tags = "notify_private";
if (friend_chat) if (friend_chat)
@ -353,10 +354,10 @@ twc_group_invite_callback(Tox *tox,
{ {
weechat_printf_date_tags(friend_chat->buffer, 0, tags, weechat_printf_date_tags(friend_chat->buffer, 0, tags,
"%s%s%s%s invites you to join %s, but we failed to " "%s%s%s%s invites you to join %s, but we failed to "
"process the invite. Please try again.", "process the invite with error %d. Please try again.",
weechat_prefix("network"), weechat_prefix("network"),
weechat_color("chat_nick_other"), friend_name, weechat_color("chat_nick_other"), friend_name,
weechat_color("reset"), rc); weechat_color("reset"), rc, err);
tags = ""; tags = "";
} }
weechat_printf_date_tags(profile->buffer, 0, tags, weechat_printf_date_tags(profile->buffer, 0, tags,
@ -375,8 +376,10 @@ twc_handle_group_message(Tox *tox,
int32_t group_number, int32_t peer_number, int32_t group_number, int32_t peer_number,
const uint8_t *message, uint16_t length, const uint8_t *message, uint16_t length,
void *data, void *data,
enum TWC_MESSAGE_TYPE message_type) TOX_MESSAGE_TYPE message_type)
{ {
TOX_ERR_CONFERENCE_PEER_QUERY err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
bool rc;
struct t_twc_profile *profile = data; struct t_twc_profile *profile = data;
struct t_twc_chat *chat = twc_chat_search_group(profile, struct t_twc_chat *chat = twc_chat_search_group(profile,
@ -389,7 +392,8 @@ twc_handle_group_message(Tox *tox,
char *message_nt = twc_null_terminate(message, length); char *message_nt = twc_null_terminate(message, length);
const char *nick_color; const char *nick_color;
if (tox_group_peernumber_is_ours(tox, group_number, peer_number)) rc = tox_conference_peer_number_is_ours(tox, group_number, peer_number, &err);
if (rc && (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK))
nick_color = weechat_color("chat_nick_self"); nick_color = weechat_color("chat_nick_self");
else else
nick_color = weechat_info_get("nick_color", name); nick_color = weechat_info_get("nick_color", name);
@ -406,9 +410,9 @@ twc_handle_group_message(Tox *tox,
void void
twc_group_message_callback(Tox *tox, twc_group_message_callback(Tox *tox,
int32_t group_number, int32_t peer_number, uint32_t group_number, uint32_t peer_number,
const uint8_t *message, uint16_t length, TOX_MESSAGE_TYPE type, const uint8_t *message,
void *data) size_t length, void *data)
{ {
twc_handle_group_message(tox, twc_handle_group_message(tox,
group_number, group_number,
@ -416,28 +420,13 @@ twc_group_message_callback(Tox *tox,
message, message,
length, length,
data, data,
TWC_MESSAGE_TYPE_MESSAGE); type);
}
void
twc_group_action_callback(Tox *tox,
int32_t group_number, int32_t peer_number,
const uint8_t *message, uint16_t length,
void *data)
{
twc_handle_group_message(tox,
group_number,
peer_number,
message,
length,
data,
TWC_MESSAGE_TYPE_ACTION);
} }
void void
twc_group_namelist_change_callback(Tox *tox, twc_group_namelist_change_callback(Tox *tox,
int group_number, int peer_number, uint32_t group_number, uint32_t peer_number,
uint8_t change_type, TOX_CONFERENCE_STATE_CHANGE change_type,
void *data) void *data)
{ {
struct t_twc_profile *profile = data; struct t_twc_profile *profile = data;
@ -449,8 +438,8 @@ twc_group_namelist_change_callback(Tox *tox,
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number); char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
char *prev_name = NULL; char *prev_name = NULL;
if (change_type == TOX_CHAT_CHANGE_PEER_DEL if (change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT
|| change_type == TOX_CHAT_CHANGE_PEER_NAME) || change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE)
{ {
nick = weechat_hashtable_get(chat->nicks, &peer_number); nick = weechat_hashtable_get(chat->nicks, &peer_number);
if (nick) if (nick)
@ -462,8 +451,8 @@ twc_group_namelist_change_callback(Tox *tox,
} }
} }
if (change_type == TOX_CHAT_CHANGE_PEER_ADD if (change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_JOIN
|| change_type == TOX_CHAT_CHANGE_PEER_NAME) || change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE)
{ {
nick = weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group, nick = weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group,
name, NULL, NULL, NULL, 1); name, NULL, NULL, NULL, 1);
@ -473,17 +462,17 @@ twc_group_namelist_change_callback(Tox *tox,
switch (change_type) switch (change_type)
{ {
case TOX_CHAT_CHANGE_PEER_NAME: case TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE:
if (prev_name && name) if (prev_name && name)
weechat_printf(chat->buffer, "%s%s is now known as %s", weechat_printf(chat->buffer, "%s%s is now known as %s",
weechat_prefix("network"), prev_name, name); weechat_prefix("network"), prev_name, name);
break; break;
case TOX_CHAT_CHANGE_PEER_ADD: case TOX_CONFERENCE_STATE_CHANGE_PEER_JOIN:
if (name) if (name)
weechat_printf(chat->buffer, "%s%s just joined the group chat", weechat_printf(chat->buffer, "%s%s just joined the group chat",
weechat_prefix("join"), name); weechat_prefix("join"), name);
break; break;
case TOX_CHAT_CHANGE_PEER_DEL: case TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT:
if (prev_name) if (prev_name)
weechat_printf(chat->buffer, "%s%s just left the group chat", weechat_printf(chat->buffer, "%s%s just left the group chat",
weechat_prefix("quit"), prev_name); weechat_prefix("quit"), prev_name);
@ -496,8 +485,8 @@ twc_group_namelist_change_callback(Tox *tox,
void void
twc_group_title_callback(Tox *tox, twc_group_title_callback(Tox *tox,
int group_number, int peer_number, uint32_t group_number, uint32_t peer_number,
const uint8_t *title, uint8_t length, const uint8_t *title, size_t length,
void *data) void *data)
{ {
struct t_twc_profile *profile = data; struct t_twc_profile *profile = data;
@ -506,14 +495,11 @@ twc_group_title_callback(Tox *tox,
true); true);
twc_chat_queue_refresh(chat); twc_chat_queue_refresh(chat);
if (peer_number >= 0)
{
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number); char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
char *topic = strndup((char *)title, length); char *topic = strndup((char *)title, length);
weechat_printf(chat->buffer, "%s%s has changed the topic to \"%s\"", weechat_printf(chat->buffer, "%s%s has changed the topic to \"%s\"",
weechat_prefix("network"), name, topic); weechat_prefix("network"), name, topic);
free(topic); free(topic);
}
} }

View File

@ -28,9 +28,8 @@ twc_do_timer_cb(const void *pointer, void *data,
void void
twc_friend_message_callback(Tox *tox, uint32_t friend_number, twc_friend_message_callback(Tox *tox, uint32_t friend_number,
TOX_MESSAGE_TYPE type, TOX_MESSAGE_TYPE type, const uint8_t *message,
const uint8_t *message, size_t length, size_t length, void *data);
void *data);
void void
twc_connection_status_callback(Tox *tox, uint32_t friend_number, twc_connection_status_callback(Tox *tox, uint32_t friend_number,
@ -57,32 +56,26 @@ twc_friend_request_callback(Tox *tox, const uint8_t *public_key,
void void
twc_group_invite_callback(Tox *tox, twc_group_invite_callback(Tox *tox,
int32_t friend_number, uint8_t type, uint32_t friend_number, TOX_CONFERENCE_TYPE type,
const uint8_t *invite_data, uint16_t length, const uint8_t *invite_data, size_t length,
void *data); void *data);
void void
twc_group_message_callback(Tox *tox, twc_group_message_callback(Tox *tox,
int32_t group_number, int32_t peer_number, uint32_t group_number, uint32_t peer_number,
const uint8_t *message, uint16_t length, TOX_MESSAGE_TYPE type, const uint8_t *message,
void *data); size_t length, void *data);
void
twc_group_action_callback(Tox *tox,
int32_t group_number, int32_t peer_number,
const uint8_t *message, uint16_t length,
void *data);
void void
twc_group_namelist_change_callback(Tox *tox, twc_group_namelist_change_callback(Tox *tox,
int group_number, int peer_number, uint32_t group_number, uint32_t peer_number,
uint8_t change_type, TOX_CONFERENCE_STATE_CHANGE change_type,
void *data); void *data);
void void
twc_group_title_callback(Tox *tox, twc_group_title_callback(Tox *tox,
int group_number, int peer_number, uint32_t group_number, uint32_t peer_number,
const uint8_t *title, uint8_t length, const uint8_t *title, size_t length,
void *data); void *data);
#endif // TOX_WEECHAT_TOX_CALLBACKS_H #endif // TOX_WEECHAT_TOX_CALLBACKS_H

View File

@ -124,12 +124,19 @@ char *
twc_get_peer_name_nt(Tox *tox, int32_t group_number, int32_t peer_number) twc_get_peer_name_nt(Tox *tox, int32_t group_number, int32_t peer_number)
{ {
uint8_t name[TOX_MAX_NAME_LENGTH+1] = {0}; uint8_t name[TOX_MAX_NAME_LENGTH+1] = {0};
TOX_ERR_CONFERENCE_PEER_QUERY err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
int length = tox_group_peername(tox, group_number, peer_number, name); int length = tox_conference_peer_get_name_size(tox, group_number, peer_number, &err);
if (length >= 0) if ((err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) && (length <= TOX_MAX_NAME_LENGTH))
{
tox_conference_peer_get_name(tox, group_number, peer_number, name, &err);
if (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK)
return twc_null_terminate(name, length); return twc_null_terminate(name, length);
else else
return "<unknown>"; return "<unknown>";
}
else
return "<unknown>";
} }
/** /**