0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

modules: Replace individual client event appending with m::append().

This commit is contained in:
Jason Volk 2019-03-11 16:02:48 -07:00
parent c4c95916c2
commit c416be8398
5 changed files with 40 additions and 205 deletions

View file

@ -201,13 +201,21 @@ get__context(client &client,
room, &default_fetch_opts
};
state.for_each([&array, &request]
(const m::event &event)
state.for_each([&array, &request, &user_room]
(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))
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::user::room &user_room)
{
json::stack::object object
{
chunk
};
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"))
};
});
m::event_append_opts opts;
opts.event_idx = &event_idx;
opts.user_id = &user_room.user.user_id;
opts.user_room = &user_room;
m::append(chunk, event, opts);
}

View file

@ -193,25 +193,9 @@ get__initialsync_local(client &client,
if(!event.valid)
return true;
json::stack::object room_event
{
state
};
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)
}
};
m::event_append_opts opts;
opts.event_idx = &event.event_idx;
m::append(state, event, opts);
return true;
}});
state.~array();
@ -247,24 +231,12 @@ get__initialsync_local(client &client,
if(!visible(event_id, user.user_id))
continue;
json::stack::object room_event
{
chunk
};
const m::event &event(*it);
const auto &event_idx(it.event_idx());
room_event.append(*it);
json::stack::object unsigned_
{
room_event, "unsigned"
};
json::stack::member
{
unsigned_, "age", json::value
{
long(m::vm::current_sequence - it.event_idx())
}
};
m::event_append_opts opts;
opts.event_idx = &event_idx;
m::append(chunk, event, opts);
}
}

View file

@ -186,45 +186,11 @@ _append(json::stack::array &chunk,
const m::event::idx &event_idx,
const m::user::room &user_room)
{
json::stack::object object
{
chunk
};
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"))
};
});
m::event_append_opts opts;
opts.event_idx = &event_idx;
opts.user_id = &user_room.user.user_id;
opts.user_room = &user_room;
m::append(chunk, event, opts);
}
// Client-Server 6.3.6 query parameters

View file

@ -202,23 +202,9 @@ ircd::m::sync::room_state_append(data &data,
const m::event &event,
const m::event::idx &event_idx)
{
json::stack::object object
{
events
};
object.append(event);
json::stack::object unsigned_
{
object, "unsigned"
};
json::stack::member
{
unsigned_, "age", json::value
{
long(vm::current_sequence - event_idx)
}
};
m::event_append_opts opts;
opts.event_idx = &event_idx;
opts.client_txnid = &data.client_txnid;
opts.user_id = &data.user.user_id;
opts.user_room = &data.user_room;
}

View file

@ -16,7 +16,6 @@ IRCD_MODULE
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 event::id::buf _room_timeline_polylog_events(data &, const m::room &, bool &, bool &);
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 &event)
{
json::stack::object object
{
events
};
object.append(event);
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"))
};
});
m::event_append_opts opts;
opts.event_idx = &event_idx;
opts.client_txnid = &data.client_txnid;
opts.user_id = &data.user.user_id;
opts.user_room = &data.user_room;
m::append(events, event, opts);
}