hs2: change msgpack format and fixes
This commit is contained in:
parent
930c829031
commit
6ad2905e07
@ -215,8 +215,6 @@ void NGCHS2Rizzler::handleMsgPack(Contact3Handle sync_by_c, const std::vector<ui
|
||||
|
||||
uint32_t mid = j_entry.at("mid");
|
||||
|
||||
const std::string& type = j_entry.at("msgtype");
|
||||
|
||||
if (
|
||||
!(j_entry.count("text")) &&
|
||||
!(j_entry.count("fkind") && j_entry.count("fid"))
|
||||
@ -225,14 +223,6 @@ void NGCHS2Rizzler::handleMsgPack(Contact3Handle sync_by_c, const std::vector<ui
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
type != "text" && type != "action" &&
|
||||
type != "file"
|
||||
) {
|
||||
std::cerr << "NGCHS2Rizzler error: unknown entry '" << j_entry.dump() << "'\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
Contact3 from_c{entt::null};
|
||||
{ // from_c
|
||||
std::vector<uint8_t> id;
|
||||
@ -255,20 +245,22 @@ void NGCHS2Rizzler::handleMsgPack(Contact3Handle sync_by_c, const std::vector<ui
|
||||
|
||||
Message3Handle new_real_msg{reg, reg.create()};
|
||||
|
||||
new_real_msg.emplace<Message::Components::Timestamp>(ts); // reactive?
|
||||
|
||||
new_real_msg.emplace<Message::Components::ContactFrom>(from_c);
|
||||
new_real_msg.emplace<Message::Components::ContactTo>(sync_by_c.get<Contact::Components::Parent>().parent);
|
||||
|
||||
new_real_msg.emplace<Message::Components::ToxGroupMessageID>(mid);
|
||||
|
||||
if (type == "text" || type == "action") {
|
||||
bool is_action = type == "action";
|
||||
if (j_entry.contains("action") && static_cast<bool>(j_entry.at("action"))) {
|
||||
new_real_msg.emplace<Message::Components::TagMessageIsAction>();
|
||||
}
|
||||
|
||||
if (j_entry.contains("text")) {
|
||||
const std::string& text = j_entry.at("text");
|
||||
|
||||
new_real_msg.emplace<Message::Components::MessageText>(text);
|
||||
|
||||
if (is_action) {
|
||||
new_real_msg.emplace<Message::Components::TagMessageIsAction>();
|
||||
}
|
||||
#if 0
|
||||
std::cout
|
||||
<< "msg ts:" << ts
|
||||
@ -279,7 +271,7 @@ void NGCHS2Rizzler::handleMsgPack(Contact3Handle sync_by_c, const std::vector<ui
|
||||
<< "\n"
|
||||
;
|
||||
#endif
|
||||
} else if (type == "file") {
|
||||
} else if (j_entry.contains("fkind") && j_entry.contains("fid")) {
|
||||
uint32_t fkind = j_entry.at("fkind");
|
||||
|
||||
const auto& j_fid = j_entry.at("fid");
|
||||
@ -365,7 +357,6 @@ void NGCHS2Rizzler::handleMsgPack(Contact3Handle sync_by_c, const std::vector<ui
|
||||
|
||||
new_msg.emplace<Message::Components::TimestampProcessed>(now_ts);
|
||||
new_msg.emplace<Message::Components::TimestampWritten>(ts);
|
||||
new_msg.emplace<Message::Components::Timestamp>(ts); // reactive?
|
||||
|
||||
new_msg.emplace<Message::Components::TagUnread>();
|
||||
_rmm.throwEventConstruct(reg, new_msg);
|
||||
|
@ -319,12 +319,11 @@ std::vector<uint8_t> NGCHS2Sigma::buildChatLogFileRange(Contact3Handle c, uint64
|
||||
}
|
||||
j_entry["mid"] = msg_reg.get<Message::Components::ToxGroupMessageID>(e).id;
|
||||
|
||||
if (msg_reg.all_of<Message::Components::TagMessageIsAction>(e)) {
|
||||
j_entry["action"] = true;
|
||||
}
|
||||
|
||||
if (msg_reg.all_of<Message::Components::MessageText>(e)) {
|
||||
if (msg_reg.all_of<Message::Components::TagMessageIsAction>(e)) {
|
||||
j_entry["msgtype"] = "action"; // TODO: textaction?
|
||||
} else {
|
||||
j_entry["msgtype"] = "text";
|
||||
}
|
||||
j_entry["text"] = msg_reg.get<Message::Components::MessageText>(e).text;
|
||||
} else if (msg_reg.any_of<Message::Components::MessageFileObject>(e)) {
|
||||
const auto& o = msg_reg.get<Message::Components::MessageFileObject>(e).o;
|
||||
@ -334,7 +333,6 @@ std::vector<uint8_t> NGCHS2Sigma::buildChatLogFileRange(Contact3Handle c, uint64
|
||||
|
||||
// HACK: use tox fild_id and file_kind instead!!
|
||||
if (o.all_of<Components::FT1InfoSHA1Hash>()) {
|
||||
j_entry["msgtype"] = "file";
|
||||
j_entry["fkind"] = NGCFT1_file_kind::HASH_SHA1_INFO;
|
||||
j_entry["fid"] = nlohmann::json::binary_t{o.get<Components::FT1InfoSHA1Hash>().hash};
|
||||
} else {
|
||||
|
@ -91,8 +91,9 @@ Msgpack array of messages.
|
||||
- ts | 64bit deciseconds
|
||||
- ppk | 32bytes
|
||||
- mid | 16bit
|
||||
- msgtype | enum (string or number?)
|
||||
- if text/action |
|
||||
- if action |
|
||||
- action | bool
|
||||
- if text |
|
||||
- text | string | maybe byte array instead?
|
||||
- if file |
|
||||
- fkind | 32bit enum | is this right?
|
||||
@ -102,9 +103,6 @@ Msgpack array of messages.
|
||||
Name is the actual string key.
|
||||
Data type sizes are suggestions, if not defined by the tox protocol.
|
||||
|
||||
How unknown `msgtype`s are handled is client defined.
|
||||
They can be fully ignored or displayed as broken.
|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] figure out a pro-active approach (instead of waiting for a range request)
|
||||
|
Loading…
Reference in New Issue
Block a user