From cc9ce9c8a53e6ec9e9493879d1a21ca210a58449 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 22 Jul 2019 14:29:00 -0700 Subject: [PATCH] ircd::m::room: Move timeline definitions to module. --- ircd/m.cc | 1 + ircd/m_room.cc | 114 --------------------------------- modules/Makefile.am | 2 + modules/m_room_timeline.cc | 125 +++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 114 deletions(-) create mode 100644 modules/m_room_timeline.cc diff --git a/ircd/m.cc b/ircd/m.cc index 9fa03820f..674dabfee 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -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", diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 4e4282adf..db97a21c1 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -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 // diff --git a/modules/Makefile.am b/modules/Makefile.am index 14b69f7a3..6b06b2066 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -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 \ diff --git a/modules/m_room_timeline.cc b/modules/m_room_timeline.cc new file mode 100644 index 000000000..3e1aa59ae --- /dev/null +++ b/modules/m_room_timeline.cc @@ -0,0 +1,125 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2019 Jason Volk +// +// 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(); +}