From 8d6dfa7cd54103a62af48f1351b1c94de3bc0a78 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 23 Mar 2020 20:31:21 -0700 Subject: [PATCH] ircd::m: Add room_id(event_idx) to convenience suite. --- include/ircd/m/room/room.h | 2 ++ matrix/room.cc | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/ircd/m/room/room.h b/include/ircd/m/room/room.h index 75d92fb1e..97ee1f685 100644 --- a/include/ircd/m/room/room.h +++ b/include/ircd/m/room/room.h @@ -49,9 +49,11 @@ namespace ircd::m string_view display_name(const mutable_buffer &out, const room &); id::user::buf any_user(const room &, const string_view &host, const string_view &memshp = "join"); + id::room room_id(const mutable_buffer &, const event::idx &); // db id::room room_id(const mutable_buffer &, const id::event &); // db id::room room_id(const mutable_buffer &, const id::room_alias &); // db + net id::room room_id(const mutable_buffer &, const string_view &mxid); + id::room::buf room_id(const event::idx &); // db id::room::buf room_id(const id::event &); // db id::room::buf room_id(const id::room_alias &); // db + net id::room::buf room_id(const string_view &id_or_alias); diff --git a/matrix/room.cc b/matrix/room.cc index 787b6b093..26480c03c 100644 --- a/matrix/room.cc +++ b/matrix/room.cc @@ -363,6 +363,14 @@ ircd::m::room_id(const string_view &mxid) return room_id(buf, mxid); } +ircd::m::id::room::buf +ircd::m::room_id(const event::idx &event_idx) +{ + char buf[m::id::MAX_SIZE + 1]; + static_assert(sizeof(buf) <= 256); + return room_id(buf, event_idx); +} + ircd::m::id::room ircd::m::room_id(const mutable_buffer &out, const string_view &mxid) @@ -392,6 +400,20 @@ ircd::m::room_id(const mutable_buffer &out, } } +ircd::m::id::room +ircd::m::room_id(const mutable_buffer &out, + const event::idx &event_idx) +{ + room::id ret; + m::get(event_idx, "room_id", [&out, &ret] + (const room::id &room_id) + { + ret = string_view { data(out), copy(out, room_id) }; + }); + + return ret; +} + ircd::m::id::room ircd::m::room_id(const mutable_buffer &out, const id::event &event_id)