mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(group): set default group chat title when provided title is invalid
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.
This commit is contained in:
parent
6523ecc511
commit
f77a062120
|
@ -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)) {
|
||||
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);
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
QByteArray name(titleSize, Qt::Uninitialized);
|
||||
if (!tox_conference_get_title(tox.get(), groupId, reinterpret_cast<uint8_t*>(name.data()), &error))
|
||||
if (LogConferenceTitleError(error)) {
|
||||
continue;
|
||||
}
|
||||
emit emptyGroupCreated(groupId, getGroupPersistentId(groupId), ToxString(name).getQString());
|
||||
emit emptyGroupCreated(groupNumber, getGroupPersistentId(groupNumber), name);
|
||||
}
|
||||
|
||||
delete[] groupIds;
|
||||
delete[] groupNumbers;
|
||||
}
|
||||
|
||||
void Core::checkLastOnline(uint32_t friendId)
|
||||
|
|
Loading…
Reference in New Issue
Block a user