mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 08:23:56 +01:00
ircd:Ⓜ️ Improve interface to current event convenience suite.
This commit is contained in:
parent
8d0681e7b1
commit
c849a30aa1
6 changed files with 43 additions and 51 deletions
|
@ -29,16 +29,21 @@ namespace ircd::m
|
||||||
bool exists(const id::room &);
|
bool exists(const id::room &);
|
||||||
bool exists(const id::room_alias &, const bool &remote = false);
|
bool exists(const id::room_alias &, const bool &remote = false);
|
||||||
|
|
||||||
|
// [GET]
|
||||||
id::room room_id(const mutable_buffer &, const id::room_alias &);
|
id::room room_id(const mutable_buffer &, const id::room_alias &);
|
||||||
id::room::buf room_id(const id::room_alias &);
|
id::room::buf room_id(const id::room_alias &);
|
||||||
|
|
||||||
// [GET] Current Event suite (non-locking) (one)
|
// [GET] Current Event ID and depth suite (non-locking) (one only)
|
||||||
id::event::buf head(std::nothrow_t, const id::room &, int64_t &);
|
std::tuple<int64_t, id::event::buf> top(std::nothrow_t, const id::room &);
|
||||||
id::event::buf head(const id::room &, uint64_t &);
|
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(std::nothrow_t, const id::room &);
|
||||||
id::event::buf head(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 &);
|
int64_t depth(std::nothrow_t, const id::room &);
|
||||||
uint64_t depth(const id::room &);
|
int64_t depth(const id::room &);
|
||||||
|
|
||||||
// [SET] Lowest-level
|
// [SET] Lowest-level
|
||||||
event::id::buf commit(const room &, json::iov &event, const json::iov &content);
|
event::id::buf commit(const room &, json::iov &event, const json::iov &content);
|
||||||
|
|
|
@ -10,57 +10,49 @@
|
||||||
|
|
||||||
#include <ircd/m/m.h>
|
#include <ircd/m/m.h>
|
||||||
|
|
||||||
uint64_t
|
int64_t
|
||||||
ircd::m::depth(const id::room &room_id)
|
ircd::m::depth(const id::room &room_id)
|
||||||
{
|
{
|
||||||
uint64_t depth;
|
return std::get<0>(top(room_id));
|
||||||
head(room_id, depth);
|
|
||||||
return depth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t
|
int64_t
|
||||||
ircd::m::depth(std::nothrow_t,
|
ircd::m::depth(std::nothrow_t,
|
||||||
const id::room &room_id)
|
const id::room &room_id)
|
||||||
{
|
{
|
||||||
int64_t depth;
|
return std::get<0>(top(std::nothrow, room_id));
|
||||||
head(std::nothrow, room_id, depth);
|
|
||||||
return depth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::m::id::event::buf
|
ircd::m::id::event::buf
|
||||||
ircd::m::head(const id::room &room_id)
|
ircd::m::head(const id::room &room_id)
|
||||||
{
|
{
|
||||||
uint64_t depth;
|
return std::get<1>(top(room_id));
|
||||||
return head(room_id, depth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::m::id::event::buf
|
ircd::m::id::event::buf
|
||||||
ircd::m::head(std::nothrow_t,
|
ircd::m::head(std::nothrow_t,
|
||||||
const id::room &room_id)
|
const id::room &room_id)
|
||||||
{
|
{
|
||||||
int64_t depth;
|
return std::get<1>(top(std::nothrow, room_id));
|
||||||
return head(std::nothrow, room_id, depth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::m::id::event::buf
|
std::tuple<int64_t, ircd::m::id::event::buf>
|
||||||
ircd::m::head(const id::room &room_id,
|
ircd::m::top(const id::room &room_id)
|
||||||
uint64_t &depth)
|
|
||||||
{
|
{
|
||||||
const auto ret
|
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{};
|
throw m::NOT_FOUND{};
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::m::id::event::buf
|
std::tuple<int64_t, ircd::m::id::event::buf>
|
||||||
ircd::m::head(std::nothrow_t,
|
ircd::m::top(std::nothrow_t,
|
||||||
const id::room &room_id,
|
const id::room &room_id)
|
||||||
int64_t &depth)
|
|
||||||
{
|
{
|
||||||
const auto it
|
const auto it
|
||||||
{
|
{
|
||||||
|
@ -68,10 +60,10 @@ ircd::m::head(std::nothrow_t,
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!it)
|
if(!it)
|
||||||
{
|
return
|
||||||
depth = -1;
|
{
|
||||||
return {};
|
-1, id::event::buf{}
|
||||||
}
|
};
|
||||||
|
|
||||||
const auto &key{it->first};
|
const auto &key{it->first};
|
||||||
const auto part
|
const auto part
|
||||||
|
@ -79,8 +71,12 @@ ircd::m::head(std::nothrow_t,
|
||||||
dbs::room_events_key(key)
|
dbs::room_events_key(key)
|
||||||
};
|
};
|
||||||
|
|
||||||
depth = std::get<0>(part);
|
const auto &depth{std::get<0>(part)};
|
||||||
return std::get<1>(part);
|
const auto &event_id{std::get<1>(part)};
|
||||||
|
return
|
||||||
|
{
|
||||||
|
depth, event_id
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -402,11 +402,8 @@ ircd::m::vm::_eval_pdu(eval &eval,
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t top;
|
int64_t top;
|
||||||
const id::event::buf head
|
id::event::buf head;
|
||||||
{
|
std::tie(top, head) = m::top(std::nothrow, room_id);
|
||||||
m::head(std::nothrow, room_id, top)
|
|
||||||
};
|
|
||||||
|
|
||||||
if(top < 0 && (opts.head_must_exist || opts.history))
|
if(top < 0 && (opts.head_must_exist || opts.history))
|
||||||
throw error
|
throw error
|
||||||
{
|
{
|
||||||
|
|
|
@ -202,10 +202,8 @@ commit__iov_iov(const room &room,
|
||||||
};
|
};
|
||||||
|
|
||||||
int64_t depth;
|
int64_t depth;
|
||||||
const event::id::buf prev_event_id
|
event::id::buf prev_event_id;
|
||||||
{
|
std::tie(depth, prev_event_id) = m::top(std::nothrow, room.room_id);
|
||||||
head(std::nothrow, room.room_id, depth)
|
|
||||||
};
|
|
||||||
|
|
||||||
//TODO: X
|
//TODO: X
|
||||||
const json::iov::set_if depth_
|
const json::iov::set_if depth_
|
||||||
|
|
|
@ -61,11 +61,9 @@ get__make_join(client &client,
|
||||||
url::decode(request.parv[1], user_id)
|
url::decode(request.parv[1], user_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t depth;
|
int64_t depth;
|
||||||
const m::event::id::buf prev_event_id
|
m::id::event::buf prev_event_id;
|
||||||
{
|
std::tie(depth, prev_event_id) = m::top(room_id);
|
||||||
m::head(room_id, depth)
|
|
||||||
};
|
|
||||||
|
|
||||||
const m::event::fetch evf
|
const m::event::fetch evf
|
||||||
{
|
{
|
||||||
|
@ -124,7 +122,7 @@ get__make_join(client &client,
|
||||||
{ event, { "type", "m.room.member" }},
|
{ event, { "type", "m.room.member" }},
|
||||||
{ event, { "state_key", user_id }},
|
{ event, { "state_key", user_id }},
|
||||||
{ event, { "sender", user_id }},
|
{ event, { "sender", user_id }},
|
||||||
{ event, { "depth", int64_t(depth) + 1 }},
|
{ event, { "depth", depth + 1 }},
|
||||||
{ event, { "membership", "join" }},
|
{ event, { "membership", "join" }},
|
||||||
{ content, { "membership", "join" }},
|
{ content, { "membership", "join" }},
|
||||||
{ event, { "auth_events", { auths, 1 } }},
|
{ event, { "auth_events", { auths, 1 } }},
|
||||||
|
|
|
@ -61,11 +61,9 @@ get__make_leave(client &client,
|
||||||
url::decode(request.parv[1], user_id)
|
url::decode(request.parv[1], user_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t depth;
|
int64_t depth;
|
||||||
const m::event::id::buf prev_event_id
|
m::id::event::buf prev_event_id;
|
||||||
{
|
std::tie(depth, prev_event_id) = m::top(room_id);
|
||||||
m::head(room_id, depth)
|
|
||||||
};
|
|
||||||
|
|
||||||
const m::event::fetch evf
|
const m::event::fetch evf
|
||||||
{
|
{
|
||||||
|
@ -101,7 +99,7 @@ get__make_leave(client &client,
|
||||||
{ event, { "type", "m.room.member" }},
|
{ event, { "type", "m.room.member" }},
|
||||||
{ event, { "sender", user_id }},
|
{ event, { "sender", user_id }},
|
||||||
{ event, { "state_key", user_id }},
|
{ event, { "state_key", user_id }},
|
||||||
{ event, { "depth", int64_t(depth) + 1 }},
|
{ event, { "depth", depth + 1 }},
|
||||||
{ event, { "membership", "leave" }},
|
{ event, { "membership", "leave" }},
|
||||||
{ content, { "membership", "leave" }},
|
{ content, { "membership", "leave" }},
|
||||||
{ event, { "auth_events", auth_events }},
|
{ event, { "auth_events", auth_events }},
|
||||||
|
|
Loading…
Reference in a new issue