Skip to content

Commit

Permalink
Add a handler to send a list of Rocket.Chat rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
exul committed Feb 12, 2017
1 parent 0af4ecc commit f44e982
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tests/matrix-rocketchat-test/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use iron::prelude::*;
use iron::{Handler, status};
use matrix_rocketchat::errors::{MatrixErrorResponse, RocketchatErrorResponse};
Expand Down Expand Up @@ -53,9 +55,41 @@ impl Handler for RocketchatLogin {
}
}

pub struct RocketchatChannelsList {
channels: HashMap<&'static str, Vec<&'static str>>,
status: status::Status,
}

impl Handler for RocketchatChannelsList {
fn handle(&self, _request: &mut Request) -> IronResult<Response> {
let payload = "".to_string();

for (channel_name, user_names) in self.channels.iter() {
r#"{
"_id": "CHANNEL_ID",
"name": "CHANNEL_NAME",
"t": "c",
"usernames": [
CHANNEL_USERNAMES
],
"msgs": 0,
"u": CHANNEL_USERS,
"ts": "2017-02-12T13:20:22.092Z",
"ro": false,
"sysMes": true,
"_updatedAt": "2017-02-12T13:20:22.092Z"
}"#
.replace("CHANNEL_NAME", channel_name)
.replace("CHANNEL_USERNAMES", &user_names.join(","));
}

Ok(Response::with((self.status, payload)))
}
}

pub struct RocketchatErrorResponder {
pub status: status::Status,
pub message: String,
pub status: status::Status,
}

impl Handler for RocketchatErrorResponder {
Expand Down

0 comments on commit f44e982

Please sign in to comment.