diff --git a/include/ircd/m/user/user.h b/include/ircd/m/user/user.h index dfe950ef0..4390e7aef 100644 --- a/include/ircd/m/user/user.h +++ b/include/ircd/m/user/user.h @@ -21,6 +21,8 @@ namespace ircd::m bool active(const user &); bool is_oper(const user &); + id::room::buf viewing(const user &, size_t i = 0); + user create(const id::user &, const json::members &args = {}); } diff --git a/matrix/user.cc b/matrix/user.cc index e91c2c9bf..913e02d6c 100644 --- a/matrix/user.cc +++ b/matrix/user.cc @@ -14,6 +14,29 @@ namespace ircd::m static room create_user_room(const user::id &, const room::id &, const json::members &contents); } +ircd::m::room::id::buf +ircd::m::viewing(const user &user, + size_t i) +{ + const m::breadcrumbs breadcrumbs + { + user + }; + + room::id::buf ret; + breadcrumbs.for_each([&ret, &i] + (const auto &room_id) + { + if(i-- > 0) + return true; + + ret = room_id; + return false; + }); + + return ret; +} + bool ircd::m::is_oper(const user &user) { diff --git a/modules/console.cc b/modules/console.cc index cbdaaddc4..0bc15628f 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -13535,6 +13535,38 @@ console_cmd__user__breadcrumbs(opt &out, const string_view &line) return true; } +bool +console_cmd__user__viewing(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "user_id", "idx" + }}; + + const m::user::id user_id + { + param.at("user_id") + }; + + const size_t idx + { + param.at("idx", 0UL) + }; + + const m::user user + { + user_id + }; + + const auto room_id + { + m::viewing(user, idx) + }; + + out << room_id << std::endl; + return true; +} + bool console_cmd__user__pushrules(opt &out, const string_view &line) {