void Core::requestFriendship(const QString& friendAddress, const QString& message) { qDebug() << "Core: requesting friendship of "+friendAddress; CString cMessage(message); int friendId = tox_add_friend(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size()); const QString userId = friendAddress.mid(0, TOX_CLIENT_ID_SIZE * 2); if (friendId < 0) { emit failedToAddFriend(userId); } else { // Update our friendAddresses bool found=false; QList<QString>& friendAddresses = Settings::getInstance().friendAddresses; for (QString& addr : friendAddresses) { if (addr.toUpper().contains(friendAddress)) { addr = friendAddress; found = true; } } if (!found) friendAddresses.append(friendAddress); emit friendAdded(friendId, userId); } saveConfiguration(); }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { CString cMessage(message); int friendId = tox_addfriend(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size()); const QString userId = friendAddress.mid(0, TOX_CLIENT_ID_SIZE * 2); // TODO: better error handling if (friendId < 0) { emit failedToAddFriend(userId); } else { emit friendAdded(friendId, userId); } }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { qDebug() << "Core: requesting friendship of "+friendAddress; CString cMessage(message); int friendId = tox_add_friend(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size()); const QString userId = friendAddress.mid(0, TOX_CLIENT_ID_SIZE * 2); if (friendId < 0) { emit failedToAddFriend(userId); } else { emit friendAdded(friendId, userId); } saveConfiguration(); }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { const QString userId = friendAddress.mid(0, TOX_PUBLIC_KEY_SIZE * 2); if (message.isEmpty()) { emit failedToAddFriend(userId, tr("You need to write a message with your request")); } else if (message.size() > TOX_MAX_FRIEND_REQUEST_LENGTH) { emit failedToAddFriend(userId, tr("Your message is too long!")); } else if (hasFriendWithAddress(friendAddress)) { emit failedToAddFriend(userId, tr("Friend is already added")); } else { CString cMessage(message); uint32_t friendId = tox_friend_add(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size(), nullptr); if (friendId == std::numeric_limits<uint32_t>::max()) { qDebug() << "Failed to request friendship"; emit failedToAddFriend(userId); } else { qDebug() << "Requested friendship of "<<friendId; // Update our friendAddresses Settings::getInstance().updateFriendAddress(friendAddress); QString inviteStr = tr("/me offers friendship."); if (message.length()) inviteStr = tr("/me offers friendship, \"%1\"").arg(message); Profile* profile = Nexus::getProfile(); if (profile->isHistoryEnabled()) profile->getHistory()->addNewMessage(userId, inviteStr, getSelfId().publicKey, QDateTime::currentDateTime(), true, QString()); emit friendAdded(friendId, userId); emit friendshipChanged(friendId); } } profile.saveToxSave(); }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { const QString userId = friendAddress.mid(0, TOX_PUBLIC_KEY_SIZE * 2); if (message.isEmpty()) { emit failedToAddFriend(userId, tr("You need to write a message with your request")); } else if (message.size() > TOX_MAX_FRIEND_REQUEST_LENGTH) { emit failedToAddFriend(userId, tr("Your message is too long!")); } else if (hasFriendWithAddress(friendAddress)) { emit failedToAddFriend(userId, tr("Friend is already added")); } else { qDebug() << "Core: requesting friendship of "+friendAddress; CString cMessage(message); uint32_t friendId = tox_friend_add(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size(), nullptr); if (friendId == std::numeric_limits<uint32_t>::max()) { emit failedToAddFriend(userId); } else { // Update our friendAddresses Settings::getInstance().updateFriendAdress(friendAddress); QString inviteStr = tr("/me offers friendship."); if (message.length()) inviteStr = tr("/me offers friendship, \"%1\"").arg(message); HistoryKeeper::getInstance()->addChatEntry(userId, inviteStr, getSelfId().publicKey, QDateTime::currentDateTime(), true); emit friendAdded(friendId, userId); } } saveConfiguration(); }