tauri_plugin_matrix_svelte/matrix/
requests.rs

1use matrix_sdk::{
2    room::{edit::EditedContent, RoomMember},
3    ruma::{
4        events::room::message::RoomMessageEventContent, matrix_uri::MatrixId, OwnedEventId,
5        OwnedRoomAliasId, OwnedRoomId, OwnedUserId,
6    },
7    OwnedServerName, RoomMemberships,
8};
9use matrix_sdk_ui::timeline::TimelineEventItemId;
10
11use super::{singletons::REQUEST_SENDER, timeline::PaginationDirection};
12
13/// Submits a request to the worker thread to be executed asynchronously.
14pub fn submit_async_request(req: MatrixRequest) {
15    REQUEST_SENDER
16        .get()
17        .unwrap() // this is initialized
18        .send(req)
19        .expect("BUG: async worker task receiver has died!");
20}
21
22/// The set of requests for async work that can be made to the worker thread.
23#[allow(clippy::large_enum_variant)]
24pub enum MatrixRequest {
25    /// Request to paginate the older (or newer) events of a room's timeline.
26    PaginateRoomTimeline {
27        room_id: OwnedRoomId,
28        /// The maximum number of timeline events to fetch in each pagination batch.
29        num_events: u16,
30        direction: PaginationDirection,
31    },
32    /// Request to edit the content of an event in the given room's timeline.
33    EditMessage {
34        room_id: OwnedRoomId,
35        timeline_event_item_id: TimelineEventItemId,
36        edited_content: EditedContent,
37    },
38    /// Request to fetch the full details of the given event in the given room's timeline.
39    FetchDetailsForEvent {
40        room_id: OwnedRoomId,
41        event_id: OwnedEventId,
42    },
43    /// Request to fetch profile information for all members of a room.
44    /// This can be *very* slow depending on the number of members in the room.
45    SyncRoomMemberList { room_id: OwnedRoomId },
46    /// Request to join the given room.
47    JoinRoom { room_id: OwnedRoomId },
48    /// Request to leave the given room.
49    LeaveRoom { room_id: OwnedRoomId },
50    /// Request to get the actual list of members in a room.
51    /// This returns the list of members that can be displayed in the UI.
52    GetRoomMembers {
53        room_id: OwnedRoomId,
54        memberships: RoomMemberships,
55        /// * If `true` (not recommended), only the local cache will be accessed.
56        /// * If `false` (recommended), details will be fetched from the server.
57        local_only: bool,
58    },
59    /// Request to fetch profile information for the given user ID.
60    GetUserProfile {
61        user_id: OwnedUserId,
62        /// * If `Some`, the user is known to be a member of a room, so this will
63        ///   fetch the user's profile from that room's membership info.
64        /// * If `None`, the user's profile info will be fetched from the server
65        ///   in a room-agnostic manner, and no room membership info will be returned.
66        room_id: Option<OwnedRoomId>,
67        /// * If `true` (not recommended), only the local cache will be accessed.
68        /// * If `false` (recommended), details will be fetched from the server.
69        local_only: bool,
70    },
71    /// Request to fetch the number of unread messages in the given room.
72    GetNumberUnreadMessages { room_id: OwnedRoomId },
73    /// Request to ignore/block or unignore/unblock a user.
74    IgnoreUser {
75        /// Whether to ignore (`true`) or unignore (`false`) the user.
76        ignore: bool,
77        /// The room membership info of the user to (un)ignore.
78        room_member: RoomMember,
79        /// The room ID of the room where the user is a member,
80        /// which is only needed because it isn't present in the `RoomMember` object.
81        room_id: OwnedRoomId,
82    },
83    /// Request to resolve a room alias into a room ID and the servers that know about that room.
84    ResolveRoomAlias(OwnedRoomAliasId),
85    /// Request to fetch an Avatar image from the server.
86    /// Upon completion of the async media request, the `on_fetched` function
87    /// will be invoked with the content of an `AvatarUpdate`.
88    // FetchAvatar {
89    //     mxc_uri: OwnedMxcUri,
90    //     on_fetched: fn(AvatarUpdate),
91    // },
92    /// Request to fetch media from the server.
93    /// Upon completion of the async media request, the `on_fetched` function
94    /// will be invoked with four arguments: the `destination`, the `media_request`,
95    /// the result of the media fetch, and the `update_sender`.
96    // FetchMedia {
97    //     media_request: MediaRequestParameters,
98    //     on_fetched: OnMediaFetchedFn,
99    //     destination: MediaCacheEntryRef,
100    //     update_sender: Option<crossbeam_channel::Sender<TimelineUpdate>>,
101    // },
102    /// Request to send a message to the given room.
103    SendMessage {
104        room_id: OwnedRoomId,
105        message: RoomMessageEventContent,
106        // replied_to: Option<RepliedToInfo>,
107    },
108    /// Sends a notice to the given room that the current user is or is not typing.
109    ///
110    /// This request does not return a response or notify the UI thread, and
111    /// furthermore, there is no need to send a follow-up request to stop typing
112    /// (though you certainly can do so).
113    SendTypingNotice { room_id: OwnedRoomId, typing: bool },
114    /// Subscribe to typing notices for the given room.
115    ///
116    /// This request does not return a response or notify the UI thread.
117    SubscribeToTypingNotices {
118        room_id: OwnedRoomId,
119        /// Whether to subscribe or unsubscribe from typing notices for this room.
120        subscribe: bool,
121    },
122    /// Subscribe to changes in the read receipts of our own user.
123    ///
124    /// This request does not return a response or notify the UI thread.
125    SubscribeToOwnUserReadReceiptsChanged {
126        room_id: OwnedRoomId,
127        /// Whether to subscribe or unsubscribe to changes in the read receipts of our own user for this room
128        subscribe: bool,
129    },
130    /// Sends a read receipt for the given event in the given room.
131    ReadReceipt {
132        room_id: OwnedRoomId,
133        event_id: OwnedEventId,
134    },
135    /// Sends a fully-read receipt for the given event in the given room.
136    FullyReadReceipt {
137        room_id: OwnedRoomId,
138        event_id: OwnedEventId,
139    },
140    /// Sends a request to obtain the power levels for this room.
141    ///
142    /// The response is delivered back to the main UI thread via [`TimelineUpdate::UserPowerLevels`].
143    GetRoomPowerLevels { room_id: OwnedRoomId },
144    /// Toggles the given reaction to the given event in the given room.
145    ToggleReaction {
146        room_id: OwnedRoomId,
147        timeline_event_id: TimelineEventItemId,
148        reaction: String,
149    },
150    /// Redacts (deletes) the given event in the given room.
151    #[doc(alias("delete"))]
152    RedactMessage {
153        room_id: OwnedRoomId,
154        timeline_event_id: TimelineEventItemId,
155        reason: Option<String>,
156    },
157    /// Sends a request to obtain the room's pill link info for the given Matrix ID.
158    ///
159    /// The MatrixLinkPillInfo::Loaded variant is sent back to the main UI thread via.
160    GetMatrixRoomLinkPillInfo {
161        matrix_id: MatrixId,
162        via: Vec<OwnedServerName>,
163    },
164}
165// Deserialize trait is implemented in models/matrix_requests.rs