2018-11-29 23:54:50 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
2019-08-30 23:26:07 +02:00
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
2018-11-29 23:54:50 +01:00
|
|
|
//
|
|
|
|
// 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
|
2019-08-30 23:26:07 +02:00
|
|
|
#define HAVE_IRCD_M_ROOM_EVENTS_H
|
2018-11-29 23:54:50 +01:00
|
|
|
|
2019-08-30 23:26:07 +02:00
|
|
|
/// Interface to room events
|
2018-11-29 23:54:50 +01:00
|
|
|
///
|
2019-08-30 23:26:07 +02:00
|
|
|
/// This interface has the form of an STL-style iterator over room events
|
2018-11-29 23:54:50 +01:00
|
|
|
/// which are state and non-state events from all integrated timelines.
|
|
|
|
/// Moving the iterator is cheap, but the dereference operators fetch a
|
|
|
|
/// full event. One can iterate just event_idx's by using event_idx() instead
|
|
|
|
/// of the dereference operators.
|
|
|
|
///
|
2019-08-30 23:26:07 +02:00
|
|
|
struct ircd::m::room::events
|
2018-11-29 23:54:50 +01:00
|
|
|
{
|
2019-08-31 04:41:48 +02:00
|
|
|
struct sounding;
|
2019-08-31 08:15:00 +02:00
|
|
|
struct missing;
|
2023-02-17 05:41:09 +01:00
|
|
|
struct horizon;
|
2019-08-31 04:41:48 +02:00
|
|
|
|
2019-09-06 02:31:54 +02:00
|
|
|
static conf::item<ssize_t> viewport_size;
|
2019-09-06 01:17:19 +02:00
|
|
|
|
2018-11-29 23:54:50 +01:00
|
|
|
m::room room;
|
2019-06-11 21:55:14 +02:00
|
|
|
db::domain::const_iterator it;
|
2018-11-29 23:54:50 +01:00
|
|
|
event::fetch _event;
|
|
|
|
|
|
|
|
public:
|
2019-08-16 12:00:51 +02:00
|
|
|
explicit operator bool() const { return bool(it); }
|
2018-11-29 23:54:50 +01:00
|
|
|
bool operator!() const { return !it; }
|
|
|
|
|
2019-09-24 23:26:29 +02:00
|
|
|
// Observers from the current valid iterator
|
|
|
|
uint64_t depth() const;
|
|
|
|
event::idx event_idx() const;
|
2019-05-06 23:36:49 +02:00
|
|
|
explicit operator event::idx() const;
|
|
|
|
|
2019-09-24 23:26:29 +02:00
|
|
|
// Perform a new lookup / iterator
|
2021-02-11 07:26:00 +01:00
|
|
|
bool seek_idx(const event::idx &, const bool &lower_bound = false);
|
2019-02-05 03:10:23 +01:00
|
|
|
bool seek(const uint64_t &depth = -1);
|
2018-11-29 23:54:50 +01:00
|
|
|
bool seek(const event::id &);
|
|
|
|
|
2019-09-25 00:37:37 +02:00
|
|
|
// Prefetch a new iterator lookup (async)
|
|
|
|
bool preseek(const uint64_t &depth = -1);
|
|
|
|
|
2019-09-24 23:26:29 +02:00
|
|
|
// Move the iterator
|
2018-11-29 23:54:50 +01:00
|
|
|
auto &operator++() { return --it; }
|
|
|
|
auto &operator--() { return ++it; }
|
|
|
|
|
2019-09-24 23:26:29 +02:00
|
|
|
// Fetch the actual event data at the iterator's position
|
2023-02-10 20:35:12 +01:00
|
|
|
const m::event &fetch(std::nothrow_t, bool *valid = nullptr);
|
2019-09-24 23:26:29 +02:00
|
|
|
const m::event &fetch();
|
2023-02-10 20:35:12 +01:00
|
|
|
const m::event &operator*() { return fetch(std::nothrow); }
|
|
|
|
const m::event *operator->() { return &operator*(); }
|
2019-09-24 23:26:29 +02:00
|
|
|
|
2019-09-25 00:37:37 +02:00
|
|
|
// Prefetch the actual event data at the iterator's position (async)
|
2019-09-24 23:26:29 +02:00
|
|
|
bool prefetch(const string_view &event_prop);
|
|
|
|
bool prefetch(); // uses supplied fetch::opts.
|
2018-11-29 23:54:50 +01:00
|
|
|
|
2022-07-09 23:10:28 +02:00
|
|
|
// Seeks to closest event in the room by depth; room.event_id ignored.
|
2019-08-30 23:26:07 +02:00
|
|
|
events(const m::room &,
|
|
|
|
const uint64_t &depth,
|
|
|
|
const event::fetch::opts *const & = nullptr);
|
2018-11-29 23:54:50 +01:00
|
|
|
|
2022-07-09 23:10:28 +02:00
|
|
|
// Seeks to event_id; null iteration when not found; seekless when empty.
|
2019-08-30 23:26:07 +02:00
|
|
|
events(const m::room &,
|
|
|
|
const event::id &,
|
|
|
|
const event::fetch::opts *const & = nullptr);
|
2018-11-29 23:54:50 +01:00
|
|
|
|
2022-07-09 23:10:28 +02:00
|
|
|
// Seeks to latest event in the room unless room.event_id given. Null
|
|
|
|
// iteration when given and not found.
|
2019-08-30 23:26:07 +02:00
|
|
|
events(const m::room &,
|
|
|
|
const event::fetch::opts *const & = nullptr);
|
2018-11-29 23:54:50 +01:00
|
|
|
|
2019-08-30 23:26:07 +02:00
|
|
|
events() = default;
|
|
|
|
events(const events &) = delete;
|
|
|
|
events &operator=(const events &) = delete;
|
2019-08-30 23:50:11 +02:00
|
|
|
|
2019-09-25 00:37:37 +02:00
|
|
|
// Prefetch a new iterator (without any construction)
|
|
|
|
static bool preseek(const m::room &, const uint64_t &depth = -1);
|
|
|
|
|
|
|
|
// Prefetch the actual room event data for a range; or most recent.
|
|
|
|
using depth_range = std::pair<uint64_t, uint64_t>;
|
|
|
|
static size_t prefetch(const m::room &, const depth_range &);
|
|
|
|
static size_t prefetch_viewport(const m::room &);
|
|
|
|
|
2019-08-30 23:50:11 +02:00
|
|
|
// Note the range here is unusual: The start index is exclusive, the ending
|
|
|
|
// index is inclusive. The start index must be valid and in the room.
|
2019-09-24 06:48:29 +02:00
|
|
|
static size_t count(const m::room &, const event::idx_range &);
|
|
|
|
static size_t count(const event::idx_range &);
|
2018-11-29 23:54:50 +01:00
|
|
|
};
|