mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 09:40:12 +01:00
modules: Replace individual client event appending with m::append().
This commit is contained in:
parent
c4c95916c2
commit
c416be8398
5 changed files with 40 additions and 205 deletions
|
@ -201,13 +201,21 @@ get__context(client &client,
|
||||||
room, &default_fetch_opts
|
room, &default_fetch_opts
|
||||||
};
|
};
|
||||||
|
|
||||||
state.for_each([&array, &request]
|
state.for_each([&array, &request, &user_room]
|
||||||
(const m::event &event)
|
(const m::event::idx &event_idx)
|
||||||
{
|
{
|
||||||
|
const m::event::fetch event
|
||||||
|
{
|
||||||
|
event_idx, std::nothrow
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!event.valid)
|
||||||
|
return;
|
||||||
|
|
||||||
if(!visible(event, request.user_id))
|
if(!visible(event, request.user_id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
array.append(event);
|
_append(array, event, event_idx, user_room);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,43 +228,9 @@ _append(json::stack::array &chunk,
|
||||||
const m::event::idx &event_idx,
|
const m::event::idx &event_idx,
|
||||||
const m::user::room &user_room)
|
const m::user::room &user_room)
|
||||||
{
|
{
|
||||||
json::stack::object object
|
m::event_append_opts opts;
|
||||||
{
|
opts.event_idx = &event_idx;
|
||||||
chunk
|
opts.user_id = &user_room.user.user_id;
|
||||||
};
|
opts.user_room = &user_room;
|
||||||
|
m::append(chunk, event, opts);
|
||||||
object.append(event);
|
|
||||||
|
|
||||||
json::stack::object unsigned_
|
|
||||||
{
|
|
||||||
object, "unsigned"
|
|
||||||
};
|
|
||||||
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "age", json::value
|
|
||||||
{
|
|
||||||
long(m::vm::current_sequence - event_idx)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if(at<"sender"_>(event) != user_room.user.user_id)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto txnid_idx
|
|
||||||
{
|
|
||||||
user_room.get(std::nothrow, "ircd.client.txnid", at<"event_id"_>(event))
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!txnid_idx)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m::get(std::nothrow, txnid_idx, "content", [&unsigned_]
|
|
||||||
(const json::object &content)
|
|
||||||
{
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "transaction_id", unquote(content.get("transaction_id"))
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,25 +193,9 @@ get__initialsync_local(client &client,
|
||||||
if(!event.valid)
|
if(!event.valid)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
json::stack::object room_event
|
m::event_append_opts opts;
|
||||||
{
|
opts.event_idx = &event.event_idx;
|
||||||
state
|
m::append(state, event, opts);
|
||||||
};
|
|
||||||
|
|
||||||
room_event.append(event);
|
|
||||||
json::stack::object unsigned_
|
|
||||||
{
|
|
||||||
room_event, "unsigned"
|
|
||||||
};
|
|
||||||
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "age", json::value
|
|
||||||
{
|
|
||||||
long(m::vm::current_sequence - event.event_idx)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}});
|
}});
|
||||||
state.~array();
|
state.~array();
|
||||||
|
@ -247,24 +231,12 @@ get__initialsync_local(client &client,
|
||||||
if(!visible(event_id, user.user_id))
|
if(!visible(event_id, user.user_id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
json::stack::object room_event
|
const m::event &event(*it);
|
||||||
{
|
const auto &event_idx(it.event_idx());
|
||||||
chunk
|
|
||||||
};
|
|
||||||
|
|
||||||
room_event.append(*it);
|
m::event_append_opts opts;
|
||||||
json::stack::object unsigned_
|
opts.event_idx = &event_idx;
|
||||||
{
|
m::append(chunk, event, opts);
|
||||||
room_event, "unsigned"
|
|
||||||
};
|
|
||||||
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "age", json::value
|
|
||||||
{
|
|
||||||
long(m::vm::current_sequence - it.event_idx())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,45 +186,11 @@ _append(json::stack::array &chunk,
|
||||||
const m::event::idx &event_idx,
|
const m::event::idx &event_idx,
|
||||||
const m::user::room &user_room)
|
const m::user::room &user_room)
|
||||||
{
|
{
|
||||||
json::stack::object object
|
m::event_append_opts opts;
|
||||||
{
|
opts.event_idx = &event_idx;
|
||||||
chunk
|
opts.user_id = &user_room.user.user_id;
|
||||||
};
|
opts.user_room = &user_room;
|
||||||
|
m::append(chunk, event, opts);
|
||||||
object.append(event);
|
|
||||||
|
|
||||||
json::stack::object unsigned_
|
|
||||||
{
|
|
||||||
object, "unsigned"
|
|
||||||
};
|
|
||||||
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "age", json::value
|
|
||||||
{
|
|
||||||
long(m::vm::current_sequence - event_idx)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if(at<"sender"_>(event) != user_room.user.user_id)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto txnid_idx
|
|
||||||
{
|
|
||||||
user_room.get(std::nothrow, "ircd.client.txnid", at<"event_id"_>(event))
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!txnid_idx)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m::get(std::nothrow, txnid_idx, "content", [&unsigned_]
|
|
||||||
(const json::object &content)
|
|
||||||
{
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "transaction_id", unquote(content.get("transaction_id"))
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client-Server 6.3.6 query parameters
|
// Client-Server 6.3.6 query parameters
|
||||||
|
|
|
@ -202,23 +202,9 @@ ircd::m::sync::room_state_append(data &data,
|
||||||
const m::event &event,
|
const m::event &event,
|
||||||
const m::event::idx &event_idx)
|
const m::event::idx &event_idx)
|
||||||
{
|
{
|
||||||
json::stack::object object
|
m::event_append_opts opts;
|
||||||
{
|
opts.event_idx = &event_idx;
|
||||||
events
|
opts.client_txnid = &data.client_txnid;
|
||||||
};
|
opts.user_id = &data.user.user_id;
|
||||||
|
opts.user_room = &data.user_room;
|
||||||
object.append(event);
|
|
||||||
|
|
||||||
json::stack::object unsigned_
|
|
||||||
{
|
|
||||||
object, "unsigned"
|
|
||||||
};
|
|
||||||
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "age", json::value
|
|
||||||
{
|
|
||||||
long(vm::current_sequence - event_idx)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ IRCD_MODULE
|
||||||
|
|
||||||
namespace ircd::m::sync
|
namespace ircd::m::sync
|
||||||
{
|
{
|
||||||
static void _room_timeline_append_txnid(data &, json::stack::object &, const m::event &);
|
|
||||||
static void _room_timeline_append(data &, json::stack::array &, const m::event::idx &, const m::event &);
|
static void _room_timeline_append(data &, json::stack::array &, const m::event::idx &, const m::event &);
|
||||||
static event::id::buf _room_timeline_polylog_events(data &, const m::room &, bool &, bool &);
|
static event::id::buf _room_timeline_polylog_events(data &, const m::room &, bool &, bool &);
|
||||||
static bool room_timeline_polylog(data &);
|
static bool room_timeline_polylog(data &);
|
||||||
|
@ -187,72 +186,10 @@ ircd::m::sync::_room_timeline_append(data &data,
|
||||||
const m::event::idx &event_idx,
|
const m::event::idx &event_idx,
|
||||||
const m::event &event)
|
const m::event &event)
|
||||||
{
|
{
|
||||||
json::stack::object object
|
m::event_append_opts opts;
|
||||||
{
|
opts.event_idx = &event_idx;
|
||||||
events
|
opts.client_txnid = &data.client_txnid;
|
||||||
};
|
opts.user_id = &data.user.user_id;
|
||||||
|
opts.user_room = &data.user_room;
|
||||||
object.append(event);
|
m::append(events, event, opts);
|
||||||
|
|
||||||
json::stack::object unsigned_
|
|
||||||
{
|
|
||||||
object, "unsigned"
|
|
||||||
};
|
|
||||||
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "age", json::value
|
|
||||||
{
|
|
||||||
long(vm::current_sequence - event_idx)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
_room_timeline_append_txnid(data, unsigned_, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ircd::m::sync::_room_timeline_append_txnid(data &data,
|
|
||||||
json::stack::object &unsigned_,
|
|
||||||
const m::event &event)
|
|
||||||
{
|
|
||||||
if(data.client_txnid)
|
|
||||||
{
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "transaction_id", data.client_txnid
|
|
||||||
};
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(json::get<"sender"_>(event) != data.user.user_id)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto txnid_idx
|
|
||||||
{
|
|
||||||
data.user_room.get(std::nothrow, "ircd.client.txnid", at<"event_id"_>(event))
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!txnid_idx)
|
|
||||||
{
|
|
||||||
log::dwarning
|
|
||||||
{
|
|
||||||
log, "Could not find transaction_id for %s from %s in %s",
|
|
||||||
json::get<"event_id"_>(event),
|
|
||||||
json::get<"sender"_>(event),
|
|
||||||
json::get<"room_id"_>(event)
|
|
||||||
};
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m::get(std::nothrow, txnid_idx, "content", [&unsigned_]
|
|
||||||
(const json::object &content)
|
|
||||||
{
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "transaction_id", unquote(content.get("transaction_id"))
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue