1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Accept and default to AV groupchats

We don't send or play any audio yet, though
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-11 16:05:01 +01:00
parent bd6795bf73
commit 8fceb4b78b
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
5 changed files with 52 additions and 15 deletions

View File

@ -484,11 +484,12 @@ void Core::onGroupInvite(Tox*, int friendnumber, uint8_t type, const uint8_t *da
if (type == TOX_GROUPCHAT_TYPE_TEXT)
{
qDebug() << QString("Core: Text group invite by %1").arg(friendnumber);
emit static_cast<Core*>(core)->groupInviteReceived(friendnumber, data,length);
emit static_cast<Core*>(core)->groupInviteReceived(friendnumber,type,data,length);
}
else if (type == TOX_GROUPCHAT_TYPE_AV)
{
qDebug() << QString("Core: AV group invite by %1, not implemented").arg(friendnumber);
qDebug() << QString("Core: AV group invite by %1").arg(friendnumber);
emit static_cast<Core*>(core)->groupInviteReceived(friendnumber,type,data,length);
}
else
{
@ -1480,10 +1481,23 @@ QList<QString> Core::getGroupPeerNames(int groupId) const
return names;
}
int Core::joinGroupchat(int32_t friendnumber, const uint8_t* friend_group_public_key,uint16_t length) const
int Core::joinGroupchat(int32_t friendnumber, uint8_t type, const uint8_t* friend_group_public_key,uint16_t length) const
{
qDebug() << QString("Trying to join groupchat invite by friend %1").arg(friendnumber);
return tox_join_groupchat(tox, friendnumber, friend_group_public_key,length);
if (type == TOX_GROUPCHAT_TYPE_TEXT)
{
qDebug() << QString("Trying to join text groupchat invite sent by friend %1").arg(friendnumber);
return tox_join_groupchat(tox, friendnumber, friend_group_public_key,length);
}
else if (type == TOX_GROUPCHAT_TYPE_AV)
{
qDebug() << QString("Trying to join AV groupchat invite sent by friend %1").arg(friendnumber);
return toxav_join_av_groupchat(tox, friendnumber, friend_group_public_key, length, playGroupAudio, const_cast<Core*>(this));
}
else
{
qWarning() << "Core::joinGroupchat: Unknown groupchat type "<<type;
return -1;
}
}
void Core::quitGroupChat(int groupId) const
@ -1614,9 +1628,14 @@ void Core::groupInviteFriend(int friendId, int groupId)
tox_invite_friend(tox, friendId, groupId);
}
void Core::createGroup()
void Core::createGroup(uint8_t type)
{
emit emptyGroupCreated(tox_add_groupchat(tox));
if (type == TOX_GROUPCHAT_TYPE_TEXT)
emit emptyGroupCreated(tox_add_groupchat(tox));
else if (type == TOX_GROUPCHAT_TYPE_AV)
emit emptyGroupCreated(toxav_add_av_groupchat(tox, playGroupAudio, this));
else
qWarning() << "Core::createGroup: Unknown type "<<type;
}
bool Core::hasFriendWithAddress(const QString &addr) const

View File

@ -21,6 +21,8 @@
#include <QObject>
#include <QMutex>
#include <tox/tox.h>
#include "corestructs.h"
#include "coreav.h"
#include "coredefines.h"
@ -56,7 +58,7 @@ public:
QString getFriendUsername(int friendNumber) const; ///< Get the username of a friend
bool hasFriendWithAddress(const QString &addr) const; ///< Check if we have a friend by address
bool hasFriendWithPublicKey(const QString &pubkey) const; ///< Check if we have a friend by public key
int joinGroupchat(int32_t friendNumber, const uint8_t* pubkey,uint16_t length) const; ///< Accept a groupchat invite
int joinGroupchat(int32_t friendNumber, uint8_t type, const uint8_t* pubkey,uint16_t length) const; ///< Accept a groupchat invite
void quitGroupChat(int groupId) const; ///< Quit a groupchat
void saveConfiguration();
@ -83,7 +85,7 @@ public slots:
void acceptFriendRequest(const QString& userId);
void requestFriendship(const QString& friendAddress, const QString& message);
void groupInviteFriend(int friendId, int groupId);
void createGroup();
void createGroup(uint8_t type = TOX_GROUPCHAT_TYPE_AV);
void removeFriend(int friendId);
void removeGroup(int groupId);
@ -143,7 +145,7 @@ signals:
void friendLastSeenChanged(int friendId, const QDateTime& dateTime);
void emptyGroupCreated(int groupnumber);
void groupInviteReceived(int friendnumber, const uint8_t *group_public_key,uint16_t length);
void groupInviteReceived(int friendnumber, uint8_t type, const uint8_t *group_public_key,uint16_t length);
void groupMessageReceived(int groupnumber, const QString& message, const QString& author, bool isAction);
void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
@ -231,6 +233,9 @@ private:
static void onAvPeerTimeout(void* toxav, int32_t call_index, void* core);
static void onAvMediaChange(void *toxav, int32_t call_index, void* core);
static void playGroupAudio(Tox* tox, int groupnumber, int friendgroupnumber, const int16_t* out_audio,
unsigned out_audio_samples, uint8_t decoder_channels, unsigned audio_sample_rate, void* userdata);
static void prepareCall(int friendId, int callId, ToxAv *toxav, bool videoEnabled);
static void cleanupCall(int callId);
static void playCallAudio(ToxAv *toxav, int32_t callId, int16_t *data, int samples, void *user_data); // Callback

View File

@ -587,3 +587,8 @@ VideoSource *Core::getVideoSourceFromCall(int callNumber)
return &calls[callNumber].videoSource;
}
void Core::playGroupAudio(Tox* tox, int groupnumber, int friendgroupnumber, const int16_t* out_audio,
unsigned out_audio_samples, uint8_t decoder_channels, unsigned audio_sample_rate, void* userdata)
{
qDebug() << "Core::playGroupAudio: Not implemented";
}

View File

@ -870,12 +870,20 @@ void Widget::copyFriendIdToClipboard(int friendId)
}
}
void Widget::onGroupInviteReceived(int32_t friendId, const uint8_t* publicKey,uint16_t length)
void Widget::onGroupInviteReceived(int32_t friendId, uint8_t type, const uint8_t* publicKey,uint16_t length)
{
int groupId = core->joinGroupchat(friendId, publicKey,length);
if (groupId == -1)
if (type == TOX_GROUPCHAT_TYPE_TEXT || type == TOX_GROUPCHAT_TYPE_AV)
{
qWarning() << "Widget::onGroupInviteReceived: Unable to accept invitation";
int groupId = core->joinGroupchat(friendId, type, publicKey,length);
if (groupId < 0)
{
qWarning() << "Widget::onGroupInviteReceived: Unable to accept group invite";
return;
}
}
else
{
qWarning() << "Widget::onGroupInviteReceived: Unknown groupchat type:"<<type;
return;
}
}

View File

@ -112,7 +112,7 @@ private slots:
void onFriendRequestReceived(const QString& userId, const QString& message);
void onReceiptRecieved(int friendId, int receipt);
void onEmptyGroupCreated(int groupId);
void onGroupInviteReceived(int32_t friendId, const uint8_t *publicKey,uint16_t length);
void onGroupInviteReceived(int32_t friendId, uint8_t type, const uint8_t *publicKey,uint16_t length);
void onGroupMessageReceived(int groupnumber, const QString& message, const QString& author, bool isAction);
void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
void removeFriend(int friendId);