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

ircd:Ⓜ️🧾 Reorg/rename interface; simplify impl; add options argument.

ircd:Ⓜ️🧾 Remove central linkage cruft for interface.
This commit is contained in:
Jason Volk 2019-09-06 11:13:58 -07:00
parent 7d0c44eb3c
commit 6a59036f4e
8 changed files with 81 additions and 161 deletions

View file

@ -27,12 +27,11 @@ namespace ircd::m::receipt
bool ignoring(const m::user &, const id::room &);
// [GET] Get the last event the user has read in the room.
bool read(const id::room &, const id::user &, const id::event::closure &);
id::event read(id::event::buf &out, const id::room &, const id::user &);
bool get(const id::room &, const id::user &, const id::event::closure &);
id::event get(id::event::buf &out, const id::room &, const id::user &);
// [SET] Indicate that the user has read the event in the room.
id::event::buf read(const id::room &, const id::user &, const id::event &, const time_t &);
id::event::buf read(const id::room &, const id::user &, const id::event &); // now
id::event::buf read(const id::room &, const id::user &, const id::event &, const json::object & = {});
};
struct ircd::m::edu::m_receipt
@ -50,3 +49,16 @@ struct ircd::m::edu::m_receipt::m_read
using super_type::tuple;
using super_type::operator=;
};
inline ircd::m::event::id
ircd::m::receipt::get(event::id::buf &out,
const room::id &room_id,
const user::id &user_id)
{
const event::id::closure copy
{
[&out](const auto &event_id) { out = event_id; }
};
return get(room_id, user_id, copy)? event::id{out} : event::id{};
}

118
ircd/m.cc
View file

@ -1666,124 +1666,6 @@ ircd::m::visible(const event &event,
return call(event, mxid);
}
///////////////////////////////////////////////////////////////////////////////
//
// m/receipt.h
//
ircd::m::event::id::buf
ircd::m::receipt::read(const id::room &room_id,
const id::user &user_id,
const id::event &event_id)
{
return read(room_id, user_id, event_id, ircd::time<milliseconds>());
}
ircd::m::event::id::buf
ircd::m::receipt::read(const room::id &room_id,
const user::id &user_id,
const event::id &event_id,
const time_t &ms)
{
using prototype = event::id::buf (const room::id &, const user::id &, const event::id &, const time_t &);
static mods::import<prototype> function
{
"m_receipt", "ircd::m::receipt::read"
};
return function(room_id, user_id, event_id, ms);
}
ircd::m::event::id
ircd::m::receipt::read(event::id::buf &out,
const room::id &room_id,
const user::id &user_id)
{
const event::id::closure copy{[&out]
(const event::id &event_id)
{
out = event_id;
}};
return read(room_id, user_id, copy)?
event::id{out}:
event::id{};
}
bool
ircd::m::receipt::read(const room::id &room_id,
const user::id &user_id,
const event::id::closure &closure)
{
using prototype = bool (const room::id &, const user::id &, const event::id::closure &);
static mods::import<prototype> function
{
"m_receipt", "ircd::m::receipt::read"
};
return function(room_id, user_id, closure);
}
bool
ircd::m::receipt::ignoring(const user &user,
const room::id &room_id)
{
using prototype = bool (const m::user &, const m::room::id &);
static mods::import<prototype> function
{
"m_receipt", "ircd::m::receipt::ignoring"
};
return function(user, room_id);
}
bool
ircd::m::receipt::ignoring(const user &user,
const event::id &event_id)
{
using prototype = bool (const m::user &, const m::event::id &);
static mods::import<prototype> function
{
"m_receipt", "ircd::m::receipt::ignoring"
};
return function(user, event_id);
}
bool
ircd::m::receipt::freshest(const room::id &room_id,
const user::id &user_id,
const event::id &event_id)
{
using prototype = bool (const m::room::id &, const m::user::id &, const m::event::id &);
static mods::import<prototype> function
{
"m_receipt", "ircd::m::receipt::freshest"
};
return function(room_id, user_id, event_id);
}
bool
ircd::m::receipt::exists(const room::id &room_id,
const user::id &user_id,
const event::id &event_id)
{
using prototype = bool (const m::room::id &, const m::user::id &, const m::event::id &);
static mods::import<prototype> function
{
"m_receipt", "ircd::m::receipt::exists"
};
return function(room_id, user_id, event_id);
}
///////////////////////////////////////////////////////////////////////////////
//
// m/presence.h

View file

@ -91,7 +91,7 @@ handle_m_fully_read(client &client,
m::log, "Ignoring duplicate m.fully_read marker for %s in %s by %s",
string_view{event_id},
string_view{room_id},
request.user_id,
string_view{request.user_id},
};
return;

View file

@ -80,5 +80,15 @@ handle_receipt_m_read(client &client,
if(m::receipt::ignoring(request.user_id, event_id))
return;
m::receipt::read(room_id, request.user_id, event_id);
// The options object starts with anything in the request content, which
// differs depending on whether this is being called from a /receipt or
// /read_markers resource handler. The receipt::read() implementation
// looks for properties knowing this call pattern, thus it's best to just
// convey the whole content here for forward compat.
const json::object &options
{
request
};
m::receipt::read(room_id, request.user_id, event_id, options);
}

View file

@ -83,7 +83,7 @@ ircd::m::sync::room_unread_notifications_linear(data &data)
m::event::id::buf last_read;
if(likely(!is_self_read))
if(!m::receipt::read(last_read, room.room_id, data.user))
if(!m::receipt::get(last_read, room.room_id, data.user))
return false;
const auto start_idx
@ -160,7 +160,7 @@ ircd::m::sync::room_unread_notifications_polylog(data &data)
m::event::id::buf last_read_buf;
const auto last_read
{
m::receipt::read(last_read_buf, room.room_id, data.user)
m::receipt::get(last_read_buf, room.room_id, data.user)
};
const auto start_idx

View file

@ -10761,7 +10761,10 @@ console_cmd__user__read__receipt(opt &out, const string_view &line)
const auto eid
{
m::receipt::read(room_id, user_id, event_id, ms)
m::receipt::read(room_id, user_id, event_id, json::strung{json::members
{
{ "ts", ms },
}})
};
out << eid << std::endl;

View file

@ -368,7 +368,11 @@ command__read(const mutable_buffer &buf,
m::head(room)
};
m::receipt::read(room, user, event_id, ms);
m::receipt::read(room, user, event_id, json::strung{json::members
{
{ "ts", ms },
}});
return {};
}
else if(m::valid(m::id::ROOM, arg) || m::valid(m::id::ROOM_ALIAS, arg))
@ -388,7 +392,11 @@ command__read(const mutable_buffer &buf,
m::head(room)
};
m::receipt::read(room, user, event_id, ms);
m::receipt::read(room, user, event_id, json::strung{json::members
{
{ "ts", ms },
}});
return {};
}
@ -492,7 +500,11 @@ command__read(const mutable_buffer &buf,
}
// Commit the receipt.
m::receipt::read(room_id, user, event_id, ms);
m::receipt::read(room_id, user, event_id, json::strung{json::members
{
{ "ts", ms },
}});
put(room_id, event_id);
++matched;
});

View file

@ -34,7 +34,7 @@ extern m::hookfn<m::vm::eval &> _ircd_read_eval;
static void handle_implicit_receipt(const m::event &, m::vm::eval &);
extern m::hookfn<m::vm::eval &> _implicit_receipt;
static void handle_m_receipt_m_read(const m::room::id &, const m::user::id &, const m::event::id &, const time_t &);
static void handle_m_receipt_m_read(const m::room::id &, const m::user::id &, const m::event::id &, const json::object &data);
static void handle_m_receipt_m_read(const m::room::id &, const m::user::id &, const m::edu::m_receipt::m_read &);
static void handle_m_receipt_m_read(const m::event &, const m::room::id &, const json::object &);
static void handle_m_receipt(const m::event &, const m::room::id &, const json::object &);
@ -172,14 +172,9 @@ handle_m_receipt_m_read(const m::room::id &room_id,
json::get<"data"_>(receipt)
};
const time_t &ts
{
data.get<time_t>("ts")
};
for(const json::string &event_id : event_ids) try
{
handle_m_receipt_m_read(room_id, user_id, event_id, ts);
handle_m_receipt_m_read(room_id, user_id, event_id, data);
}
catch(const std::exception &e)
{
@ -198,7 +193,7 @@ void
handle_m_receipt_m_read(const m::room::id &room_id,
const m::user::id &user_id,
const m::event::id &event_id,
const time_t &ts)
const json::object &data)
try
{
const m::user user
@ -227,7 +222,7 @@ try
const auto evid
{
m::receipt::read(room_id, user_id, event_id, ts)
m::receipt::read(room_id, user_id, event_id, data)
};
}
catch(const std::exception &e)
@ -251,13 +246,18 @@ IRCD_MODULE_EXPORT
ircd::m::receipt::read(const m::room::id &room_id,
const m::user::id &user_id,
const m::event::id &event_id,
const time_t &ms)
const json::object &options)
{
const m::user::room user_room
{
user_id
};
const time_t &ms
{
options.get("ts", ircd::time<milliseconds>())
};
const auto evid
{
send(user_room, user_id, "ircd.read", room_id,
@ -269,11 +269,11 @@ ircd::m::receipt::read(const m::room::id &room_id,
log::info
{
receipt_log, "%s read by %s in %s @ %zd",
receipt_log, "%s read by %s in %s options:%s",
string_view{event_id},
string_view{user_id},
string_view{room_id},
ms
string_view{options},
};
return evid;
@ -281,29 +281,26 @@ ircd::m::receipt::read(const m::room::id &room_id,
bool
IRCD_MODULE_EXPORT
ircd::m::receipt::read(const m::room::id &room_id,
const m::user::id &user_id,
const m::event::id::closure &closure)
ircd::m::receipt::get(const m::room::id &room_id,
const m::user::id &user_id,
const m::event::id::closure &closure)
{
static const m::event::fetch::opts fopts
{
m::event::keys::include
{
"content"
}
};
const m::user::room user_room
{
user_id, nullptr, &fopts
user_id
};
return user_room.get(std::nothrow, "ircd.read", room_id, [&closure]
(const m::event &event)
const auto event_idx
{
const m::event::id &event_id
user_room.get(std::nothrow, "ircd.read", room_id)
};
return m::get(std::nothrow, event_idx, "content", [&closure]
(const json::object &content)
{
const json::string &event_id
{
unquote(at<"content"_>(event).get("event_id"))
content["event_id"]
};
closure(event_id);
@ -471,14 +468,18 @@ try
event.event_id
};
const time_t &ms
char databuf[64];
const json::object &data
{
at<"origin_server_ts"_>(event)
json::stringify(mutable_buffer{databuf}, json::members
{
{ "ts", at<"origin_server_ts"_>(event) },
})
};
const auto receipt_event_id
{
m::receipt::read(room_id, user_id, event_id, ms)
m::receipt::read(room_id, user_id, event_id, data)
};
}
catch(const std::exception &e)