mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd:Ⓜ️:room: Add aliases interface.
This commit is contained in:
parent
19ca15eff7
commit
317fa612fb
5 changed files with 166 additions and 0 deletions
|
@ -85,4 +85,5 @@ namespace ircd::m
|
|||
#include "room/head.h"
|
||||
#include "room/auth.h"
|
||||
#include "room/power.h"
|
||||
#include "room/aliases.h"
|
||||
#include "room/stats.h"
|
||||
|
|
34
include/ircd/m/room/aliases.h
Normal file
34
include/ircd/m/room/aliases.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2019 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_MEMBERS_H
|
||||
|
||||
/// Interface to the aliases
|
||||
///
|
||||
/// This interface focuses specifically on room aliases. These are aliases contained
|
||||
/// in a room's state.
|
||||
///
|
||||
struct ircd::m::room::aliases
|
||||
{
|
||||
using closure_bool = std::function<bool (const alias &)>;
|
||||
|
||||
m::room room;
|
||||
|
||||
bool for_each(const string_view &server, const closure_bool &) const;
|
||||
bool for_each(const closure_bool &) const;
|
||||
bool has(const alias &) const;
|
||||
size_t count(const string_view &server) const;
|
||||
size_t count() const;
|
||||
|
||||
aliases(const m::room &room)
|
||||
:room{room}
|
||||
{}
|
||||
};
|
|
@ -37,6 +37,7 @@ struct ircd::m::room
|
|||
struct head;
|
||||
struct auth;
|
||||
struct power;
|
||||
struct aliases;
|
||||
struct stats;
|
||||
|
||||
using id = m::id::room;
|
||||
|
|
|
@ -2359,6 +2359,103 @@ ircd::m::room::auth::make_refs(const auth &a,
|
|||
return call(a, out, t, u);
|
||||
}
|
||||
|
||||
//
|
||||
// room::aliases
|
||||
//
|
||||
|
||||
size_t
|
||||
ircd::m::room::aliases::count()
|
||||
const
|
||||
{
|
||||
return count(string_view{});
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::room::aliases::count(const string_view &server)
|
||||
const
|
||||
{
|
||||
size_t ret(0);
|
||||
for_each(server, [&ret](const auto &a)
|
||||
{
|
||||
++ret;
|
||||
return true;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::aliases::has(const alias &alias)
|
||||
const
|
||||
{
|
||||
return !for_each(alias.host(), [&alias]
|
||||
(const id::room_alias &a)
|
||||
{
|
||||
assert(a.host() == alias.host());
|
||||
return a == alias? false : true; // false to break on found
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::aliases::for_each(const closure_bool &closure)
|
||||
const
|
||||
{
|
||||
const room::state state
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
return state.for_each("m.room.aliases", room::state::keys_bool{[this, &closure]
|
||||
(const string_view &state_key)
|
||||
{
|
||||
return for_each(state_key, closure);
|
||||
}});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::aliases::for_each(const string_view &server,
|
||||
const closure_bool &closure)
|
||||
const
|
||||
{
|
||||
if(!server)
|
||||
return for_each(closure);
|
||||
|
||||
const room::state state
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
const event::idx &event_idx
|
||||
{
|
||||
state.get(std::nothrow, "m.room.aliases", server)
|
||||
};
|
||||
|
||||
if(!event_idx)
|
||||
return true;
|
||||
|
||||
bool ret{true};
|
||||
m::get(std::nothrow, event_idx, "content", [&closure, &ret]
|
||||
(const json::object &content)
|
||||
{
|
||||
const json::array &aliases
|
||||
{
|
||||
content["aliases"]
|
||||
};
|
||||
|
||||
for(auto it(begin(aliases)); it != end(aliases) && ret; ++it)
|
||||
{
|
||||
const json::string &alias(*it);
|
||||
if(!valid(m::id::ROOM_ALIAS, alias))
|
||||
continue;
|
||||
|
||||
if(!closure(alias))
|
||||
ret = false;
|
||||
}
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// room::power
|
||||
//
|
||||
|
|
|
@ -7080,6 +7080,39 @@ console_cmd__room__visible(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__room__aliases(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"room_id", "server"
|
||||
}};
|
||||
|
||||
const auto &room_id
|
||||
{
|
||||
m::room_id(param.at(0))
|
||||
};
|
||||
|
||||
const string_view &server
|
||||
{
|
||||
param["server"]
|
||||
};
|
||||
|
||||
const m::room::aliases aliases
|
||||
{
|
||||
room_id
|
||||
};
|
||||
|
||||
aliases.for_each(server, [&out]
|
||||
(const m::room::alias &alias)
|
||||
{
|
||||
out << alias << std::endl;
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__room__members(opt &out, const string_view &line)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue