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

fix(groups): fix assert on group invite accept

This commit is contained in:
Anthony Bilinski 2019-04-13 14:16:39 -07:00
parent df62463e27
commit 0f5ad725d7
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
5 changed files with 26 additions and 12 deletions

View File

@ -1096,7 +1096,8 @@ bool Core::parsePeerQueryError(Tox_Err_Conference_Peer_Query error) const
}
}
GroupId Core::getGroupPersistentId(uint32_t groupNumber) {
GroupId Core::getGroupPersistentId(uint32_t groupNumber) const
{
QMutexLocker ml{&coreLoopLock};
size_t conferenceIdSize = TOX_CONFERENCE_UID_SIZE;
@ -1273,7 +1274,7 @@ bool Core::parseConferenceJoinError(Tox_Err_Conference_Join error) const
*
* @return Conference number on success, UINT32_MAX on failure.
*/
uint32_t Core::joinGroupchat(const GroupInvite& inviteInfo) const
uint32_t Core::joinGroupchat(const GroupInvite& inviteInfo)
{
QMutexLocker ml{&coreLoopLock};
@ -1282,25 +1283,30 @@ uint32_t Core::joinGroupchat(const GroupInvite& inviteInfo) const
const QByteArray invite = inviteInfo.getInvite();
const uint8_t* const cookie = reinterpret_cast<const uint8_t*>(invite.data());
const size_t cookieLength = invite.length();
uint32_t groupNum{std::numeric_limits<uint32_t>::max()};
switch (confType) {
case TOX_CONFERENCE_TYPE_TEXT: {
qDebug() << QString("Trying to join text groupchat invite sent by friend %1").arg(friendId);
Tox_Err_Conference_Join error;
uint32_t groupId = tox_conference_join(tox.get(), friendId, cookie, cookieLength, &error);
return parseConferenceJoinError(error) ? groupId : std::numeric_limits<uint32_t>::max();
groupNum = tox_conference_join(tox.get(), friendId, cookie, cookieLength, &error);
if (!parseConferenceJoinError(error)) {
groupNum = std::numeric_limits<uint32_t>::max();
}
break;
}
case TOX_CONFERENCE_TYPE_AV: {
qDebug() << QString("Trying to join AV groupchat invite sent by friend %1").arg(friendId);
return toxav_join_av_groupchat(tox.get(), friendId, cookie, cookieLength,
groupNum = toxav_join_av_groupchat(tox.get(), friendId, cookie, cookieLength,
CoreAV::groupCallCallback, const_cast<Core*>(this));
break;
}
default:
qWarning() << "joinGroupchat: Unknown groupchat type " << confType;
}
return std::numeric_limits<uint32_t>::max();
if (groupNum != std::numeric_limits<uint32_t>::max()) {
emit groupJoined(groupNum, getGroupPersistentId(groupNum));
}
return groupNum;
}
void Core::groupInviteFriend(uint32_t friendId, int groupId)

View File

@ -81,7 +81,7 @@ public:
static QStringList splitMessage(const QString& message, int maxLen);
QString getPeerName(const ToxPk& id) const;
QVector<uint32_t> getFriendList() const;
GroupId getGroupPersistentId(uint32_t groupNumber);
GroupId getGroupPersistentId(uint32_t groupNumber) const;
uint32_t getGroupNumberPeers(int groupId) const;
QString getGroupPeerName(int groupId, int peerId) const;
ToxPk getGroupPeerPk(int groupId, int peerId) const;
@ -92,7 +92,7 @@ public:
bool isFriendOnline(uint32_t friendId) const;
bool hasFriendWithPublicKey(const ToxPk& publicKey) const;
uint32_t joinGroupchat(const GroupInvite& inviteInfo) const;
uint32_t joinGroupchat(const GroupInvite& inviteInfo);
void quitGroupChat(int groupId) const;
QString getUsername() const;
@ -181,6 +181,7 @@ signals:
void groupTitleChanged(int groupnumber, const QString& author, const QString& title);
void groupPeerAudioPlaying(int groupnumber, ToxPk peerPk);
void groupSentFailed(int groupId);
void groupJoined(int groupnumber, GroupId groupId);
void actionSentResult(uint32_t friendId, const QString& action, int success);
void receiptRecieved(int friedId, ReceiptNum receipt);

View File

@ -214,6 +214,7 @@ void Nexus::showMainGUI()
connect(core, &Core::groupTitleChanged, widget, &Widget::onGroupTitleChanged);
connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying);
connect(core, &Core::emptyGroupCreated, widget, &Widget::onEmptyGroupCreated);
connect(core, &Core::groupJoined, widget, &Widget::onGroupJoined);
connect(core, &Core::friendTypingChanged, widget, &Widget::onFriendTypingChanged);
connect(core, &Core::groupSentFailed, widget, &Widget::onGroupSendFailed);
connect(core, &Core::usernameSet, widget, &Widget::refreshPeerListsLocal);

View File

@ -1901,6 +1901,11 @@ void Widget::onEmptyGroupCreated(int groupId, const GroupId& groupPersistentId,
}
}
void Widget::onGroupJoined(int groupId, const GroupId& groupPersistentId)
{
createGroup(groupId, groupPersistentId);
}
/**
* @brief Used to reset the blinking icon.
*/

View File

@ -170,7 +170,8 @@ public slots:
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
void onFriendRequestReceived(const ToxPk& friendPk, const QString& message);
void updateFriendActivity(const Friend* frnd);
void onEmptyGroupCreated(int groupId, const GroupId& groupPersistentId, const QString& title);
void onEmptyGroupCreated(int groupNum, const GroupId& groupId, const QString& title);
void onGroupJoined(int groupNum, const GroupId& groupId);
void onGroupInviteReceived(const GroupInvite& inviteInfo);
void onGroupInviteAccepted(const GroupInvite& inviteInfo);
void onGroupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction);