0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-03-16 22:41:46 +01:00

ircd:Ⓜ️:user: Add unit and preliminary interface stubs for pushrules.

This commit is contained in:
Jason Volk 2020-03-17 21:57:44 -07:00
parent da736eb438
commit 0bb52f57a3
4 changed files with 124 additions and 0 deletions

View file

@ -0,0 +1,37 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 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.
#pragma once
#define HAVE_IRCD_M_USER_PUSHRULES_H
struct ircd::m::user::pushrules
{
using path = std::tuple<string_view, string_view, string_view>; // path, kind, ruleid
using closure_bool = std::function<bool ()>;
using closure = std::function<void ()>;
m::user user;
public:
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;
pushrules(const m::user &user) noexcept;
};
inline
ircd::m::user::pushrules::pushrules(const m::user &user)
noexcept
:user{user}
{}

View file

@ -43,6 +43,7 @@ struct ircd::m::user
struct ignores;
struct highlight;
struct registar;
struct pushrules;
using id = m::id::user;
using closure = std::function<void (const user &)>;
@ -92,3 +93,4 @@ const
#include "ignores.h"
#include "highlight.h"
#include "register.h"
#include "pushrules.h"

View file

@ -97,6 +97,7 @@ libircd_matrix_la_SOURCES += user_filter.cc
libircd_matrix_la_SOURCES += user_highlight.cc
libircd_matrix_la_SOURCES += user_mitsein.cc
libircd_matrix_la_SOURCES += user_profile.cc
libircd_matrix_la_SOURCES += user_pushrules.cc
libircd_matrix_la_SOURCES += user_register.cc
libircd_matrix_la_SOURCES += user_room_account_data.cc
libircd_matrix_la_SOURCES += user_room_tags.cc

84
matrix/user_pushrules.cc Normal file
View file

@ -0,0 +1,84 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 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::m::event::id::buf
ircd::m::user::pushrules::set(const path &path,
const json::object &value)
const
{
const m::user::room user_room
{
user
};
return {};
}
void
ircd::m::user::pushrules::get(const path &path,
const closure &closure)
const
{
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),
string_view{user.user_id}
};
}
bool
ircd::m::user::pushrules::get(std::nothrow_t,
const path &path,
const closure &closure)
const
{
const user::room user_room
{
user
};
const room::state state
{
user_room
};
const event::idx &event_idx
{
0U
};
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;
}