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

Merge pull request #5695

jenli669 (2):
      fix(group): set default group chat title when provided title is invalid
      fix(group): Condense invalid title handling logic, clang-format
This commit is contained in:
sudden6 2019-06-18 21:32:14 +02:00
commit 63e903f950
No known key found for this signature in database
GPG Key ID: 279509B499E032B9

View File

@ -28,8 +28,8 @@
#include "src/core/toxstring.h" #include "src/core/toxstring.h"
#include "src/model/groupinvite.h" #include "src/model/groupinvite.h"
#include "src/model/status.h" #include "src/model/status.h"
#include "src/nexus.h"
#include "src/net/bootstrapnodeupdater.h" #include "src/net/bootstrapnodeupdater.h"
#include "src/nexus.h"
#include "src/persistence/profile.h" #include "src/persistence/profile.h"
#include "src/util/strongtype.h" #include "src/util/strongtype.h"
@ -51,8 +51,7 @@ const QString Core::TOX_EXT = ".tox";
namespace { namespace {
bool LogConferenceTitleError(TOX_ERR_CONFERENCE_TITLE error) bool LogConferenceTitleError(TOX_ERR_CONFERENCE_TITLE error)
{ {
switch(error) switch (error) {
{
case TOX_ERR_CONFERENCE_TITLE_OK: case TOX_ERR_CONFERENCE_TITLE_OK:
break; break;
case TOX_ERR_CONFERENCE_TITLE_CONFERENCE_NOT_FOUND: case TOX_ERR_CONFERENCE_TITLE_CONFERENCE_NOT_FOUND:
@ -529,7 +528,8 @@ void Core::onUserStatusChanged(Tox*, uint32_t friendId, Tox_User_Status userstat
void Core::onConnectionStatusChanged(Tox*, uint32_t friendId, Tox_Connection status, void* vCore) void Core::onConnectionStatusChanged(Tox*, uint32_t friendId, Tox_Connection status, void* vCore)
{ {
Core* core = static_cast<Core*>(vCore); Core* core = static_cast<Core*>(vCore);
Status::Status friendStatus = status != TOX_CONNECTION_NONE ? Status::Status::Online : Status::Status::Offline; Status::Status friendStatus =
status != TOX_CONNECTION_NONE ? Status::Status::Online : Status::Status::Offline;
// Ignore Online because it will be emited from onUserStatusChanged // Ignore Online because it will be emited from onUserStatusChanged
bool isOffline = friendStatus == Status::Status::Offline; bool isOffline = friendStatus == Status::Status::Offline;
if (isOffline) { if (isOffline) {
@ -669,19 +669,21 @@ void Core::requestFriendship(const ToxId& friendId, const QString& message)
emit saveRequest(); emit saveRequest();
} }
bool Core::sendMessageWithType(uint32_t friendId, const QString& message, Tox_Message_Type type, ReceiptNum& receipt) bool Core::sendMessageWithType(uint32_t friendId, const QString& message, Tox_Message_Type type,
ReceiptNum& receipt)
{ {
int size = message.toUtf8().size(); int size = message.toUtf8().size();
auto maxSize = tox_max_message_length(); auto maxSize = tox_max_message_length();
if (size > maxSize) { if (size > maxSize) {
qCritical() << "Core::sendMessageWithType called with message of size:" << size << "when max is:" << maxSize <<". Ignoring."; qCritical() << "Core::sendMessageWithType called with message of size:" << size
<< "when max is:" << maxSize << ". Ignoring.";
return false; return false;
} }
ToxString cMessage(message); ToxString cMessage(message);
Tox_Err_Friend_Send_Message error; Tox_Err_Friend_Send_Message error;
receipt = ReceiptNum{tox_friend_send_message(tox.get(), friendId, type, receipt = ReceiptNum{tox_friend_send_message(tox.get(), friendId, type, cMessage.data(),
cMessage.data(), cMessage.size(), &error)}; cMessage.size(), &error)};
if (parseFriendSendMessageError(error)) { if (parseFriendSendMessageError(error)) {
return true; return true;
} }
@ -1026,26 +1028,27 @@ void Core::loadGroups()
return; return;
} }
uint32_t* groupIds = new uint32_t[groupCount]; auto groupNumbers = new uint32_t[groupCount];
tox_conference_get_chatlist(tox.get(), groupIds); tox_conference_get_chatlist(tox.get(), groupNumbers);
for (size_t i = 0; i < groupCount; ++i) { for (size_t i = 0; i < groupCount; ++i) {
TOX_ERR_CONFERENCE_TITLE error; TOX_ERR_CONFERENCE_TITLE error;
const auto groupId = static_cast<int>(groupIds[i]); QString name;
size_t titleSize = tox_conference_get_title_size(tox.get(), groupId, &error); const auto groupNumber = groupNumbers[i];
size_t titleSize = tox_conference_get_title_size(tox.get(), groupNumber, &error);
if (LogConferenceTitleError(error)) { if (LogConferenceTitleError(error)) {
continue; name = tr("Groupchat %1").arg(getGroupPersistentId(groupNumber).toString().left(8));
} else {
QByteArray nameByteArray = QByteArray(static_cast<int>(titleSize), Qt::Uninitialized);
tox_conference_get_title(tox.get(), groupNumber,
reinterpret_cast<uint8_t*>(nameByteArray.data()), &error);
name = ToxString(nameByteArray).getQString();
} }
QByteArray name(titleSize, Qt::Uninitialized); emit emptyGroupCreated(groupNumber, getGroupPersistentId(groupNumber), name);
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());
} }
delete[] groupIds; delete[] groupNumbers;
} }
void Core::checkLastOnline(uint32_t friendId) void Core::checkLastOnline(uint32_t friendId)
@ -1106,7 +1109,8 @@ GroupId Core::getGroupPersistentId(uint32_t groupNumber) const
size_t conferenceIdSize = TOX_CONFERENCE_UID_SIZE; size_t conferenceIdSize = TOX_CONFERENCE_UID_SIZE;
QByteArray groupPersistentId(conferenceIdSize, Qt::Uninitialized); QByteArray groupPersistentId(conferenceIdSize, Qt::Uninitialized);
if (tox_conference_get_id(tox.get(), groupNumber, reinterpret_cast<uint8_t*>(groupPersistentId.data()))) { if (tox_conference_get_id(tox.get(), groupNumber,
reinterpret_cast<uint8_t*>(groupPersistentId.data()))) {
return GroupId{groupPersistentId}; return GroupId{groupPersistentId};
} else { } else {
qCritical() << "Failed to get conference ID of group" << groupNumber; qCritical() << "Failed to get conference ID of group" << groupNumber;