0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd:Ⓜ️ Elaborate room.maxdepth() into the m::head(room)/m::depth(room) (non-array) suite.

This commit is contained in:
Jason Volk 2018-02-08 20:59:48 -08:00
parent fd7792d32b
commit 39fed550cd
2 changed files with 46 additions and 29 deletions

View file

@ -24,7 +24,12 @@ namespace ircd::m
bool my(const room &);
bool exists(const id::room &);
// Lowest-level
// [GET] Current Event suite (non-locking) (one)
id::event::buf head(const id::room &, int64_t &); // gives depth
id::event::buf head(const id::room &);
int64_t depth(const id::room &);
// [SET] Lowest-level
event::id::buf commit(const room &, json::iov &event, const json::iov &content);
// Send state to room
@ -96,8 +101,6 @@ struct ircd::m::room
// observer misc
bool membership(const m::id::user &, const string_view &membership = "join") const;
int64_t maxdepth(event::id::buf &) const;
int64_t maxdepth() const;
// modify
room(const alias &, const event::id &event_id = {});

View file

@ -220,6 +220,46 @@ ircd::m::commit(const room &room,
return m::vm::commit(event, contents);
}
int64_t
ircd::m::depth(const id::room &room_id)
{
int64_t depth;
head(room_id, depth);
return depth;
}
ircd::m::id::event::buf
ircd::m::head(const id::room &room_id)
{
int64_t depth;
return head(room_id, depth);
}
ircd::m::id::event::buf
ircd::m::head(const id::room &room_id,
int64_t &depth)
{
const auto it
{
dbs::room_events.begin(room_id)
};
if(!it)
{
depth = -1;
return {};
}
const auto &key{it->first};
const auto part
{
dbs::room_events_key(key)
};
depth = std::get<0>(part);
return std::get<1>(part);
}
bool
ircd::m::exists(const id::room &room_id)
{
@ -409,32 +449,6 @@ const
return m::vm::test(query, closure);
}
int64_t
ircd::m::room::maxdepth()
const
{
event::id::buf buf;
return maxdepth(buf);
}
int64_t
ircd::m::room::maxdepth(event::id::buf &buf)
const
{
const auto it
{
dbs::room_events.begin(room_id)
};
if(!it)
return -1;
const auto &key(it->first);
const auto parts{dbs::room_events_key(key)};
buf = std::get<1>(parts);
return std::get<0>(parts);
}
//
// room::members
//