mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(core): remove duplicate code and checks
This commit is contained in:
parent
b033b5095b
commit
f03262e98b
|
@ -912,9 +912,7 @@ QPair<QByteArray, QByteArray> Core::getKeypair() const
|
||||||
QMutexLocker ml{&coreLoopLock};
|
QMutexLocker ml{&coreLoopLock};
|
||||||
|
|
||||||
QPair<QByteArray, QByteArray> keypair;
|
QPair<QByteArray, QByteArray> keypair;
|
||||||
if (!tox) {
|
assert(tox != nullptr);
|
||||||
return keypair;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray pk(TOX_PUBLIC_KEY_SIZE, 0x00);
|
QByteArray pk(TOX_PUBLIC_KEY_SIZE, 0x00);
|
||||||
QByteArray sk(TOX_SECRET_KEY_SIZE, 0x00);
|
QByteArray sk(TOX_SECRET_KEY_SIZE, 0x00);
|
||||||
|
@ -932,15 +930,15 @@ QString Core::getStatusMessage() const
|
||||||
{
|
{
|
||||||
QMutexLocker ml{&coreLoopLock};
|
QMutexLocker ml{&coreLoopLock};
|
||||||
|
|
||||||
QString sname;
|
assert(tox != nullptr);
|
||||||
if (!tox) {
|
|
||||||
return sname;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = tox_self_get_status_message_size(tox.get());
|
size_t size = tox_self_get_status_message_size(tox.get());
|
||||||
|
if (size == 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
uint8_t* name = new uint8_t[size];
|
uint8_t* name = new uint8_t[size];
|
||||||
tox_self_get_status_message(tox.get(), name);
|
tox_self_get_status_message(tox.get(), name);
|
||||||
sname = ToxString(name, size).getQString();
|
QString sname = ToxString(name, size).getQString();
|
||||||
delete[] name;
|
delete[] name;
|
||||||
return sname;
|
return sname;
|
||||||
}
|
}
|
||||||
|
@ -1201,10 +1199,7 @@ QStringList Core::getGroupPeerNames(int groupId) const
|
||||||
{
|
{
|
||||||
QMutexLocker ml{&coreLoopLock};
|
QMutexLocker ml{&coreLoopLock};
|
||||||
|
|
||||||
if (!tox) {
|
assert(tox != nullptr);
|
||||||
qWarning() << "Can't get group peer names, tox is null";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t nPeers = getGroupNumberPeers(groupId);
|
uint32_t nPeers = getGroupNumberPeers(groupId);
|
||||||
if (nPeers == std::numeric_limits<uint32_t>::max()) {
|
if (nPeers == std::numeric_limits<uint32_t>::max()) {
|
||||||
|
@ -1212,19 +1207,9 @@ QStringList Core::getGroupPeerNames(int groupId) const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Tox_Err_Conference_Peer_Query error;
|
|
||||||
uint32_t count = tox_conference_peer_count(tox.get(), groupId, &error);
|
|
||||||
if (!parsePeerQueryError(error)) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count != nPeers) {
|
|
||||||
qWarning() << "getGroupPeerNames: Unexpected peer count";
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList names;
|
QStringList names;
|
||||||
for (uint32_t i = 0; i < nPeers; ++i) {
|
for (uint32_t i = 0; i < nPeers; ++i) {
|
||||||
|
TOX_ERR_CONFERENCE_PEER_QUERY error;
|
||||||
size_t length = tox_conference_peer_get_name_size(tox.get(), groupId, i, &error);
|
size_t length = tox_conference_peer_get_name_size(tox.get(), groupId, i, &error);
|
||||||
if (!parsePeerQueryError(error)) {
|
if (!parsePeerQueryError(error)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1403,8 +1388,8 @@ bool Core::isFriendOnline(uint32_t friendId) const
|
||||||
{
|
{
|
||||||
QMutexLocker ml{&coreLoopLock};
|
QMutexLocker ml{&coreLoopLock};
|
||||||
|
|
||||||
Tox_Connection connetion = tox_friend_get_connection_status(tox.get(), friendId, nullptr);
|
Tox_Connection connection = tox_friend_get_connection_status(tox.get(), friendId, nullptr);
|
||||||
return connetion != TOX_CONNECTION_NONE;
|
return connection != TOX_CONNECTION_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user