0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd:Ⓜ️ Split filter into compilation unit; reactivate interface.

This commit is contained in:
Jason Volk 2018-02-11 12:01:33 -08:00
parent f770a1638e
commit 939957c02a
4 changed files with 56 additions and 65 deletions

View file

@ -50,11 +50,11 @@ namespace ircd
#include "state.h"
#include "room.h"
#include "user.h"
#include "filter.h"
#include "request.h"
#include "session.h"
#include "v1/v1.h"
#include "vm.h"
#include "filter.h"
#include "keys.h"
#include "txn.h"

View file

@ -97,6 +97,7 @@ libircd_la_SOURCES = \
m/state.cc \
m/room.cc \
m/user.cc \
m/filter.cc \
m/request.cc \
m/v1.cc \
m/vm.cc \

54
ircd/m/filter.cc Normal file
View file

@ -0,0 +1,54 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 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.
#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,
const mutable_buffer &buf)
{
size_t len{0};
filters.get("ircd.filter"_sv, filter_id, [&buf, &len]
(const m::event &event)
{
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
{
json::get<"content"_>(event)
};
len = size(filter);
});
return len;
}

View file

@ -273,67 +273,3 @@ ircd::m::leave_ircd_room()
{
leave(my_room, me.user_id);
}
///////////////////////////////////////////////////////////////////////////////
//
// m/filter.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,
const mutable_buffer &buf)
{
const m::vm::query<m::vm::where::equal> query
{
{ "room_id", filters.room_id },
{ "type", "ircd.filter" },
{ "state_key", filter_id },
};
size_t len{0};
m::vm::test(query, [&buf, &len]
(const auto &event)
{
len = copy(buf, json::get<"content"_>(event));
return true;
});
new (this) filter{json::object{buf}};
}
size_t
ircd::m::filter::size(const string_view &filter_id)
{
const m::vm::query<m::vm::where::equal> query
{
{ "room_id", filters.room_id },
{ "type", "ircd.filter" },
{ "state_key", filter_id },
};
size_t ret{0};
m::vm::test(query, [&ret]
(const auto &event)
{
const string_view content
{
json::get<"content"_>(event)
};
ret = content.size();
return true;
});
return ret;
}