From 9c68d01d866965ef7afbea67b40a5c9a7b60c30c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 12 Sep 2019 10:14:08 -0700 Subject: [PATCH] ircd::m::room: Remove cruft. --- include/ircd/m/room/room.h | 2 - include/ircd/m/room/timeline.h | 49 ----------- ircd/m.cc | 1 - modules/Makefile.am | 2 - modules/console.cc | 97 --------------------- modules/m_room_timeline.cc | 152 --------------------------------- 6 files changed, 303 deletions(-) delete mode 100644 include/ircd/m/room/timeline.h delete mode 100644 modules/m_room_timeline.cc diff --git a/include/ircd/m/room/room.h b/include/ircd/m/room/room.h index df0d6e41c..b3c8e21e0 100644 --- a/include/ircd/m/room/room.h +++ b/include/ircd/m/room/room.h @@ -107,7 +107,6 @@ namespace ircd::m struct ircd::m::room { struct events; - struct timeline; struct state; struct members; struct origins; @@ -193,7 +192,6 @@ struct ircd::m::room }; #include "events.h" -#include "timeline.h" #include "state.h" #include "state_space.h" #include "state_history.h" diff --git a/include/ircd/m/room/timeline.h b/include/ircd/m/room/timeline.h deleted file mode 100644 index d1e3605b9..000000000 --- a/include/ircd/m/room/timeline.h +++ /dev/null @@ -1,49 +0,0 @@ -// 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. - -#pragma once -#define HAVE_IRCD_M_ROOM_TIMELINE_H - -namespace ircd::m -{ - uint64_t latency(const room::timeline &, const room::timeline &); -} - -/// Interface to room timeline -/// -struct ircd::m::room::timeline -{ - struct coord; - using closure = std::function; - - m::room room; - - public: - static event::idx next(const event::idx &, const int64_t &x = 0); - - bool has_past(const event::id &) const; - bool has_future(const event::id &) const; - - bool for_each(coord &, const closure &) const; - bool for_each(const closure &) const; - - timeline(const m::room &); - timeline() = default; - timeline(const timeline &) = delete; - timeline &operator=(const timeline &) = delete; - - static void rebuild(const m::room &); -}; - -struct ircd::m::room::timeline::coord -{ - int64_t x {0}; - int64_t y {0}; -}; diff --git a/ircd/m.cc b/ircd/m.cc index fb4fb2e20..102cb6500 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -213,7 +213,6 @@ ircd::m::module_names "m_room_events", "m_room_auth", "m_room_head", - "m_room_timeline", "m_room_aliases", "m_room_canonical_alias", "m_room_create", diff --git a/modules/Makefile.am b/modules/Makefile.am index 359f9ef38..4443a9717 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -134,7 +134,6 @@ m_room_la_SOURCES = m_room.cc m_room_events_la_SOURCES = m_room_events.cc m_room_auth_la_SOURCES = m_room_auth.cc m_room_head_la_SOURCES = m_room_head.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_la_SOURCES = m_room_join.cc @@ -194,7 +193,6 @@ m_module_LTLIBRARIES = \ m_room_events.la \ m_room_auth.la \ m_room_head.la \ - m_room_timeline.la \ m_room_create.la \ m_room_member.la \ m_room_join.la \ diff --git a/modules/console.cc b/modules/console.cc index c7ec8c01f..191ba9659 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -9857,103 +9857,6 @@ console_cmd__room__messages(opt &out, const string_view &line) return true; } -bool -console_cmd__room__timeline(opt &out, const string_view &line) -{ - const params param{line, " ", - { - "room_id", "x", "y" - }}; - - const auto &room_id - { - m::room_id(param.at("room_id")) - }; - - const m::room room - { - room_id - }; - - const m::room::timeline timeline - { - room - }; - - const auto closure{[&out, &room] - (auto &coord, const auto &event_idx) - -> m::room::timeline::coord & - { - if(coord.y > m::depth(std::nothrow, room)) - return coord; - - if(!event_idx) - { - ++coord.y; - return coord; - } - - const m::event::fetch event - { - event_idx, std::nothrow - }; - - if(!event.valid) - { - ++coord.x; - return coord; - } - - out << "(" - << std::left - << std::setw(2) << coord.x - << " " - << std::right - << std::setw(3) << coord.y - << ") " - << std::left - << std::setw(11) << event_idx - << " " - << pretty_oneline(event, false) - << std::endl; - - ++coord.x; - return coord; - }}; - - m::room::timeline::coord coord - { - param.at("x", 0L), - param.at("y", 0L), - }; - - timeline.for_each(coord, closure); - return true; -} - -bool -console_cmd__room__timeline__rebuild(opt &out, const string_view &line) -{ - const params param{line, " ", - { - "room_id" - }}; - - const auto &room_id - { - m::room_id(param.at("room_id")) - }; - - const m::room room - { - room_id - }; - - m::room::timeline::rebuild(room); - out << "done" << std::endl; - return true; -} - bool console_cmd__room__get(opt &out, const string_view &line) { diff --git a/modules/m_room_timeline.cc b/modules/m_room_timeline.cc deleted file mode 100644 index 541c80d79..000000000 --- a/modules/m_room_timeline.cc +++ /dev/null @@ -1,152 +0,0 @@ -// 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 -{ - struct coord coord; - return for_each(coord, closure); -} - -bool -ircd::m::room::timeline::for_each(coord &coord, - const closure &closure) -const -{ - events it - { - this->room, uint64_t(coord.y) - }; - - if(!it) - return true; - - event::idx next(it.event_idx()); do - { - const auto last(coord); - coord = closure(coord, next); - if(coord.x == last.x && coord.y == last.y) - return true; - - if(coord.y != last.y) - if(!it.seek(coord.y)) - return true; - - next = timeline::next(it.event_idx(), coord.x); - if(next == 0 && coord.x == 0) - continue; - - if(next == it.event_idx()) - return false; - - if(next == 0) - coord.x = 0; - } - while(1); - - 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; -} - -// -// static util -// - -void -ircd::m::room::timeline::rebuild(const m::room &room) -{ - m::room::events 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(); -} - -ircd::m::event::idx -ircd::m::room::timeline::next(const event::idx &event_idx, - const int64_t &x) -{ - const m::event::refs refs - { - event_idx - }; - - int64_t _x(0); - event::idx ret(0); - refs.for_each(dbs::ref::NEXT, [&_x, &x, &ret] - (const auto &event_idx, const auto &) - { - if(_x++ < x) - return true; - - ret = event_idx; - return false; - }); - - return ret; -}