add friend and group lists

This commit is contained in:
Green Sky 2023-05-12 23:45:36 +02:00
parent b32e5ba64b
commit c4c32f5554
No known key found for this signature in database
3 changed files with 39 additions and 2 deletions

View File

@ -107,6 +107,17 @@ bool ToxDefaultImpl::toxFriendExists(uint32_t friend_number) {
return tox_friend_exists(_tox, friend_number); return tox_friend_exists(_tox, friend_number);
} }
size_t ToxDefaultImpl::toxSelfGetFriendListSize(void) {
return tox_self_get_friend_list_size(_tox);
}
std::vector<uint32_t> ToxDefaultImpl::toxSelfGetFriendList(void) {
std::vector<uint32_t> friend_list;
friend_list.resize(tox_self_get_friend_list_size(_tox));
tox_self_get_friend_list(_tox, friend_list.data());
return friend_list;
}
std::optional<std::vector<uint8_t>> ToxDefaultImpl::toxFriendGetPublicKey(uint32_t friend_number) { std::optional<std::vector<uint8_t>> ToxDefaultImpl::toxFriendGetPublicKey(uint32_t friend_number) {
std::vector<uint8_t> pub(TOX_PUBLIC_KEY_SIZE); std::vector<uint8_t> pub(TOX_PUBLIC_KEY_SIZE);
Tox_Err_Friend_Get_Public_Key err = TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK; Tox_Err_Friend_Get_Public_Key err = TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK;
@ -511,6 +522,26 @@ std::optional<std::vector<uint8_t>> ToxDefaultImpl::toxGroupGetChatId(uint32_t g
} }
} }
size_t ToxDefaultImpl::toxGroupGetNumberGroups(void) {
return tox_group_get_number_groups(_tox);
}
std::vector<uint32_t> ToxDefaultImpl::toxGroupGetList(void) {
std::vector<uint32_t> group_list;
size_t group_count = tox_group_get_number_groups(_tox);
// HACK: we guess number until we have count
for (uint32_t i = 0; i < group_count + 10'000u && group_list.size() < group_count; i++) {
Tox_Err_Group_Self_Query err = TOX_ERR_GROUP_SELF_QUERY_OK;
tox_group_self_get_peer_id(_tox, i, &err);
if (err == TOX_ERR_GROUP_SELF_QUERY_OK) {
group_list.push_back(i);
}
}
return group_list;
}
std::tuple<std::optional<uint32_t>, Tox_Err_Group_Send_Message> ToxDefaultImpl::toxGroupSendMessage(uint32_t group_number, Tox_Message_Type type, std::string_view message) { std::tuple<std::optional<uint32_t>, Tox_Err_Group_Send_Message> ToxDefaultImpl::toxGroupSendMessage(uint32_t group_number, Tox_Message_Type type, std::string_view message) {
Tox_Err_Group_Send_Message err = TOX_ERR_GROUP_SEND_MESSAGE_OK; Tox_Err_Group_Send_Message err = TOX_ERR_GROUP_SEND_MESSAGE_OK;
uint32_t message_id = 0; uint32_t message_id = 0;

View File

@ -32,6 +32,8 @@ struct ToxDefaultImpl : public ToxI {
Tox_Err_Friend_Delete toxFriendDelete(uint32_t friend_number) override; Tox_Err_Friend_Delete toxFriendDelete(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; 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; bool toxFriendExists(uint32_t friend_number) override;
size_t toxSelfGetFriendListSize(void) override;
std::vector<uint32_t> toxSelfGetFriendList(void) override;
std::optional<std::vector<uint8_t>> toxFriendGetPublicKey(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<uint64_t> toxFriendGetLastOnline(uint32_t friend_number) override;
std::optional<std::string> toxFriendGetName(uint32_t friend_number) override; std::optional<std::string> toxFriendGetName(uint32_t friend_number) override;
@ -90,7 +92,8 @@ struct ToxDefaultImpl : public ToxI {
std::optional<std::vector<uint8_t>> toxGroupGetChatId(uint32_t group_number) override; std::optional<std::vector<uint8_t>> toxGroupGetChatId(uint32_t group_number) override;
// TODO: str // TODO: str
//virtual uint32_t toxGroupGetNumberGroups(void) = 0; size_t toxGroupGetNumberGroups(void) override;
std::vector<uint32_t> toxGroupGetList(void) override;
//virtual Tox_Group_Privacy_State toxGroupGetPrivacyState(uint32_t group_number, Tox_Err_Group_State_Queries *error) = 0; //virtual Tox_Group_Privacy_State toxGroupGetPrivacyState(uint32_t group_number, Tox_Err_Group_State_Queries *error) = 0;
//virtual Tox_Group_Voice_State toxGroupGetVoiceState(uint32_t group_number, Tox_Err_Group_State_Queries *error) = 0; //virtual Tox_Group_Voice_State toxGroupGetVoiceState(uint32_t group_number, Tox_Err_Group_State_Queries *error) = 0;

View File

@ -48,7 +48,8 @@ struct ToxI_raw {
virtual Tox_Err_Friend_Delete toxFriendDelete(uint32_t friend_number) = 0; virtual Tox_Err_Friend_Delete toxFriendDelete(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 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; virtual bool toxFriendExists(uint32_t friend_number) = 0;
// tox_self_get_friend_list virtual size_t toxSelfGetFriendListSize(void) = 0;
virtual std::vector<uint32_t> toxSelfGetFriendList(void) = 0;
virtual std::optional<std::vector<uint8_t>> toxFriendGetPublicKey(uint32_t friend_number) = 0; 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<uint64_t> toxFriendGetLastOnline(uint32_t friend_number) = 0;
virtual std::optional<std::string> toxFriendGetName(uint32_t friend_number) = 0; virtual std::optional<std::string> toxFriendGetName(uint32_t friend_number) = 0;
@ -134,6 +135,8 @@ struct ToxI_raw {
// TODO: str // TODO: str
//virtual uint32_t toxGroupGetNumberGroups(void) = 0; //virtual uint32_t toxGroupGetNumberGroups(void) = 0;
virtual size_t toxGroupGetNumberGroups(void) = 0;
virtual std::vector<uint32_t> toxGroupGetList(void) = 0;
//virtual Tox_Group_Privacy_State toxGroupGetPrivacyState(uint32_t group_number, Tox_Err_Group_State_Queries *error) = 0; //virtual Tox_Group_Privacy_State toxGroupGetPrivacyState(uint32_t group_number, Tox_Err_Group_State_Queries *error) = 0;
//virtual Tox_Group_Voice_State toxGroupGetVoiceState(uint32_t group_number, Tox_Err_Group_State_Queries *error) = 0; //virtual Tox_Group_Voice_State toxGroupGetVoiceState(uint32_t group_number, Tox_Err_Group_State_Queries *error) = 0;