2019-07-17 23:20:28 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
2022-08-20 01:17:48 +02:00
|
|
|
bool
|
|
|
|
ircd::m::user::rooms::prefetch()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const m::events::state::tuple query
|
|
|
|
{
|
|
|
|
user,
|
|
|
|
"m.room.member"_sv,
|
|
|
|
m::room::id{},
|
|
|
|
-1L,
|
|
|
|
0UL
|
|
|
|
};
|
|
|
|
|
|
|
|
bool ret{false};
|
|
|
|
return m::events::state::for_each(query, [this, &ret]
|
|
|
|
(const auto &tuple)
|
|
|
|
{
|
|
|
|
const auto &[state_key, type, room_id, depth, event_idx]
|
|
|
|
{
|
|
|
|
tuple
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(type == "m.room.member");
|
|
|
|
assert(state_key == user);
|
|
|
|
ret |= m::membership_prefetch(event_idx);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-17 23:20:28 +02:00
|
|
|
size_t
|
|
|
|
ircd::m::user::rooms::count()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
size_t ret{0};
|
|
|
|
for_each([&ret]
|
2022-07-04 22:15:53 +02:00
|
|
|
(const m::room &, const string_view &membership) noexcept
|
2019-07-17 23:20:28 +02:00
|
|
|
{
|
|
|
|
++ret;
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ircd::m::user::rooms::count(const string_view &membership)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
size_t ret{0};
|
|
|
|
for_each(membership, [&ret]
|
2022-07-04 22:15:53 +02:00
|
|
|
(const m::room &, const string_view &membership) noexcept
|
2019-07-17 23:20:28 +02:00
|
|
|
{
|
|
|
|
++ret;
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::m::user::rooms::for_each(const closure_bool &closure)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return for_each(string_view{}, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-12-12 01:24:46 +01:00
|
|
|
ircd::m::user::rooms::for_each(const string_view &membership_,
|
2019-07-17 23:20:28 +02:00
|
|
|
const closure_bool &closure)
|
|
|
|
const
|
|
|
|
{
|
2020-04-13 20:10:47 +02:00
|
|
|
const m::events::state::tuple query
|
|
|
|
{
|
|
|
|
user,
|
|
|
|
"m.room.member"_sv,
|
|
|
|
m::room::id{},
|
|
|
|
-1L,
|
|
|
|
0UL
|
|
|
|
};
|
2019-07-17 23:20:28 +02:00
|
|
|
|
2020-03-02 02:13:15 +01:00
|
|
|
m::room::id::buf room_id_;
|
2020-12-12 01:24:46 +01:00
|
|
|
return m::events::state::for_each(query, [this, &membership_, &closure, &room_id_]
|
2020-03-02 02:13:15 +01:00
|
|
|
(const auto &tuple)
|
2019-07-17 23:20:28 +02:00
|
|
|
{
|
2020-03-02 02:13:15 +01:00
|
|
|
const auto &[state_key, type, room_id, depth, event_idx]
|
|
|
|
{
|
|
|
|
tuple
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(type == "m.room.member");
|
|
|
|
assert(state_key == user);
|
2020-12-12 01:24:46 +01:00
|
|
|
if(room_id_ != room_id)
|
2020-03-02 02:13:15 +01:00
|
|
|
room_id_ = room_id;
|
|
|
|
else
|
2020-12-12 01:24:46 +01:00
|
|
|
return true;
|
2020-03-02 02:13:15 +01:00
|
|
|
|
2020-12-12 01:24:46 +01:00
|
|
|
char buf[m::room::MEMBERSHIP_MAX_SIZE];
|
|
|
|
const string_view &membership
|
2019-07-17 23:20:28 +02:00
|
|
|
{
|
2020-12-12 01:24:46 +01:00
|
|
|
m::membership(buf, event_idx)
|
|
|
|
};
|
2019-07-17 23:20:28 +02:00
|
|
|
|
2020-12-12 01:24:46 +01:00
|
|
|
if(likely(!membership_ || membership == membership_))
|
|
|
|
return closure(m::room::id(room_id), membership);
|
2019-07-17 23:20:28 +02:00
|
|
|
|
2020-12-12 01:24:46 +01:00
|
|
|
return true;
|
2019-07-17 23:20:28 +02:00
|
|
|
});
|
|
|
|
}
|