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

Commit

Permalink
fix(group): set default group chat title when provided title is invalid
Browse files Browse the repository at this point in the history
Add handling logic for when a group exists but has an invalid title.
Title is created using the first 8 hexadecimals of the group chat id.
  • Loading branch information
Kribylet committed Jun 14, 2019
1 parent 6523ecc commit f77a062
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,26 +1026,37 @@ void Core::loadGroups()
return;
}

uint32_t* groupIds = new uint32_t[groupCount];
tox_conference_get_chatlist(tox.get(), groupIds);
auto groupNumbers = new uint32_t[groupCount];
tox_conference_get_chatlist(tox.get(), groupNumbers);

for(size_t i = 0; i < groupCount; ++i) {
TOX_ERR_CONFERENCE_TITLE error;
const auto groupId = static_cast<int>(groupIds[i]);
size_t titleSize = tox_conference_get_title_size(tox.get(), groupId, &error);
if (LogConferenceTitleError(error)) {
continue;
QByteArray nameByteArray;
QString name;
bool invalidTitle;
const auto groupNumber = groupNumbers[i];
size_t titleSize = tox_conference_get_title_size(tox.get(), groupNumber, &error);
invalidTitle = LogConferenceTitleError(error);
if (!invalidTitle)
{
nameByteArray = QByteArray(static_cast<int>(titleSize), Qt::Uninitialized);
tox_conference_get_title(tox.get(), groupNumber, reinterpret_cast<uint8_t*>(nameByteArray.data()), &error);
invalidTitle = LogConferenceTitleError(error);
}

QByteArray name(titleSize, Qt::Uninitialized);
if (!tox_conference_get_title(tox.get(), groupId, reinterpret_cast<uint8_t*>(name.data()), &error))
if (LogConferenceTitleError(error)) {
if (error == TOX_ERR_CONFERENCE_TITLE_CONFERENCE_NOT_FOUND)
continue;

if (invalidTitle)
{
name = tr("Groupchat %1").arg(getGroupPersistentId(groupNumber).toString().left(8));
} else {
name = ToxString(nameByteArray).getQString();
}
emit emptyGroupCreated(groupId, getGroupPersistentId(groupId), ToxString(name).getQString());

emit emptyGroupCreated(groupNumber, getGroupPersistentId(groupNumber), name);
}

delete[] groupIds;
delete[] groupNumbers;
}

void Core::checkLastOnline(uint32_t friendId)
Expand Down

0 comments on commit f77a062

Please sign in to comment.