0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

modules: Move m::device definitions from m_user to m_device.

This commit is contained in:
Jason Volk 2019-02-20 09:39:57 -08:00
parent 717214859c
commit 18a41f81f1
4 changed files with 113 additions and 96 deletions

View file

@ -1585,7 +1585,7 @@ ircd::m::device::set(const m::user &user,
static mods::import<prototype> 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<prototype> 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<prototype> 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<prototype> 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<prototype> function
{
"m_user", "ircd::m::device::for_each"
"m_device", "ircd::m::device::for_each"
};
return function(user, c);

View file

@ -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 \

106
modules/m_device.cc Normal file
View file

@ -0,0 +1,106 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
//
// 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);
}

View file

@ -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)