migration to TokTok c-toxcore
This commit is contained in:
parent
8d395d8011
commit
cc9d370105
@ -80,6 +80,7 @@ twc_chat_new(struct t_twc_profile *profile, const char *name)
|
||||
twc_chat_buffer_close_callback);
|
||||
weechat_buffer_set_pointer(chat->buffer, "close_callback_pointer", chat);
|
||||
}
|
||||
|
||||
free(full_name);
|
||||
|
||||
if (!(chat->buffer))
|
||||
@ -152,6 +153,9 @@ twc_chat_refresh(const struct t_twc_chat *chat)
|
||||
{
|
||||
char *name = NULL;
|
||||
char *title = NULL;
|
||||
bool rc = false;
|
||||
TOX_ERR_CONFERENCE_TITLE err = TOX_ERR_CONFERENCE_TITLE_OK;
|
||||
|
||||
if (chat->friend_number >= 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
char group_name[TOX_MAX_NAME_LENGTH + 1] = {0};
|
||||
int len = tox_group_get_title(chat->profile->tox, chat->group_number,
|
||||
(uint8_t *)group_name,
|
||||
TOX_MAX_NAME_LENGTH);
|
||||
if (len <= 0)
|
||||
int len = tox_conference_get_title_size(chat->profile->tox, chat->group_number,
|
||||
&err);
|
||||
if ((err == TOX_ERR_CONFERENCE_TITLE_OK) && (len <= TOX_MAX_NAME_LENGTH))
|
||||
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);
|
||||
|
||||
name = title = strdup((char *)group_name);
|
||||
@ -278,17 +284,17 @@ twc_chat_print_message(struct t_twc_chat *chat,
|
||||
const char *color,
|
||||
const char *sender,
|
||||
const char *message,
|
||||
enum TWC_MESSAGE_TYPE message_type)
|
||||
TOX_MESSAGE_TYPE message_type)
|
||||
{
|
||||
switch (message_type)
|
||||
{
|
||||
case TWC_MESSAGE_TYPE_MESSAGE:
|
||||
case TOX_MESSAGE_TYPE_NORMAL:
|
||||
weechat_printf_date_tags(chat->buffer, 0, tags,
|
||||
"%s%s%s\t%s",
|
||||
color, sender,
|
||||
weechat_color("reset"), message);
|
||||
break;
|
||||
case TWC_MESSAGE_TYPE_ACTION:
|
||||
case TOX_MESSAGE_TYPE_ACTION:
|
||||
weechat_printf_date_tags(chat->buffer, 0, tags,
|
||||
"%s%s%s%s %s",
|
||||
weechat_prefix("action"),
|
||||
@ -303,9 +309,9 @@ twc_chat_print_message(struct t_twc_chat *chat,
|
||||
*/
|
||||
void
|
||||
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)
|
||||
{
|
||||
twc_message_queue_add_friend_message(chat->profile,
|
||||
@ -319,29 +325,26 @@ twc_chat_send_message(struct t_twc_chat *chat, const char *message,
|
||||
}
|
||||
else if (chat->group_number >= 0)
|
||||
{
|
||||
if (message_type == TWC_MESSAGE_TYPE_MESSAGE)
|
||||
int len = strlen(message);
|
||||
while (len > 0)
|
||||
{
|
||||
int len = strlen(message);
|
||||
while (len > 0)
|
||||
{
|
||||
int fit_len = twc_fit_utf8(message, TWC_MAX_GROUP_MESSAGE_LENGTH);
|
||||
rc = tox_group_message_send(chat->profile->tox, chat->group_number,
|
||||
(uint8_t *)message, fit_len);
|
||||
if (rc < 0)
|
||||
break;
|
||||
message += fit_len;
|
||||
len -= fit_len;
|
||||
}
|
||||
int fit_len = twc_fit_utf8(message, TWC_MAX_GROUP_MESSAGE_LENGTH);
|
||||
err = TOX_ERR_CONFERENCE_SEND_MESSAGE_OK;
|
||||
tox_conference_send_message(chat->profile->tox, chat->group_number,
|
||||
message_type, (uint8_t *)message, fit_len,
|
||||
&err);
|
||||
if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK)
|
||||
break;
|
||||
message += fit_len;
|
||||
len -= fit_len;
|
||||
}
|
||||
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)
|
||||
if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK)
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%s%sFailed to send message%s",
|
||||
"%s%sFailed to send message with error %d%s",
|
||||
weechat_prefix("error"),
|
||||
weechat_color("chat_highlight"),
|
||||
err,
|
||||
weechat_color("reset"));
|
||||
}
|
||||
}
|
||||
@ -357,7 +360,7 @@ twc_chat_buffer_input_callback(const void *pointer, void *data,
|
||||
{
|
||||
/* TODO: don't strip the const */
|
||||
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;
|
||||
}
|
||||
@ -370,16 +373,17 @@ twc_chat_buffer_close_callback(const void *pointer, void *data,
|
||||
struct t_gui_buffer *weechat_buffer)
|
||||
{
|
||||
/* TODO: don't strip the const */
|
||||
TOX_ERR_CONFERENCE_DELETE err = TOX_ERR_CONFERENCE_DELETE_OK;
|
||||
struct t_twc_chat *chat = (void *)pointer;
|
||||
|
||||
if (chat->profile->tox && chat->group_number >= 0)
|
||||
{
|
||||
int rc = tox_del_groupchat(chat->profile->tox, chat->group_number);
|
||||
if (rc != 0)
|
||||
tox_conference_delete(chat->profile->tox, chat->group_number, &err);
|
||||
if (err != TOX_ERR_CONFERENCE_DELETE_OK)
|
||||
{
|
||||
weechat_printf(chat->profile->buffer,
|
||||
"%swarning: failed to leave group chat",
|
||||
weechat_prefix("error"));
|
||||
"%swarning: failed to leave group chat with error %d",
|
||||
weechat_prefix("error"), err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,12 +29,6 @@ extern const char *twc_tag_unsent_message;
|
||||
extern const char *twc_tag_sent_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_profile *profile;
|
||||
@ -64,11 +58,11 @@ twc_chat_print_message(struct t_twc_chat *chat,
|
||||
const char *color,
|
||||
const char *sender,
|
||||
const char *message,
|
||||
enum TWC_MESSAGE_TYPE message_type);
|
||||
TOX_MESSAGE_TYPE message_type);
|
||||
|
||||
void
|
||||
twc_chat_send_message(struct t_twc_chat *chat, const char *message,
|
||||
enum TWC_MESSAGE_TYPE message_type);
|
||||
TOX_MESSAGE_TYPE message_type);
|
||||
|
||||
void
|
||||
twc_chat_queue_refresh(struct t_twc_chat *chat);
|
||||
|
@ -534,19 +534,20 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
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_LOADED(profile);
|
||||
|
||||
// /group create
|
||||
if (argc == 2 && weechat_strcasecmp(argv[1], "create") == 0)
|
||||
{
|
||||
int rc = tox_add_groupchat(profile->tox);
|
||||
if (rc >= 0)
|
||||
int rc = tox_conference_new(profile->tox, &err);
|
||||
if (err == TOX_ERR_CONFERENCE_NEW_OK)
|
||||
twc_chat_search_group(profile, rc, true);
|
||||
else
|
||||
weechat_printf(profile->buffer,
|
||||
"%sCould not create group chat (unknown error)",
|
||||
weechat_prefix("error"));
|
||||
"%sCould not create group chat with error %d",
|
||||
weechat_prefix("error"), err);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
@ -626,6 +627,7 @@ twc_cmd_invite(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
if (argc == 1)
|
||||
return WEECHAT_RC_ERROR;
|
||||
|
||||
TOX_ERR_CONFERENCE_INVITE err = TOX_ERR_CONFERENCE_INVITE_OK;
|
||||
|
||||
struct t_twc_chat *chat = twc_chat_search_buffer(buffer);
|
||||
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]);
|
||||
TWC_CHECK_FRIEND_NUMBER(chat->profile, friend_number, argv_eol[1]);
|
||||
|
||||
int rc = tox_invite_friend(chat->profile->tox,
|
||||
friend_number, chat->group_number);
|
||||
tox_conference_invite(chat->profile->tox, friend_number, chat->group_number, &err);
|
||||
|
||||
if (rc == 0)
|
||||
if (err == TOX_ERR_CONFERENCE_INVITE_OK)
|
||||
{
|
||||
char *friend_name = twc_get_name_nt(chat->profile->tox, friend_number);
|
||||
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
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%sFailed to send group chat invite (unknown error)",
|
||||
weechat_prefix("error"));
|
||||
"%sFailed to send group chat invite with error %d",
|
||||
weechat_prefix("error"), err);
|
||||
}
|
||||
|
||||
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_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;
|
||||
}
|
||||
@ -714,7 +715,7 @@ twc_cmd_msg(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
if (message)
|
||||
twc_chat_send_message(chat,
|
||||
weechat_string_strip(message, 1, 1, " "),
|
||||
TWC_MESSAGE_TYPE_MESSAGE);
|
||||
TOX_MESSAGE_TYPE_NORMAL);
|
||||
|
||||
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)
|
||||
{
|
||||
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_GROUP_CHAT(chat);
|
||||
|
||||
int rc = tox_del_groupchat(chat->profile->tox, chat->group_number);
|
||||
if (rc == 0)
|
||||
tox_conference_delete(chat->profile->tox, chat->group_number, &err);
|
||||
if (err == TOX_ERR_CONFERENCE_DELETE_OK)
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%sYou have left the group chat",
|
||||
@ -873,8 +875,8 @@ twc_cmd_part(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
else
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%sFailed to leave group chat",
|
||||
weechat_prefix("error"));
|
||||
"%sFailed to leave group chat with error %d",
|
||||
weechat_prefix("error"), err);
|
||||
}
|
||||
|
||||
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)
|
||||
return WEECHAT_RC_ERROR;
|
||||
|
||||
TOX_ERR_CONFERENCE_TITLE err = TOX_ERR_CONFERENCE_TITLE_OK;
|
||||
|
||||
struct t_twc_chat *chat = twc_chat_search_buffer(buffer);
|
||||
TWC_CHECK_CHAT(chat);
|
||||
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];
|
||||
|
||||
int result = tox_group_set_title(chat->profile->tox, chat->group_number,
|
||||
(uint8_t *)topic, strlen(topic));
|
||||
if (result == -1)
|
||||
tox_conference_set_title(chat->profile->tox, chat->group_number,
|
||||
(uint8_t *)topic, strlen(topic), &err);
|
||||
if (err != TOX_ERR_CONFERENCE_TITLE_OK)
|
||||
{
|
||||
weechat_printf(chat->buffer, "%s%s",
|
||||
weechat_prefix("error"), "Could not set topic.");
|
||||
|
@ -71,15 +71,15 @@ int
|
||||
twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite)
|
||||
{
|
||||
int rc;
|
||||
TOX_ERR_CONFERENCE_JOIN err = TOX_ERR_CONFERENCE_JOIN_OK;
|
||||
switch (invite->group_chat_type)
|
||||
{
|
||||
case TOX_GROUPCHAT_TYPE_TEXT:
|
||||
rc = tox_join_groupchat(invite->profile->tox,
|
||||
invite->friend_number,
|
||||
invite->data, invite->data_size);
|
||||
case TOX_CONFERENCE_TYPE_TEXT:
|
||||
rc = tox_conference_join(invite->profile->tox, invite->friend_number,
|
||||
invite->data, invite->data_size, &err);
|
||||
break;
|
||||
#ifdef TOXAV_ENABLED
|
||||
case TOX_GROUPCHAT_TYPE_AV:
|
||||
case TOX_CONFERENCE_TYPE_AV:
|
||||
rc = toxav_join_av_groupchat(invite->profile->tox,
|
||||
invite->friend_number,
|
||||
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);
|
||||
|
||||
if (err != TOX_ERR_CONFERENCE_JOIN_OK)
|
||||
return -1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ struct t_twc_group_chat_invite
|
||||
{
|
||||
struct t_twc_profile *profile;
|
||||
|
||||
int32_t friend_number;
|
||||
uint32_t friend_number;
|
||||
uint8_t group_chat_type;
|
||||
uint8_t *data;
|
||||
size_t data_size;
|
||||
|
@ -56,7 +56,7 @@ void
|
||||
twc_message_queue_add_friend_message(struct t_twc_profile *profile,
|
||||
int32_t friend_number,
|
||||
const char *message,
|
||||
enum TWC_MESSAGE_TYPE message_type)
|
||||
TOX_MESSAGE_TYPE message_type)
|
||||
{
|
||||
int len = strlen(message);
|
||||
while (len > 0)
|
||||
@ -107,9 +107,7 @@ twc_message_queue_flush_friend(struct t_twc_profile *profile,
|
||||
TOX_ERR_FRIEND_SEND_MESSAGE err;
|
||||
(void)tox_friend_send_message(profile->tox,
|
||||
friend_number,
|
||||
queued_message->message_type == TWC_MESSAGE_TYPE_MESSAGE?
|
||||
TOX_MESSAGE_TYPE_NORMAL:
|
||||
TOX_MESSAGE_TYPE_ACTION,
|
||||
queued_message->message_type,
|
||||
(uint8_t *)queued_message->message,
|
||||
strlen(queued_message->message),
|
||||
&err);
|
||||
|
@ -33,14 +33,14 @@ struct t_twc_queued_message
|
||||
{
|
||||
struct tm *time;
|
||||
char *message;
|
||||
enum TWC_MESSAGE_TYPE message_type;
|
||||
TOX_MESSAGE_TYPE message_type;
|
||||
};
|
||||
|
||||
void
|
||||
twc_message_queue_add_friend_message(struct t_twc_profile *profile,
|
||||
int32_t friend_number,
|
||||
const char *message,
|
||||
enum TWC_MESSAGE_TYPE message_type);
|
||||
TOX_MESSAGE_TYPE message_type);
|
||||
|
||||
void
|
||||
twc_message_queue_flush_friend(struct t_twc_profile *profile,
|
||||
|
@ -416,17 +416,16 @@ twc_profile_load(struct t_twc_profile *profile)
|
||||
twc_do_timer_cb(profile, NULL, 0);
|
||||
|
||||
// register Tox callbacks
|
||||
tox_callback_friend_message(profile->tox, twc_friend_message_callback, profile);
|
||||
tox_callback_friend_connection_status(profile->tox, twc_connection_status_callback, profile);
|
||||
tox_callback_friend_name(profile->tox, twc_name_change_callback, profile);
|
||||
tox_callback_friend_status(profile->tox, twc_user_status_callback, profile);
|
||||
tox_callback_friend_status_message(profile->tox, twc_status_message_callback, profile);
|
||||
tox_callback_friend_request(profile->tox, twc_friend_request_callback, profile);
|
||||
tox_callback_group_invite(profile->tox, twc_group_invite_callback, profile);
|
||||
tox_callback_group_message(profile->tox, twc_group_message_callback, profile);
|
||||
tox_callback_group_action(profile->tox, twc_group_action_callback, profile);
|
||||
tox_callback_group_namelist_change(profile->tox, twc_group_namelist_change_callback, profile);
|
||||
tox_callback_group_title(profile->tox, twc_group_title_callback, profile);
|
||||
tox_callback_friend_message(profile->tox, twc_friend_message_callback);
|
||||
tox_callback_friend_connection_status(profile->tox, twc_connection_status_callback);
|
||||
tox_callback_friend_name(profile->tox, twc_name_change_callback);
|
||||
tox_callback_friend_status(profile->tox, twc_user_status_callback);
|
||||
tox_callback_friend_status_message(profile->tox, twc_status_message_callback);
|
||||
tox_callback_friend_request(profile->tox, twc_friend_request_callback);
|
||||
tox_callback_conference_invite(profile->tox, twc_group_invite_callback);
|
||||
tox_callback_conference_message(profile->tox, twc_group_message_callback);
|
||||
tox_callback_conference_namelist_change(profile->tox, twc_group_namelist_change_callback);
|
||||
tox_callback_conference_title(profile->tox, twc_group_title_callback);
|
||||
return TWC_RC_OK;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ twc_do_timer_cb(const void *pointer, void *data,
|
||||
/* TODO: don't strip the const */
|
||||
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),
|
||||
0, 1, twc_do_timer_cb, profile, NULL);
|
||||
profile->tox_do_timer = hook;
|
||||
@ -240,10 +240,11 @@ twc_friend_request_callback(Tox *tox, const uint8_t *public_key,
|
||||
|
||||
void
|
||||
twc_group_invite_callback(Tox *tox,
|
||||
int32_t friend_number, uint8_t type,
|
||||
const uint8_t *invite_data, uint16_t length,
|
||||
uint32_t friend_number, TOX_CONFERENCE_TYPE type,
|
||||
const uint8_t *invite_data, size_t length,
|
||||
void *data)
|
||||
{
|
||||
TOX_ERR_CONFERENCE_JOIN err = TOX_ERR_CONFERENCE_JOIN_OK;
|
||||
struct t_twc_profile *profile = data;
|
||||
char *friend_name = twc_get_name_nt(profile->tox, friend_number);
|
||||
struct t_twc_chat *friend_chat
|
||||
@ -254,10 +255,10 @@ twc_group_invite_callback(Tox *tox,
|
||||
char *type_str;
|
||||
switch (type)
|
||||
{
|
||||
case TOX_GROUPCHAT_TYPE_TEXT:
|
||||
case TOX_CONFERENCE_TYPE_TEXT:
|
||||
type_str = "a text-only group chat"; break;
|
||||
case TOX_GROUPCHAT_TYPE_AV:
|
||||
type_str = "an audio/video group chat"; break;
|
||||
case TOX_CONFERENCE_TYPE_AV:
|
||||
type_str = "an audio/vikdeo group chat"; break;
|
||||
default:
|
||||
type_str = "a group chat"; break;
|
||||
}
|
||||
@ -266,12 +267,12 @@ twc_group_invite_callback(Tox *tox,
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TOX_GROUPCHAT_TYPE_TEXT:
|
||||
rc = tox_join_groupchat(tox, friend_number,
|
||||
invite_data, length);
|
||||
case TOX_CONFERENCE_TYPE_TEXT:
|
||||
rc = tox_conference_join(tox, friend_number,
|
||||
invite_data, length, &err);
|
||||
break;
|
||||
#ifdef TOXAV_ENABLED
|
||||
case TOX_GROUPCHAT_TYPE_AV:
|
||||
case TOX_CONFERENCE_TYPE_AV:
|
||||
rc = toxav_join_av_groupchat(tox, friend_number,
|
||||
invite_data, length,
|
||||
NULL, NULL);
|
||||
@ -282,7 +283,7 @@ twc_group_invite_callback(Tox *tox,
|
||||
break;
|
||||
}
|
||||
|
||||
if (rc >= 0)
|
||||
if (rc >= 0 && err == TOX_ERR_CONFERENCE_JOIN_OK)
|
||||
{
|
||||
tags = "notify_private";
|
||||
if (friend_chat)
|
||||
@ -353,10 +354,10 @@ twc_group_invite_callback(Tox *tox,
|
||||
{
|
||||
weechat_printf_date_tags(friend_chat->buffer, 0, tags,
|
||||
"%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_color("chat_nick_other"), friend_name,
|
||||
weechat_color("reset"), rc);
|
||||
weechat_color("reset"), rc, err);
|
||||
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,
|
||||
const uint8_t *message, uint16_t length,
|
||||
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_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);
|
||||
|
||||
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");
|
||||
else
|
||||
nick_color = weechat_info_get("nick_color", name);
|
||||
@ -406,9 +410,9 @@ twc_handle_group_message(Tox *tox,
|
||||
|
||||
void
|
||||
twc_group_message_callback(Tox *tox,
|
||||
int32_t group_number, int32_t peer_number,
|
||||
const uint8_t *message, uint16_t length,
|
||||
void *data)
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
TOX_MESSAGE_TYPE type, const uint8_t *message,
|
||||
size_t length, void *data)
|
||||
{
|
||||
twc_handle_group_message(tox,
|
||||
group_number,
|
||||
@ -416,28 +420,13 @@ twc_group_message_callback(Tox *tox,
|
||||
message,
|
||||
length,
|
||||
data,
|
||||
TWC_MESSAGE_TYPE_MESSAGE);
|
||||
}
|
||||
|
||||
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);
|
||||
type);
|
||||
}
|
||||
|
||||
void
|
||||
twc_group_namelist_change_callback(Tox *tox,
|
||||
int group_number, int peer_number,
|
||||
uint8_t change_type,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
TOX_CONFERENCE_STATE_CHANGE change_type,
|
||||
void *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 *prev_name = NULL;
|
||||
|
||||
if (change_type == TOX_CHAT_CHANGE_PEER_DEL
|
||||
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
|
||||
if (change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT
|
||||
|| change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE)
|
||||
{
|
||||
nick = weechat_hashtable_get(chat->nicks, &peer_number);
|
||||
if (nick)
|
||||
@ -462,8 +451,8 @@ twc_group_namelist_change_callback(Tox *tox,
|
||||
}
|
||||
}
|
||||
|
||||
if (change_type == TOX_CHAT_CHANGE_PEER_ADD
|
||||
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
|
||||
if (change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_JOIN
|
||||
|| change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE)
|
||||
{
|
||||
nick = weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group,
|
||||
name, NULL, NULL, NULL, 1);
|
||||
@ -473,17 +462,17 @@ twc_group_namelist_change_callback(Tox *tox,
|
||||
|
||||
switch (change_type)
|
||||
{
|
||||
case TOX_CHAT_CHANGE_PEER_NAME:
|
||||
case TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE:
|
||||
if (prev_name && name)
|
||||
weechat_printf(chat->buffer, "%s%s is now known as %s",
|
||||
weechat_prefix("network"), prev_name, name);
|
||||
break;
|
||||
case TOX_CHAT_CHANGE_PEER_ADD:
|
||||
case TOX_CONFERENCE_STATE_CHANGE_PEER_JOIN:
|
||||
if (name)
|
||||
weechat_printf(chat->buffer, "%s%s just joined the group chat",
|
||||
weechat_prefix("join"), name);
|
||||
break;
|
||||
case TOX_CHAT_CHANGE_PEER_DEL:
|
||||
case TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT:
|
||||
if (prev_name)
|
||||
weechat_printf(chat->buffer, "%s%s just left the group chat",
|
||||
weechat_prefix("quit"), prev_name);
|
||||
@ -496,8 +485,8 @@ twc_group_namelist_change_callback(Tox *tox,
|
||||
|
||||
void
|
||||
twc_group_title_callback(Tox *tox,
|
||||
int group_number, int peer_number,
|
||||
const uint8_t *title, uint8_t length,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
const uint8_t *title, size_t length,
|
||||
void *data)
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
@ -506,14 +495,11 @@ twc_group_title_callback(Tox *tox,
|
||||
true);
|
||||
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);
|
||||
weechat_printf(chat->buffer, "%s%s has changed the topic to \"%s\"",
|
||||
weechat_prefix("network"), name, topic);
|
||||
free(topic);
|
||||
}
|
||||
char *topic = strndup((char *)title, length);
|
||||
weechat_printf(chat->buffer, "%s%s has changed the topic to \"%s\"",
|
||||
weechat_prefix("network"), name, topic);
|
||||
free(topic);
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,8 @@ twc_do_timer_cb(const void *pointer, void *data,
|
||||
|
||||
void
|
||||
twc_friend_message_callback(Tox *tox, uint32_t friend_number,
|
||||
TOX_MESSAGE_TYPE type,
|
||||
const uint8_t *message, size_t length,
|
||||
void *data);
|
||||
TOX_MESSAGE_TYPE type, const uint8_t *message,
|
||||
size_t length, void *data);
|
||||
|
||||
void
|
||||
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
|
||||
twc_group_invite_callback(Tox *tox,
|
||||
int32_t friend_number, uint8_t type,
|
||||
const uint8_t *invite_data, uint16_t length,
|
||||
uint32_t friend_number, TOX_CONFERENCE_TYPE type,
|
||||
const uint8_t *invite_data, size_t length,
|
||||
void *data);
|
||||
|
||||
void
|
||||
twc_group_message_callback(Tox *tox,
|
||||
int32_t group_number, int32_t peer_number,
|
||||
const uint8_t *message, uint16_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);
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
TOX_MESSAGE_TYPE type, const uint8_t *message,
|
||||
size_t length, void *data);
|
||||
|
||||
void
|
||||
twc_group_namelist_change_callback(Tox *tox,
|
||||
int group_number, int peer_number,
|
||||
uint8_t change_type,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
TOX_CONFERENCE_STATE_CHANGE change_type,
|
||||
void *data);
|
||||
|
||||
void
|
||||
twc_group_title_callback(Tox *tox,
|
||||
int group_number, int peer_number,
|
||||
const uint8_t *title, uint8_t length,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
const uint8_t *title, size_t length,
|
||||
void *data);
|
||||
|
||||
#endif // TOX_WEECHAT_TOX_CALLBACKS_H
|
||||
|
@ -124,10 +124,17 @@ char *
|
||||
twc_get_peer_name_nt(Tox *tox, int32_t group_number, int32_t peer_number)
|
||||
{
|
||||
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);
|
||||
if (length >= 0)
|
||||
return twc_null_terminate(name, length);
|
||||
int length = tox_conference_peer_get_name_size(tox, group_number, peer_number, &err);
|
||||
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);
|
||||
else
|
||||
return "<unknown>";
|
||||
}
|
||||
else
|
||||
return "<unknown>";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user