Update FilterDefinition to be lifetime-generic
This commit is contained in:
parent
f101611c3d
commit
a1ee6c74c0
@ -6,6 +6,7 @@ pub mod get_filter;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
|
use ruma_api::Outgoing;
|
||||||
use ruma_identifiers::{RoomId, UserId};
|
use ruma_identifiers::{RoomId, UserId};
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{MapAccess, Visitor},
|
de::{MapAccess, Visitor},
|
||||||
@ -184,8 +185,9 @@ impl Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A filter definition
|
/// A filter definition
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Outgoing, Serialize)]
|
||||||
pub struct FilterDefinition {
|
#[incoming_derive(Clone, Serialize)]
|
||||||
|
pub struct FilterDefinition<'a> {
|
||||||
/// List of event fields to include.
|
/// List of event fields to include.
|
||||||
///
|
///
|
||||||
/// If this list is absent then all fields are included. The entries may include '.' charaters
|
/// If this list is absent then all fields are included. The entries may include '.' charaters
|
||||||
@ -193,7 +195,7 @@ pub struct FilterDefinition {
|
|||||||
/// object. A literal '.' character in a field name may be escaped using a '\'. A server may
|
/// object. A literal '.' character in a field name may be escaped using a '\'. A server may
|
||||||
/// include more fields than were requested.
|
/// include more fields than were requested.
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub event_fields: Option<Vec<String>>,
|
pub event_fields: Option<&'a [String]>,
|
||||||
|
|
||||||
/// The format to use for events.
|
/// The format to use for events.
|
||||||
///
|
///
|
||||||
@ -215,7 +217,7 @@ pub struct FilterDefinition {
|
|||||||
pub room: Option<RoomFilter>,
|
pub room: Option<RoomFilter>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FilterDefinition {
|
impl<'a> FilterDefinition<'a> {
|
||||||
/// A filter that can be used to ignore all events
|
/// A filter that can be used to ignore all events
|
||||||
pub fn ignore_all() -> Self {
|
pub fn ignore_all() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
|
||||||
use super::FilterDefinition;
|
use super::{FilterDefinition, IncomingFilterDefinition};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -25,7 +25,7 @@ ruma_api! {
|
|||||||
|
|
||||||
/// The filter definition.
|
/// The filter definition.
|
||||||
#[ruma_api(body)]
|
#[ruma_api(body)]
|
||||||
pub filter: FilterDefinition,
|
pub filter: FilterDefinition<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
@ -39,7 +39,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given user ID and filter definition.
|
/// Creates a new `Request` with the given user ID and filter definition.
|
||||||
pub fn new(user_id: &'a UserId, filter: FilterDefinition) -> Self {
|
pub fn new(user_id: &'a UserId, filter: FilterDefinition<'a>) -> Self {
|
||||||
Self { user_id, filter }
|
Self { user_id, filter }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
|
||||||
use super::FilterDefinition;
|
use super::IncomingFilterDefinition;
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -30,7 +30,7 @@ ruma_api! {
|
|||||||
response: {
|
response: {
|
||||||
/// The filter definition.
|
/// The filter definition.
|
||||||
#[ruma_api(body)]
|
#[ruma_api(body)]
|
||||||
pub filter: FilterDefinition,
|
pub filter: IncomingFilterDefinition,
|
||||||
}
|
}
|
||||||
|
|
||||||
error: crate::Error
|
error: crate::Error
|
||||||
@ -45,7 +45,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given filter definition.
|
/// Creates a new `Response` with the given filter definition.
|
||||||
pub fn new(filter: FilterDefinition) -> Self {
|
pub fn new(filter: IncomingFilterDefinition) -> Self {
|
||||||
Self { filter }
|
Self { filter }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use ruma_events::{
|
|||||||
use ruma_identifiers::{DeviceKeyAlgorithm, RoomId, UserId};
|
use ruma_identifiers::{DeviceKeyAlgorithm, RoomId, UserId};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::r0::filter::FilterDefinition;
|
use crate::r0::filter::{FilterDefinition, IncomingFilterDefinition};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -110,7 +110,7 @@ pub enum Filter<'a> {
|
|||||||
// (there are probably some corner cases like leading whitespace)
|
// (there are probably some corner cases like leading whitespace)
|
||||||
#[serde(with = "ruma_serde::json_string")]
|
#[serde(with = "ruma_serde::json_string")]
|
||||||
/// A complete filter definition serialized to JSON.
|
/// A complete filter definition serialized to JSON.
|
||||||
FilterDefinition(FilterDefinition),
|
FilterDefinition(FilterDefinition<'a>),
|
||||||
|
|
||||||
/// The ID of a filter saved on the server.
|
/// The ID of a filter saved on the server.
|
||||||
FilterId(&'a str),
|
FilterId(&'a str),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user