Added support for joining A/V group chats.

This commit is contained in:
Håvard Pettersson 2014-11-19 04:49:39 +01:00
parent b6015a60bb
commit 708f4d77aa
3 changed files with 46 additions and 22 deletions

View File

@ -21,6 +21,7 @@
#include <weechat/weechat-plugin.h>
#include <tox/tox.h>
#include <tox/toxav.h>
#include "twc.h"
#include "twc-list.h"
@ -36,9 +37,8 @@
*/
int
twc_group_chat_invite_add(struct t_twc_profile *profile,
int32_t friend_number,
uint8_t *data,
size_t size)
int32_t friend_number, uint8_t group_chat_type,
uint8_t *data, size_t size)
{
// create a new invite object
struct t_twc_group_chat_invite *invite
@ -51,6 +51,7 @@ twc_group_chat_invite_add(struct t_twc_profile *profile,
invite->profile = profile;
invite->friend_number = friend_number;
invite->group_chat_type = group_chat_type;
invite->data = data_copy;
invite->data_size = size;
@ -66,10 +67,22 @@ twc_group_chat_invite_add(struct t_twc_profile *profile,
int
twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite)
{
int rc = tox_join_groupchat(invite->profile->tox,
invite->friend_number,
invite->data,
invite->data_size);
int rc;
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);
break;
case TOX_GROUPCHAT_TYPE_AV:
rc = toxav_join_av_groupchat(invite->profile->tox,
invite->friend_number,
invite->data, invite->data_size,
NULL, NULL);
break;
}
twc_group_chat_invite_remove(invite);
return rc;

View File

@ -34,15 +34,15 @@ struct t_twc_group_chat_invite
struct t_twc_profile *profile;
int32_t friend_number;
uint8_t group_chat_type;
uint8_t *data;
size_t data_size;
};
int
twc_group_chat_invite_add(struct t_twc_profile *profile,
int32_t friend_number,
uint8_t *data,
size_t size);
int32_t friend_number, uint8_t group_chat_type,
uint8_t *data, size_t size);
int
twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite);

View File

@ -234,22 +234,33 @@ twc_group_invite_callback(Tox *tox,
struct t_twc_profile *profile = data;
char *friend_name = twc_get_name_nt(profile->tox, friend_number);
if (type == TOX_GROUPCHAT_TYPE_TEXT)
{
int64_t rc = twc_group_chat_invite_add(profile, friend_number,
(uint8_t *)invite_data, length);
int64_t rc = twc_group_chat_invite_add(profile, friend_number, type,
(uint8_t *)invite_data, length);
weechat_printf(profile->buffer,
"%sReceived a group chat invite from %s; "
"join with \"/group join %d\"",
weechat_prefix("network"), friend_name, rc);
char *type_str;
switch (type)
{
case TOX_GROUPCHAT_TYPE_TEXT:
type_str = "a text-only group chat"; break;
case TOX_GROUPCHAT_TYPE_AV:
type_str = "an audio/video group chat"; break;
default:
type_str = "a group chat of unknown type"; break;
}
else if (type == TOX_GROUPCHAT_TYPE_AV)
if (rc >= 0)
{
weechat_printf(profile->buffer,
"%sReceived an audio group chat invite from %s; "
"these are currently unsupported and can not be joined",
weechat_prefix("network"), friend_name);
"%sReceived %s invite from %s; "
"join with \"/group join %d\"",
weechat_prefix("network"), type_str, friend_name, rc);
}
else
{
weechat_printf(profile->buffer,
"%sReceived a group chat invite from %s, but failed to "
"process it; try again",
weechat_prefix("error"), friend_name, rc);
}
free(friend_name);