zulip_api/message/realm_filter.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{impl_default, impl_display};
4
5/// Represents a legacy property for [linkifiers](crate::RealmLinkifier).
6///
7/// Present if `realm_filters` is present in `fetch_event_types`.
8///
9/// When present, this is always an empty array.
10///
11/// **Changes**: Prior to Zulip 7.0 (feature level 176), this was
12/// an array of tuples, where each tuple described a linkifier. The first
13/// element of the tuple was a string regex pattern which represented the
14/// pattern to be linkified on matching, for example `"#(?P<id>[123])"`.
15/// The second element was a URL format string that the pattern should be
16/// linkified with. A URL format string for the above example would be
17/// `"https://realm.com/my_realm_filter/%(id)s"`. And the third element
18/// was the ID of the realm filter.
19///
20/// **Deprecated** in Zulip 4.0 (feature level 54), replaced by the
21/// `realm_linkifiers` key.
22///
23/// Modified from `openapi-generator-cli` output:
24///
25/// ```shell,no_build,no_run
26/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
27/// ```
28///
29/// ```text
30/// /*
31/// * Zulip REST API
32/// *
33/// * Powerful open source group chat
34/// *
35/// * The version of the OpenAPI document: 1.0.0
36/// *
37/// * Generated by: https://openapi-generator.tech
38/// */
39/// ```
40///
41/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
42///
43/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
44#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
45pub struct RealmFilter(String, String, u64);
46
47impl RealmFilter {
48 /// Creates a new [RealmFilter].
49 pub const fn new() -> Self {
50 Self(String::new(), String::new(), 0)
51 }
52
53 /// Gets the regex pattern which represented the pattern to be linkified on matching, for example `"#(?P<id>[123])"`.
54 pub fn linkified_regex(&self) -> &str {
55 self.0.as_str()
56 }
57
58 /// Sets the regex pattern which represented the pattern to be linkified on matching, for example `"#(?P<id>[123])"`.
59 pub fn set_linkified_regex(&mut self, val: String) {
60 self.0 = val;
61 }
62
63 /// Builder function that sets the regex pattern which represented the pattern to be linkified on matching, for example `"#(?P<id>[123])"`.
64 pub fn with_linkified_regex(self, val: String) -> Self {
65 Self(val, self.1, self.2)
66 }
67
68 /// Gets the URL format string that the pattern should be linkified with.
69 ///
70 /// A URL format string for the above example would be `"https://realm.com/my_realm_filter/%(id)s"`.
71 pub fn url_format(&self) -> &str {
72 self.1.as_str()
73 }
74
75 /// Sets the URL format string that the pattern should be linkified with.
76 ///
77 /// A URL format string for the above example would be `"https://realm.com/my_realm_filter/%(id)s"`.
78 pub fn set_url_format(&mut self, val: String) {
79 self.1 = val;
80 }
81
82 /// Builder function that sets the URL format string that the pattern should be linkified with.
83 ///
84 /// A URL format string for the above example would be `"https://realm.com/my_realm_filter/%(id)s"`.
85 pub fn with_url_format(self, val: String) -> Self {
86 Self(self.0, val, self.2)
87 }
88
89 /// Gets the realm filter ID.
90 pub const fn id(&self) -> u64 {
91 self.2
92 }
93
94 /// Sets the realm filter ID.
95 pub fn set_id(&mut self, val: u64) {
96 self.2 = val;
97 }
98
99 /// Builder function that sets the realm filter ID.
100 pub fn with_id(self, val: u64) -> Self {
101 Self(self.0, self.1, val)
102 }
103}
104
105impl_default!(RealmFilter);
106impl_display!(RealmFilter);