add the conference api to the interface

This commit is contained in:
Green Sky 2024-05-24 00:05:04 +02:00
parent cf3679018b
commit 7cd6a2b0de
No known key found for this signature in database
5 changed files with 219 additions and 20 deletions

View File

@ -1,4 +1,5 @@
`plant !` `plant !`
### requires ngc events [rp](https://github.com/TokTok/c-toxcore/pull/2378) Toxcore interfaces for solanaceae.
Makes use of the events api

View File

@ -257,6 +257,72 @@ Tox_Err_File_Send_Chunk ToxDefaultImpl::toxFileSendChunk(uint32_t friend_number,
return err; return err;
} }
Tox_Err_Conference_Delete ToxDefaultImpl::toxConferenceDelete(uint32_t conference_number) {
Tox_Err_Conference_Delete err = TOX_ERR_CONFERENCE_DELETE_OK;
tox_conference_delete(_tox, conference_number, &err);
return err;
}
std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Peer_Query> ToxDefaultImpl::toxConferencePeerCount(uint32_t conference_number) {
Tox_Err_Conference_Peer_Query err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
const auto res = tox_conference_peer_count(_tox, conference_number, &err);
if (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
return {res, err};
} else {
return {std::nullopt, err};
}
}
std::tuple<std::optional<std::string>, Tox_Err_Conference_Peer_Query> ToxDefaultImpl::toxConferencePeerGetName(uint32_t conference_number, uint32_t peer_number) {
std::string name;
Tox_Err_Conference_Peer_Query err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
const auto size = tox_conference_peer_get_name_size(_tox, conference_number, peer_number, &err);
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
return {std::nullopt, err};
}
name.resize(size);
tox_conference_peer_get_name(_tox, conference_number, peer_number, reinterpret_cast<uint8_t*>(name.data()), &err);
if (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
return {name, err};
} else {
return {std::nullopt, err};
}
}
std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_Conference_Peer_Query> ToxDefaultImpl::toxConferencePeerGetPublicKey(uint32_t conference_number, uint32_t peer_number) {
std::vector<uint8_t> public_key(TOX_PUBLIC_KEY_SIZE);
Tox_Err_Conference_Peer_Query err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
tox_conference_peer_get_public_key(_tox, conference_number, peer_number, public_key.data(), &err);
if (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
return {public_key, err};
} else {
return {std::nullopt, err};
}
}
std::tuple<std::optional<bool>, Tox_Err_Conference_Peer_Query> ToxDefaultImpl::toxConferencePeerNumberIsOurs(uint32_t conference_number, uint32_t peer_number) {
Tox_Err_Conference_Peer_Query err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
const auto res = tox_conference_peer_number_is_ours(_tox, conference_number, peer_number, &err);
if (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
return {res, err};
} else {
return {std::nullopt, err};
}
}
Tox_Err_Conference_Set_Max_Offline ToxDefaultImpl::toxConferenceSetMaxOffline(uint32_t conference_number, uint32_t max_offline_peers) {
Tox_Err_Conference_Set_Max_Offline err = TOX_ERR_CONFERENCE_SET_MAX_OFFLINE_OK;
tox_conference_set_max_offline(_tox, conference_number, max_offline_peers, &err);
return err;
}
Tox_Err_Conference_Invite ToxDefaultImpl::toxConferenceInvite(uint32_t friend_number, uint32_t conference_number) {
Tox_Err_Conference_Invite err = TOX_ERR_CONFERENCE_INVITE_OK;
tox_conference_invite(_tox, friend_number, conference_number, &err);
return err;
}
std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Join> ToxDefaultImpl::toxConferenceJoin(uint32_t friend_number, const std::vector<uint8_t>& cookie) { std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Join> ToxDefaultImpl::toxConferenceJoin(uint32_t friend_number, const std::vector<uint8_t>& cookie) {
Tox_Err_Conference_Join err = TOX_ERR_CONFERENCE_JOIN_OK; Tox_Err_Conference_Join err = TOX_ERR_CONFERENCE_JOIN_OK;
auto res = tox_conference_join(_tox, friend_number, cookie.data(), cookie.size(), &err); auto res = tox_conference_join(_tox, friend_number, cookie.data(), cookie.size(), &err);
@ -273,6 +339,71 @@ Tox_Err_Conference_Send_Message ToxDefaultImpl::toxConferenceSendMessage(uint32_
return err; return err;
} }
std::tuple<std::optional<std::string>, Tox_Err_Conference_Title> ToxDefaultImpl::toxConferenceGetTitle(uint32_t conference_number) {
std::string title;
Tox_Err_Conference_Title err = TOX_ERR_CONFERENCE_TITLE_OK;
const auto size = tox_conference_get_title_size(_tox, conference_number, &err);
if (err != TOX_ERR_CONFERENCE_TITLE_OK) {
return {std::nullopt, err};
}
title.resize(size);
tox_conference_get_title(_tox, conference_number, reinterpret_cast<uint8_t*>(title.data()), &err);
if (err == TOX_ERR_CONFERENCE_TITLE_OK) {
return {title, err};
} else {
return {std::nullopt, err};
}
}
Tox_Err_Conference_Title ToxDefaultImpl::toxConferenceSetTitle(uint32_t conference_number, std::string_view title) {
Tox_Err_Conference_Title err = TOX_ERR_CONFERENCE_TITLE_OK;
tox_conference_set_title(_tox, conference_number, reinterpret_cast<const uint8_t*>(title.data()), title.size(), &err);
return err;
}
std::vector<uint32_t> ToxDefaultImpl::toxConferenceGetChatlist(void) {
std::vector<uint32_t> list;
const auto size = tox_conference_get_chatlist_size(_tox);
list.resize(size);
tox_conference_get_chatlist(_tox, list.data());
return list;
}
std::tuple<std::optional<Tox_Conference_Type>, Tox_Err_Conference_Get_Type> ToxDefaultImpl::toxConferenceGetType(uint32_t conference_number) {
Tox_Err_Conference_Get_Type err = TOX_ERR_CONFERENCE_GET_TYPE_OK;
const auto ret = tox_conference_get_type(_tox, conference_number, &err);
if (err == TOX_ERR_CONFERENCE_GET_TYPE_OK) {
return {ret, err};
} else {
return {std::nullopt, err};
}
}
std::optional<std::vector<uint8_t>> ToxDefaultImpl::toxConferenceGetID(uint32_t conference_number) {
std::vector<uint8_t> id(TOX_CONFERENCE_ID_SIZE);
const auto ret = tox_conference_get_id(_tox, conference_number, id.data());
if (ret) {
return id;
} else {
return std::nullopt;
}
}
std::tuple<std::optional<uint32_t>, Tox_Err_Conference_By_Id> ToxDefaultImpl::toxConferenceByID(const std::vector<uint8_t>& id) {
if (id.size() != TOX_CONFERENCE_ID_SIZE) {
return {std::nullopt, TOX_ERR_CONFERENCE_BY_ID_NOT_FOUND};
}
Tox_Err_Conference_By_Id err = TOX_ERR_CONFERENCE_BY_ID_OK;
const auto res = tox_conference_by_id(_tox, id.data(), &err);
if (err == TOX_ERR_CONFERENCE_BY_ID_OK) {
return {res, err};
} else {
return {std::nullopt, err};
}
}
Tox_Err_Friend_Custom_Packet ToxDefaultImpl::toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) { Tox_Err_Friend_Custom_Packet ToxDefaultImpl::toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) {
Tox_Err_Friend_Custom_Packet err = TOX_ERR_FRIEND_CUSTOM_PACKET_OK; Tox_Err_Friend_Custom_Packet err = TOX_ERR_FRIEND_CUSTOM_PACKET_OK;
tox_friend_send_lossy_packet(_tox, friend_number, data.data(), data.size(), &err); tox_friend_send_lossy_packet(_tox, friend_number, data.data(), data.size(), &err);

View File

@ -53,9 +53,24 @@ struct ToxDefaultImpl : public ToxI {
Tox_Err_File_Send_Chunk toxFileSendChunk(uint32_t friend_number, uint32_t file_number, uint64_t position, const std::vector<uint8_t>& data) override; Tox_Err_File_Send_Chunk toxFileSendChunk(uint32_t friend_number, uint32_t file_number, uint64_t position, const std::vector<uint8_t>& data) override;
// conferece // conferece
Tox_Err_Conference_Delete toxConferenceDelete(uint32_t conference_number) override;
std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Peer_Query> toxConferencePeerCount(uint32_t conference_number) override;
std::tuple<std::optional<std::string>, Tox_Err_Conference_Peer_Query> toxConferencePeerGetName(uint32_t conference_number, uint32_t peer_number) override;
std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_Conference_Peer_Query> toxConferencePeerGetPublicKey(uint32_t conference_number, uint32_t peer_number) override;
std::tuple<std::optional<bool>, Tox_Err_Conference_Peer_Query> toxConferencePeerNumberIsOurs(uint32_t conference_number, uint32_t peer_number) override;
Tox_Err_Conference_Set_Max_Offline toxConferenceSetMaxOffline(uint32_t conference_number, uint32_t max_offline_peers) override;
Tox_Err_Conference_Invite toxConferenceInvite(uint32_t friend_number, uint32_t conference_number) override;
std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Join> toxConferenceJoin(uint32_t friend_number, const std::vector<uint8_t>& cookie) override; std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Join> toxConferenceJoin(uint32_t friend_number, const std::vector<uint8_t>& cookie) override;
Tox_Err_Conference_Send_Message toxConferenceSendMessage(uint32_t conference_number, Tox_Message_Type type, std::string_view message) override; Tox_Err_Conference_Send_Message toxConferenceSendMessage(uint32_t conference_number, Tox_Message_Type type, std::string_view message) override;
std::tuple<std::optional<std::string>, Tox_Err_Conference_Title> toxConferenceGetTitle(uint32_t conference_number) override;
Tox_Err_Conference_Title toxConferenceSetTitle(uint32_t conference_number, std::string_view title) override;
std::vector<uint32_t> toxConferenceGetChatlist(void) override;
std::tuple<std::optional<Tox_Conference_Type>, Tox_Err_Conference_Get_Type> toxConferenceGetType(uint32_t conference_number) override;
std::optional<std::vector<uint8_t>> toxConferenceGetID(uint32_t conference_number) override;
std::tuple<std::optional<uint32_t>, Tox_Err_Conference_By_Id> toxConferenceByID(const std::vector<uint8_t>& id) override;
Tox_Err_Friend_Custom_Packet toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) override; Tox_Err_Friend_Custom_Packet toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) override;
Tox_Err_Friend_Custom_Packet toxFriendSendLosslessPacket(uint32_t friend_number, const std::vector<uint8_t>& data) override; Tox_Err_Friend_Custom_Packet toxFriendSendLosslessPacket(uint32_t friend_number, const std::vector<uint8_t>& data) override;

