mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd:Ⓜ️ Move filters into the user's user room.
This commit is contained in:
parent
9c145394f9
commit
67fba3cd7b
4 changed files with 102 additions and 62 deletions
|
@ -77,14 +77,16 @@ struct ircd::m::filter
|
|||
json::property<name::presence, event_filter>
|
||||
>
|
||||
{
|
||||
static room filters;
|
||||
|
||||
using super_type::tuple;
|
||||
using super_type::operator=;
|
||||
|
||||
static size_t size(const string_view &filter_id);
|
||||
using closure = std::function<void (const json::object &)>;
|
||||
|
||||
filter(const string_view &filter_id, const mutable_buffer &);
|
||||
static bool get(std::nothrow_t, const user &, const string_view &filter_id, const closure &);
|
||||
static void get(const user &, const string_view &filter_id, const closure &);
|
||||
static string_view set(const mutable_buffer &id, const user &, const json::object &filter);
|
||||
|
||||
filter(const user &, const string_view &filter_id, const mutable_buffer &);
|
||||
};
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
|
117
ircd/m/filter.cc
117
ircd/m/filter.cc
|
@ -10,46 +10,93 @@
|
|||
|
||||
#include <ircd/m/m.h>
|
||||
|
||||
const ircd::m::room::id::buf
|
||||
filters_room_id
|
||||
{
|
||||
"filters", ircd::my_host()
|
||||
};
|
||||
|
||||
ircd::m::room
|
||||
ircd::m::filter::filters
|
||||
{
|
||||
filters_room_id
|
||||
};
|
||||
|
||||
ircd::m::filter::filter(const string_view &filter_id,
|
||||
ircd::m::filter::filter(const user &user,
|
||||
const string_view &filter_id,
|
||||
const mutable_buffer &buf)
|
||||
{
|
||||
size_t len{0};
|
||||
//TODO: really has to become event in user's room
|
||||
filters.get("ircd.filter"_sv, filter_id, [&buf, &len]
|
||||
(const m::event &event)
|
||||
get(user, filter_id, [this, &buf]
|
||||
(const json::object &filter)
|
||||
{
|
||||
len = copy(buf, json::get<"content"_>(event));
|
||||
});
|
||||
|
||||
new (this) filter{json::object{buf}};
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::filter::size(const string_view &filter_id)
|
||||
{
|
||||
size_t len{0};
|
||||
filters.get("ircd.filter"_sv, filter_id, [&len]
|
||||
(const m::event &event)
|
||||
{
|
||||
const string_view filter
|
||||
const size_t len
|
||||
{
|
||||
json::get<"content"_>(event)
|
||||
copy(buf, string_view{filter})
|
||||
};
|
||||
|
||||
len = size(filter);
|
||||
new (this) m::filter
|
||||
{
|
||||
json::object
|
||||
{
|
||||
data(buf), len
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::filter::set(const mutable_buffer &idbuf,
|
||||
const user &user,
|
||||
const json::object &filter)
|
||||
{
|
||||
const auto user_room_id
|
||||
{
|
||||
user.room_id()
|
||||
};
|
||||
|
||||
const m::room room
|
||||
{
|
||||
user_room_id
|
||||
};
|
||||
|
||||
const sha256::buf hash
|
||||
{
|
||||
sha256{filter}
|
||||
};
|
||||
|
||||
const string_view filter_id
|
||||
{
|
||||
b64encode_unpadded(idbuf, hash)
|
||||
};
|
||||
|
||||
send(room, user.user_id, "ircd.filter", filter_id, filter);
|
||||
return filter_id;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::filter::get(const user &user,
|
||||
const string_view &filter_id,
|
||||
const closure &closure)
|
||||
{
|
||||
if(!get(std::nothrow, user, filter_id, closure))
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"Filter not found"
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::filter::get(std::nothrow_t,
|
||||
const user &user,
|
||||
const string_view &filter_id,
|
||||
const closure &closure)
|
||||
{
|
||||
const auto user_room_id
|
||||
{
|
||||
user.room_id()
|
||||
};
|
||||
|
||||
const m::room room
|
||||
{
|
||||
user_room_id
|
||||
};
|
||||
|
||||
return room.get(std::nothrow, "ircd.filter", filter_id, [&closure]
|
||||
(const m::event &event)
|
||||
{
|
||||
const json::object &content
|
||||
{
|
||||
at<"content"_>(event)
|
||||
};
|
||||
|
||||
closure(content);
|
||||
});
|
||||
|
||||
return len;
|
||||
}
|
||||
|
|
|
@ -231,12 +231,6 @@ ircd::m::init::bootstrap()
|
|||
{ "name", "User Tokens" }
|
||||
});
|
||||
|
||||
create(filter::filters, me.user_id);
|
||||
send(filter::filters, me.user_id, "m.room.name", "",
|
||||
{
|
||||
{ "name", "User Filters Database" }
|
||||
});
|
||||
|
||||
_keys.bootstrap();
|
||||
|
||||
message(control, me.user_id, "Welcome to the control room.");
|
||||
|
|
|
@ -24,27 +24,23 @@ get_filter(client &client,
|
|||
const resource::request &request,
|
||||
const m::user::id &user_id)
|
||||
{
|
||||
m::event::id::buf filter_id
|
||||
char filter_id_buf[64];
|
||||
const auto filter_id
|
||||
{
|
||||
url::decode(request.parv[2], filter_id)
|
||||
url::decode(request.parv[2], filter_id_buf)
|
||||
};
|
||||
|
||||
//TODO: ??
|
||||
const unique_buffer<mutable_buffer> buffer
|
||||
m::filter::get(user_id, filter_id, [&client]
|
||||
(const json::object &filter)
|
||||
{
|
||||
m::filter::size(filter_id)
|
||||
};
|
||||
resource::response
|
||||
{
|
||||
client, filter
|
||||
};
|
||||
});
|
||||
|
||||
//TODO: get direct
|
||||
const m::filter filter
|
||||
{
|
||||
filter_id, buffer
|
||||
};
|
||||
|
||||
return resource::response
|
||||
{
|
||||
client, json::object{buffer}
|
||||
};
|
||||
// Responded from closure.
|
||||
return {};
|
||||
}
|
||||
|
||||
// (5.2) Uploads a new filter definition to the homeserver. Returns a filter ID that
|
||||
|
@ -105,9 +101,10 @@ post_filter(client &client,
|
|||
json::get<"presence"_>(request)
|
||||
};
|
||||
|
||||
char filter_id_buf[64];
|
||||
const auto filter_id
|
||||
{
|
||||
send(m::filter::filters, user_id, "ircd.filter"_sv, request.body)
|
||||
m::filter::set(filter_id_buf, user_id, request.body)
|
||||
};
|
||||
|
||||
return resource::response
|
||||
|
|
Loading…
Reference in a new issue