0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 15:04:10 +01:00

ircd:Ⓜ️ Improve interface to current event convenience suite.

This commit is contained in:
Jason Volk 2018-04-05 21:57:17 -07:00
parent 8d0681e7b1
commit c849a30aa1
6 changed files with 43 additions and 51 deletions

View file

@ -29,16 +29,21 @@ namespace ircd::m
bool exists(const id::room &);
bool exists(const id::room_alias &, const bool &remote = false);
// [GET]
id::room room_id(const mutable_buffer &, const id::room_alias &);
id::room::buf room_id(const id::room_alias &);
// [GET] Current Event suite (non-locking) (one)
id::event::buf head(std::nothrow_t, const id::room &, int64_t &);
id::event::buf head(const id::room &, uint64_t &);
// [GET] Current Event ID and depth suite (non-locking) (one only)
std::tuple<int64_t, id::event::buf> top(std::nothrow_t, const id::room &);
std::tuple<int64_t, id::event::buf> top(const id::room &);
// [GET] Current Event ID (non-locking) (one only)
id::event::buf head(std::nothrow_t, const id::room &);
id::event::buf head(const id::room &);
// [GET] Current Event depth (non-locking) (one only)
int64_t depth(std::nothrow_t, const id::room &);
uint64_t depth(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);

View file

@ -10,57 +10,49 @@
#include <ircd/m/m.h>
uint64_t
int64_t
ircd::m::depth(const id::room &room_id)
{
uint64_t depth;
head(room_id, depth);
return depth;
return std::get<0>(top(room_id));
}
int64_t
ircd::m::depth(std::nothrow_t,
const id::room &room_id)
{
int64_t depth;
head(std::nothrow, room_id, depth);
return depth;
return std::get<0>(top(std::nothrow, room_id));
}
ircd::m::id::event::buf
ircd::m::head(const id::room &room_id)
{
uint64_t depth;
return head(room_id, depth);
return std::get<1>(top(room_id));
}
ircd::m::id::event::buf
ircd::m::head(std::nothrow_t,
const id::room &room_id)
{
int64_t depth;
return head(std::nothrow, room_id, depth);
return std::get<1>(top(std::nothrow, room_id));
}
ircd::m::id::event::buf
ircd::m::head(const id::room &room_id,
uint64_t &depth)
std::tuple<int64_t, ircd::m::id::event::buf>
ircd::m::top(const id::room &room_id)
{
const auto ret
{
head(std::nothrow, room_id, reinterpret_cast<int64_t &>(depth))
top(std::nothrow, room_id)
};
if(depth == uint64_t(-1))
if(std::get<0>(ret) == -1)
throw m::NOT_FOUND{};
return ret;
}
ircd::m::id::event::buf
ircd::m::head(std::nothrow_t,
const id::room &room_id,
int64_t &depth)
std::tuple<int64_t, ircd::m::id::event::buf>
ircd::m::top(std::nothrow_t,
const id::room &room_id)
{
const auto it
{
@ -68,10 +60,10 @@ ircd::m::head(std::nothrow_t,
};
if(!it)
{
depth = -1;
return {};
}
return
{
-1, id::event::buf{}
};
const auto &key{it->first};
const auto part
@ -79,8 +71,12 @@ ircd::m::head(std::nothrow_t,
dbs::room_events_key(key)
};
depth = std::get<0>(part);
return std::get<1>(part);
const auto &depth{std::get<0>(part)};
const auto &event_id{std::get<1>(part)};
return
{
depth, event_id
};
}
bool

View file

@ -402,11 +402,8 @@ ircd::m::vm::_eval_pdu(eval &eval,
}
int64_t top;
const id::event::buf head
{
m::head(std::nothrow, room_id, top)
};
id::event::buf head;
std::tie(top, head) = m::top(std::nothrow, room_id);
if(top < 0 && (opts.head_must_exist || opts.history))
throw error
{

View file

@ -202,10 +202,8 @@ commit__iov_iov(const room &room,
};
int64_t depth;
const event::id::buf prev_event_id
{
head(std::nothrow, room.room_id, depth)
};
event::id::buf prev_event_id;
std::tie(depth, prev_event_id) = m::top(std::nothrow, room.room_id);
//TODO: X
const json::iov::set_if depth_

View file

@ -61,11 +61,9 @@ get__make_join(client &client,
url::decode(request.parv[1], user_id)
};
uint64_t depth;
const m::event::id::buf prev_event_id
{
m::head(room_id, depth)
};
int64_t depth;
m::id::event::buf prev_event_id;
std::tie(depth, prev_event_id) = m::top(room_id);
const m::event::fetch evf
{
@ -124,7 +122,7 @@ get__make_join(client &client,
{ event, { "type", "m.room.member" }},
{ event, { "state_key", user_id }},
{ event, { "sender", user_id }},
{ event, { "depth", int64_t(depth) + 1 }},
{ event, { "depth", depth + 1 }},
{ event, { "membership", "join" }},
{ content, { "membership", "join" }},
{ event, { "auth_events", { auths, 1 } }},

View file

@ -61,11 +61,9 @@ get__make_leave(client &client,
url::decode(request.parv[1], user_id)
};
uint64_t depth;
const m::event::id::buf prev_event_id
{
m::head(room_id, depth)
};
int64_t depth;
m::id::event::buf prev_event_id;
std::tie(depth, prev_event_id) = m::top(room_id);
const m::event::fetch evf
{
@ -101,7 +99,7 @@ get__make_leave(client &client,
{ event, { "type", "m.room.member" }},
{ event, { "sender", user_id }},
{ event, { "state_key", user_id }},
{ event, { "depth", int64_t(depth) + 1 }},
{ event, { "depth", depth + 1 }},
{ event, { "membership", "leave" }},
{ content, { "membership", "leave" }},
{ event, { "auth_events", auth_events }},