fill in the friends section in tox interface

This commit is contained in:
Green Sky 2023-04-18 17:32:16 +02:00
parent e1a15aca1b
commit 2a63dcd3f6
No known key found for this signature in database
3 changed files with 126 additions and 10 deletions

View File

@ -1,4 +1,5 @@
#include "./tox_default_impl.hpp"
#include "tox/tox.h"
#include <optional>
Tox_Connection ToxDefaultImpl::toxSelfGetConnectionStatus(void) {
@ -93,17 +94,110 @@ Tox_Err_Friend_Delete ToxDefaultImpl::toxFriendDelete(uint32_t friend_number) {
return err;
}
std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_Friend_Get_Public_Key> ToxDefaultImpl::toxFriendGetPublicKey(uint32_t friend_number) {
std::tuple<std::optional<uint32_t>, Tox_Err_Friend_By_Public_Key> ToxDefaultImpl::toxFriendByPublicKey(const std::vector<uint8_t>& public_key) {
// TODO: check size
Tox_Err_Friend_By_Public_Key err = TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK;
auto res = tox_friend_by_public_key(_tox, public_key.data(), &err);
if (err == TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK) {
return {res, err};
} else {
return {std::nullopt, err};
}
}
bool ToxDefaultImpl::toxFriendExists(uint32_t friend_number) {
return tox_friend_exists(_tox, friend_number);
}
std::optional<std::vector<uint8_t>> ToxDefaultImpl::toxFriendGetPublicKey(uint32_t friend_number) {
std::vector<uint8_t> pub(TOX_PUBLIC_KEY_SIZE);
Tox_Err_Friend_Get_Public_Key err = TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK;
tox_friend_get_public_key(_tox, friend_number, pub.data(), &err);
if (err == TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK) {
return {pub, err};
return pub;
} else {
return {std::nullopt, err};
return std::nullopt;
}
}
std::optional<uint64_t> ToxDefaultImpl::toxFriendGetLastOnline(uint32_t friend_number) {
Tox_Err_Friend_Get_Last_Online err = TOX_ERR_FRIEND_GET_LAST_ONLINE_OK;
auto res = tox_friend_get_last_online(_tox, friend_number, &err);
if (res == TOX_ERR_FRIEND_GET_LAST_ONLINE_OK) {
return res;
} else {
return std::nullopt;
}
}
std::optional<std::string> ToxDefaultImpl::toxFriendGetName(uint32_t friend_number) {
std::string name;
Tox_Err_Friend_Query err = TOX_ERR_FRIEND_QUERY_OK;
const auto size = tox_friend_get_name_size(_tox, friend_number, &err);
if (err != TOX_ERR_FRIEND_QUERY_OK) {
return std::nullopt;
}
name.resize(size);
tox_friend_get_name(_tox, friend_number, reinterpret_cast<uint8_t*>(name.data()), &err);
if (err == TOX_ERR_FRIEND_QUERY_OK) {
return name;
} else {
return std::nullopt;
}
}
std::optional<std::string> ToxDefaultImpl::toxFriendGetStatusMessage(uint32_t friend_number) {
std::string status;
Tox_Err_Friend_Query err = TOX_ERR_FRIEND_QUERY_OK;
const auto size = tox_friend_get_status_message_size(_tox, friend_number, &err);
if (err != TOX_ERR_FRIEND_QUERY_OK) {
return std::nullopt;
}
status.resize(size);
tox_friend_get_status_message(_tox, friend_number, reinterpret_cast<uint8_t*>(status.data()), &err);
if (err == TOX_ERR_FRIEND_QUERY_OK) {
return status;
} else {
return std::nullopt;
}
}
std::optional<Tox_User_Status> ToxDefaultImpl::toxFriendGetStatus(uint32_t friend_number) {
Tox_Err_Friend_Query err = TOX_ERR_FRIEND_QUERY_OK;
auto res = tox_friend_get_status(_tox, friend_number, &err);
if (err == TOX_ERR_FRIEND_QUERY_OK) {
return res;
} else {
return std::nullopt;
}
}
std::optional<Tox_Connection> ToxDefaultImpl::toxFriendGetConnectionStatus(uint32_t friend_number) {
Tox_Err_Friend_Query err = TOX_ERR_FRIEND_QUERY_OK;
auto res = tox_friend_get_connection_status(_tox, friend_number, &err);
if (err == TOX_ERR_FRIEND_QUERY_OK) {
return res;
} else {
return std::nullopt;
}
}
std::optional<bool> ToxDefaultImpl::toxFriendGetTyping(uint32_t friend_number) {
Tox_Err_Friend_Query err = TOX_ERR_FRIEND_QUERY_OK;
auto res = tox_friend_get_typing(_tox, friend_number, &err);
if (err == TOX_ERR_FRIEND_QUERY_OK) {
return res;
} else {
return std::nullopt;
}
}
Tox_Err_Set_Typing ToxDefaultImpl::toxSelfSetTyping(uint32_t friend_number, bool typing) {
Tox_Err_Set_Typing err = TOX_ERR_SET_TYPING_OK;
tox_self_set_typing(_tox, friend_number, typing, &err);
return err;
}
std::tuple<std::optional<uint32_t>, Tox_Err_Friend_Send_Message> ToxDefaultImpl::toxFriendSendMessage(uint32_t friend_number, Tox_Message_Type type, std::string_view message) {
Tox_Err_Friend_Send_Message err = TOX_ERR_FRIEND_SEND_MESSAGE_OK;
auto res = tox_friend_send_message(_tox, friend_number, type, reinterpret_cast<const uint8_t*>(message.data()), message.size(), &err);

View File

@ -30,8 +30,16 @@ struct ToxDefaultImpl : public ToxI {
std::tuple<std::optional<uint32_t>, Tox_Err_Friend_Add> toxFriendAdd(const std::vector<uint8_t>& address, std::string_view message) override;
std::tuple<std::optional<uint32_t>, Tox_Err_Friend_Add> toxFriendAddNorequest(const std::vector<uint8_t>& public_key) override;
Tox_Err_Friend_Delete toxFriendDelete(uint32_t friend_number) override;
std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_Friend_Get_Public_Key> toxFriendGetPublicKey(uint32_t friend_number) override;
std::tuple<std::optional<uint32_t>, Tox_Err_Friend_By_Public_Key> toxFriendByPublicKey(const std::vector<uint8_t>& public_key) override;
bool toxFriendExists(uint32_t friend_number) override;
std::optional<std::vector<uint8_t>> toxFriendGetPublicKey(uint32_t friend_number) override;
std::optional<uint64_t> toxFriendGetLastOnline(uint32_t friend_number) override;
std::optional<std::string> toxFriendGetName(uint32_t friend_number) override;
std::optional<std::string> toxFriendGetStatusMessage(uint32_t friend_number) override;
std::optional<Tox_User_Status> toxFriendGetStatus(uint32_t friend_number) override;
std::optional<Tox_Connection> toxFriendGetConnectionStatus(uint32_t friend_number) override;
std::optional<bool> toxFriendGetTyping(uint32_t friend_number) override;
Tox_Err_Set_Typing toxSelfSetTyping(uint32_t friend_number, bool typing) override;
std::tuple<std::optional<uint32_t>, Tox_Err_Friend_Send_Message> toxFriendSendMessage(uint32_t friend_number, Tox_Message_Type type, std::string_view message) override;
// files

View File

@ -15,6 +15,13 @@
struct ToxI_raw {
virtual ~ToxI_raw(void) {}
// TODO: tox version
// size stuff
// options? (no)
// get save data?
// bootstrap
// add tcp relay
virtual Tox_Connection toxSelfGetConnectionStatus(void) = 0;
virtual uint32_t toxIterationInterval(void) = 0;
@ -39,15 +46,22 @@ struct ToxI_raw {
virtual std::tuple<std::optional<uint32_t>, Tox_Err_Friend_Add> toxFriendAdd(const std::vector<uint8_t>& address, std::string_view message) = 0;
virtual std::tuple<std::optional<uint32_t>, Tox_Err_Friend_Add> toxFriendAddNorequest(const std::vector<uint8_t>& public_key) = 0;
virtual Tox_Err_Friend_Delete toxFriendDelete(uint32_t friend_number) = 0;
virtual std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_Friend_Get_Public_Key> toxFriendGetPublicKey(uint32_t friend_number) = 0;
virtual std::tuple<std::optional<uint32_t>, Tox_Err_Friend_By_Public_Key> toxFriendByPublicKey(const std::vector<uint8_t>& public_key) = 0;
virtual bool toxFriendExists(uint32_t friend_number) = 0;
// tox_self_get_friend_list
virtual std::optional<std::vector<uint8_t>> toxFriendGetPublicKey(uint32_t friend_number) = 0;
virtual std::optional<uint64_t> toxFriendGetLastOnline(uint32_t friend_number) = 0;
virtual std::optional<std::string> toxFriendGetName(uint32_t friend_number) = 0;
virtual std::optional<std::string> toxFriendGetStatusMessage(uint32_t friend_number) = 0;
virtual std::optional<Tox_User_Status> toxFriendGetStatus(uint32_t friend_number) = 0;
virtual std::optional<Tox_Connection> toxFriendGetConnectionStatus(uint32_t friend_number) = 0;
virtual std::optional<bool> toxFriendGetTyping(uint32_t friend_number) = 0;
virtual Tox_Err_Set_Typing toxSelfSetTyping(uint32_t friend_number, bool typing) = 0;
virtual std::tuple<std::optional<uint32_t>, Tox_Err_Friend_Send_Message> toxFriendSendMessage(uint32_t friend_number, Tox_Message_Type type, std::string_view message) = 0;
// files
// TODO: array? make it type agnostic?
virtual std::vector<uint8_t> toxHash(const std::vector<uint8_t>& data);
// files
virtual Tox_Err_File_Control toxFileControl(uint32_t friend_number, uint32_t file_number, Tox_File_Control control) = 0;
virtual Tox_Err_File_Seek toxFileSeek(uint32_t friend_number, uint32_t file_number, uint64_t position) = 0;
virtual std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_File_Get> toxFileGetFileID(uint32_t friend_number, uint32_t file_number) = 0;