0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-16 17:08:20 +02:00

ircd:Ⓜ️:fetch: Remove ambiguating event_id() util.

This commit is contained in:
Jason Volk 2019-07-05 22:01:34 -07:00
parent 1097829102
commit 261151f539
15 changed files with 42 additions and 63 deletions

View file

@ -57,9 +57,6 @@ struct ircd::m::event::fetch
fetch(const id &, const opts & = default_opts);
fetch(const idx &, const opts & = default_opts);
fetch(const opts & = default_opts);
static bool event_id(const idx &, std::nothrow_t, const id::closure &);
static void event_id(const idx &, const id::closure &);
};
namespace ircd::m

View file

@ -1382,25 +1382,6 @@ decltype(ircd::m::event::fetch::default_opts)
ircd::m::event::fetch::default_opts
{};
void
ircd::m::event::fetch::event_id(const idx &idx,
const id::closure &closure)
{
if(!get(std::nothrow, idx, "event_id", closure))
throw m::NOT_FOUND
{
"%lu not found in database", idx
};
}
bool
ircd::m::event::fetch::event_id(const idx &idx,
std::nothrow_t,
const id::closure &closure)
{
return get(std::nothrow, idx, "event_id", closure);
}
//
// event::fetch::fetch
//

View file

@ -970,7 +970,7 @@ ircd::m::top(std::nothrow_t,
event::id::buf{}, depth, event_idx
};
event::fetch::event_id(event_idx, std::nothrow, [&ret]
m::event_id(event_idx, std::nothrow, [&ret]
(const event::id &event_id)
{
std::get<event::id::buf>(ret) = event_id;
@ -1505,7 +1505,7 @@ const
(const event::idx &idx)
{
bool ret{true};
event::fetch::event_id(idx, std::nothrow, [&ret, &closure]
m::event_id(idx, std::nothrow, [&ret, &closure]
(const event::id &event_id)
{
ret = closure(event_id);
@ -1820,14 +1820,7 @@ ircd::m::event::id::buf
ircd::m::room::messages::event_id()
const
{
event::id::buf ret;
event::fetch::event_id(this->event_idx(), [&ret]
(const event::id &event_id)
{
ret = event_id;
});
return ret;
return m::event_id(this->event_idx(), std::nothrow);
}
uint64_t
@ -1985,10 +1978,18 @@ ircd::m::room::state::get(const string_view &type,
const event::id::closure &closure)
const
{
get(type, state_key, event::closure_idx{[&closure]
get(type, state_key, event::closure_idx{[&]
(const event::idx &idx)
{
event::fetch::event_id(idx, closure);
if(!m::event_id(idx, std::nothrow, closure))
throw m::NOT_FOUND
{
"(%s,%s) in %s idx:%lu event_id :not found",
type,
state_key,
string_view{room_id},
idx,
};
}});
}
@ -2058,7 +2059,7 @@ const
return get(std::nothrow, type, state_key, event::closure_idx{[&closure]
(const event::idx &idx)
{
event::fetch::event_id(idx, std::nothrow, closure);
m::event_id(idx, std::nothrow, closure);
}});
}
@ -2223,7 +2224,7 @@ const
(const event::idx &idx)
{
bool ret{true};
event::fetch::event_id(idx, std::nothrow, [&ret, &closure]
m::event_id(idx, std::nothrow, [&ret, &closure]
(const event::id &id)
{
ret = closure(id);
@ -2405,7 +2406,7 @@ const
(const event::idx &idx)
{
bool ret{true};
event::fetch::event_id(idx, std::nothrow, [&ret, &closure]
m::event_id(idx, std::nothrow, [&ret, &closure]
(const event::id &id)
{
ret = closure(id);

View file

@ -154,7 +154,7 @@ save_transaction_id(const m::event &event,
if(!eval.copts->client_txnid)
return;
if(!json::get<"event_id"_>(event))
if(!event.event_id)
return;
assert(my_host(at<"origin"_>(event)));

View file

@ -7421,7 +7421,7 @@ console_cmd__eval__file(opt &out, const string_view &line)
if(room_id && json::get<"room_id"_>(event) != room_id)
continue;
if(event_id && json::get<"event_id"_>(event) != event_id)
if(event_id && event.event_id != event_id)
continue;
if(sender && json::get<"sender"_>(event) != sender)
@ -8569,7 +8569,7 @@ console_cmd__room__state(opt &out, const string_view &line)
<< std::left << " ] [ "
<< std::setw(50) << state_key
<< std::left << " ] "
<< std::setw(72) << json::get<"event_id"_>(event)
<< std::setw(72) << string_view{event.event_id}
<< std::left << " "
;
@ -10475,7 +10475,7 @@ console_cmd__user__tokens(opt &out, const string_view &line)
<< " "
<< pretty(now - ost) << " ago"
<< " "
<< json::get<"event_id"_>(event);
<< string_view{event.event_id};
if(clear)

View file

@ -37,7 +37,7 @@ unit::unit(std::string s, const enum type &type)
}
unit::unit(const m::event &event)
:type{json::get<"event_id"_>(event)? PDU : EDU}
:type{event.event_id? PDU : EDU}
,s{[this, &event]() -> std::string
{
switch(this->type)

View file

@ -123,7 +123,7 @@ try
const m::event::id &event_id
{
at<"event_id"_>(event)
event.event_id
};
const m::room::id &room_id
@ -148,7 +148,7 @@ try
{
log, "%s %s %s ac:%zu ae:%zu pc:%zu pe:%zu pf:%zu",
loghead(eval),
json::get<"event_id"_>(event),
string_view{event.event_id},
json::get<"room_id"_>(event),
tab.auth_count,
tab.auth_exists,
@ -163,7 +163,7 @@ catch(const std::exception &e)
{
log, "%s %s :%s",
loghead(eval),
json::get<"event_id"_>(event),
string_view{event.event_id},
e.what(),
};
@ -202,7 +202,7 @@ ircd::m::fetch::hook_handle_auth(const event &event,
{
log, "%s %s auth_events:%zu hit:%zu miss:%zu",
loghead(eval),
at<"event_id"_>(event),
string_view{event.event_id},
tab.auth_count,
tab.auth_exists,
tab.auth_count - tab.auth_exists,
@ -227,7 +227,7 @@ ircd::m::fetch::hook_handle_auth(const event &event,
throw vm::error
{
vm::fault::EVENT, "Failed to fetch auth_events for %s in %s",
json::get<"event_id"_>(event),
string_view{event.event_id},
json::get<"room_id"_>(event)
};
@ -284,7 +284,7 @@ ircd::m::fetch::hook_handle_prev(const event &event,
{
log, "%s %s prev_events:%zu hit:%zu miss:%zu fetching:%zu",
loghead(eval),
at<"event_id"_>(event),
string_view{event.event_id},
tab.prev_count,
tab.prev_exists,
tab.prev_count - tab.prev_exists,
@ -317,7 +317,7 @@ ircd::m::fetch::hook_handle_prev(const event &event,
throw vm::error
{
vm::fault::EVENT, "Failed to fetch any prev_events for %s in %s",
json::get<"event_id"_>(event),
string_view{event.event_id},
json::get<"room_id"_>(event)
};
@ -329,7 +329,7 @@ ircd::m::fetch::hook_handle_prev(const event &event,
{
vm::fault::EVENT, "Failed to fetch all %zu required prev_events for %s in %s",
tab.prev_count,
json::get<"event_id"_>(event),
string_view{event.event_id},
json::get<"room_id"_>(event)
};
}

View file

@ -418,7 +418,7 @@ handle_implicit_receipt(const m::event &event,
m::vm::eval &eval)
try
{
if(!json::get<"event_id"_>(event))
if(!event.event_id)
return;
const m::user::id &user_id
@ -455,7 +455,7 @@ catch(const std::exception &e)
log::error
{
receipt_log, "Implicit receipt hook for %s :%s",
json::get<"event_id"_>(event),
string_view{event.event_id},
e.what(),
};
}
@ -576,7 +576,7 @@ catch(const std::exception &e)
log::error
{
receipt_log, "ircd.read hook on %s for federation broadcast :%s",
json::get<"event_id"_>(event),
string_view{event.event_id},
e.what(),
};
}

View file

@ -154,7 +154,7 @@ _changed_aliases(const m::event &event,
m::log, "Updated aliases of %s by %s in %s with %s",
string_view{room_id},
json::get<"sender"_>(event),
json::get<"event_id"_>(event),
string_view{event.event_id},
string_view{alias},
};
}
@ -165,7 +165,7 @@ _changed_aliases(const m::event &event,
m::log, "Updating aliases of %s by %s in %s with %s :%s",
string_view{room_id},
json::get<"sender"_>(event),
json::get<"event_id"_>(event),
string_view{event.event_id},
string_view{alias},
e.what(),
};

View file

@ -53,7 +53,7 @@ _changed_canonical_alias(const m::event &event,
string_view{room_id},
string_view{alias},
json::get<"sender"_>(event),
json::get<"event_id"_>(event),
string_view{event.event_id},
string_view{event_id}
};
}

View file

@ -112,7 +112,7 @@ ircd::m::visible(const m::event &event,
{
const m::room room
{
at<"room_id"_>(event), json::get<"event_id"_>(event)
at<"room_id"_>(event), event.event_id
};
static const m::event::fetch::opts fopts
@ -160,7 +160,7 @@ _changed_visibility(const m::event &event,
json::get<"room_id"_>(event),
json::get<"content"_>(event).get("history_visibility"),
json::get<"sender"_>(event),
json::get<"event_id"_>(event)
string_view{event.event_id}
};
}

View file

@ -64,7 +64,7 @@ _changed_rules_notify(const m::event &event,
m::log, "%s changed join_rules in %s [%s] to %s",
json::get<"sender"_>(event),
json::get<"room_id"_>(event),
json::get<"event_id"_>(event),
string_view{event.event_id},
json::get<"content"_>(event).get("join_rule"),
};
}

View file

@ -29,7 +29,7 @@ _message_notify(const m::event &event,
{
m::log, "%s said %s in %s %s :%s%s",
json::get<"sender"_>(event),
json::get<"event_id"_>(event),
string_view{event.event_id},
json::get<"room_id"_>(event),
json::get<"content"_>(event).get("msgtype"),
trunc(body, 128),

View file

@ -27,7 +27,7 @@ _has_power(const m::event &event,
const auto &event_id
{
json::get<"event_id"_>(event)
event.event_id
};
if(!room_id || !event_id) // Not evaluated here
@ -113,7 +113,7 @@ _changed_levels(const m::event &event,
m::log, "%s changed power_levels in %s [%s]",
json::get<"sender"_>(event),
json::get<"room_id"_>(event),
json::get<"event_id"_>(event)
string_view{event.event_id}
};
}

View file

@ -71,7 +71,7 @@ ircd::m::on_changed_room_server_acl(const event &event,
m::log, "%s changed server access control list in %s [%s]",
json::get<"sender"_>(event),
json::get<"room_id"_>(event),
json::get<"event_id"_>(event)
string_view{event.event_id},
};
}