2019-09-18 19:30:23 +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.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_MEMBERSHIP_H
|
|
|
|
|
|
|
|
namespace ircd::m
|
|
|
|
{
|
|
|
|
// Extract membership string from event data.
|
2023-02-18 19:53:26 +01:00
|
|
|
[[gnu::pure]] string_view membership(const event &);
|
2019-09-18 19:30:23 +02:00
|
|
|
|
|
|
|
// Query and copy membership string to buffer. Note that the event type
|
|
|
|
// is not checked here, only content.membership is sought.
|
|
|
|
string_view membership(const mutable_buffer &out, const event::idx &);
|
|
|
|
|
|
|
|
// Query and copy membership string to buffer; queries room state. (also room.h)
|
|
|
|
string_view membership(const mutable_buffer &out, const room &, const id::user &);
|
|
|
|
|
2019-09-18 19:53:51 +02:00
|
|
|
// Query and compare membership string to argument string. Returns true on
|
|
|
|
// equal; false on not equal; false on not found. Note in addition to this
|
|
|
|
// we allow the user to pass an empty membership string which will test for
|
|
|
|
// non-membership as well and return true.
|
|
|
|
bool membership(const event::idx &, const string_view &);
|
|
|
|
|
2019-09-18 19:30:23 +02:00
|
|
|
// Query and compare membership string; queries room state. (also room.h)
|
2019-09-18 19:53:51 +02:00
|
|
|
// also see overload notes.
|
2019-09-18 19:30:23 +02:00
|
|
|
bool membership(const room &, const id::user &, const string_view &);
|
2019-09-18 20:25:09 +02:00
|
|
|
|
|
|
|
// Convenience suite with optimal aggregate queries; if the membership
|
|
|
|
// is equal to any of the strings (including the non-membership empty
|
|
|
|
// string described above) these functions return true. An empty vector is
|
|
|
|
// also a non-membership query.
|
2020-04-23 10:42:41 +02:00
|
|
|
bool membership(const event &, const vector_view<const string_view> &);
|
2019-09-18 20:25:09 +02:00
|
|
|
bool membership(const event::idx &, const vector_view<const string_view> &);
|
|
|
|
bool membership(const room &, const id::user &, const vector_view<const string_view> &);
|
|
|
|
|
2022-08-20 01:06:21 +02:00
|
|
|
// Prefetch suite
|
|
|
|
bool membership_prefetch(const event::idx &);
|
|
|
|
bool membership_prefetch(const room::state &, const id::user &);
|
|
|
|
|
2020-04-04 02:14:35 +02:00
|
|
|
// Convenience definitions of membership states for atomic queries.
|
2022-07-04 05:16:07 +02:00
|
|
|
extern const std::initializer_list<const string_view>
|
|
|
|
membership_positive, // join, invite
|
|
|
|
membership_negative; // leave, ban, knock, [non-membership]
|
2019-09-18 20:25:09 +02:00
|
|
|
}
|
|
|
|
|
2022-08-20 01:06:21 +02:00
|
|
|
inline bool
|
|
|
|
ircd::m::membership_prefetch(const room::state &state,
|
|
|
|
const user::id &user_id)
|
|
|
|
{
|
|
|
|
if(state.prefetch("m.room.member", user_id))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// The above prefetch didn't launch; this query is cached.
|
|
|
|
const auto event_idx
|
|
|
|
{
|
|
|
|
state.get(std::nothrow, "m.room.member", user_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
return membership_prefetch(event_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::m::membership_prefetch(const event::idx &event_idx)
|
|
|
|
{
|
|
|
|
return m::prefetch(event_idx, "content");
|
|
|
|
}
|
|
|
|
|
2019-09-18 20:25:09 +02:00
|
|
|
inline bool
|
|
|
|
ircd::m::membership(const room &room,
|
|
|
|
const id::user &user_id,
|
|
|
|
const string_view &membership)
|
|
|
|
{
|
|
|
|
const vector_view<const string_view> memberships
|
|
|
|
{
|
|
|
|
std::addressof(membership), 1
|
|
|
|
};
|
|
|
|
|
|
|
|
return m::membership(room, user_id, memberships);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::m::membership(const event::idx &event_idx,
|
|
|
|
const string_view &membership)
|
|
|
|
{
|
|
|
|
const vector_view<const string_view> memberships
|
|
|
|
{
|
|
|
|
std::addressof(membership), 1
|
|
|
|
};
|
|
|
|
|
|
|
|
return m::membership(event_idx, memberships);
|
2019-09-18 19:30:23 +02:00
|
|
|
}
|