Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(core): save tox profile when updating group or friend states
Browse files Browse the repository at this point in the history
Makes sure persistent groups are stored in the case of a qTox crash.
  • Loading branch information
anthonybilinski committed Sep 16, 2019
1 parent f7a2a7d commit 3d7a872
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ void Core::onFriendMessage(Tox*, uint32_t friendId, Tox_Message_Type type, const
void Core::onFriendNameChange(Tox*, uint32_t friendId, const uint8_t* cName, size_t cNameSize, void* core)
{
QString newName = ToxString(cName, cNameSize).getQString();
// no saveRequest, this callback is called on every connection, not just on name change
emit static_cast<Core*>(core)->friendUsernameChanged(friendId, newName);
}

Expand All @@ -500,6 +501,7 @@ void Core::onStatusMessageChanged(Tox*, uint32_t friendId, const uint8_t* cMessa
size_t cMessageSize, void* core)
{
QString message = ToxString(cMessage, cMessageSize).getQString();
// no saveRequest, this callback is called on every connection, not just on name change
emit static_cast<Core*>(core)->friendStatusMessageChanged(friendId, message);
}

Expand All @@ -520,6 +522,7 @@ void Core::onUserStatusChanged(Tox*, uint32_t friendId, Tox_User_Status userstat
break;
}

// no saveRequest, this callback is called on every connection, not just on name change
emit static_cast<Core*>(core)->friendStatusChanged(friendId, status);
}

Expand Down Expand Up @@ -571,6 +574,7 @@ void Core::onGroupPeerListChange(Tox*, uint32_t groupId, void* vCore)
{
const auto core = static_cast<Core*>(vCore);
qDebug() << QString("Group %1 peerlist changed").arg(groupId);
// no saveRequest, this callback is called on every connection to group peer, not just on brand new peers
emit core->groupPeerlistChanged(groupId);
}

Expand All @@ -589,6 +593,7 @@ void Core::onGroupTitleChange(Tox*, uint32_t groupId, uint32_t peerId, const uin
{
Core* core = static_cast<Core*>(vCore);
QString author = core->getGroupPeerName(groupId, peerId);
emit core->saveRequest();
emit core->groupTitleChanged(groupId, author, ToxString(cTitle, length).getQString());
}

Expand Down Expand Up @@ -752,6 +757,7 @@ void Core::changeGroupTitle(int groupId, const QString& title)
Tox_Err_Conference_Title error;
bool success = tox_conference_set_title(tox.get(), groupId, cTitle.data(), cTitle.size(), &error);
if (success && error == TOX_ERR_CONFERENCE_TITLE_OK) {
emit saveRequest();
emit groupTitleChanged(groupId, getUsername(), title);
return;
}
Expand Down Expand Up @@ -795,6 +801,7 @@ void Core::removeGroup(int groupId)
Tox_Err_Conference_Delete error;
bool success = tox_conference_delete(tox.get(), groupId, &error);
if (success && error == TOX_ERR_CONFERENCE_DELETE_OK) {
emit saveRequest();
av->leaveGroupCall(groupId);
return;
}
Expand Down Expand Up @@ -1323,6 +1330,7 @@ uint32_t Core::joinGroupchat(const GroupInvite& inviteInfo)
qWarning() << "joinGroupchat: Unknown groupchat type " << confType;
}
if (groupNum != std::numeric_limits<uint32_t>::max()) {
emit saveRequest();
emit groupJoined(groupNum, getGroupPersistentId(groupNum));
}
return groupNum;
Expand Down Expand Up @@ -1362,6 +1370,7 @@ int Core::createGroup(uint8_t type)

switch (error) {
case TOX_ERR_CONFERENCE_NEW_OK:
emit saveRequest();
emit emptyGroupCreated(groupId, getGroupPersistentId(groupId));
return groupId;

Expand All @@ -1374,6 +1383,7 @@ int Core::createGroup(uint8_t type)
}
} else if (type == TOX_CONFERENCE_TYPE_AV) {
uint32_t groupId = toxav_add_av_groupchat(tox.get(), CoreAV::groupCallCallback, this);
emit saveRequest();
emit emptyGroupCreated(groupId, getGroupPersistentId(groupId));
return groupId;
} else {
Expand Down

0 comments on commit 3d7a872

Please sign in to comment.