diff --git a/ircd/m.cc b/ircd/m.cc index fe84ce055..8cd108f51 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -1585,7 +1585,7 @@ ircd::m::device::set(const m::user &user, static mods::import function { - "m_user", "ircd::m::device::set" + "m_device", "ircd::m::device::set" }; return function(user, device_); @@ -1599,7 +1599,7 @@ ircd::m::device::del(const m::user &user, static mods::import function { - "m_user", "ircd::m::device::del" + "m_device", "ircd::m::device::del" }; return function(user, id); @@ -1636,7 +1636,7 @@ ircd::m::device::get(std::nothrow_t, static mods::import function { - "m_user", "ircd::m::device::get" + "m_device", "ircd::m::device::get" }; return function(std::nothrow, user, id, c); @@ -1650,7 +1650,7 @@ ircd::m::device::for_each(const m::user &user, static mods::import function { - "m_user", "ircd::m::device::for_each" + "m_device", "ircd::m::device::for_each" }; return function(user, c); @@ -1664,7 +1664,7 @@ ircd::m::device::for_each(const m::user &user, static mods::import function { - "m_user", "ircd::m::device::for_each" + "m_device", "ircd::m::device::for_each" }; return function(user, c); diff --git a/modules/Makefile.am b/modules/Makefile.am index 353fb0889..ea2628416 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -102,6 +102,7 @@ m_moduledir = @moduledir@ m_noop_la_SOURCES = m_noop.cc m_user_la_SOURCES = m_user.cc m_event_la_SOURCES = m_event.cc +m_device_la_SOURCES = m_device.cc m_typing_la_SOURCES = m_typing.cc m_receipt_la_SOURCES = m_receipt.cc m_presence_la_SOURCES = m_presence.cc @@ -122,6 +123,7 @@ m_module_LTLIBRARIES = \ m_noop.la \ m_user.la \ m_event.la \ + m_device.la \ m_typing.la \ m_receipt.la \ m_presence.la \ diff --git a/modules/m_device.cc b/modules/m_device.cc new file mode 100644 index 000000000..5886ed9e2 --- /dev/null +++ b/modules/m_device.cc @@ -0,0 +1,106 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2019 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. + +ircd::mapi::header +IRCD_MODULE +{ + "Matrix device library; modular components." +}; + +bool +IRCD_MODULE_EXPORT +ircd::m::device::set(const m::user &user, + const device &device) +{ + return true; +} + +bool +IRCD_MODULE_EXPORT +ircd::m::device::del(const m::user &user, + const string_view &id) +{ + const m::user::room user_room{user}; + const m::room::state state{user_room}; + const m::event::idx event_idx + { + state.get(std::nothrow, "ircd.device", id) + }; + + if(!event_idx) + return false; + + const m::event::id::buf event_id + { + m::event_id(event_idx, std::nothrow) + }; + + m::redact(user_room, user, event_id, "deleted"); + return true; +} + +bool +IRCD_MODULE_EXPORT +ircd::m::device::get(std::nothrow_t, + const m::user &user, + const string_view &id, + const closure &closure) +{ + const m::user::room user_room{user}; + const m::room::state state{user_room}; + const m::event::idx event_idx + { + state.get(std::nothrow, "ircd.device", id) + }; + + if(!event_idx) + return false; + + return m::get(std::nothrow, event_idx, "content", [&closure] + (const json::object &content) + { + closure(content); + }); +} + +bool +IRCD_MODULE_EXPORT +ircd::m::device::for_each(const m::user &user, + const closure_bool &closure) +{ + return for_each(user, id_closure_bool{[&user, &closure] + (const string_view &device_id) + { + bool ret(true); + get(std::nothrow, user, device_id, [&closure, &ret] + (const device &device) + { + ret = closure(device); + }); + + return ret; + }}); +} + +bool +IRCD_MODULE_EXPORT +ircd::m::device::for_each(const m::user &user, + const id_closure_bool &closure) +{ + const m::room::state::keys_bool state_key{[&closure] + (const string_view &state_key) + { + return closure(state_key); + }}; + + const m::user::room user_room{user}; + const m::room::state state{user_room}; + return state.for_each("ircd.device", state_key); +} diff --git a/modules/m_user.cc b/modules/m_user.cc index e12396534..1ceb6cbc6 100644 --- a/modules/m_user.cc +++ b/modules/m_user.cc @@ -17,97 +17,6 @@ IRCD_MODULE "Matrix user library; modular components." }; -bool -IRCD_MODULE_EXPORT -ircd::m::device::set(const m::user &user, - const device &device) -{ - return true; -} - -bool -IRCD_MODULE_EXPORT -ircd::m::device::del(const m::user &user, - const string_view &id) -{ - const m::user::room user_room{user}; - const m::room::state state{user_room}; - const m::event::idx event_idx - { - state.get(std::nothrow, "ircd.device", id) - }; - - if(!event_idx) - return false; - - const m::event::id::buf event_id - { - m::event_id(event_idx, std::nothrow) - }; - - m::redact(user_room, user, event_id, "deleted"); - return true; -} - -bool -IRCD_MODULE_EXPORT -ircd::m::device::get(std::nothrow_t, - const m::user &user, - const string_view &id, - const closure &closure) -{ - const m::user::room user_room{user}; - const m::room::state state{user_room}; - const m::event::idx event_idx - { - state.get(std::nothrow, "ircd.device", id) - }; - - if(!event_idx) - return false; - - return m::get(std::nothrow, event_idx, "content", [&closure] - (const json::object &content) - { - closure(content); - }); -} - -bool -IRCD_MODULE_EXPORT -ircd::m::device::for_each(const m::user &user, - const closure_bool &closure) -{ - return for_each(user, id_closure_bool{[&user, &closure] - (const string_view &device_id) - { - bool ret(true); - get(std::nothrow, user, device_id, [&closure, &ret] - (const device &device) - { - ret = closure(device); - }); - - return ret; - }}); -} - -bool -IRCD_MODULE_EXPORT -ircd::m::device::for_each(const m::user &user, - const id_closure_bool &closure) -{ - const m::room::state::keys_bool state_key{[&closure] - (const string_view &state_key) - { - return closure(state_key); - }}; - - const m::user::room user_room{user}; - const m::room::state state{user_room}; - return state.for_each("ircd.device", state_key); -} - extern "C" m::user user_create(const m::user::id &user_id, const json::members &contents)