...
 
Commits (2)
  • Christopher Davis's avatar
    Add m.room.member support · 2bbfd3c0
    Christopher Davis authored
    Shows membership events like join & leave that were previously hidden.
    These events can be somewhat important to knowing what's going on in
    the room (like if someone you want to respond to leaves), so hiding
    them can leave users confused. A few things need to be changed
    before this can be finalized.
    
    TODO
    ----
    
    * [ ] Bundle room events under a dropdown like Polari (needs design)
    * [ ] Change styling of room events (should they look like emotes? Should they use dim-label?)
    * [ ] Decide if membership events should move rooms around like they do in Riot
    * [ ] Change hardcoded strings to use gettext
    2bbfd3c0
  • Christopher Davis's avatar
    Fix style class logic · 69f02d77
    Christopher Davis authored
    I had made a mistake in the logic to add a style class. This style class
    is temporary.
    69f02d77
......@@ -89,7 +89,7 @@ impl AppOp {
fn has_small_mtype(&self, msg: &Message) -> bool {
match msg.mtype.as_ref() {
"m.emote" => true,
"m.emote" | "m.room.member" => true,
_ => false,
}
}
......
......@@ -148,6 +148,7 @@ impl<'a> MessageBox<'a> {
match msg.mtype.as_ref() {
"m.sticker" => self.build_room_msg_sticker(),
"m.image" => self.build_room_msg_image(),
"m.room.member" => self.build_room_msg_member(&msg),
"m.emote" => self.build_room_msg_emote(&msg),
"m.audio" => self.build_room_audio_player(),
"m.video" | "m.file" => self.build_room_msg_file(),
......@@ -237,8 +238,9 @@ impl<'a> MessageBox<'a> {
if String::from(body).contains(uname) && msg.sender != uid {
style.add_class("msg-mention");
}
// emotes
if msg.mtype == "m.emote" {
// emotes & membership
if msg.mtype == "m.emote" || msg.mtype == "m.room.member" {
style.add_class("msg-emote");
}
}
......@@ -573,6 +575,20 @@ impl<'a> MessageBox<'a> {
bx
}
fn build_room_msg_member(&self, msg: &Message) -> gtk::Box {
let bx = gtk::Box::new(gtk::Orientation::Horizontal, 0);
let msg_label = gtk::Label::new("");
let body: &str = &msg.body;
msg_label.set_markup(&format!("<b>{}</b>", markup_text(body)));
self.set_label_styles(&msg_label);
self.connect_right_click_menu(msg_label.clone().upcast::<gtk::Widget>());
bx.add(&msg_label);
bx
}
fn connect_right_click_menu(&self, w: gtk::Widget) {
let eb = self.row_event_box.clone();
let msg = self.msg.clone();
......
......@@ -32,7 +32,7 @@ pub fn sync(bk: &Backend) -> Result<(), Error> {
\"not_types\": [\"m.room.member\"]
}},
\"timeline\": {{
\"types\": [\"m.room.message\", \"m.sticker\"],
\"types\": [\"m.room.message\", \"m.room.member\", \"m.sticker\"],
\"limit\": {}
}},
\"ephemeral\": {{ \"types\": [] }}
......
......@@ -5,6 +5,7 @@ extern crate time;
use self::chrono::prelude::*;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::str::FromStr;
use self::serde_json::Value as JsonValue;
use self::time::Duration;
......@@ -100,9 +101,10 @@ impl Message {
/// List all supported types. By default a message map a m.room.message event, but there's
/// other events that we want to show in the message history so we map other event types to our
/// Message struct, like stickers
pub fn types() -> [&'static str; 2] {
pub fn types() -> [&'static str; 3] {
[
"m.room.message",
"m.room.member",
"m.sticker",
]
}
......@@ -158,6 +160,7 @@ impl Message {
let c = &msg["content"];
match type_ {
"m.room.message" => Message::parse_m_room_message(&mut message, c),
"m.room.member" => Message::parse_m_room_member(&mut message, c),
"m.sticker" => Message::parse_m_sticker(&mut message, c),
_ => {}
};
......@@ -191,6 +194,30 @@ impl Message {
msg.format = format;
}
fn parse_m_room_member(msg: &mut Message, c: &JsonValue) {
let membership = c["membership"].as_str().unwrap_or("");
let displayname = c["displayname"].as_str().unwrap_or(&msg.sender);
let mut action: String = String::new();
match membership {
"join" => {
action = String::from_str(displayname).unwrap();
action.push_str(" joined");
},
"leave" => {
action = String::from_str(displayname).unwrap();
action.push_str(" left");
},
"invite" => {
action = String::from_str(displayname).unwrap();
action.push_str(" was invited");
},
_ => {}
}
msg.body = action;
}
fn parse_m_sticker(msg: &mut Message, c: &JsonValue) {
let body = c["body"].as_str().unwrap_or("");
......