replayer-mx

git clone git://archive.git.mtrnord.blog/MTRNord/replayer-mx.git
Log | Files | Refs

commit a5321c38567a6af6fc06f6917e6c310a197c9c57
parent b909b98cf68fcd19fba8367a120bb2411bf213a6
Author: MTRNord <mtrnord1@gmail.com>
Date:   Sat, 16 Apr 2022 23:00:36 +0200

Add rest of m.room.message types

Diffstat:
Mschema/matrix.capnp | 13++++++++++---
Msrc/events/message.rs | 172+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Msrc/events/mod.rs | 30++++++++++++++++++++++++++++++
Msrc/main.rs | 3++-
4 files changed, 188 insertions(+), 30 deletions(-)

diff --git a/schema/matrix.capnp b/schema/matrix.capnp @@ -83,7 +83,7 @@ struct MessageEvent { struct LocationInfo { # Only present if image thumbnail is set - thumbnailInfo @0: ImageInfo; + thumbnailInfo @0: ThumbnailInfo; # Only present if image thumbnail is set thumbnailUrl @1: Text; # Only exists on E2EE encrypted messages @@ -101,7 +101,7 @@ struct MessageEvent { # Only present if image thumbnail is set thumbnailFile @5: Text; # Only present if image thumbnail is set - thumbnailInfo @6: ImageInfo; + thumbnailInfo @6: ThumbnailInfo; # Only present if image thumbnail is set thumbnailUrl @7: Text; } @@ -150,10 +150,17 @@ struct ImageInfo { # Only present if image thumbnail is set thumbnailFile @1: Text; # Only present if image thumbnail is set - thumbnailInfo @2: Text; + thumbnailInfo @2: ThumbnailInfo; # Only present if image thumbnail is set thumbnailUrl @3: Text; size @4: UInt64; h @5: UInt64; w @6: UInt64; +} + +struct ThumbnailInfo { + mimeType @0: Text; + size @4: UInt64; + h @5: UInt64; + w @6: UInt64; } \ No newline at end of file diff --git a/src/events/message.rs b/src/events/message.rs @@ -1,26 +1,5 @@ -use std::borrow::Cow; - use minicbor::{Decode, Encode}; - -use crate::events::common::Unsigned; - -#[derive(Encode, Decode, Debug)] -pub(crate) struct Event<'a> { - #[b(0)] - pub(crate) content: Content<'a>, - #[b(1)] - pub(crate) room_id: Cow<'a, str>, - #[b(2)] - pub(crate) event_id: Cow<'a, str>, - #[b(3)] - pub(crate) sender: Cow<'a, str>, - #[b(4)] - pub(crate) origin_server_ts: u64, - #[b(5)] - pub(crate) unsigned: Unsigned<'a, Content<'a>>, - #[b(6)] - pub(crate) state_key: Option<Cow<'a, str>>, -} +use std::borrow::Cow; #[derive(Encode, Decode, Debug)] pub(crate) enum RoomMessageContent<'a> { @@ -28,6 +7,12 @@ pub(crate) enum RoomMessageContent<'a> { Text(#[b(0)] TextContent<'a>), #[b(1)] Audio(#[b(0)] AudioContent<'a>), + #[b(2)] + File(#[b(0)] FileContent<'a>), + #[b(3)] + Image(#[b(0)] ImageContent<'a>), + #[b(4)] + Video(#[b(0)] VideoContent<'a>), } /// Use for text, emotes and notices @@ -42,6 +27,13 @@ pub(crate) struct TextContent<'a> { } #[derive(Encode, Decode, Debug)] +#[cbor(index_only)] +pub(crate) enum FormatType { + #[b(0)] + Html, +} + +#[derive(Encode, Decode, Debug)] pub(crate) struct AudioContent<'a> { #[b(0)] pub(crate) body: Cow<'a, str>, @@ -62,14 +54,142 @@ pub(crate) struct AudioInfo<'a> { } #[derive(Encode, Decode, Debug)] +pub(crate) struct FileContent<'a> { + #[b(0)] + pub(crate) body: Cow<'a, str>, + #[b(1)] + pub(crate) filename: Cow<'a, str>, + #[b(2)] + pub(crate) url: Cow<'a, str>, + #[b(3)] + pub(crate) info: Option<FileInfo<'a>>, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) struct FileInfo<'a> { + #[b(0)] + pub(crate) mime_type: Cow<'a, str>, + #[b(1)] + pub(crate) size: u64, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) struct ImageContent<'a> { + #[b(0)] + pub(crate) body: Cow<'a, str>, + #[b(1)] + pub(crate) url: Cow<'a, str>, + #[b(2)] + pub(crate) info: Option<ImageInfo<'a>>, + #[b(3)] + pub(crate) file: Option<Cow<'a, str>>, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) struct ImageInfo<'a> { + #[b(0)] + pub(crate) mime_type: Cow<'a, str>, + #[b(1)] + pub(crate) size: u64, + #[b(2)] + pub(crate) h: Option<u64>, + #[b(3)] + pub(crate) w: Option<u64>, + #[b(4)] + pub(crate) thumbnail_file: Option<Cow<'a, str>>, + #[b(5)] + pub(crate) thumbnail_info: Option<ThumbnailInfo<'a>>, + #[b(6)] + pub(crate) thumbnail_url: Option<Cow<'a, str>>, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) struct ThumbnailInfo<'a> { + #[b(0)] + pub(crate) mime_type: Cow<'a, str>, + #[b(1)] + pub(crate) size: u64, + #[b(2)] + pub(crate) h: Option<u64>, + #[b(3)] + pub(crate) w: Option<u64>, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) struct VideoContent<'a> { + #[b(0)] + pub(crate) body: Cow<'a, str>, + #[b(1)] + pub(crate) url: Cow<'a, str>, + #[b(2)] + pub(crate) info: Option<VideoInfo<'a>>, + #[b(3)] + pub(crate) file: Option<Cow<'a, str>>, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) struct VideoInfo<'a> { + #[b(0)] + pub(crate) duration: u64, + #[b(1)] + pub(crate) mime_type: Cow<'a, str>, + #[b(2)] + pub(crate) size: u64, + #[b(3)] + pub(crate) h: Option<u64>, + #[b(4)] + pub(crate) w: Option<u64>, + #[b(5)] + pub(crate) thumbnail_file: Option<Cow<'a, str>>, + #[b(6)] + pub(crate) thumbnail_info: Option<ThumbnailInfo<'a>>, + #[b(7)] + pub(crate) thumbnail_url: Option<Cow<'a, str>>, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) struct LocationContent<'a> { + #[b(0)] + pub(crate) body: Cow<'a, str>, + #[b(1)] + pub(crate) geo_uri: Cow<'a, str>, + #[b(2)] + pub(crate) info: Option<LocationInfo<'a>>, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) struct LocationInfo<'a> { + #[b(0)] + pub(crate) thumbnail_file: Option<Cow<'a, str>>, + #[b(1)] + pub(crate) thumbnail_info: Option<ThumbnailInfo<'a>>, + #[b(2)] + pub(crate) thumbnail_url: Option<Cow<'a, str>>, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) struct ServerNotice<'a> { + #[b(0)] + pub(crate) admin_contact: Cow<'a, str>, + #[b(1)] + pub(crate) body: Cow<'a, str>, + #[b(2)] + pub(crate) server_notice_type: ServerNoticeType<'a>, + #[b(3)] + pub(crate) limit_type: Option<LimitType>, +} + +#[derive(Encode, Decode, Debug)] #[cbor(index_only)] -pub(crate) enum FormatType { +pub(crate) enum LimitType { #[b(0)] - Html, + MontlyActiveUser, } #[derive(Encode, Decode, Debug)] -pub(crate) enum Content<'a> { +pub(crate) enum ServerNoticeType<'a> { #[b(0)] - RoomMessage(#[b(0)] RoomMessageContent<'a>), + UsageLimitExceeded, + #[b(1)] + Other(#[b(0)] Cow<'a, str>), } diff --git a/src/events/mod.rs b/src/events/mod.rs @@ -1,2 +1,32 @@ pub(crate) mod common; pub(crate) mod message; + +use std::borrow::Cow; + +use minicbor::{Decode, Encode}; + +use crate::events::{common::Unsigned, message::RoomMessageContent}; + +#[derive(Encode, Decode, Debug)] +pub(crate) struct Event<'a> { + #[b(0)] + pub(crate) content: Content<'a>, + #[b(1)] + pub(crate) room_id: Cow<'a, str>, + #[b(2)] + pub(crate) event_id: Cow<'a, str>, + #[b(3)] + pub(crate) sender: Cow<'a, str>, + #[b(4)] + pub(crate) origin_server_ts: u64, + #[b(5)] + pub(crate) unsigned: Unsigned<'a, Content<'a>>, + #[b(6)] + pub(crate) state_key: Option<Cow<'a, str>>, +} + +#[derive(Encode, Decode, Debug)] +pub(crate) enum Content<'a> { + #[b(0)] + RoomMessage(#[b(0)] RoomMessageContent<'a>), +} diff --git a/src/main.rs b/src/main.rs @@ -8,7 +8,8 @@ use std::{ use crate::events::{ common::Unsigned, - message::{Content, Event, RoomMessageContent, TextContent}, + message::{RoomMessageContent, TextContent}, + Content, Event, }; mod events;