mirror of
https://github.com/matrix-construct/construct
synced 2024-07-01 08:18:20 +02:00
modules/client/rooms/receipt: Check for duplicate receipts on commission.
This commit is contained in:
parent
cb73ba1d10
commit
389d5a9f18
|
@ -18,6 +18,11 @@ commit__m_receipt_m_read(const m::room::id &,
|
|||
const m::event::id &,
|
||||
const time_t &);
|
||||
|
||||
extern "C" bool
|
||||
exists__m_receipt_m_read(const m::room::id &,
|
||||
const m::user::id &,
|
||||
const m::event::id &);
|
||||
|
||||
resource::response
|
||||
post__receipt(client &client,
|
||||
const resource::request &request,
|
||||
|
@ -57,6 +62,9 @@ commit__m_receipt_m_read(const m::room::id &room_id,
|
|||
const m::event::id &event_id,
|
||||
const time_t &ms)
|
||||
{
|
||||
if(exists__m_receipt_m_read(room_id, user_id, event_id))
|
||||
return {};
|
||||
|
||||
const json::value event_ids[]
|
||||
{
|
||||
{ event_id }
|
||||
|
@ -95,3 +103,28 @@ commit__m_receipt_m_read(const m::room::id &room_id,
|
|||
|
||||
return m::vm::commit(event, content, opts);
|
||||
}
|
||||
|
||||
bool
|
||||
exists__m_receipt_m_read(const m::room::id &room_id,
|
||||
const m::user::id &user_id,
|
||||
const m::event::id &event_id)
|
||||
{
|
||||
const m::user::room user_room
|
||||
{
|
||||
user_id
|
||||
};
|
||||
|
||||
bool ret{false};
|
||||
user_room.get(std::nothrow, "m.read", room_id, [&ret, &event_id]
|
||||
(const m::event &event)
|
||||
{
|
||||
const auto &content
|
||||
{
|
||||
at<"content"_>(event)
|
||||
};
|
||||
|
||||
ret = unquote(content.get("event_id")) == event_id;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue