From 708f4d77aa0466002ea2b6a87e6d2d944a39690f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Pettersson?= Date: Wed, 19 Nov 2014 04:49:39 +0100 Subject: [PATCH] Added support for joining A/V group chats. --- src/twc-group-invite.c | 27 ++++++++++++++++++++------- src/twc-group-invite.h | 6 +++--- src/twc-tox-callbacks.c | 35 +++++++++++++++++++++++------------ 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/twc-group-invite.c b/src/twc-group-invite.c index 3479899..3239b02 100644 --- a/src/twc-group-invite.c +++ b/src/twc-group-invite.c @@ -21,6 +21,7 @@ #include #include +#include #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; diff --git a/src/twc-group-invite.h b/src/twc-group-invite.h index c4657b5..1a73424 100644 --- a/src/twc-group-invite.h +++ b/src/twc-group-invite.h @@ -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); diff --git a/src/twc-tox-callbacks.c b/src/twc-tox-callbacks.c index 88f5d4d..52fa7a4 100644 --- a/src/twc-tox-callbacks.c +++ b/src/twc-tox-callbacks.c @@ -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);