message.rs (4426B)
1 use minicbor::{Decode, Encode}; 2 use std::borrow::Cow; 3 4 #[derive(Encode, Decode, Debug)] 5 pub(crate) enum RoomMessageContent<'a> { 6 #[b(0)] 7 Text(#[b(0)] TextContent<'a>), 8 #[b(1)] 9 Audio(#[b(0)] AudioContent<'a>), 10 #[b(2)] 11 File(#[b(0)] FileContent<'a>), 12 #[b(3)] 13 Image(#[b(0)] ImageContent<'a>), 14 #[b(4)] 15 Video(#[b(0)] VideoContent<'a>), 16 } 17 18 /// Use for text, emotes and notices 19 #[derive(Encode, Decode, Debug)] 20 pub(crate) struct TextContent<'a> { 21 #[b(0)] 22 pub(crate) body: Cow<'a, str>, 23 #[b(1)] 24 pub(crate) format: Option<FormatType>, 25 #[b(2)] 26 pub(crate) formatted_body: Option<Cow<'a, str>>, 27 } 28 29 #[derive(Encode, Decode, Debug)] 30 #[cbor(index_only)] 31 pub(crate) enum FormatType { 32 #[b(0)] 33 Html, 34 } 35 36 #[derive(Encode, Decode, Debug)] 37 pub(crate) struct AudioContent<'a> { 38 #[b(0)] 39 pub(crate) body: Cow<'a, str>, 40 #[b(1)] 41 pub(crate) url: Cow<'a, str>, 42 #[b(2)] 43 pub(crate) info: Option<AudioInfo<'a>>, 44 } 45 46 #[derive(Encode, Decode, Debug)] 47 pub(crate) struct AudioInfo<'a> { 48 #[b(0)] 49 pub(crate) duration: u64, 50 #[b(1)] 51 pub(crate) mime_type: Cow<'a, str>, 52 #[b(2)] 53 pub(crate) size: u64, 54 } 55 56 #[derive(Encode, Decode, Debug)] 57 pub(crate) struct FileContent<'a> { 58 #[b(0)] 59 pub(crate) body: Cow<'a, str>, 60 #[b(1)] 61 pub(crate) filename: Cow<'a, str>, 62 #[b(2)] 63 pub(crate) url: Cow<'a, str>, 64 #[b(3)] 65 pub(crate) info: Option<FileInfo<'a>>, 66 } 67 68 #[derive(Encode, Decode, Debug)] 69 pub(crate) struct FileInfo<'a> { 70 #[b(0)] 71 pub(crate) mime_type: Cow<'a, str>, 72 #[b(1)] 73 pub(crate) size: u64, 74 } 75 76 #[derive(Encode, Decode, Debug)] 77 pub(crate) struct ImageContent<'a> { 78 #[b(0)] 79 pub(crate) body: Cow<'a, str>, 80 #[b(1)] 81 pub(crate) url: Cow<'a, str>, 82 #[b(2)] 83 pub(crate) info: Option<ImageInfo<'a>>, 84 #[b(3)] 85 pub(crate) file: Option<Cow<'a, str>>, 86 } 87 88 #[derive(Encode, Decode, Debug)] 89 pub(crate) struct ImageInfo<'a> { 90 #[b(0)] 91 pub(crate) mime_type: Cow<'a, str>, 92 #[b(1)] 93 pub(crate) size: u64, 94 #[b(2)] 95 pub(crate) h: Option<u64>, 96 #[b(3)] 97 pub(crate) w: Option<u64>, 98 #[b(4)] 99 pub(crate) thumbnail_file: Option<Cow<'a, str>>, 100 #[b(5)] 101 pub(crate) thumbnail_info: Option<ThumbnailInfo<'a>>, 102 #[b(6)] 103 pub(crate) thumbnail_url: Option<Cow<'a, str>>, 104 } 105 106 #[derive(Encode, Decode, Debug)] 107 pub(crate) struct ThumbnailInfo<'a> { 108 #[b(0)] 109 pub(crate) mime_type: Cow<'a, str>, 110 #[b(1)] 111 pub(crate) size: u64, 112 #[b(2)] 113 pub(crate) h: Option<u64>, 114 #[b(3)] 115 pub(crate) w: Option<u64>, 116 } 117 118 #[derive(Encode, Decode, Debug)] 119 pub(crate) struct VideoContent<'a> { 120 #[b(0)] 121 pub(crate) body: Cow<'a, str>, 122 #[b(1)] 123 pub(crate) url: Cow<'a, str>, 124 #[b(2)] 125 pub(crate) info: Option<VideoInfo<'a>>, 126 #[b(3)] 127 pub(crate) file: Option<Cow<'a, str>>, 128 } 129 130 #[derive(Encode, Decode, Debug)] 131 pub(crate) struct VideoInfo<'a> { 132 #[b(0)] 133 pub(crate) duration: u64, 134 #[b(1)] 135 pub(crate) mime_type: Cow<'a, str>, 136 #[b(2)] 137 pub(crate) size: u64, 138 #[b(3)] 139 pub(crate) h: Option<u64>, 140 #[b(4)] 141 pub(crate) w: Option<u64>, 142 #[b(5)] 143 pub(crate) thumbnail_file: Option<Cow<'a, str>>, 144 #[b(6)] 145 pub(crate) thumbnail_info: Option<ThumbnailInfo<'a>>, 146 #[b(7)] 147 pub(crate) thumbnail_url: Option<Cow<'a, str>>, 148 } 149 150 #[derive(Encode, Decode, Debug)] 151 pub(crate) struct LocationContent<'a> { 152 #[b(0)] 153 pub(crate) body: Cow<'a, str>, 154 #[b(1)] 155 pub(crate) geo_uri: Cow<'a, str>, 156 #[b(2)] 157 pub(crate) info: Option<LocationInfo<'a>>, 158 } 159 160 #[derive(Encode, Decode, Debug)] 161 pub(crate) struct LocationInfo<'a> { 162 #[b(0)] 163 pub(crate) thumbnail_file: Option<Cow<'a, str>>, 164 #[b(1)] 165 pub(crate) thumbnail_info: Option<ThumbnailInfo<'a>>, 166 #[b(2)] 167 pub(crate) thumbnail_url: Option<Cow<'a, str>>, 168 } 169 170 #[derive(Encode, Decode, Debug)] 171 pub(crate) struct ServerNotice<'a> { 172 #[b(0)] 173 pub(crate) admin_contact: Cow<'a, str>, 174 #[b(1)] 175 pub(crate) body: Cow<'a, str>, 176 #[b(2)] 177 pub(crate) server_notice_type: ServerNoticeType<'a>, 178 #[b(3)] 179 pub(crate) limit_type: Option<LimitType>, 180 } 181 182 #[derive(Encode, Decode, Debug)] 183 #[cbor(index_only)] 184 pub(crate) enum LimitType { 185 #[b(0)] 186 MontlyActiveUser, 187 } 188 189 #[derive(Encode, Decode, Debug)] 190 pub(crate) enum ServerNoticeType<'a> { 191 #[b(0)] 192 UsageLimitExceeded, 193 #[b(1)] 194 Other(#[b(0)] Cow<'a, str>), 195 }