mirror of
https://github.com/matrix-construct/construct
synced 2024-09-26 18:38:52 +02:00
ircd:Ⓜ️ Generalize room::lonly into more efficient room::origins::only(origin).
This commit is contained in:
parent
8038faf8e0
commit
08d45dc838
2 changed files with 24 additions and 7 deletions
|
@ -343,6 +343,7 @@ struct ircd::m::room::origins
|
|||
bool test(const closure_bool &view) const;
|
||||
void for_each(const closure &view) const;
|
||||
bool has(const string_view &origin) const;
|
||||
bool only(const string_view &origin) const;
|
||||
size_t count() const;
|
||||
|
||||
origins(const m::room &room)
|
||||
|
|
|
@ -171,13 +171,7 @@ ircd::m::room::lonly()
|
|||
const
|
||||
{
|
||||
const origins origins(*this);
|
||||
if(origins.count() != 1)
|
||||
return false;
|
||||
|
||||
if(!origins.has(m::my_host()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return origins.only(my_host());
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -1571,6 +1565,28 @@ const
|
|||
return ret;
|
||||
}
|
||||
|
||||
/// Tests if argument is the only origin in the room.
|
||||
/// If a zero or more than one origins exist, returns false. If the only origin
|
||||
/// in the room is the argument origin, returns true.
|
||||
bool
|
||||
ircd::m::room::origins::only(const string_view &origin)
|
||||
const
|
||||
{
|
||||
bool ret{false};
|
||||
test([&ret, &origin]
|
||||
(const string_view &origin_)
|
||||
{
|
||||
if(origin == origin_)
|
||||
ret = true;
|
||||
else if(ret)
|
||||
ret = false;
|
||||
|
||||
return ret;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::origins::has(const string_view &origin)
|
||||
const
|
||||
|
|
Loading…
Reference in a new issue