2019-01-04 02:21:02 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 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
|
|
|
|
{
|
|
|
|
"Client Sync :Room Timeline"
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace ircd::m::sync
|
|
|
|
{
|
2019-01-10 05:39:12 +01:00
|
|
|
static event::id::buf _room_timeline_polylog_events(data &, const m::room &, bool &);
|
2019-01-10 22:19:07 +01:00
|
|
|
static void room_timeline_polylog(data &);
|
2019-01-10 05:39:12 +01:00
|
|
|
|
|
|
|
static event::id::buf _room_timeline_linear_events(data &, const m::room &, bool &);
|
2019-01-10 22:19:07 +01:00
|
|
|
static void room_timeline_linear(data &);
|
2019-01-10 05:39:12 +01:00
|
|
|
|
|
|
|
extern const event::keys::include default_keys;
|
2019-01-04 02:21:02 +01:00
|
|
|
extern item room_timeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::m::sync::room_timeline)
|
|
|
|
ircd::m::sync::room_timeline
|
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
"rooms.timeline",
|
2019-01-10 05:39:12 +01:00
|
|
|
room_timeline_polylog,
|
|
|
|
room_timeline_linear,
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::sync::default_keys)
|
|
|
|
ircd::m::sync::default_keys
|
|
|
|
{
|
|
|
|
"content",
|
|
|
|
"depth",
|
|
|
|
"event_id",
|
|
|
|
"origin_server_ts",
|
|
|
|
"prev_events",
|
|
|
|
"redacts",
|
|
|
|
"room_id",
|
|
|
|
"sender",
|
|
|
|
"state_key",
|
|
|
|
"type",
|
2019-01-04 02:21:02 +01:00
|
|
|
};
|
|
|
|
|
2019-01-10 22:19:07 +01:00
|
|
|
void
|
2019-01-10 05:39:12 +01:00
|
|
|
ircd::m::sync::room_timeline_linear(data &data)
|
2019-01-04 02:21:02 +01:00
|
|
|
{
|
2019-01-10 22:19:07 +01:00
|
|
|
return;
|
2019-01-10 05:39:12 +01:00
|
|
|
|
2019-01-09 00:10:06 +01:00
|
|
|
json::stack::object object
|
|
|
|
{
|
|
|
|
data.out
|
|
|
|
};
|
2019-01-04 02:21:02 +01:00
|
|
|
|
2019-01-10 05:39:12 +01:00
|
|
|
m::room room;
|
|
|
|
|
2019-01-04 02:21:02 +01:00
|
|
|
// events
|
|
|
|
bool limited{false};
|
2019-01-09 00:10:06 +01:00
|
|
|
m::event::id::buf prev
|
2019-01-04 02:21:02 +01:00
|
|
|
{
|
2019-01-10 05:39:12 +01:00
|
|
|
_room_timeline_linear_events(data, room, limited)
|
2019-01-09 00:10:06 +01:00
|
|
|
};
|
2019-01-04 02:21:02 +01:00
|
|
|
|
|
|
|
// prev_batch
|
|
|
|
json::stack::member
|
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
object, "prev_batch", string_view{prev}
|
2019-01-04 02:21:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// limited
|
|
|
|
json::stack::member
|
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
object, "limited", json::value{limited}
|
2019-01-04 02:21:02 +01:00
|
|
|
};
|
|
|
|
|
2019-01-10 22:19:07 +01:00
|
|
|
return;
|
2019-01-04 02:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::event::id::buf
|
2019-01-10 05:39:12 +01:00
|
|
|
ircd::m::sync::_room_timeline_linear_events(data &data,
|
|
|
|
const m::room &room,
|
|
|
|
bool &limited)
|
2019-01-04 02:21:02 +01:00
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
json::stack::array array
|
|
|
|
{
|
|
|
|
data.out, "events"
|
|
|
|
};
|
|
|
|
|
2019-01-10 05:39:12 +01:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-01-10 22:19:07 +01:00
|
|
|
void
|
2019-01-10 05:39:12 +01:00
|
|
|
ircd::m::sync::room_timeline_polylog(data &data)
|
|
|
|
{
|
|
|
|
json::stack::object object
|
|
|
|
{
|
|
|
|
data.out
|
|
|
|
};
|
|
|
|
|
|
|
|
// events
|
|
|
|
bool limited{false};
|
|
|
|
m::event::id::buf prev
|
2019-01-04 02:21:02 +01:00
|
|
|
{
|
2019-01-10 05:39:12 +01:00
|
|
|
_room_timeline_polylog_events(data, *data.room, limited)
|
|
|
|
};
|
|
|
|
|
|
|
|
// prev_batch
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
object, "prev_batch", string_view{prev}
|
|
|
|
};
|
|
|
|
|
|
|
|
// limited
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
object, "limited", json::value{limited}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::event::id::buf
|
|
|
|
ircd::m::sync::_room_timeline_polylog_events(data &data,
|
|
|
|
const m::room &room,
|
|
|
|
bool &limited)
|
|
|
|
{
|
|
|
|
static const event::fetch::opts fopts
|
|
|
|
{
|
|
|
|
default_keys
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::array array
|
|
|
|
{
|
|
|
|
data.out, "events"
|
2019-01-04 02:21:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// messages seeks to the newest event, but the client wants the oldest
|
|
|
|
// event first so we seek down first and then iterate back up. Due to
|
|
|
|
// an issue with rocksdb's prefix-iteration this iterator becomes
|
|
|
|
// toxic as soon as it becomes invalid. As a result we have to copy the
|
|
|
|
// event_id on the way down in case of renewing the iterator for the
|
|
|
|
// way back. This is not a big deal but rocksdb should fix their shit.
|
|
|
|
ssize_t i(0);
|
|
|
|
m::event::id::buf event_id;
|
|
|
|
m::room::messages it
|
|
|
|
{
|
|
|
|
room, &fopts
|
|
|
|
};
|
|
|
|
|
|
|
|
for(; it && i < 10; --it, ++i)
|
|
|
|
{
|
|
|
|
event_id = it.event_id();
|
2019-01-10 22:19:07 +01:00
|
|
|
if(it.event_idx() < data.range.first)
|
2019-01-04 02:21:02 +01:00
|
|
|
break;
|
|
|
|
|
2019-01-10 22:19:07 +01:00
|
|
|
if(it.event_idx() >= data.range.second)
|
2019-01-04 02:21:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
limited = i >= 10;
|
|
|
|
if(i > 0)
|
|
|
|
data.commit();
|
|
|
|
|
|
|
|
if(i > 0 && !it)
|
|
|
|
it.seek(event_id);
|
|
|
|
|
|
|
|
if(i > 0 && it)
|
|
|
|
{
|
2019-01-10 05:39:12 +01:00
|
|
|
data.commit();
|
2019-01-09 00:10:06 +01:00
|
|
|
//const m::event &event{*it};
|
|
|
|
//data.state_at = at<"depth"_>(event);
|
2019-01-04 02:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(i > 0)
|
|
|
|
for(; it && i > -1; ++it, --i)
|
2019-01-11 01:56:32 +01:00
|
|
|
{
|
|
|
|
json::stack::object object
|
|
|
|
{
|
|
|
|
array
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::event &event(*it);
|
|
|
|
object.append(event);
|
|
|
|
|
|
|
|
json::stack::object unsigned_
|
|
|
|
{
|
|
|
|
object, "unsigned"
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
unsigned_, "age", json::value
|
|
|
|
{
|
|
|
|
long(vm::current_sequence - it.event_idx())
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-01-04 02:21:02 +01:00
|
|
|
|
|
|
|
return event_id;
|
|
|
|
}
|