mirror of
https://github.com/matrix-construct/construct
synced 2024-11-14 14:01:08 +01:00
modules/client: Eliminate internal _append() kludge.
This commit is contained in:
parent
c39876990d
commit
4e7f5af457
4 changed files with 143 additions and 112 deletions
|
@ -39,14 +39,6 @@ context_log
|
|||
"m.context"
|
||||
};
|
||||
|
||||
static bool
|
||||
_append(json::stack::array &,
|
||||
const m::event &,
|
||||
const m::event::idx &,
|
||||
const m::user::room &,
|
||||
const int64_t &,
|
||||
const bool &query_txnid = true);
|
||||
|
||||
m::resource::response
|
||||
get__context(client &client,
|
||||
const m::resource::request &request,
|
||||
|
@ -179,7 +171,18 @@ get__context(client &client,
|
|||
if(!visible(event, request.user_id))
|
||||
continue;
|
||||
|
||||
counts.before += _append(array, event, before.event_idx(), user_room, room_depth);
|
||||
const auto event_idx(before.event_idx());
|
||||
counts.before += m::event::append
|
||||
{
|
||||
array, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &user_room.user.user_id,
|
||||
.user_room = &user_room,
|
||||
.room_depth = &room_depth,
|
||||
.query_txnid = true,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if(before && limit > 0)
|
||||
|
@ -219,7 +222,18 @@ get__context(client &client,
|
|||
if(!visible(event, request.user_id))
|
||||
continue;
|
||||
|
||||
counts.after += _append(array, event, after.event_idx(), user_room, room_depth);
|
||||
const auto event_idx(after.event_idx());
|
||||
counts.after += m::event::append
|
||||
{
|
||||
array, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &user_room.user.user_id,
|
||||
.user_room = &user_room,
|
||||
.room_depth = &room_depth,
|
||||
.query_txnid = true,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if(after && limit > 0)
|
||||
|
@ -277,7 +291,18 @@ get__context(client &client,
|
|||
if(!visible(event, request.user_id))
|
||||
return true;
|
||||
|
||||
counts.state += _append(array, event, event_idx, user_room, room_depth, false);
|
||||
counts.state += m::event::append
|
||||
{
|
||||
array, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &user_room.user.user_id,
|
||||
.user_room = &user_room,
|
||||
.room_depth = &room_depth,
|
||||
.query_txnid = false,
|
||||
}
|
||||
};
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -297,23 +322,3 @@ get__context(client &client,
|
|||
|
||||
return response;
|
||||
}
|
||||
|
||||
bool
|
||||
_append(json::stack::array &chunk,
|
||||
const m::event &event,
|
||||
const m::event::idx &event_idx,
|
||||
const m::user::room &user_room,
|
||||
const int64_t &room_depth,
|
||||
const bool &query_txnid)
|
||||
{
|
||||
return m::event::append
|
||||
{
|
||||
chunk, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &user_room.user.user_id,
|
||||
.user_room = &user_room,
|
||||
.room_depth = &room_depth,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -22,13 +22,6 @@ struct pagination_tokens
|
|||
pagination_tokens(const m::resource::request &);
|
||||
};
|
||||
|
||||
static bool
|
||||
_append(json::stack::array &chunk,
|
||||
const m::event &,
|
||||
const m::event::idx &,
|
||||
const m::user::room &user_room,
|
||||
const int64_t &room_depth);
|
||||
|
||||
conf::item<size_t>
|
||||
max_filter_miss
|
||||
{
|
||||
|
@ -149,13 +142,23 @@ get__messages(client &client,
|
|||
if(hit >= page.limit || miss >= size_t(max_filter_miss))
|
||||
break;
|
||||
|
||||
const m::event::idx event_idx{it};
|
||||
const bool ok
|
||||
{
|
||||
(empty(filter_json) || match(filter, event))
|
||||
|
||||
&& visible(event, request.user_id)
|
||||
|
||||
&& _append(chunk, event, it.event_idx(), user_room, room_depth)
|
||||
&& m::event::append
|
||||
{
|
||||
chunk, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &user_room.user.user_id,
|
||||
.user_room = &user_room,
|
||||
.room_depth = &room_depth,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
hit += ok;
|
||||
|
@ -214,25 +217,6 @@ get__messages(client &client,
|
|||
return {};
|
||||
}
|
||||
|
||||
bool
|
||||
_append(json::stack::array &chunk,
|
||||
const m::event &event,
|
||||
const m::event::idx &event_idx,
|
||||
const m::user::room &user_room,
|
||||
const int64_t &room_depth)
|
||||
{
|
||||
return m::event::append
|
||||
{
|
||||
chunk, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &user_room.user.user_id,
|
||||
.user_room = &user_room,
|
||||
.room_depth = &room_depth,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Client-Server 6.3.6 query parameters
|
||||
pagination_tokens::pagination_tokens(const m::resource::request &request)
|
||||
try
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
namespace ircd::m::sync
|
||||
{
|
||||
static bool room_state_append(data &, json::stack::array &, const m::event &, const m::event::idx &, const bool &query_prev);
|
||||
|
||||
static bool room_state_phased_member_events(data &, json::stack::array &);
|
||||
static bool room_state_phased_events(data &);
|
||||
static bool room_state_phased_prefetch(data &);
|
||||
|
@ -192,8 +190,18 @@ ircd::m::sync::room_state_linear_events(data &data)
|
|||
std::nothrow, event_idx
|
||||
};
|
||||
|
||||
if(event.valid)
|
||||
ret |= room_state_append(data, array, event, event_idx, true);
|
||||
ret |= event.valid && m::event::append
|
||||
{
|
||||
array, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
.query_txnid = false,
|
||||
.query_prev_state = true,
|
||||
}
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -226,7 +234,19 @@ ircd::m::sync::room_state_linear_events(data &data)
|
|||
state.get(std::nothrow, "m.room.member", sender, append);
|
||||
}
|
||||
|
||||
ret |= room_state_append(data, array, *data.event, data.event_idx, true);
|
||||
ret |= m::event::append
|
||||
{
|
||||
array, *data.event,
|
||||
{
|
||||
.event_idx = &data.event_idx,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
.query_txnid = false,
|
||||
.query_prev_state = true,
|
||||
}
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -348,7 +368,18 @@ ircd::m::sync::room_state_polylog_events(data &data)
|
|||
|
||||
assert(event.valid);
|
||||
const std::lock_guard lock{mutex};
|
||||
ret |= room_state_append(data, array, event, event_idx, false);
|
||||
ret |= m::event::append
|
||||
{
|
||||
array, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
.query_txnid = false,
|
||||
.query_prev_state = false,
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -477,7 +508,18 @@ ircd::m::sync::room_state_phased_events(data &data)
|
|||
(const m::event::idx &event_idx, const m::event &event)
|
||||
{
|
||||
const std::lock_guard lock{mutex};
|
||||
ret |= room_state_append(data, array, event, event_idx, true);
|
||||
ret |= m::event::append
|
||||
{
|
||||
array, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
.query_txnid = false,
|
||||
.query_prev_state = true,
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -613,29 +655,19 @@ ircd::m::sync::room_state_phased_member_events(data &data,
|
|||
if(!seek(std::nothrow, event, sender_idx))
|
||||
return;
|
||||
|
||||
ret |= room_state_append(data, array, event, sender_idx, false);
|
||||
ret |= m::event::append
|
||||
{
|
||||
array, event,
|
||||
{
|
||||
.event_idx = &sender_idx,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
.query_txnid = false,
|
||||
.query_prev_state = false,
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::sync::room_state_append(data &data,
|
||||
json::stack::array &events,
|
||||
const m::event &event,
|
||||
const m::event::idx &event_idx,
|
||||
const bool &query_prev)
|
||||
{
|
||||
return m::event::append
|
||||
{
|
||||
events, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
.query_txnid = false,
|
||||
.query_prev_state = query_prev,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
namespace ircd::m::sync
|
||||
{
|
||||
static bool _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 &);
|
||||
|
||||
|
@ -209,7 +208,17 @@ ircd::m::sync::room_timeline_linear(data &data)
|
|||
*data.out, "events"
|
||||
};
|
||||
|
||||
return _room_timeline_append(data, array, data.event_idx, *data.event);
|
||||
return m::event::append
|
||||
{
|
||||
array, *data.event,
|
||||
{
|
||||
.event_idx = &data.event_idx,
|
||||
.client_txnid = &data.client_txnid,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -258,7 +267,17 @@ ircd::m::sync::_room_timeline_linear_command(data &data)
|
|||
data.event, &event
|
||||
};
|
||||
|
||||
return _room_timeline_append(data, array, data.event_idx, event);
|
||||
return m::event::append
|
||||
{
|
||||
array, *data.event,
|
||||
{
|
||||
.event_idx = &data.event_idx,
|
||||
.client_txnid = &data.client_txnid,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -349,34 +368,25 @@ ircd::m::sync::_room_timeline_polylog_events(data &data,
|
|||
if(i > 0 && it)
|
||||
for(++it; i > 0 && it; --i, ++it)
|
||||
{
|
||||
const m::event &event
|
||||
const auto event_idx
|
||||
{
|
||||
*it
|
||||
it.event_idx()
|
||||
};
|
||||
|
||||
ret |= _room_timeline_append(data, array, it.event_idx(), event);
|
||||
ret |= m::event::append
|
||||
{
|
||||
array, *it,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.client_txnid = &data.client_txnid,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
assert(i >= 0);
|
||||
event_idx &= boolmask<event::idx>(ret);
|
||||
return m::event_id(std::nothrow, event_idx);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::sync::_room_timeline_append(data &data,
|
||||
json::stack::array &events,
|
||||
const m::event::idx &event_idx,
|
||||
const m::event &event)
|
||||
{
|
||||
return m::event::append
|
||||
{
|
||||
events, event,
|
||||
{
|
||||
.event_idx = &event_idx,
|
||||
.client_txnid = &data.client_txnid,
|
||||
.user_id = &data.user.user_id,
|
||||
.user_room = &data.user_room,
|
||||
.room_depth = &data.room_depth,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue