/** * @brief Returns the list of friendIds in our friendlist, an empty list on error */ QVector<uint32_t> Core::getFriendList() const { QVector<uint32_t> friends; friends.resize(tox_self_get_friend_list_size(tox)); tox_self_get_friend_list(tox, friends.data()); return friends; }
void friend_cleanup(Tox *tox) { uint32_t friend_count = tox_self_get_friend_list_size(tox); if (friend_count == 0) { return; } uint32_t friends[friend_count]; tox_self_get_friend_list(tox, friends); uint64_t curr_time = time(NULL); for (uint32_t i = 0; i < friend_count; i++) { TOX_ERR_FRIEND_GET_LAST_ONLINE err; uint32_t friend = friends[i]; uint64_t last_online = tox_friend_get_last_online(tox, friend, &err); if (err != TOX_ERR_FRIEND_GET_LAST_ONLINE_OK) { printf("couldn't obtain 'last online', this should never happen\n"); continue; } if (curr_time - last_online > 2629743) { printf("removing friend %d\n", friend); tox_friend_delete(tox, friend, NULL); } }
/** * @brief Checks if we have a friend by public key */ bool Core::hasFriendWithPublicKey(const QString &pubkey) const { // Valid length check if (pubkey.length() != (TOX_PUBLIC_KEY_SIZE * 2)) return false; bool found = false; const size_t friendCount = tox_self_get_friend_list_size(tox); if (friendCount > 0) { uint32_t *ids = new uint32_t[friendCount]; tox_self_get_friend_list(tox, ids); for (int32_t i = 0; i < static_cast<int32_t>(friendCount); ++i) { // getFriendAddress may return either id (public key) or address QString addrOrId = getFriendAddress(ids[i]); // Set true if found if (addrOrId.toUpper().startsWith(pubkey.toUpper())) { found = true; break; } } delete[] ids; } return found; }
static void purge_inactive_friends(Tox *m) { size_t numfriends = tox_self_get_friend_list_size(m); if (numfriends == 0) return; uint32_t friend_list[numfriends]; tox_self_get_friend_list(m, friend_list); size_t i; for (i = 0; i < numfriends; ++i) { uint32_t friendnum = friend_list[i]; if (!tox_friend_exists(m, friendnum)) continue; TOX_ERR_FRIEND_GET_LAST_ONLINE err; uint64_t last_online = tox_friend_get_last_online(m, friendnum, &err); if (err != TOX_ERR_FRIEND_GET_LAST_ONLINE_OK) continue; if (((uint64_t) time(NULL)) - last_online > Tox_Bot.inactive_limit) tox_friend_delete(m, friendnum, NULL); } }
int utox_avatar_update_friends(Tox *tox){ uint32_t i, friend_count, error_count = 0; friend_count = tox_self_get_friend_list_size(tox); uint32_t friend_loop[friend_count]; tox_self_get_friend_list(tox, friend_loop); for(i = 0; i < friend_count; i++){ if (tox_friend_get_connection_status(tox, friend_loop[i], 0)) { error_count += !avatar_on_friend_online(tox, friend_loop[i]); } } return error_count; }
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 clientId[TOX_PUBLIC_KEY_SIZE]; for (int32_t i = 0; i < static_cast<int32_t>(friendCount); ++i) { if (tox_friend_get_public_key(tox, ids[i], clientId, nullptr)) { emit friendAdded(ids[i], CUserId::toString(clientId)); 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; } }
static void cb_friend_connection_change(Tox *m, uint32_t friendnumber, TOX_CONNECTION connection_status, void *userdata) { /* Count the number of online friends. * * We have to do this the hard way because our convenient API function to get * the number of online friends has mysteriously vanished */ Tox_Bot.num_online_friends = 0; size_t i, size = tox_self_get_friend_list_size(m); if (size == 0) return; uint32_t list[size]; tox_self_get_friend_list(m, list); for (i = 0; i < size; ++i) { if (tox_friend_get_connection_status(m, list[i], NULL) != TOX_CONNECTION_NONE) ++Tox_Bot.num_online_friends; } }
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; }