2018-02-14 21:23:20 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#include "rooms.h"
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
resource::response
|
|
|
|
post__read_markers(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const m::room::id &room_id)
|
|
|
|
{
|
2018-03-15 06:10:40 +01:00
|
|
|
const string_view m_fully_read
|
|
|
|
{
|
|
|
|
unquote(request["m.fully_read"])
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view m_read
|
|
|
|
{
|
|
|
|
unquote(request["m.read"])
|
|
|
|
};
|
|
|
|
|
2018-03-16 20:47:39 +01:00
|
|
|
const auto &marker
|
|
|
|
{
|
|
|
|
m_read?: m_fully_read
|
|
|
|
};
|
|
|
|
|
2019-02-12 00:23:43 +01:00
|
|
|
m::event::id::buf head;
|
2018-03-27 01:35:18 +02:00
|
|
|
if(marker) switch(m::sigil(marker))
|
|
|
|
{
|
|
|
|
case m::id::EVENT:
|
2019-02-12 00:23:43 +01:00
|
|
|
head = marker;
|
2018-03-27 01:35:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case m::id::ROOM:
|
2019-02-12 00:23:43 +01:00
|
|
|
head = m::head(m::room::id(marker));
|
2018-03-27 01:35:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: log::dwarning
|
|
|
|
{
|
|
|
|
"Unhandled read marker '%s' sigil type",
|
|
|
|
string_view{marker}
|
|
|
|
};
|
|
|
|
}
|
2018-03-15 06:10:40 +01:00
|
|
|
|
2019-02-12 00:23:43 +01:00
|
|
|
const bool useful
|
|
|
|
{
|
|
|
|
head &&
|
|
|
|
|
|
|
|
// Check if the marker is more recent than the last marker they sent.
|
|
|
|
// We currently don't do anything with markers targeting the past
|
|
|
|
m::receipt::freshest(room_id, request.user_id, head) &&
|
|
|
|
|
|
|
|
// Check if the user wants to prevent sending a receipt to the room.
|
|
|
|
!m::receipt::ignoring(request.user_id, room_id) &&
|
|
|
|
|
|
|
|
// Check if the user wants to prevent based on this event's specifics.
|
|
|
|
!m::receipt::ignoring(request.user_id, head)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(useful)
|
|
|
|
m::receipt::read(room_id, request.user_id, head);
|
|
|
|
|
2018-02-14 21:23:20 +01:00
|
|
|
return resource::response
|
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
}
|