Commit e89fa429 authored by Christopher Davis's avatar Christopher Davis Committed by Daniel Garcia Moreno

Basic markdown sending with no UI changes

parent 3eecea6d
...@@ -216,7 +216,10 @@ pub fn send_msg(bk: &Backend, msg: Message) -> Result<(), Error> { ...@@ -216,7 +216,10 @@ pub fn send_msg(bk: &Backend, msg: Message) -> Result<(), Error> {
let mut attrs = json!({ let mut attrs = json!({
"body": msg.body.clone(), "body": msg.body.clone(),
"msgtype": msg.mtype.clone() "msgtype": msg.mtype.clone(),
"url": msg.url.clone(),
"formatted_body": msg.formatted_body.clone(),
"format": msg.format.clone(),
}); });
if let Some(u) = msg.url { if let Some(u) = msg.url {
...@@ -389,6 +392,8 @@ pub fn attach_send(bk: &Backend, roomid: String, body: String, contents: Vec<u8> ...@@ -389,6 +392,8 @@ pub fn attach_send(bk: &Backend, roomid: String, body: String, contents: Vec<u8>
thumb: None, thumb: None,
url: None, url: None,
id: None, id: None,
formatted_body: None,
format: None,
}; };
let tx = bk.tx.clone(); let tx = bk.tx.clone();
......
extern crate chrono; extern crate chrono;
use self::chrono::prelude::*; use self::chrono::prelude::*;
#[derive(Debug)] #[derive(Debug)]
...@@ -14,6 +13,8 @@ pub struct Message { ...@@ -14,6 +13,8 @@ pub struct Message {
pub thumb: Option<String>, pub thumb: Option<String>,
pub url: Option<String>, pub url: Option<String>,
pub id: Option<String>, pub id: Option<String>,
pub formatted_body: Option<String>,
pub format: Option<String>,
} }
impl Clone for Message { impl Clone for Message {
...@@ -27,6 +28,8 @@ impl Clone for Message { ...@@ -27,6 +28,8 @@ impl Clone for Message {
thumb: self.thumb.clone(), thumb: self.thumb.clone(),
url: self.url.clone(), url: self.url.clone(),
id: self.id.clone(), id: self.id.clone(),
formatted_body: self.formatted_body.clone(),
format: self.format.clone(),
} }
} }
} }
...@@ -42,6 +45,8 @@ impl Default for Message { ...@@ -42,6 +45,8 @@ impl Default for Message {
thumb: None, thumb: None,
url: None, url: None,
id: None, id: None,
formatted_body: None,
format: None,
} }
} }
} }
...@@ -740,6 +740,8 @@ pub fn parse_room_message(baseu: &Url, roomid: String, msg: &JsonValue) -> Messa ...@@ -740,6 +740,8 @@ pub fn parse_room_message(baseu: &Url, roomid: String, msg: &JsonValue) -> Messa
let c = &msg["content"]; let c = &msg["content"];
let mtype = c["msgtype"].as_str().unwrap_or(""); let mtype = c["msgtype"].as_str().unwrap_or("");
let body = c["body"].as_str().unwrap_or(""); let body = c["body"].as_str().unwrap_or("");
let formatted_body = c["formatted_body"].as_str().unwrap_or("");
let format = c["format"].as_str().unwrap_or("");
let mut url = String::new(); let mut url = String::new();
let mut thumb = String::new(); let mut thumb = String::new();
...@@ -765,6 +767,8 @@ pub fn parse_room_message(baseu: &Url, roomid: String, msg: &JsonValue) -> Messa ...@@ -765,6 +767,8 @@ pub fn parse_room_message(baseu: &Url, roomid: String, msg: &JsonValue) -> Messa
url: Some(url), url: Some(url),
thumb: Some(thumb), thumb: Some(thumb),
id: Some(String::from(id)), id: Some(String::from(id)),
formatted_body: Some(String::from(formatted_body)),
format: Some(String::from(format)),
} }
} }
......
...@@ -22,6 +22,7 @@ url = "1.7.0" ...@@ -22,6 +22,7 @@ url = "1.7.0"
rand = "0.4.2" rand = "0.4.2"
html2pango = { git = "https://gitlab.gnome.org/World/html2pango" } html2pango = { git = "https://gitlab.gnome.org/World/html2pango" }
unicode-segmentation = "1.2.0" unicode-segmentation = "1.2.0"
comrak = "0.2"
# newer stuff do not compile inside flatpak # newer stuff do not compile inside flatpak
html5ever = "=0.22.0" html5ever = "=0.22.0"
......
...@@ -4,6 +4,7 @@ extern crate chrono; ...@@ -4,6 +4,7 @@ extern crate chrono;
extern crate gdk; extern crate gdk;
extern crate notify_rust; extern crate notify_rust;
extern crate rand; extern crate rand;
extern crate comrak;
use std::env; use std::env;
...@@ -16,6 +17,8 @@ use self::chrono::prelude::*; ...@@ -16,6 +17,8 @@ use self::chrono::prelude::*;
use self::rand::{thread_rng, Rng}; use self::rand::{thread_rng, Rng};
use self::comrak::{markdown_to_html,ComrakOptions};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::sync::mpsc::{Sender, Receiver}; use std::sync::mpsc::{Sender, Receiver};
...@@ -1359,15 +1362,24 @@ impl AppOp { ...@@ -1359,15 +1362,24 @@ impl AppOp {
thumb: None, thumb: None,
url: None, url: None,
id: None, id: None,
formatted_body: None,
format: None,
}; };
if msg.starts_with("/me ") { if msg.starts_with("/me ") {
m.body = msg.trim_left_matches("/me ").to_owned(); m.body = msg.trim_left_matches("/me ").to_owned();
m.mtype = strn!("m.emote"); m.mtype = strn!("m.emote");
}; }
/* reenable autoscroll to jump to new message in history */ /* reenable autoscroll to jump to new message in history */
self.autoscroll = true; self.autoscroll = true;
let md_parsed_msg = markdown_to_html(&msg, &ComrakOptions::default());
if !(md_parsed_msg.replace("<p>","").replace("</p>","") == msg.clone() + "\n") {
m.formatted_body = Some(md_parsed_msg);
m.format = Some(String::from("org.matrix.custom.html"));
}
self.add_tmp_room_message(m.clone()); self.add_tmp_room_message(m.clone());
self.backend.send(BKCommand::SendMsg(m)).unwrap(); self.backend.send(BKCommand::SendMsg(m)).unwrap();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment