modules: Stub federation/timestamp_to_event; stub client/rooms/timestamp_to_event.

This commit is contained in:
Jason Volk 2023-03-06 18:58:11 -08:00
parent 48950bf1c9
commit ae10f735ec
6 changed files with 177 additions and 0 deletions

View File

@ -109,6 +109,7 @@ ircd::m::module_names
"federation_send_leave",
"federation_send",
"federation_state",
"federation_timestamp_to_event",
"federation_user_devices",
"federation_user_keys_claim",
"federation_user_keys_query",

View File

@ -226,6 +226,7 @@ federation_federation_user_keys_query_la_SOURCES = federation/user_keys_query.cc
federation_federation_user_keys_claim_la_SOURCES = federation/user_keys_claim.cc
federation_federation_rooms_la_SOURCES = federation/rooms.cc
federation_federation_hierarchy_la_SOURCES = federation/hierarchy.cc
federation_federation_timestamp_to_event_la_SOURCES = federation/timestamp_to_event.cc
federation_module_LTLIBRARIES = \
federation/federation_send.la \
@ -250,6 +251,7 @@ federation_module_LTLIBRARIES = \
federation/federation_user_keys_claim.la \
federation/federation_rooms.la \
federation/federation_hierarchy.la \
federation/federation_timestamp_to_event.la \
###
###############################################################################
@ -346,6 +348,7 @@ client_client_rooms_la_SOURCES = \
client/rooms/aliases.cc \
client/rooms/hierarchy.cc \
client/rooms/threads.cc \
client/rooms/timestamp_to_event.cc \
client/rooms/rooms.cc \
###

View File

@ -81,6 +81,9 @@ get_rooms(client &client,
if(cmd == "threads")
return get__threads(client, request, room_id);
if(cmd == "timestamp_to_event")
return get__timestamp_to_event(client, request, room_id);
throw m::NOT_FOUND
{
"/rooms command not found"

View File

@ -264,3 +264,13 @@ ircd::m::resource::response
get__threads(ircd::client &,
const ircd::m::resource::request &,
const ircd::m::room::id &);
///////////////////////////////////////////////////////////////////////////////
//
// timestamp_to_event.cc
//
ircd::m::resource::response
get__timestamp_to_event(ircd::client &,
const ircd::m::resource::request &,
const ircd::m::room::id &);

View File

@ -0,0 +1,64 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2023 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;
m::resource::response
get__timestamp_to_event(client &client,
const m::resource::request &request,
const m::room::id &room_id)
{
const auto &dir
{
request.query["dir"]
};
const milliseconds ts
{
request.query.at<long>("ts")
};
const m::event::idx event_idx
{
0UL
};
const m::event::fetch event
{
std::nothrow, event_idx
};
const long &event_ts
{
json::get<"origin_server_ts"_>(event)
};
const m::room room
{
room_id, event.event_id
};
if(!visible(room, request.user_id))
throw m::ACCESS_DENIED
{
"You are not permitted to view the room at this event"
};
return m::resource::response
{
client, http::NOT_IMPLEMENTED, json::members
{
{ "event_id", event.event_id },
{ "origin_server_ts", event_ts },
}
};
}

View File

@ -0,0 +1,96 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2023 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.
using namespace ircd;
mapi::header
IRCD_MODULE
{
"federation timestamp to event"
};
m::resource
timestamp_to_event_resource
{
"/_matrix/federation/v1/timestamp_to_event/",
{
"federation timestamp to event",
resource::DIRECTORY,
}
};
m::resource::response
get__timestamp_to_event(client &client,
const m::resource::request &request);
m::resource::method
method_get
{
timestamp_to_event_resource, "GET", get__timestamp_to_event,
{
method_get.VERIFY_ORIGIN
}
};
m::resource::response
get__timestamp_to_event(client &client,
const m::resource::request &request)
{
if(request.parv.size() < 1)
throw m::NEED_MORE_PARAMS
{
"room_id path parameter required"
};
m::room::id::buf room_id
{
url::decode(room_id, request.parv[0])
};
if(m::room::server_acl::enable_read && !m::room::server_acl::check(room_id, request.node_id))
throw m::ACCESS_DENIED
{
"You are not permitted by the room's server access control list."
};
const auto dir
{
request.query["dir"]
};
const milliseconds ts
{
request.query.at<long>("ts")
};
const m::event::idx event_idx
{
0UL
};
const m::event::fetch event
{
std::nothrow, event_idx
};
const long &event_ts
{
json::get<"origin_server_ts"_>(event)
};
return m::resource::response
{
client, http::NOT_IMPLEMENTED, json::members
{
{ "event_id", event.event_id },
{ "origin_server_ts", event_ts },
}
};
}