Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
0.8: completely overhaul event & content handling
Browse files Browse the repository at this point in the history
- Big changes are afoot! This release decouples event metadata from event
  content, and decouples event content from the massive enum it once was.
- Also, we now actually check the event type instead of using untagged
  enums.
- Essentially, each possible matrix event now has its content struct
  somewhere in the types::content module.
- Documentation exists, too!
  • Loading branch information
eeeeeta committed Oct 26, 2017
1 parent fd7f525 commit 63d95c3
Show file tree
Hide file tree
Showing 17 changed files with 691 additions and 284 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: rust
rust:
- stable
- beta
- nightly
matrix:
allow_failures:
- rust: nightly
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "CC0-1.0"
name = "glitch-in-the-matrix"
readme = "README.md"
repository = "https://github.com/eeeeeta/glitch-in-the-matrix"
version = "0.7.0"
version = "0.8.0"

[dependencies]
error-chain = "0.10"
Expand Down
13 changes: 6 additions & 7 deletions examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio_core::reactor::Core;
use gm::{MatrixClient, MatrixFuture};
use gm::types::messages::{Message};
use gm::types::content::{Content};
use gm::types::events::{EventTypes};
use gm::types::events::{EventMetadata, Event};
use rpassword::prompt_password_stdout;
use std::env;

Expand All @@ -32,17 +32,16 @@ fn main() {
let fut = ss.skip(1).for_each(|sync| {
let mut futs: Vec<MatrixFuture<()>> = vec![];
for (room, events) in sync.rooms.join {
for event in events.timeline.events {
// we only want messages, so we ignore the other event types
if let EventTypes::Event(event) = event {
for Event(meta, content) in events.timeline.events {
if let EventMetadata::Full(meta) = meta {
// only echo messages from other users
if event.sender == mx.user_id() {
if meta.sender == mx.user_id() {
continue;
}
// tell the server we have read the event
let mut rc = room.cli(&mut mx);
futs.push(Box::new(rc.read_receipt(&event.event_id).map(|_| ())));
if let Content::Message(m) = event.content {
futs.push(Box::new(rc.read_receipt(&meta.event_id).map(|_| ())));
if let Content::RoomMessage(m) = content {
if let Message::Text { body, .. } = m {
futs.push(Box::new(rc.send_simple(body).map(|_| ())));
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern crate tokio_core;
extern crate percent_encoding;

pub mod errors {
#![allow(unused_doc_comment)]
//! Error handling, using `error_chain`.
error_chain! {
types {
Expand Down Expand Up @@ -55,7 +56,7 @@ mod util;
use util::*;
use errors::*;
use types::replies::*;
use types::content::{Presence};
use types::content::root::types::Presence;
use hyper::{Method, Body};
use Method::*;
use hyper::client::{HttpConnector, Request};
Expand Down
10 changes: 10 additions & 0 deletions src/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ impl<'a, 'b, 'c> RoomClient<'a, 'b, 'c> {
MatrixRequest::new_basic(Post, format!("/rooms/{}/receipt/m.read/{}", self.room.id, eventid))
.discarding_send(self.cli)
}
/* /// Looks up the contents of a state event in a room. If the user is joined
/// to the room then the state is taken from the current state of the room.
/// If the user has left the room then the state is taken from the state of
/// the room when they left.
///
/// The return value here can be any object that implements `Deserialize`,
/// allowing you to use the state API to store arbitrary objects. Common
/// state events, such as `m.room.name`, can be found in ...
pub fn get_state<T: Deserialize>(&mut self, ev_type: &str, key: Option<&str>) -> MatrixFuture<T> {
}*/
/// Strips all information out of an event which isn't critical to the
/// integrity of the server-side representation of the room.
///
Expand Down
168 changes: 0 additions & 168 deletions src/types/content.rs

This file was deleted.

58 changes: 58 additions & 0 deletions src/types/content/call/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! Content types for `m.call.*` events.
pub mod types;
/// `m.call.invite`
///
/// This event is sent by the caller when they wish to establish a call.
#[derive(Serialize, Deserialize, Debug)]
pub struct Invite {
/// A unique identifer for the call.
call_id: String,
/// The session description object
offer: types::Offer,
/// The version of the VoIP specification this message adheres to. This specification is version 0.
version: i32,
/// The time in milliseconds that the invite is valid for. Once the
/// invite age exceeds this value, clients should discard it. They
/// should also no longer show the call as awaiting an answer in the UI.
lifetime: i32,
}
/// `m.call.candidates`
///
/// This event is sent by callers after sending an invite and by the callee
/// after answering. Its purpose is to give the other party additional ICE
/// candidates to try using to communicate.
#[derive(Serialize, Deserialize, Debug)]
pub struct Candidates {
/// The ID of the call this event relates to.
call_id: String,
/// Array of objects describing the candidates.
candidates: Vec<types::Candidate>,
/// The version of the VoIP specification this messages adheres to. This specification is version 0.
version: i32,
}
/// `m.call.answer`
///
/// This event is sent by the callee when they wish to answer the call.
#[derive(Serialize, Deserialize, Debug)]
pub struct Answer {
/// The ID of the call this event relates to.
call_id: String,
/// The session description object
answer: types::Answer,
/// The version of the VoIP specification this message adheres to. This
/// specification is version 0.
version: i32,
}
/// `m.call.hangup`
///
/// Sent by either party to signal their termination of the call. This can be
/// sent either once the call has has been established or before to abort the
/// call.
#[derive(Serialize, Deserialize, Debug)]
pub struct Hangup {
/// The ID of the call this event relates to.
call_id: String,
/// The version of the VoIP specification this message adheres to. This specification is version 0.
version: i32,
}
31 changes: 31 additions & 0 deletions src/types/content/call/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

#[derive(Serialize, Deserialize, Debug)]
pub struct Offer {
/// The type of session description. Must be 'offer'.
#[serde(rename = "type")]
session_type: String,
/// The SDP text of the session description.
sdp: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Candidate {
/// The SDP media type this candidate is intended for.
#[serde(rename = "sdpMid")]
sdp_m_id: String,
/// The index of the SDP 'm' line this candidate is intended for.
#[serde(rename = "sdpMLineIndex")]
sdp_m_line_index: i32,
/// The SDP 'a' line of the candidate.
candidate: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Answer {
/// The type of session description. Must be 'answer'.
#[serde(rename = "type")]
session_type: String,
/// The SDP text of the session description.
sdp: String,
}

Loading

0 comments on commit 63d95c3

Please sign in to comment.