ruma_client_api/threads/get_thread_subscriptions_changes.rs
1//! `GET /_matrix/client/*/thread_subscriptions`
2//!
3//! Retrieve a paginated range of thread subscriptions across all rooms.
4
5pub mod unstable {
6 //! `/unstable/` ([spec])
7 //!
8 //! [spec]: https://github.com/matrix-org/matrix-spec-proposals/pull/4308
9
10 use std::collections::BTreeMap;
11
12 use js_int::UInt;
13 use ruma_common::{
14 OwnedEventId, OwnedRoomId,
15 api::{Direction, auth_scheme::AccessToken, request, response},
16 metadata,
17 };
18 use serde::{Deserialize, Serialize};
19
20 metadata! {
21 method: GET,
22 rate_limited: true,
23 authentication: AccessToken,
24 history: {
25 unstable("org.matrix.msc4308") => "/_matrix/client/unstable/io.element.msc4308/thread_subscriptions",
26 }
27 }
28
29 /// Request type for the `get_thread_subscriptions_changes` endpoint.
30 #[request(error = crate::Error)]
31 pub struct Request {
32 /// The direction to use for pagination.
33 ///
34 /// Only `Direction::Backward` is meant to be supported, which is why this field is private
35 /// for now (as of 2025-08-21).
36 #[ruma_api(query)]
37 dir: Direction,
38
39 /// A token to continue pagination from.
40 ///
41 /// This token can be acquired from a previous `/thread_subscriptions` response, or the
42 /// `prev_batch` in a sliding sync response's `thread_subscriptions` field.
43 ///
44 /// The token is opaque and has no client-discernible meaning.
45 ///
46 /// If not provided, then the pagination starts from the "end".
47 #[ruma_api(query)]
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub from: Option<String>,
50
51 /// A token used to limit the pagination.
52 ///
53 /// The token can be set to the value of a sliding sync `pos` field used in a request that
54 /// returned new thread subscriptions with a `prev_batch` token.
55 #[ruma_api(query)]
56 #[serde(skip_serializing_if = "Option::is_none")]
57 pub to: Option<String>,
58
59 /// A maximum number of thread subscriptions to fetch in one response.
60 ///
61 /// Defaults to 100, if not provided. Servers may impose a smaller limit than requested.
62 #[ruma_api(query)]
63 #[serde(skip_serializing_if = "Option::is_none")]
64 pub limit: Option<UInt>,
65 }
66
67 /// A thread has been subscribed to at some point.
68 #[derive(Clone, Debug, Serialize, Deserialize)]
69 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
70 pub struct ThreadSubscription {
71 /// Whether the subscription was made automatically by a client, not by manual user choice.
72 pub automatic: bool,
73
74 /// The bump stamp of the thread subscription, to be used to compare with other changes
75 /// related to the same thread.
76 pub bump_stamp: UInt,
77 }
78
79 impl ThreadSubscription {
80 /// Create a new [`ThreadSubscription`] with the given values.
81 pub fn new(automatic: bool, bump_stamp: UInt) -> Self {
82 Self { automatic, bump_stamp }
83 }
84 }
85
86 /// A thread has been unsubscribed to at some point.
87 #[derive(Clone, Debug, Serialize, Deserialize)]
88 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
89 pub struct ThreadUnsubscription {
90 /// The bump stamp of the thread subscription, to be used to compare with other changes
91 /// related to the same thread.
92 pub bump_stamp: UInt,
93 }
94
95 impl ThreadUnsubscription {
96 /// Create a new [`ThreadUnsubscription`] with the given bump stamp.
97 pub fn new(bump_stamp: UInt) -> Self {
98 Self { bump_stamp }
99 }
100 }
101
102 /// Response type for the `get_thread_subscriptions_changes` endpoint.
103 #[response(error = crate::Error)]
104 pub struct Response {
105 /// New thread subscriptions.
106 #[serde(skip_serializing_if = "BTreeMap::is_empty")]
107 pub subscribed: BTreeMap<OwnedRoomId, BTreeMap<OwnedEventId, ThreadSubscription>>,
108
109 /// New thread unsubscriptions.
110 #[serde(skip_serializing_if = "BTreeMap::is_empty")]
111 pub unsubscribed: BTreeMap<OwnedRoomId, BTreeMap<OwnedEventId, ThreadUnsubscription>>,
112
113 /// If there are still more results to fetch, this is the token to use as the next `from`
114 /// value.
115 #[serde(skip_serializing_if = "Option::is_none")]
116 pub end: Option<String>,
117 }
118
119 impl Request {
120 /// Creates a new empty `Request`.
121 pub fn new() -> Self {
122 Self { dir: Direction::Backward, from: None, to: None, limit: None }
123 }
124 }
125
126 impl Response {
127 /// Creates a new empty `Response`.
128 pub fn new() -> Self {
129 Self { subscribed: BTreeMap::new(), unsubscribed: BTreeMap::new(), end: None }
130 }
131 }
132}