mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd:Ⓜ️:user: Add interface definitions for push rule events to user room.
This commit is contained in:
parent
2aec995edd
commit
a3037b7cd4
2 changed files with 142 additions and 38 deletions
|
@ -14,18 +14,18 @@
|
|||
struct ircd::m::user::pushrules
|
||||
{
|
||||
using path = push::path;
|
||||
using closure_bool = std::function<bool ()>;
|
||||
using closure = std::function<void ()>;
|
||||
using closure_bool = std::function<bool (const path &, const json::object &)>;
|
||||
using closure = std::function<void (const path &, const json::object &)>;
|
||||
|
||||
m::user user;
|
||||
|
||||
public:
|
||||
bool for_each(const path &, const closure_bool &) const;
|
||||
bool for_each(const closure_bool &) const;
|
||||
|
||||
bool get(std::nothrow_t, const path &, const closure &) const;
|
||||
void get(const path &, const closure &) const;
|
||||
|
||||
event::id::buf set(const path &, const json::object &value) const;
|
||||
bool set(const path &, const json::object &value) const;
|
||||
bool del(const path &) const;
|
||||
|
||||
pushrules(const m::user &user) noexcept;
|
||||
};
|
||||
|
|
|
@ -8,17 +8,79 @@
|
|||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::user::pushrules::set(const path &path,
|
||||
const json::object &value)
|
||||
bool
|
||||
ircd::m::user::pushrules::del(const path &path)
|
||||
const
|
||||
{
|
||||
const auto &[scope, kind, ruleid]
|
||||
{
|
||||
path
|
||||
};
|
||||
|
||||
char typebuf[event::TYPE_MAX_SIZE];
|
||||
const string_view &type
|
||||
{
|
||||
push::make_type(typebuf, path)
|
||||
};
|
||||
|
||||
const m::user::room user_room
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
return {};
|
||||
const event::idx &event_idx
|
||||
{
|
||||
user_room.get(type, ruleid)
|
||||
};
|
||||
|
||||
const m::event::id::buf event_id
|
||||
{
|
||||
m::event_id(event_idx, std::nothrow)
|
||||
};
|
||||
|
||||
if(!event_id)
|
||||
return false;
|
||||
|
||||
const auto redact_id
|
||||
{
|
||||
m::redact(user_room, user, event_id, "deleted")
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::user::pushrules::set(const path &path,
|
||||
const json::object &content)
|
||||
const
|
||||
{
|
||||
const auto &[scope, kind, ruleid]
|
||||
{
|
||||
path
|
||||
};
|
||||
|
||||
const push::rule rule
|
||||
{
|
||||
content
|
||||
};
|
||||
|
||||
char typebuf[event::TYPE_MAX_SIZE];
|
||||
const string_view &type
|
||||
{
|
||||
push::make_type(typebuf, path)
|
||||
};
|
||||
|
||||
const m::user::room user_room
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
const auto rule_event_id
|
||||
{
|
||||
m::send(user_room, user, type, ruleid, content)
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -26,13 +88,18 @@ ircd::m::user::pushrules::get(const path &path,
|
|||
const closure &closure)
|
||||
const
|
||||
{
|
||||
const auto &[scope, kind, ruleid]
|
||||
{
|
||||
path
|
||||
};
|
||||
|
||||
if(!get(std::nothrow, path, closure))
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"push rule (%s,%s,%s) for user %s not found",
|
||||
std::get<0>(path),
|
||||
std::get<1>(path),
|
||||
std::get<2>(path),
|
||||
scope,
|
||||
kind,
|
||||
ruleid,
|
||||
string_view{user.user_id}
|
||||
};
|
||||
}
|
||||
|
@ -43,6 +110,57 @@ ircd::m::user::pushrules::get(std::nothrow_t,
|
|||
const closure &closure)
|
||||
const
|
||||
{
|
||||
const auto &[scope, kind, ruleid]
|
||||
{
|
||||
path
|
||||
};
|
||||
|
||||
char typebuf[event::TYPE_MAX_SIZE];
|
||||
const string_view &type
|
||||
{
|
||||
push::make_type(typebuf, path)
|
||||
};
|
||||
|
||||
const m::user::room user_room
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
const event::idx &event_idx
|
||||
{
|
||||
user_room.get(type, ruleid)
|
||||
};
|
||||
|
||||
return m::get(std::nothrow, event_idx, "content", [&path, &closure]
|
||||
(const json::object &content)
|
||||
{
|
||||
closure(path, content);
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::user::pushrules::for_each(const closure_bool &closure)
|
||||
const
|
||||
{
|
||||
return for_each(path{}, closure);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::user::pushrules::for_each(const path &path,
|
||||
const closure_bool &closure)
|
||||
const
|
||||
{
|
||||
const auto &[scope, kind, ruleid]
|
||||
{
|
||||
path
|
||||
};
|
||||
|
||||
char typebuf[event::TYPE_MAX_SIZE];
|
||||
const room::state::type_prefix type
|
||||
{
|
||||
push::make_type(typebuf, path)
|
||||
};
|
||||
|
||||
const user::room user_room
|
||||
{
|
||||
user
|
||||
|
@ -53,32 +171,18 @@ const
|
|||
user_room
|
||||
};
|
||||
|
||||
const event::idx &event_idx
|
||||
return state.for_each(type, room::state::closure_bool{[&closure]
|
||||
(const string_view &type, const string_view &state_key, const m::event::idx &event_idx)
|
||||
{
|
||||
0U
|
||||
};
|
||||
const auto path
|
||||
{
|
||||
push::make_path(type, state_key)
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::user::pushrules::for_each(const closure_bool &closure)
|
||||
const
|
||||
{
|
||||
static const event::fetch::opts fopts
|
||||
{
|
||||
event::keys::include {"state_key", "content"}
|
||||
};
|
||||
|
||||
const user::room user_room
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
const room::state state
|
||||
{
|
||||
user_room, &fopts
|
||||
};
|
||||
|
||||
return true;
|
||||
return m::query<bool>(std::nothrow, event_idx, "content", true, [&path, &closure]
|
||||
(const json::object &content)
|
||||
{
|
||||
return closure(path, content);
|
||||
});
|
||||
}});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue