This commit is contained in:
Green Sky 2022-09-29 02:39:54 +02:00
parent 3832906ebb
commit ba168d5f2d
No known key found for this signature in database
2 changed files with 65 additions and 5 deletions

View File

@ -2,10 +2,35 @@
#include <cstdint>
#include <new>
#include <unordered_map>
#include <map>
#include <list>
struct _GroupID {
}
std::array<uint8_t, TOX_GROUP_CHAT_ID_SIZE> data;
bool operator<(const _GroupID& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] > rhs.data[i]) {
return false;
}
}
return true;
}
};
struct _PeerID {
std::array<uint8_t, TOX_GROUP_PEER_PUBLIC_KEY_SIZE> data;
bool operator<(const _PeerID& rhs) const {
for (size_t i = 0; i < data.size(); i++) {
if (data[i] > rhs.data[i]) {
return false;
}
}
return true;
}
};
struct NGC_HS1 {
void* temp;
@ -14,6 +39,28 @@ struct NGC_HS1 {
// key - key - key - value store
// group pubkey - peer pubkey - msg_id - message(type + text)
struct Message {
uint32_t msg_id{};
Tox_Message_Type type;
std::string text;
};
struct Messages {
std::map<uint32_t, Message> dict;
std::list<uint32_t> order; // ordered list of message ids
void append(uint32_t msg_id, Tox_Message_Type type, const std::string& text) {
order.push_back(msg_id);
// overwrites
auto& new_msg = dict[msg_id];
new_msg.msg_id = msg_id;
new_msg.type = type;
new_msg.text = text;
}
};
std::map<_GroupID, std::map<_PeerID, Messages>> history;
};
NGC_HS1* NGC_HS1_new(const struct NGC_HS1_options* options) {
@ -44,13 +91,13 @@ bool NGC_HS1_shim_group_send_message(
) {
uint32_t* msg_id_ptr = message_id;
uint32_t msg_id_placeholder = 0;
if (msg_id_ptr == NULL) {
if (msg_id_ptr == nullptr) {
msg_id_ptr = &msg_id_placeholder;
}
bool ret = tox_group_send_message(tox, group_number, type, message, length, msg_id_ptr, error);
NGC_HS1_record_own_message(tox, group_number, type, message, length, *msg_id_ptr);
NGC_HS1_record_own_message(tox, ngc_hs1_ctx, group_number, type, message, length, *msg_id_ptr);
return ret;
}
@ -66,5 +113,18 @@ void NGC_HS1_record_own_message(
Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t message_id
) {
printf("record_own_message %u\n", message_id);
// get group id
_GroupID g_id{};
{ // TODO: error
tox_group_get_chat_id(tox, group_number, g_id.data.data(), nullptr);
}
// get peer id
_PeerID p_id{};
{ // TODO: error
tox_group_self_get_public_key(tox, group_number, p_id.data.data(), nullptr);
}
ngc_hs1_ctx->history[g_id];
}

View File

@ -39,7 +39,7 @@ struct NGC_HS1_options {
// 2 mods
// 3 founders
// 4 no one (above founder)
uint8_t default_trust_level = 2;
uint8_t default_trust_level /*= 2*/;
//bool test;
};