0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 08:42:34 +01:00

ircd:Ⓜ️:room: Move timeline definitions to module.

This commit is contained in:
Jason Volk 2019-07-22 14:29:00 -07:00
parent 6513fdf19f
commit cc9ce9c8a5
4 changed files with 128 additions and 114 deletions

View file

@ -210,6 +210,7 @@ ircd::m::module_names
"m_user_highlight",
"m_user_profile",
"m_ignored_user_list",
"m_room_timeline",
"m_room_aliases",
"m_room_canonical_alias",
"m_room_create",

View file

@ -1666,120 +1666,6 @@ const
return true;
}
//
// room::timeline
//
uint64_t
ircd::m::latency(const room::timeline &a,
const room::timeline &b)
{
return 0UL;
}
//
// room::timeline::timeline
//
ircd::m::room::timeline::timeline(const m::room &room)
:room{room}
{
}
bool
ircd::m::room::timeline::for_each(const closure &closure,
const coord &branch)
const
{
m::event::refs refs
{
room.event_id?
index(room.event_id):
room::index(room)
};
if(!refs.idx)
return true;
timeline::coord coord;
if(!closure(coord, refs.idx))
return false;
for(++coord.y; coord.y <= branch.y; ++coord.y, coord.x = 0)
{
auto idx(0);
refs.for_each(dbs::ref::NEXT, [&coord, &branch, &idx]
(const auto &event_idx, const auto &)
{
if(coord.x <= branch.x)
idx = event_idx;
if(coord.x < branch.x)
{
++coord.x;
return true;
}
else return false;
});
if(!idx)
return true;
if(!closure(coord, idx))
return false;
refs.idx = idx;
}
return true;
}
bool
ircd::m::room::timeline::has_future(const event::id &event_id)
const
{
return true;
}
bool
ircd::m::room::timeline::has_past(const event::id &event_id)
const
{
return true;
}
void
ircd::m::room::timeline::rebuild(const m::room &room)
{
m::room::messages it
{
room, 0UL
};
if(!it)
return;
db::txn txn
{
*m::dbs::events
};
for(; it; ++it)
{
const m::event &event{*it};
m::dbs::write_opts opts;
opts.event_idx = it.event_idx();
opts.appendix.reset();
opts.appendix.set(dbs::appendix::EVENT_REFS);
opts.event_refs.reset();
opts.event_refs.set(uint(dbs::ref::NEXT));
m::dbs::write(txn, event, opts);
}
txn();
}
//
// room::messages
//

View file

@ -109,6 +109,7 @@ m_ignored_user_list_la_SOURCES = m_ignored_user_list.cc
m_breadcrumb_rooms_la_SOURCES = m_breadcrumb_rooms.cc
m_events_la_SOURCES = m_events.cc
m_rooms_la_SOURCES = m_rooms.cc
m_room_timeline_la_SOURCES = m_room_timeline.cc
m_room_create_la_SOURCES = m_room_create.cc
m_room_member_la_SOURCES = m_room_member.cc
m_room_join_rules_la_SOURCES = m_room_join_rules.cc
@ -146,6 +147,7 @@ m_module_LTLIBRARIES = \
m_breadcrumb_rooms.la \
m_events.la \
m_rooms.la \
m_room_timeline.la \
m_room_create.la \
m_room_member.la \
m_room_join_rules.la \

125
modules/m_room_timeline.cc Normal file
View file

@ -0,0 +1,125 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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::mapi::header
IRCD_MODULE
{
"Matrix room library; timeline modular components."
};
uint64_t
ircd::m::latency(const room::timeline &a,
const room::timeline &b)
{
return 0UL;
}
//
// room::timeline::timeline
//
ircd::m::room::timeline::timeline(const m::room &room)
:room{room}
{
}
bool
ircd::m::room::timeline::for_each(const closure &closure,
const coord &branch)
const
{
m::event::refs refs
{
room.event_id?
index(room.event_id):
room::index(room)
};
if(!refs.idx)
return true;
timeline::coord coord;
if(!closure(coord, refs.idx))
return false;
for(++coord.y; coord.y <= branch.y; ++coord.y, coord.x = 0)
{
auto idx(0);
refs.for_each(dbs::ref::NEXT, [&coord, &branch, &idx]
(const auto &event_idx, const auto &)
{
if(coord.x <= branch.x)
idx = event_idx;
if(coord.x < branch.x)
{
++coord.x;
return true;
}
else return false;
});
if(!idx)
return true;
if(!closure(coord, idx))
return false;
refs.idx = idx;
}
return true;
}
bool
ircd::m::room::timeline::has_future(const event::id &event_id)
const
{
return true;
}
bool
ircd::m::room::timeline::has_past(const event::id &event_id)
const
{
return true;
}
void
ircd::m::room::timeline::rebuild(const m::room &room)
{
m::room::messages it
{
room, 0UL
};
if(!it)
return;
db::txn txn
{
*m::dbs::events
};
for(; it; ++it)
{
const m::event &event{*it};
m::dbs::write_opts opts;
opts.event_idx = it.event_idx();
opts.appendix.reset();
opts.appendix.set(dbs::appendix::EVENT_REFS);
opts.event_refs.reset();
opts.event_refs.set(uint(dbs::ref::NEXT));
m::dbs::write(txn, event, opts);
}
txn();
}