View File

@ -10,11 +10,14 @@
#include <optional> #include <optional>
// TODO: c++20 span // TODO: c++20 span
// TODO: use span in utils
// TODO: asyncable
// defines the full interface for tox // defines the full interface for tox
// HACK: raw // HACK: raw
struct ToxI_raw { struct ToxI_raw {
static constexpr const char* version {"8"}; static constexpr const char* version {"9"};
virtual ~ToxI_raw(void) {} virtual ~ToxI_raw(void) {}
@ -73,31 +76,29 @@ struct ToxI_raw {
virtual Tox_Err_File_Send_Chunk toxFileSendChunk(uint32_t friend_number, uint32_t file_number, uint64_t position, const std::vector<uint8_t>& data) = 0; virtual Tox_Err_File_Send_Chunk toxFileSendChunk(uint32_t friend_number, uint32_t file_number, uint64_t position, const std::vector<uint8_t>& data) = 0;
// conferece // conferece
//bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error); virtual Tox_Err_Conference_Delete toxConferenceDelete(uint32_t conference_number) = 0;
//uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error); virtual std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Peer_Query> toxConferencePeerCount(uint32_t conference_number) = 0;
//size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number, virtual std::tuple<std::optional<std::string>, Tox_Err_Conference_Peer_Query> toxConferencePeerGetName(uint32_t conference_number, uint32_t peer_number) = 0;
//bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name, virtual std::tuple<std::optional<std::vector<uint8_t>>, Tox_Err_Conference_Peer_Query> toxConferencePeerGetPublicKey(uint32_t conference_number, uint32_t peer_number) = 0;
//bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number, // TODO: simplify return value
//bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number, virtual std::tuple<std::optional<bool>, Tox_Err_Conference_Peer_Query> toxConferencePeerNumberIsOurs(uint32_t conference_number, uint32_t peer_number) = 0;
// TODO: do offline conf stuff
//uint32_t tox_conference_offline_peer_count(const Tox *tox, uint32_t conference_number, //uint32_t tox_conference_offline_peer_count(const Tox *tox, uint32_t conference_number,
//size_t tox_conference_offline_peer_get_name_size(const Tox *tox, uint32_t conference_number, //size_t tox_conference_offline_peer_get_name_size(const Tox *tox, uint32_t conference_number,
//bool tox_conference_offline_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t offline_peer_number, //bool tox_conference_offline_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t offline_peer_number,
//bool tox_conference_offline_peer_get_public_key(const Tox *tox, uint32_t conference_number, //bool tox_conference_offline_peer_get_public_key(const Tox *tox, uint32_t conference_number,
//uint64_t tox_conference_offline_peer_get_last_active(const Tox *tox, uint32_t conference_number, //uint64_t tox_conference_offline_peer_get_last_active(const Tox *tox, uint32_t conference_number,
//bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number, uint32_t max_offline_peers, Tox_Err_Conference_Set_Max_Offline *error); // TODO: 2 value enum, use bool instead?
//bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number, Tox_Err_Conference_Invite *error); virtual Tox_Err_Conference_Set_Max_Offline toxConferenceSetMaxOffline(uint32_t conference_number, uint32_t max_offline_peers) = 0;
virtual Tox_Err_Conference_Invite toxConferenceInvite(uint32_t friend_number, uint32_t conference_number) = 0;
virtual std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Join> toxConferenceJoin(uint32_t friend_number, const std::vector<uint8_t>& cookie) = 0; virtual std::tuple<std::optional<uint32_t>, Tox_Err_Conference_Join> toxConferenceJoin(uint32_t friend_number, const std::vector<uint8_t>& cookie) = 0;
virtual Tox_Err_Conference_Send_Message toxConferenceSendMessage(uint32_t conference_number, Tox_Message_Type type, std::string_view message) = 0; virtual Tox_Err_Conference_Send_Message toxConferenceSendMessage(uint32_t conference_number, Tox_Message_Type type, std::string_view message) = 0;
//size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error); virtual std::tuple<std::optional<std::string>, Tox_Err_Conference_Title> toxConferenceGetTitle(uint32_t conference_number) = 0;
//bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title, Tox_Err_Conference_Title *error); virtual Tox_Err_Conference_Title toxConferenceSetTitle(uint32_t conference_number, std::string_view title) = 0;
//bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length, Tox_Err_Conference_Title *error); virtual std::vector<uint32_t> toxConferenceGetChatlist(void) = 0;
//size_t tox_conference_get_chatlist_size(const Tox *tox); virtual std::tuple<std::optional<Tox_Conference_Type>, Tox_Err_Conference_Get_Type> toxConferenceGetType(uint32_t conference_number) = 0;
//void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist); virtual std::optional<std::vector<uint8_t>> toxConferenceGetID(uint32_t conference_number) = 0;
//Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Get_Type *error); virtual std::tuple<std::optional<uint32_t>, Tox_Err_Conference_By_Id> toxConferenceByID(const std::vector<uint8_t>& id) = 0;
//bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id);
//uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Conference_By_Id *error);
//bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid);
//uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error);
virtual Tox_Err_Friend_Custom_Packet toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) = 0; virtual Tox_Err_Friend_Custom_Packet toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) = 0;
@ -206,6 +207,10 @@ struct ToxI : public ToxI_raw {
return toxConferenceSendMessage(conference_number, type, message); return toxConferenceSendMessage(conference_number, type, message);
} }
Tox_Err_Conference_Title toxConferenceSetTitle_str(uint32_t conference_number, const std::string& title) {
return toxConferenceSetTitle(conference_number, title);
}
std::tuple<std::optional<uint32_t>, Tox_Err_Group_New> toxGroupNew_str(Tox_Group_Privacy_State privacy_state, const std::string& group_name, const std::string& name) { std::tuple<std::optional<uint32_t>, Tox_Err_Group_New> toxGroupNew_str(Tox_Group_Privacy_State privacy_state, const std::string& group_name, const std::string& name) {
return toxGroupNew(privacy_state, group_name, name); return toxGroupNew(privacy_state, group_name, name);
} }

