From 58a98806e97dac09457ac235675fe5be547f2105 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 1 Mar 2019 12:57:04 -0800 Subject: [PATCH] ircd::m::user::room_account_data: Expose type prefixing in interface. --- include/ircd/m/user.h | 10 ++++++++++ modules/client/user/rooms.cc | 22 +++++----------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/include/ircd/m/user.h b/include/ircd/m/user.h index bfd33f4c7..aa9c531c6 100644 --- a/include/ircd/m/user.h +++ b/include/ircd/m/user.h @@ -227,6 +227,16 @@ struct ircd::m::user::room_account_data using closure_bool = std::function; using closure = std::function; + static constexpr const string_view &type_prefix + { + "ircd.account_data" + }; + + static constexpr const size_t &typebuf_size + { + m::room::id::MAX_SIZE + size(type_prefix) + }; + m::user user; m::room room; diff --git a/modules/client/user/rooms.cc b/modules/client/user/rooms.cc index eb3456102..2d2d37624 100644 --- a/modules/client/user/rooms.cc +++ b/modules/client/user/rooms.cc @@ -161,18 +161,6 @@ get__account_data(client &client, return {}; // responded from closure } -constexpr string_view -room_account_data_type_prefix -{ - "ircd.account_data"_sv -}; - -constexpr size_t -room_account_data_typebuf_size -{ - m::room::id::MAX_SIZE + size(room_account_data_type_prefix) -}; - m::event::id::buf IRCD_MODULE_EXPORT ircd::m::user::room_account_data::set(const m::user &user, @@ -180,7 +168,7 @@ ircd::m::user::room_account_data::set(const m::user &user, const string_view &user_type, const json::object &value) { - char typebuf[room_account_data_typebuf_size]; + char typebuf[typebuf_size]; const string_view type { _type(typebuf, room.room_id) @@ -202,7 +190,7 @@ ircd::m::user::room_account_data::get(std::nothrow_t, const string_view &user_type, const closure &closure) { - char typebuf[room_account_data_typebuf_size]; + char typebuf[typebuf_size]; const string_view type { _type(typebuf, room.room_id) @@ -228,7 +216,7 @@ ircd::m::user::room_account_data::for_each(const m::user &user, const m::room &room, const closure_bool &closure) { - char typebuf[room_account_data_typebuf_size]; + char typebuf[typebuf_size]; const string_view type { _type(typebuf, room.room_id) @@ -267,10 +255,10 @@ IRCD_MODULE_EXPORT ircd::m::user::room_account_data::_type(const mutable_buffer &out, const m::room::id &room_id) { - assert(size(out) >= room_account_data_typebuf_size); + assert(size(out) >= typebuf_size); string_view ret; - ret = strlcpy(out, room_account_data_type_prefix); + ret = strlcpy(out, type_prefix); ret = strlcat(out, room_id); return ret; }