diff --git a/include/ircd/m/m.h b/include/ircd/m/m.h index 1a0970b9c..306fc2f88 100644 --- a/include/ircd/m/m.h +++ b/include/ircd/m/m.h @@ -59,6 +59,7 @@ namespace ircd #include "state.h" #include "vm.h" #include "room.h" +#include "rooms.h" #include "user.h" #include "node.h" #include "login.h" diff --git a/include/ircd/m/rooms.h b/include/ircd/m/rooms.h new file mode 100644 index 000000000..d6d7c2c98 --- /dev/null +++ b/include/ircd/m/rooms.h @@ -0,0 +1,22 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2018 Jason Volk +// +// 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_ROOMS_H + +/// Convenience iterface for iterations of rooms +/// +namespace ircd::m::rooms +{ + void for_each(const room::id::closure_bool &); + void for_each(const room::id::closure &); + void for_each(const room::closure_bool &); + void for_each(const room::closure &); +} diff --git a/ircd/m/m.cc b/ircd/m/m.cc index f13ff7fc3..bf46b5a4e 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -1229,6 +1229,58 @@ ircd::m::user::room::room(const m::user &user) static_cast(*this) = room_id; } +/////////////////////////////////////////////////////////////////////////////// +// +// m/rooms.h +// + +void +ircd::m::rooms::for_each(const room::closure &closure) +{ + for_each(room::closure_bool{[&closure] + (const room &room) + { + closure(room); + return true; + }}); +} + +void +ircd::m::rooms::for_each(const room::closure_bool &closure) +{ + for_each(room::id::closure_bool{[&closure] + (const room::id &room_id) + { + return closure(room_id); + }}); +} + +void +ircd::m::rooms::for_each(const room::id::closure &closure) +{ + for_each(room::id::closure_bool{[&closure] + (const room::id &room_id) + { + closure(room_id); + return true; + }}); +} + +void +ircd::m::rooms::for_each(const room::id::closure_bool &closure) +{ + const room::state state + { + my_room + }; + + state.test("ircd.room", room::state::keys_bool{[&closure] + (const string_view &key) + { + return !closure(key); + }}); +} + /////////////////////////////////////////////////////////////////////////////// // // m/room.h