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;
|
|
|
|
|
2019-03-28 00:14:39 +01:00
|
|
|
void // This is in receipt.cc; not listed in rooms.h so we declare here.
|
|
|
|
handle_receipt_m_read(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const m::room::id &room_id,
|
|
|
|
const m::event::id &event_id);
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_m_fully_read(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const m::room::id &room_id,
|
|
|
|
const json::string &input);
|
|
|
|
|
2018-02-14 21:23:20 +01:00
|
|
|
resource::response
|
|
|
|
post__read_markers(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const m::room::id &room_id)
|
|
|
|
{
|
2019-03-28 00:14:39 +01:00
|
|
|
const json::string &m_read
|
2018-03-15 06:10:40 +01:00
|
|
|
{
|
2019-03-28 00:14:39 +01:00
|
|
|
request["m.read"]
|
2018-03-15 06:10:40 +01:00
|
|
|
};
|
|
|
|
|
2019-03-28 00:14:39 +01:00
|
|
|
const json::string &m_fully_read
|
2018-03-16 20:47:39 +01:00
|
|
|
{
|
2019-03-28 00:14:39 +01:00
|
|
|
request["m.fully_read"]
|
2018-03-16 20:47:39 +01:00
|
|
|
};
|
|
|
|
|
2019-03-28 00:14:39 +01:00
|
|
|
if(m_fully_read)
|
|
|
|
handle_m_fully_read(client, request, room_id, m_fully_read);
|
2018-03-27 01:35:18 +02:00
|
|
|
|
2019-03-28 00:14:39 +01:00
|
|
|
if(m_read)
|
|
|
|
handle_receipt_m_read(client, request, room_id, m_read);
|
2018-03-15 06:10:40 +01:00
|
|
|
|
2019-03-28 00:14:39 +01:00
|
|
|
return resource::response
|
2019-02-12 00:23:43 +01:00
|
|
|
{
|
2019-03-28 00:14:39 +01:00
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
}
|
2019-02-12 00:23:43 +01:00
|
|
|
|
2019-03-28 00:14:39 +01:00
|
|
|
void
|
|
|
|
handle_m_fully_read(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const m::room::id &room_id,
|
|
|
|
const json::string &input)
|
|
|
|
{
|
|
|
|
m::event::id::buf event_id_buf;
|
|
|
|
if(!m::valid(m::id::EVENT, input))
|
|
|
|
event_id_buf = m::head(room_id);
|
2019-02-12 00:23:43 +01:00
|
|
|
|
2019-03-28 00:14:39 +01:00
|
|
|
const m::event::id &event_id
|
|
|
|
{
|
|
|
|
event_id_buf?: m::event::id{input}
|
2019-02-12 00:23:43 +01:00
|
|
|
};
|
|
|
|
|
2019-03-28 00:14:39 +01:00
|
|
|
const m::user::room_account_data account_data
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
2019-03-28 00:14:39 +01:00
|
|
|
request.user_id, room_id
|
2018-02-14 21:23:20 +01:00
|
|
|
};
|
2019-03-28 00:14:39 +01:00
|
|
|
|
|
|
|
const json::strung content{json::members
|
|
|
|
{
|
|
|
|
{ "event_id", event_id }
|
|
|
|
}};
|
|
|
|
|
|
|
|
account_data.set("m.fully_read", json::object(content));
|
2018-02-14 21:23:20 +01:00
|
|
|
}
|