commit a3f070715bb576ea4d21e9b27edc41953d3c79f3
parent 2b01d34a6775845a7d57ed966e95f6d3672b86de
Author: MTRNord <mtrnord1@gmail.com>
Date: Sat, 16 Apr 2022 20:33:06 +0200
inline MessageContent
Diffstat:
4 files changed, 100 insertions(+), 125 deletions(-)
diff --git a/build.rs b/build.rs
@@ -3,7 +3,6 @@ fn main() {
.src_prefix("schema")
.import_path("schema")
.file("schema/utils.capnp")
- .file("schema/events.capnp")
.file("schema/matrix.capnp")
.run()
.expect("schema compiler command");
diff --git a/schema/events.capnp b/schema/events.capnp
@@ -1,109 +0,0 @@
-@0x9e7f64b0577ea649;
-
-using Util = import "/utils.capnp";
-
-struct MessageContent {
- union {
- text: group {
- body @0: Text;
- format @1: Util.Option(Text);
- formattedBody @2: Util.Option(Text);
- }
- emote: group {
- body @3: Text;
- format @4: Util.Option(Text);
- formattedBody @5: Util.Option(Text);
- }
- notice: group {
- body @6: Text;
- format @7: Util.Option(Text);
- formattedBody @8: Util.Option(Text);
- }
- audio: group {
- body @9: Text;
- info @10: AudioInfo;
- url @11: Text;
- }
- file: group {
- body @12: Text;
- filename @13: Text;
- info @14: FileInfo;
- url @15: Text;
- }
- image: group {
- body @16: Text;
- info @17: ImageInfo;
- file @18: Util.Option(Text);
- url @19: Text;
- }
- location: group {
- body @20: Text;
- geoUri @21: Text;
- info @22: Util.Option(LocationInfo);
- }
- video: group {
- body @23: Text;
- info @24: VideoInfo;
- url @25: Text;
- }
- serverNotice : group {
- adminContact @26: Text;
- body @27: VideoInfo;
- limitType @28: LimitType;
- serverNoticeType @29: ServerNoticeType;
- }
- }
-
- enum ServerNoticeType {
- usageLimitExceeded @0;
- }
-
- enum LimitType {
- montlyActiveUser @0;
- }
-
- struct AudioInfo {
- duration @0: UInt64;
- mimeType @1: Text;
- size @2: UInt64;
- }
-
- struct FileInfo {
- mimeType @0: Text;
- size @1: UInt64;
- }
-
- struct ImageInfo {
- mimeType @0: Text;
- size @1: UInt64;
- h @2: UInt64;
- w @3: UInt64;
- }
-
- struct LocationInfo {
- thumbnailInfo @0: ImageInfo;
- thumbnailUrl @1: Text;
- thumbnailFile @2: Util.Option(Text);
- }
-
- struct VideoInfo {
- duration @0: UInt64;
- h @1: UInt64;
- w @2: UInt64;
- size @3: UInt64;
- mimeType @4: Text;
- thumbnailInfo @5: ImageInfo;
- thumbnailUrl @6: Text;
- }
-}
-
-enum MsgType {
- text @0;
- emote @1;
- notice @2;
- audio @3;
- file @4;
- image @5;
- location @6;
- video @7;
-}
-\ No newline at end of file
diff --git a/schema/matrix.capnp b/schema/matrix.capnp
@@ -1,16 +1,106 @@
@0xeab570afa44bcb9d;
using Util = import "/utils.capnp";
-using Events = import "/events.capnp";
struct MessageEvent {
- content @0: Events.MessageContent;
- roomId @1: Text;
- stateKey @2: Util.Option(Text);
- sender @3: Text;
- eventId @4: Text;
- originServerTs @5: UInt64;
- unsigned @6: Unsigned;
+ content: union {
+ text: group {
+ body @0: Text;
+ format @1: Util.Option(Text);
+ formattedBody @2: Util.Option(Text);
+ }
+ emote: group {
+ body @3: Text;
+ format @4: Util.Option(Text);
+ formattedBody @5: Util.Option(Text);
+ }
+ notice: group {
+ body @6: Text;
+ format @7: Util.Option(Text);
+ formattedBody @8: Util.Option(Text);
+ }
+ audio: group {
+ body @9: Text;
+ info @10: AudioInfo;
+ url @11: Text;
+ }
+ file: group {
+ body @12: Text;
+ filename @13: Text;
+ info @14: FileInfo;
+ url @15: Text;
+ }
+ image: group {
+ body @16: Text;
+ info @17: ImageInfo;
+ file @18: Util.Option(Text);
+ url @19: Text;
+ }
+ location: group {
+ body @20: Text;
+ geoUri @21: Text;
+ info @22: Util.Option(LocationInfo);
+ }
+ video: group {
+ body @23: Text;
+ info @24: VideoInfo;
+ url @25: Text;
+ }
+ serverNotice : group {
+ adminContact @26: Text;
+ body @27: VideoInfo;
+ limitType @28: LimitType;
+ serverNoticeType @29: ServerNoticeType;
+ }
+ }
+ roomId @30: Text;
+ stateKey @31: Util.Option(Text);
+ sender @32: Text;
+ eventId @33: Text;
+ originServerTs @34: UInt64;
+ unsigned @35: Unsigned;
+
+ enum ServerNoticeType {
+ usageLimitExceeded @0;
+ }
+
+ enum LimitType {
+ montlyActiveUser @0;
+ }
+
+ struct AudioInfo {
+ duration @0: UInt64;
+ mimeType @1: Text;
+ size @2: UInt64;
+ }
+
+ struct FileInfo {
+ mimeType @0: Text;
+ size @1: UInt64;
+ }
+
+ struct ImageInfo {
+ mimeType @0: Text;
+ size @1: UInt64;
+ h @2: UInt64;
+ w @3: UInt64;
+ }
+
+ struct LocationInfo {
+ thumbnailInfo @0: ImageInfo;
+ thumbnailUrl @1: Text;
+ thumbnailFile @2: Util.Option(Text);
+ }
+
+ struct VideoInfo {
+ duration @0: UInt64;
+ h @1: UInt64;
+ w @2: UInt64;
+ size @3: UInt64;
+ mimeType @4: Text;
+ thumbnailInfo @5: ImageInfo;
+ thumbnailUrl @6: Text;
+ }
}
struct Unsigned(Content) {
diff --git a/src/main.rs b/src/main.rs
@@ -1,4 +1,3 @@
-use crate::events_capnp::message_content;
use crate::matrix_capnp::message_event;
use crate::utils_capnp::option;
use capnp::serialize_packed;
@@ -9,9 +8,6 @@ use std::{fs::File, io::BufReader};
pub mod matrix_capnp {
include!(concat!(env!("OUT_DIR"), "/matrix_capnp.rs"));
}
-pub mod events_capnp {
- include!(concat!(env!("OUT_DIR"), "/events_capnp.rs"));
-}
pub mod utils_capnp {
include!(concat!(env!("OUT_DIR"), "/utils_capnp.rs"));
}
@@ -74,8 +70,8 @@ fn main() -> Result<()> {
println!("event_id: {}", event.get_event_id()?);
println!("origin_server_ts: {}", event.get_origin_server_ts());
- match event.get_content()?.which() {
- Ok(message_content::Text(content)) => {
+ match event.get_content().which() {
+ Ok(message_event::content::Text(content)) => {
println!("text body: {}", content.get_body()?);
match content.get_formatted_body()?.which() {
Ok(option::Some(content)) => {