add receive confirmaton to tox friend messages
This commit is contained in:
parent
a5da51a428
commit
44163ad3a5
@ -9,6 +9,11 @@
|
||||
|
||||
namespace Message::Components {
|
||||
|
||||
struct ToxFriendMessageID {
|
||||
// only exposed for the read reciept event
|
||||
uint32_t id = 0u;
|
||||
};
|
||||
|
||||
struct ToxGroupMessageID {
|
||||
uint32_t id = 0u;
|
||||
};
|
||||
|
@ -12,6 +12,7 @@ constexpr entt::id_type entt::type_hash<x>::value() noexcept { \
|
||||
|
||||
// cross compile(r) stable ids
|
||||
|
||||
DEFINE_COMP_ID(Message::Components::ToxFriendMessageID)
|
||||
DEFINE_COMP_ID(Message::Components::ToxGroupMessageID)
|
||||
DEFINE_COMP_ID(Message::Components::Transfer::ToxTransferFriend)
|
||||
DEFINE_COMP_ID(Message::Components::Transfer::FileID)
|
||||
|
@ -105,6 +105,8 @@ bool ToxMessageManager::sendText(const Contact3 c, std::string_view message, boo
|
||||
if (!res.has_value()) {
|
||||
std::cerr << "TMM: failed to send friend message\n";
|
||||
//return true; // not online? TODO: check for other errors
|
||||
} else {
|
||||
reg.emplace<Message::Components::ToxFriendMessageID>(new_msg_e, res.value());
|
||||
}
|
||||
} else if (
|
||||
_cr.any_of<Contact::Components::ToxGroupEphemeral>(c)
|
||||
@ -207,6 +209,40 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Friend_Message* e) {
|
||||
return false; // TODO: return true?
|
||||
}
|
||||
|
||||
bool ToxMessageManager::onToxEvent(const Tox_Event_Friend_Read_Receipt* e) {
|
||||
uint32_t friend_number = tox_event_friend_read_receipt_get_friend_number(e);
|
||||
uint32_t msg_id = tox_event_friend_read_receipt_get_message_id(e);
|
||||
|
||||
// get current time unix epoch utc
|
||||
uint64_t ts = Message::getTimeMS();
|
||||
|
||||
const auto c = _tcm.getContactFriend(friend_number);
|
||||
const auto self_c = c.get<Contact::Components::Self>().self;
|
||||
|
||||
auto* reg_ptr = _rmm.get(c);
|
||||
if (reg_ptr == nullptr) {
|
||||
std::cerr << "TMM error: cant find reg\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
Message3Registry& reg = *reg_ptr;
|
||||
|
||||
// find message by message id
|
||||
// TODO: keep a short list of unconfirmed msg ids
|
||||
// this iterates in reverse, so newest messages should be pretty front
|
||||
for (const auto& [m, msg_id_comp] : reg.view<Message::Components::ToxFriendMessageID>().each()) {
|
||||
if (msg_id_comp.id == msg_id) {
|
||||
// found it
|
||||
auto& rtr = reg.get_or_emplace<Message::Components::Remote::TimestampReceived>(m);
|
||||
// insert but dont overwrite
|
||||
rtr.ts.try_emplace(c, ts);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ToxMessageManager::onToxEvent(const Tox_Event_Group_Message* e) {
|
||||
const uint32_t group_number = tox_event_group_message_get_group_number(e);
|
||||
const uint32_t peer_number = tox_event_group_message_get_peer_id(e);
|
||||
|
@ -23,6 +23,7 @@ class ToxMessageManager : public RegistryMessageModelEventI, public ToxEventI {
|
||||
|
||||
protected: // tox events
|
||||
bool onToxEvent(const Tox_Event_Friend_Message* e) override;
|
||||
bool onToxEvent(const Tox_Event_Friend_Read_Receipt* e) override;
|
||||
|
||||
bool onToxEvent(const Tox_Event_Group_Message* e) override;
|
||||
bool onToxEvent(const Tox_Event_Group_Private_Message* e) override;
|
||||
|
Loading…
Reference in New Issue
Block a user