7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | // Copyright 2022 Kévin Commaille |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | // you may not use this file except in compliance with the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | // You may obtain a copy of the License at |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | // Unless required by applicable law or agreed to in writing, software |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | // See the License for the specific language governing permissions and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | // limitations under the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | //! Types and traits for attachments. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | use std::time::Duration; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | use ruma::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | OwnedTransactionId, UInt, assign, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | events::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | Mentions, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | room::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | ImageInfo, ThumbnailInfo, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | message::{AudioInfo, FileInfo, TextMessageEventContent, VideoInfo}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | use crate::room::reply::Reply; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | /// Base metadata about an image. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | #[derive(Debug, Clone, Default)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | pub struct BaseImageInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | /// The height of the image in pixels. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | pub height: Option<UInt>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | /// The width of the image in pixels. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | pub width: Option<UInt>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | /// The file size of the image in bytes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | pub size: Option<UInt>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | /// The [BlurHash](https://blurha.sh/) for this image. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | pub blurhash: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | /// Whether this image is animated. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | pub is_animated: Option<bool>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 47 | /// Base metadata about a video. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | #[derive(Debug, Clone, Default)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | pub struct BaseVideoInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 50 | /// The duration of the video. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 51 | pub duration: Option<Duration>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 52 | /// The height of the video in pixels. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 53 | pub height: Option<UInt>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 54 | /// The width of the video in pixels. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 55 | pub width: Option<UInt>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 56 | /// The file size of the video in bytes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 57 | pub size: Option<UInt>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 58 | /// The [BlurHash](https://blurha.sh/) for this video. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 59 | pub blurhash: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 60 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 61 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 62 | /// Base metadata about an audio clip. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 63 | #[derive(Debug, Clone, Default)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 64 | pub struct BaseAudioInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 65 | /// The duration of the audio clip. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 66 | pub duration: Option<Duration>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 67 | /// The file size of the audio clip in bytes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 68 | pub size: Option<UInt>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 69 | /// The waveform of the audio clip. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 70 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 71 | /// Must only include values between 0 and 1. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 72 | pub waveform: Option<Vec<f32>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 73 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 74 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 75 | /// Base metadata about a file. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 76 | #[derive(Debug, Clone, Default)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 77 | pub struct BaseFileInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 78 | /// The size of the file in bytes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 79 | pub size: Option<UInt>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 80 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 81 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 82 | /// Types of metadata for an attachment. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 83 | #[derive(Debug)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 84 | pub enum AttachmentInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 85 | /// The metadata of an image. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 86 | Image(BaseImageInfo), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 87 | /// The metadata of a video. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 88 | Video(BaseVideoInfo), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 89 | /// The metadata of an audio clip. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 90 | Audio(BaseAudioInfo), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 91 | /// The metadata of a file. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 92 | File(BaseFileInfo), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 93 | /// The metadata of a voice message |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 94 | Voice(BaseAudioInfo), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 95 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 96 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 97 | impl From<AttachmentInfo> for ImageInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 98 | fn from(info: AttachmentInfo) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 99 | match info { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 100 | AttachmentInfo::Image(info) => assign!(ImageInfo::new(), { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 101 | height: info.height, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 102 | width: info.width, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 103 | size: info.size, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 104 | blurhash: info.blurhash, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 105 | is_animated: info.is_animated, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 106 | }), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 107 | _ => ImageInfo::new(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 108 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 109 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 110 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 111 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 112 | impl From<AttachmentInfo> for VideoInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 113 | fn from(info: AttachmentInfo) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 114 | match info { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 115 | AttachmentInfo::Video(info) => assign!(VideoInfo::new(), { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 116 | duration: info.duration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 117 | height: info.height, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 118 | width: info.width, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 119 | size: info.size, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 120 | blurhash: info.blurhash, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 121 | }), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 122 | _ => VideoInfo::new(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 123 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 124 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 125 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 126 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 127 | impl From<AttachmentInfo> for AudioInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 128 | fn from(info: AttachmentInfo) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 129 | match info { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 130 | AttachmentInfo::Audio(info) | AttachmentInfo::Voice(info) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 131 | assign!(AudioInfo::new(), { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 132 | duration: info.duration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 133 | size: info.size, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 134 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 135 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 136 | _ => AudioInfo::new(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 137 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 138 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 139 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 140 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 141 | impl From<AttachmentInfo> for FileInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 142 | fn from(info: AttachmentInfo) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 143 | match info { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 144 | AttachmentInfo::File(info) => assign!(FileInfo::new(), { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 145 | size: info.size, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 146 | }), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 147 | _ => FileInfo::new(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 148 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 149 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 150 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 151 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 152 | /// A thumbnail to upload and send for an attachment. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 153 | #[derive(Debug)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 154 | pub struct Thumbnail { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 155 | /// The raw bytes of the thumbnail. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 156 | pub data: Vec<u8>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 157 | /// The type of the thumbnail, this will be used as the content-type header. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 158 | pub content_type: mime::Mime, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 159 | /// The height of the thumbnail in pixels. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 160 | pub height: UInt, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 161 | /// The width of the thumbnail in pixels. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 162 | pub width: UInt, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 163 | /// The file size of the thumbnail in bytes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 164 | pub size: UInt, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 165 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 166 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 167 | impl Thumbnail { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 168 | /// Convert this `Thumbnail` into a `(data, content_type, info)` tuple. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 169 | pub fn into_parts(self) -> (Vec<u8>, mime::Mime, Box<ThumbnailInfo>) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 170 | let thumbnail_info = assign!(ThumbnailInfo::new(), { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 171 | height: Some(self.height), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 172 | width: Some(self.width), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 173 | size: Some(self.size), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 174 | mimetype: Some(self.content_type.to_string()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 175 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 176 | (self.data, self.content_type, Box::new(thumbnail_info)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 177 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 178 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 179 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 180 | /// Configuration for sending an attachment. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 181 | #[derive(Debug, Default)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 182 | pub struct AttachmentConfig { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 183 | /// A fixed transaction id to be used for sending this attachment. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 184 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 185 | /// Otherwise, a random one will be generated. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 186 | pub txn_id: Option<OwnedTransactionId>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 187 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 188 | /// Type-specific metadata about the attachment. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 189 | pub info: Option<AttachmentInfo>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 190 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 191 | /// An optional thumbnail to send with the attachment. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 192 | pub thumbnail: Option<Thumbnail>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 193 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 194 | /// An optional caption for the attachment. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 195 | pub caption: Option<TextMessageEventContent>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 196 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 197 | /// Intentional mentions to be included in the media event. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 198 | pub mentions: Option<Mentions>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 199 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 200 | /// Reply parameters for the attachment (replied-to event and thread-related |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 201 | /// metadata). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 202 | pub reply: Option<Reply>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 203 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 204 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 205 | impl AttachmentConfig { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 206 | /// Create a new empty `AttachmentConfig`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 207 | pub fn new() -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 208 | Self::default() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 209 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 210 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 211 | /// Set the thumbnail to send. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 212 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 213 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 214 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 215 | /// * `thumbnail` - The thumbnail of the media. If the `content_type` does |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 216 | /// not support it (e.g. audio clips), it is ignored. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 217 | #[must_use] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 218 | pub fn thumbnail(mut self, thumbnail: Option<Thumbnail>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 219 | self.thumbnail = thumbnail; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 220 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 221 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 222 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 223 | /// Set the transaction ID to send. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 224 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 225 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 226 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 227 | /// * `txn_id` - A unique ID that can be attached to a `MessageEvent` held |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 228 | /// in its unsigned field as `transaction_id`. If not given, one is |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 229 | /// created for the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 230 | #[must_use] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 231 | pub fn txn_id(mut self, txn_id: OwnedTransactionId) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 232 | self.txn_id = Some(txn_id); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 233 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 234 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 235 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 236 | /// Set the media metadata to send. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 237 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 238 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 239 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 240 | /// * `info` - The metadata of the media. If the `AttachmentInfo` type |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 241 | /// doesn't match the `content_type`, it is ignored. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 242 | #[must_use] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 243 | pub fn info(mut self, info: AttachmentInfo) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 244 | self.info = Some(info); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 245 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 246 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 247 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 248 | /// Set the optional caption. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 249 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 250 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 251 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 252 | /// * `caption` - The optional caption. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 253 | pub fn caption(mut self, caption: Option<TextMessageEventContent>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 254 | self.caption = caption; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 255 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 256 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 257 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 258 | /// Set the mentions of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 259 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 260 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 261 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 262 | /// * `mentions` - The mentions of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 263 | pub fn mentions(mut self, mentions: Option<Mentions>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 264 | self.mentions = mentions; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 265 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 266 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 267 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 268 | /// Set the reply information of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 269 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 270 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 271 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 272 | /// * `reply` - The reply information of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 273 | pub fn reply(mut self, reply: Option<Reply>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 274 | self.reply = reply; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 275 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 276 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 277 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 278 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 279 | /// Configuration for sending a gallery. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 280 | #[cfg(feature = "unstable-msc4274")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 281 | #[derive(Debug, Default)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 282 | pub struct GalleryConfig { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 283 | pub(crate) txn_id: Option<OwnedTransactionId>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 284 | pub(crate) items: Vec<GalleryItemInfo>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 285 | pub(crate) caption: Option<TextMessageEventContent>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 286 | pub(crate) mentions: Option<Mentions>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 287 | pub(crate) reply: Option<Reply>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 288 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 289 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 290 | #[cfg(feature = "unstable-msc4274")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 291 | impl GalleryConfig { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 292 | /// Create a new empty `GalleryConfig`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 293 | pub fn new() -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 294 | Self::default() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 295 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 296 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 297 | /// Set the transaction ID to send. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 298 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 299 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 300 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 301 | /// * `txn_id` - A unique ID that can be attached to a `MessageEvent` held |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 302 | /// in its unsigned field as `transaction_id`. If not given, one is |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 303 | /// created for the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 304 | #[must_use] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 305 | pub fn txn_id(mut self, txn_id: OwnedTransactionId) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 306 | self.txn_id = Some(txn_id); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 307 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 308 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 309 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 310 | /// Adds a media item to the gallery. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 311 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 312 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 313 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 314 | /// * `item` - Information about the item to be added. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 315 | #[must_use] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 316 | pub fn add_item(mut self, item: GalleryItemInfo) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 317 | self.items.push(item); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 318 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 319 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 320 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 321 | /// Set the optional caption. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 322 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 323 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 324 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 325 | /// * `caption` - The optional caption. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 326 | pub fn caption(mut self, caption: Option<TextMessageEventContent>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 327 | self.caption = caption; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 328 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 329 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 330 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 331 | /// Set the mentions of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 332 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 333 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 334 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 335 | /// * `mentions` - The mentions of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 336 | pub fn mentions(mut self, mentions: Option<Mentions>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 337 | self.mentions = mentions; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 338 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 339 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 340 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 341 | /// Set the reply information of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 342 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 343 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 344 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 345 | /// * `reply` - The reply information of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 346 | pub fn reply(mut self, reply: Option<Reply>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 347 | self.reply = reply; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 348 | self |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 349 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 350 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 351 | /// Returns the number of media items in the gallery. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 352 | pub fn len(&self) -> usize { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 353 | self.items.len() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 354 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 355 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 356 | /// Checks whether the gallery contains any media items or not. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 357 | pub fn is_empty(&self) -> bool { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 358 | self.items.is_empty() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 359 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 360 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 361 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 362 | #[cfg(feature = "unstable-msc4274")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 363 | #[derive(Debug)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 364 | /// Metadata for a gallery item |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 365 | pub struct GalleryItemInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 366 | /// The filename. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 367 | pub filename: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 368 | /// The mime type. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 369 | pub content_type: mime::Mime, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 370 | /// The binary data. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 371 | pub data: Vec<u8>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 372 | /// The attachment info. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 373 | pub attachment_info: AttachmentInfo, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 374 | /// The caption. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 375 | pub caption: Option<TextMessageEventContent>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 376 | /// The thumbnail. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 377 | pub thumbnail: Option<Thumbnail>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 378 | } |