0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

modules/client/rooms: Implement c2s r0.6.1 10.2.4 GET client/rooms/aliases.

This commit is contained in:
Jason Volk 2020-12-14 03:15:28 -08:00
parent 1949e6e37d
commit 7645cd3e72
4 changed files with 81 additions and 0 deletions

View file

@ -333,6 +333,7 @@ client_client_rooms_la_SOURCES = \
client/rooms/report.cc \
client/rooms/relations.cc \
client/rooms/upgrade.cc \
client/rooms/aliases.cc \
client/rooms/rooms.cc \
###

View file

@ -0,0 +1,67 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 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__aliases(client &client,
const m::resource::request &request,
const m::room::id &room_id)
{
if(!m::exists(room_id))
throw m::NOT_FOUND
{
"Cannot find aliases in %s which is not found.",
string_view{room_id}
};
if(!m::visible(room_id, request.user_id))
throw m::FORBIDDEN
{
"You are not allowed to view aliases of %s",
string_view{room_id},
};
const m::room::aliases aliases
{
room_id
};
m::resource::response::chunked response
{
client, http::OK
};
json::stack out
{
response.buf, response.flusher()
};
json::stack::object top
{
out
};
json::stack::array array
{
top, "aliases"
};
aliases.for_each([&array]
(const m::room::alias &room_alias)
{
array.append(room_alias);
return true;
});
return std::move(response);
}

View file

@ -82,6 +82,9 @@ get_rooms(client &client,
if(cmd == "relations")
return get__relations(client, request, room_id);
if(cmd == "aliases")
return get__aliases(client, request, room_id);
throw m::NOT_FOUND
{
"/rooms command not found"

View file

@ -234,3 +234,13 @@ ircd::m::resource::response
post__upgrade(ircd::client &,
const ircd::m::resource::request &,
const ircd::m::room::id &);
///////////////////////////////////////////////////////////////////////////////
//
// aliases.cc
//
ircd::m::resource::response
get__aliases(ircd::client &,
const ircd::m::resource::request &,
const ircd::m::room::id &);