autojoin implemented

This commit is contained in:
Gordon Quad 2016-12-03 11:33:05 +00:00
parent fa77a3084e
commit bdbbf1178d
3 changed files with 70 additions and 17 deletions

View File

@ -42,6 +42,7 @@ char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] =
{
"save_file",
"autoload",
"autojoin",
"max_friend_requests",
"proxy_address",
"proxy_port",
@ -198,6 +199,12 @@ twc_config_init_option(struct t_config_section *section,
"network when WeeChat starts";
default_value = "off";
break;
case TWC_PROFILE_OPTION_AUTOJOIN:
type = "boolean";
description = "automatically join all groups you are invited in "
"by your friends";
default_value = "off";
break;
case TWC_PROFILE_OPTION_IPV6:
type = "boolean";
description = "use IPv6 as well as IPv4 to connect to the Tox "

View File

@ -30,6 +30,7 @@ enum t_twc_profile_option
{
TWC_PROFILE_OPTION_SAVEFILE = 0,
TWC_PROFILE_OPTION_AUTOLOAD,
TWC_PROFILE_OPTION_AUTOJOIN,
TWC_PROFILE_OPTION_MAX_FRIEND_REQUESTS,
TWC_PROFILE_OPTION_PROXY_ADDRESS,
TWC_PROFILE_OPTION_PROXY_PORT,

View File

@ -22,6 +22,10 @@
#include <weechat/weechat-plugin.h>
#include <tox/tox.h>
#ifdef TOXAV_ENABLED
#include <tox/toxav.h>
#endif // TOXAV_ENABLED
#include "twc.h"
#include "twc-profile.h"
#include "twc-chat.h"
@ -209,9 +213,7 @@ twc_group_invite_callback(Tox *tox,
char *friend_name = twc_get_name_nt(profile->tox, friend_number);
struct t_twc_chat *friend_chat
= twc_chat_search_friend(profile, friend_number, true);
int64_t rc = twc_group_chat_invite_add(profile, friend_number, type,
(uint8_t *)invite_data, length);
int64_t rc;
char *type_str;
switch (type)
@ -224,6 +226,49 @@ twc_group_invite_callback(Tox *tox,
type_str = "a group chat"; break;
}
if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN))
{
switch (type)
{
case TOX_GROUPCHAT_TYPE_TEXT:
rc = tox_join_groupchat(tox, friend_number,
invite_data, length);
break;
#ifdef TOXAV_ENABLED
case TOX_GROUPCHAT_TYPE_AV:
rc = toxav_join_av_groupchat(tox, friend_number,
invite_data, length,
NULL, NULL);
break;
#endif
default:
rc = -1;
break;
}
if (rc >= 0)
{
weechat_printf(friend_chat->buffer,
"%sWe joined the %s%s%s's invite to %s.",
weechat_prefix("network"),
weechat_color("chat_nick_other"), friend_name,
weechat_color("reset"), type_str, rc);
}
else
{
weechat_printf(friend_chat->buffer,
"%s%s%s%s invites you to join %s, but we failed to "
"process the invite. Please try again.",
weechat_prefix("network"),
weechat_color("chat_nick_other"), friend_name,
weechat_color("reset"), rc);
}
}
else
{
rc = twc_group_chat_invite_add(profile, friend_number, type,
(uint8_t *)invite_data, length);
if (rc >= 0)
{
weechat_printf(friend_chat->buffer,
@ -242,7 +287,7 @@ twc_group_invite_callback(Tox *tox,
weechat_color("chat_nick_other"), friend_name,
weechat_color("reset"), rc);
}
}
free(friend_name);
}