mirror of
https://github.com/matrix-construct/construct
synced 2024-11-30 02:32:43 +01:00
modules/client/sync/rooms/state: Fix errors / rework phased member events. (#105)
modules/client/sync/rooms/state: Minor cleanup.
This commit is contained in:
parent
e26fe4b83d
commit
e099d7c52b
1 changed files with 31 additions and 19 deletions
|
@ -294,7 +294,7 @@ ircd::m::sync::room_state_phased_events(data &data)
|
||||||
*data.out, "events"
|
*data.out, "events"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::pair<string_view, string_view> keys[]
|
const std::pair<string_view, string_view> keys[]
|
||||||
{
|
{
|
||||||
{ "m.room.create", "" },
|
{ "m.room.create", "" },
|
||||||
{ "m.room.canonical_alias", "" },
|
{ "m.room.canonical_alias", "" },
|
||||||
|
@ -344,47 +344,59 @@ bool
|
||||||
ircd::m::sync::room_state_phased_member_events(data &data,
|
ircd::m::sync::room_state_phased_member_events(data &data,
|
||||||
json::stack::array &array)
|
json::stack::array &array)
|
||||||
{
|
{
|
||||||
static const auto count{10}, bufsz{48}, limit{10};
|
static const auto count{20}, bufsz{32}, limit{20};
|
||||||
|
|
||||||
|
size_t i(0), ret(0);
|
||||||
std::array<char[bufsz], count> buf;
|
std::array<char[bufsz], count> buf;
|
||||||
std::array<string_view, count> last;
|
std::array<string_view, count> last;
|
||||||
size_t i(0), ret(0);
|
const auto already
|
||||||
|
{
|
||||||
|
[&last, &ret](const string_view &sender) -> bool
|
||||||
|
{
|
||||||
|
return std::any_of(begin(last), begin(last)+ret, [&sender]
|
||||||
|
(const auto &last)
|
||||||
|
{
|
||||||
|
return startswith(last, sender);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
m::room::messages it
|
m::room::messages it
|
||||||
{
|
{
|
||||||
*data.room
|
*data.room
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto already{[&last, &ret]
|
|
||||||
(const string_view &sender) -> bool
|
|
||||||
{
|
|
||||||
return std::any_of(begin(last), begin(last)+ret, [&sender]
|
|
||||||
(const auto &last)
|
|
||||||
{
|
|
||||||
return startswith(last, sender);
|
|
||||||
});
|
|
||||||
}};
|
|
||||||
|
|
||||||
for(; it && ret < count && i < limit; --it, ++i)
|
for(; it && ret < count && i < limit; --it, ++i)
|
||||||
{
|
m::get(std::nothrow, it.event_idx(), "sender", [&]
|
||||||
const auto &event_idx(it.event_idx());
|
|
||||||
m::get(std::nothrow, event_idx, "sender", [&]
|
|
||||||
(const auto &sender)
|
(const auto &sender)
|
||||||
{
|
{
|
||||||
if(already(sender))
|
if(already(sender))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const auto sender_idx
|
||||||
|
{
|
||||||
|
data.room->get(std::nothrow, "m.room.member", sender)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!sender_idx)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// check if this is an m.room.member event in the timeline.
|
||||||
|
if(sender_idx == it.event_idx())
|
||||||
|
return;
|
||||||
|
|
||||||
const m::event::fetch event
|
const m::event::fetch event
|
||||||
{
|
{
|
||||||
event_idx, std::nothrow
|
sender_idx, std::nothrow
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!event.valid)
|
if(!event.valid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
last.at(ret) = strlcpy(buf.at(ret), sender);
|
last.at(ret) = strlcpy(buf.at(ret), sender);
|
||||||
room_state_append(data, array, event, event_idx);
|
room_state_append(data, array, event, sender_idx);
|
||||||
++ret;
|
++ret;
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue