mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 23:14:13 +01:00
ircd:Ⓜ️:typing: Add an iteration of typist state w/ console cmd.
This commit is contained in:
parent
c5e066d078
commit
3188b03943
4 changed files with 85 additions and 0 deletions
|
@ -37,6 +37,13 @@ struct ircd::m::typing
|
|||
{
|
||||
struct commit;
|
||||
|
||||
using closure_bool = std::function<bool (const typing &)>;
|
||||
using closure = std::function<void (const typing &)>;
|
||||
|
||||
//NOTE: no yielding in this iteration.
|
||||
static bool for_each(const closure_bool &);
|
||||
static void for_each(const closure &);
|
||||
|
||||
using edu::m_typing::m_typing;
|
||||
};
|
||||
|
||||
|
|
32
ircd/m/m.cc
32
ircd/m/m.cc
|
@ -800,6 +800,10 @@ ircd::m::receipt::read(const id::room &room_id,
|
|||
// m/typing.h
|
||||
//
|
||||
|
||||
//
|
||||
// m::typing::commit::commit
|
||||
//
|
||||
|
||||
ircd::m::typing::commit::commit(const m::typing &object)
|
||||
:ircd::m::event::id::buf{[&object]
|
||||
{
|
||||
|
@ -815,6 +819,34 @@ ircd::m::typing::commit::commit(const m::typing &object)
|
|||
{
|
||||
}
|
||||
|
||||
//
|
||||
// m::typing util
|
||||
//
|
||||
|
||||
void
|
||||
ircd::m::typing::for_each(const closure &closure)
|
||||
{
|
||||
for_each(closure_bool{[&closure]
|
||||
(const auto &event)
|
||||
{
|
||||
closure(event);
|
||||
return true;
|
||||
}});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::typing::for_each(const closure_bool &closure)
|
||||
{
|
||||
using prototype = bool (const m::typing::closure_bool &);
|
||||
|
||||
static mods::import<prototype> function
|
||||
{
|
||||
"m_typing", "for_each"
|
||||
};
|
||||
|
||||
return function(closure);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// m/presence.h
|
||||
|
|
|
@ -6471,6 +6471,22 @@ console_cmd__user__events__count(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// typing
|
||||
//
|
||||
|
||||
bool
|
||||
console_cmd__typing(opt &out, const string_view &line)
|
||||
{
|
||||
m::typing::for_each([&out]
|
||||
(const m::typing &event)
|
||||
{
|
||||
out << event << std::endl;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// node
|
||||
//
|
||||
|
|
|
@ -35,6 +35,7 @@ std::set<typist, typist> typists;
|
|||
static system_point calc_timesout(milliseconds relative);
|
||||
static bool update_state(const m::typing &);
|
||||
extern "C" m::event::id::buf commit(const m::typing &edu);
|
||||
extern "C" bool for_each(const m::typing::closure_bool &);
|
||||
|
||||
//
|
||||
// typing commit handler stack (local user)
|
||||
|
@ -245,6 +246,35 @@ timeout_timeout(const typist &t)
|
|||
// misc
|
||||
//
|
||||
|
||||
bool
|
||||
for_each(const m::typing::closure_bool &closure)
|
||||
{
|
||||
// User cannot yield in their closure because the iteration
|
||||
// may be invalidated by the timeout worker during their yield.
|
||||
const ctx::critical_assertion ca;
|
||||
|
||||
for(const auto &t : typists)
|
||||
{
|
||||
const time_t timeout
|
||||
{
|
||||
system_clock::to_time_t(t.timesout)
|
||||
};
|
||||
|
||||
const m::typing event
|
||||
{
|
||||
{ "user_id", t.user_id },
|
||||
{ "room_id", t.room_id },
|
||||
{ "typing", true },
|
||||
{ "timeout", timeout },
|
||||
};
|
||||
|
||||
if(!closure(event))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
update_state(const m::typing &object)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue