0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-03 22:28:52 +02:00

modules/client/rooms/receipt: Split m.read logic into subroutine.

This commit is contained in:
Jason Volk 2019-03-27 16:13:10 -07:00
parent 5cfc763002
commit 2d459d8da8

View file

@ -12,6 +12,12 @@
using namespace ircd;
void
handle_receipt_m_read(client &client,
const resource::request &request,
const m::room::id &room_id,
const m::event::id &event_id);
resource::response
post__receipt(client &client,
const resource::request &request,
@ -23,47 +29,56 @@ post__receipt(client &client,
"receipt type required"
};
if(request.parv.size() < 4)
throw m::NEED_MORE_PARAMS
{
"event_id required"
};
const string_view &receipt_type
{
request.parv[2]
};
if(receipt_type != "m.read")
throw m::UNSUPPORTED
if(receipt_type == "m.read")
{
if(request.parv.size() < 4)
throw m::NEED_MORE_PARAMS
{
"event_id required"
};
m::event::id::buf event_id
{
"Sorry, receipt type '%s' is not supported here.",
receipt_type
url::decode(event_id, request.parv[3])
};
m::event::id::buf event_id
handle_receipt_m_read(client, request, room_id, event_id);
}
else throw m::UNSUPPORTED
{
url::decode(event_id, request.parv[3])
"Sorry, receipt type '%s' is not supported here.",
receipt_type
};
const bool useful
{
// Check if event_id is more recent than the last receipt's event_id.
// We currently don't do anything with receipts targeting the past.
m::receipt::freshest(room_id, request.user_id, event_id) &&
// Check if user wants to prevent sending receipts to this room.
!m::receipt::ignoring(request.user_id, room_id) &&
// Check if user wants to prevent based on this event's specifics.
!m::receipt::ignoring(request.user_id, event_id)
};
if(useful)
m::receipt::read(room_id, request.user_id, event_id);
return resource::response
{
client, http::OK
};
}
void
handle_receipt_m_read(client &client,
const resource::request &request,
const m::room::id &room_id,
const m::event::id &event_id)
{
// Check if event_id is more recent than the last receipt's event_id.
// We currently don't do anything with receipts targeting the past.
if(!m::receipt::freshest(room_id, request.user_id, event_id))
return;
// Check if user wants to prevent sending receipts to this room.
if(m::receipt::ignoring(request.user_id, room_id))
return;
// Check if user wants to prevent based on this event's specifics.
if(m::receipt::ignoring(request.user_id, event_id))
return;
m::receipt::read(room_id, request.user_id, event_id);
}