/** * @brief Get the public key part of the ToxID only */ ToxPk Core::getFriendPublicKey(uint32_t friendNumber) const { uint8_t rawid[TOX_PUBLIC_KEY_SIZE]; if (!tox_friend_get_public_key(tox, friendNumber, rawid, nullptr)) { qWarning() << "getFriendPublicKey: Getting public key failed"; return ToxPk(); } return ToxPk(rawid); }
/** * @brief Get the public key of a peer of a group */ ToxPk Core::getGroupPeerPk(int groupId, int peerId) const { uint8_t friendPk[TOX_PUBLIC_KEY_SIZE] = {0x00}; TOX_ERR_CONFERENCE_PEER_QUERY error; bool success = tox_conference_peer_get_public_key(tox, groupId, peerId, friendPk, &error); if (!parsePeerQueryError(error) || !success) { qWarning() << "getGroupPeerToxId: Unknown error"; return ToxPk(); } return ToxPk(friendPk); }
void Core::loadFriends() { const uint32_t friendCount = tox_self_get_friend_list_size(tox); if (friendCount > 0) { // assuming there are not that many friends to fill up the whole stack uint32_t *ids = new uint32_t[friendCount]; tox_self_get_friend_list(tox, ids); uint8_t friendPk[TOX_PUBLIC_KEY_SIZE] = {0x00}; for (int32_t i = 0; i < static_cast<int32_t>(friendCount); ++i) { if (tox_friend_get_public_key(tox, ids[i], friendPk, nullptr)) { emit friendAdded(ids[i], ToxPk(friendPk)); const size_t nameSize = tox_friend_get_name_size(tox, ids[i], nullptr); if (nameSize && nameSize != SIZE_MAX) { uint8_t* name = new uint8_t[nameSize]; if (tox_friend_get_name(tox, ids[i], name, nullptr)) emit friendUsernameChanged(ids[i], CString::toString(name, nameSize)); delete[] name; } const size_t statusMessageSize = tox_friend_get_status_message_size(tox, ids[i], nullptr); if (statusMessageSize != SIZE_MAX) { uint8_t* statusMessage = new uint8_t[statusMessageSize]; if (tox_friend_get_status_message(tox, ids[i], statusMessage, nullptr)) { emit friendStatusMessageChanged(ids[i], CString::toString(statusMessage, statusMessageSize)); } delete[] statusMessage; } checkLastOnline(ids[i]); } } delete[] ids; } }
void Core::loadFriends() { const uint32_t friendCount = tox_self_get_friend_list_size(tox); if (friendCount <= 0) { return; } // assuming there are not that many friends to fill up the whole stack uint32_t* ids = new uint32_t[friendCount]; tox_self_get_friend_list(tox, ids); uint8_t friendPk[TOX_PUBLIC_KEY_SIZE] = {0x00}; for (uint32_t i = 0; i < friendCount; ++i) { if (!tox_friend_get_public_key(tox, ids[i], friendPk, nullptr)) { continue; } emit friendAdded(ids[i], ToxPk(friendPk)); GET_FRIEND_PROPERTY(Username, tox_friend_get_name, true); GET_FRIEND_PROPERTY(StatusMessage, tox_friend_get_status_message, false); checkLastOnline(ids[i]); } delete[] ids; }
/** * @brief Gets the Public Key part of the ToxID * @return Public Key of the ToxID */ ToxPk ToxId::getPublicKey() const { return ToxPk(toxId.mid(0, TOX_PUBLIC_KEY_SIZE)); }
/** * @brief Gets self public key * @return Self PK */ ToxPk Core::getSelfPublicKey() const { uint8_t friendId[TOX_ADDRESS_SIZE] = {0x00}; tox_self_get_address(tox, friendId); return ToxPk(friendId); }