View File

@ -130,6 +130,35 @@ enum Tox_Err_File_Send_Chunk {
TOX_ERR_FILE_SEND_CHUNK_WRONG_POSITION, TOX_ERR_FILE_SEND_CHUNK_WRONG_POSITION,
}; };
enum Tox_Conference_Type {
TOX_CONFERENCE_TYPE_TEXT,
TOX_CONFERENCE_TYPE_AV,
};
enum Tox_Err_Conference_Delete {
TOX_ERR_CONFERENCE_DELETE_OK,
TOX_ERR_CONFERENCE_DELETE_CONFERENCE_NOT_FOUND,
};
enum Tox_Err_Conference_Peer_Query {
TOX_ERR_CONFERENCE_PEER_QUERY_OK,
TOX_ERR_CONFERENCE_PEER_QUERY_CONFERENCE_NOT_FOUND,
TOX_ERR_CONFERENCE_PEER_QUERY_PEER_NOT_FOUND,
TOX_ERR_CONFERENCE_PEER_QUERY_NO_CONNECTION,
};
enum Tox_Err_Conference_Set_Max_Offline {
TOX_ERR_CONFERENCE_SET_MAX_OFFLINE_OK,
TOX_ERR_CONFERENCE_SET_MAX_OFFLINE_CONFERENCE_NOT_FOUND,
};
enum Tox_Err_Conference_Invite {
TOX_ERR_CONFERENCE_INVITE_OK,
TOX_ERR_CONFERENCE_INVITE_CONFERENCE_NOT_FOUND,
TOX_ERR_CONFERENCE_INVITE_FAIL_SEND,
TOX_ERR_CONFERENCE_INVITE_NO_CONNECTION,
};
enum Tox_Err_Conference_Join { enum Tox_Err_Conference_Join {
TOX_ERR_CONFERENCE_JOIN_OK, TOX_ERR_CONFERENCE_JOIN_OK,
TOX_ERR_CONFERENCE_JOIN_INVALID_LENGTH, TOX_ERR_CONFERENCE_JOIN_INVALID_LENGTH,
@ -148,6 +177,24 @@ enum Tox_Err_Conference_Send_Message {
TOX_ERR_CONFERENCE_SEND_MESSAGE_FAIL_SEND, TOX_ERR_CONFERENCE_SEND_MESSAGE_FAIL_SEND,
}; };
enum Tox_Err_Conference_Title {
TOX_ERR_CONFERENCE_TITLE_OK,
TOX_ERR_CONFERENCE_TITLE_CONFERENCE_NOT_FOUND,
TOX_ERR_CONFERENCE_TITLE_INVALID_LENGTH,
TOX_ERR_CONFERENCE_TITLE_FAIL_SEND,
};
enum Tox_Err_Conference_Get_Type {
TOX_ERR_CONFERENCE_GET_TYPE_OK,
TOX_ERR_CONFERENCE_GET_TYPE_CONFERENCE_NOT_FOUND,
};
enum Tox_Err_Conference_By_Id {
TOX_ERR_CONFERENCE_BY_ID_OK,
TOX_ERR_CONFERENCE_BY_ID_NULL,
TOX_ERR_CONFERENCE_BY_ID_NOT_FOUND,
};
enum Tox_Err_Friend_Custom_Packet { enum Tox_Err_Friend_Custom_Packet {
TOX_ERR_FRIEND_CUSTOM_PACKET_OK, TOX_ERR_FRIEND_CUSTOM_PACKET_OK,
TOX_ERR_FRIEND_CUSTOM_PACKET_NULL, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL,