mirror of
https://github.com/matrix-construct/construct
synced 2025-02-16 16:50:12 +01:00
ircd:Ⓜ️:room: Add room::auth interface w/ console cmd.
This commit is contained in:
parent
8a81a6d24e
commit
2f6384b068
6 changed files with 144 additions and 0 deletions
|
@ -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"
|
||||
|
|
30
include/ircd/m/room/auth.h
Normal file
30
include/ircd/m/room/auth.h
Normal 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}
|
||||
{}
|
||||
};
|
|
@ -35,6 +35,7 @@ struct ircd::m::room
|
|||
struct members;
|
||||
struct origins;
|
||||
struct head;
|
||||
struct auth;
|
||||
struct power;
|
||||
|
||||
using id = m::id::room;
|
||||
|
|
|
@ -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
|
||||
//
|
||||
|
|
|
@ -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
|
||||
//
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue