0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 22:18:54 +02:00

ircd:Ⓜ️:room: Add room::auth interface w/ console cmd.

This commit is contained in:
Jason Volk 2019-02-12 11:03:59 -08:00
parent 8a81a6d24e
commit 2f6384b068
6 changed files with 144 additions and 0 deletions

View file

@ -81,4 +81,5 @@ namespace ircd::m
#include "room/members.h"
#include "room/origins.h"
#include "room/head.h"
#include "room/auth.h"
#include "room/power.h"

View file

@ -0,0 +1,30 @@
// 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.
#pragma once
#define HAVE_IRCD_M_ROOM_AUTH_H
/// Interface to the auth_chain / auth_dag.
///
struct ircd::m::room::auth
{
using closure_bool = std::function<bool (const event::idx &, const event &)>;
using closure = std::function<void (const event::idx &, const event &)>;
m::room room;
static bool for_each(const auth &, const closure_bool &);
bool for_each(const closure_bool &) const;
void for_each(const closure &) const;
auth(const m::room &room)
:room{room}
{}
};

View file

@ -35,6 +35,7 @@ struct ircd::m::room
struct members;
struct origins;
struct head;
struct auth;
struct power;
using id = m::id::room;

View file

@ -2050,6 +2050,42 @@ const
return true;
}
//
// room::auth
//
void
ircd::m::room::auth::for_each(const closure &c)
const
{
for_each(closure_bool{[this, &c]
(const auto &a, const auto &b)
{
c(a, b);
return true;
}});
}
bool
ircd::m::room::auth::for_each(const closure_bool &c)
const
{
return for_each(*this, c);
}
bool
ircd::m::room::auth::for_each(const auth &a, const closure_bool &c)
{
using prototype = bool (const auth &, const closure_bool &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::auth::for_each"
};
return call(a, c);
}
//
// room::power
//

View file

@ -8157,6 +8157,69 @@ console_cmd__room__dagree(opt &out, const string_view &line)
return true;
}
bool
console_cmd__room__auth(opt &out, const string_view &line)
{
const params param{line, " ",
{
"event_id|room_id", "event_id"
}};
const string_view &p0
{
param.at("event_id|room_id")
};
const m::room::id::buf room_id{[&p0]
() -> m::room::id::buf
{
switch(m::sigil(p0))
{
case m::id::ROOM:
return p0;
case m::id::ROOM_ALIAS:
return m::room_id(p0);
case m::id::EVENT:
return m::get(m::event::id(p0), "room_id");
default: throw params::invalid
{
"%s is the wrong kind of MXID for this argument",
reflect(m::sigil(p0))
};
}
}()};
const m::event::id &event_id
{
m::sigil(p0) != m::id::EVENT?
param.at("event_id"):
p0
};
const m::room room
{
room_id, event_id
};
const m::room::auth auth
{
room
};
auth.for_each([&out]
(const m::event::idx &idx, const m::event &event)
{
out << idx
<< " " << pretty_oneline(event)
<< std::endl;
});
return true;
}
//
// user
//

View file

@ -845,3 +845,16 @@ room_herd(const m::room &room,
ctx::sleep(seconds(2));
}
}
bool
IRCD_MODULE_EXPORT
ircd::m::room::auth::for_each(const auth &a,
const closure_bool &closure)
{
const m::room &room{a.room};
const auto &event_id{room.event_id};
if(!event_id)
return false;
return true;
}