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

View File

@ -34,15 +34,15 @@ struct t_twc_group_chat_invite
struct t_twc_profile *profile; struct t_twc_profile *profile;
int32_t friend_number; int32_t friend_number;
uint8_t group_chat_type;
uint8_t *data; uint8_t *data;
size_t data_size; size_t data_size;
}; };
int int
twc_group_chat_invite_add(struct t_twc_profile *profile, twc_group_chat_invite_add(struct t_twc_profile *profile,
int32_t friend_number, int32_t friend_number, uint8_t group_chat_type,
uint8_t *data, uint8_t *data, size_t size);
size_t size);
int 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);

View File

@ -234,22 +234,33 @@ twc_group_invite_callback(Tox *tox,
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);
if (type == TOX_GROUPCHAT_TYPE_TEXT) int64_t rc = twc_group_chat_invite_add(profile, friend_number, type,
{ (uint8_t *)invite_data, length);
int64_t rc = twc_group_chat_invite_add(profile, friend_number,
(uint8_t *)invite_data, length);
weechat_printf(profile->buffer, char *type_str;
"%sReceived a group chat invite from %s; " switch (type)
"join with \"/group join %d\"", {
weechat_prefix("network"), friend_name, rc); 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, weechat_printf(profile->buffer,
"%sReceived an audio group chat invite from %s; " "%sReceived %s invite from %s; "
"these are currently unsupported and can not be joined", "join with \"/group join %d\"",
weechat_prefix("network"), friend_name); 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); free(friend_name);