Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ anyhow = "1.0"
bitflags = "^2.3"
chrono = "0.4"
clap = {version = "~4.3", features = ["derive"]}
clap_complete = "~4.3"
css-color-parser = "0.1.2"
dirs = "4.0.0"
emojis = "0.5"
Expand Down
25 changes: 16 additions & 9 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,9 +1219,10 @@ impl RoomInfo {
self.insert(ev);

if let Some((event_id, source)) = source {
if let (Some(msg), Some(image_preview)) =
(self.get_event_mut(&event_id), &settings.tunables.image_preview)
{
if let (Some(msg), Some(image_preview)) = (
self.get_event_mut(&event_id),
&settings.tunables.image_preview,
) {
msg.image_preview = ImageStatus::Downloading(image_preview.size.clone());
spawn_insert_preview(
store,
Expand Down Expand Up @@ -2249,12 +2250,18 @@ pub mod tests {
// Four users typing.
info.set_typing(users4);
assert!(info.users_typing.is_some());
assert_eq!(info.get_typing_spans(&settings), Line::from("Several people are typing..."));
assert_eq!(
info.get_typing_spans(&settings),
Line::from("Several people are typing...")
);

// Five users typing.
info.set_typing(users5);
assert!(info.users_typing.is_some());
assert_eq!(info.get_typing_spans(&settings), Line::from("Many people are typing..."));
assert_eq!(
info.get_typing_spans(&settings),
Line::from("Many people are typing...")
);

// Test that USER5 gets rendered using the configured color and name.
info.set_typing(vec![TEST_USER5.clone()]);
Expand All @@ -2277,10 +2284,10 @@ pub mod tests {
need_load.insert(room_id.clone(), Need::MESSAGES);
need_load.insert(room_id.clone(), Need::MEMBERS);

assert_eq!(need_load.into_iter().collect::<Vec<(OwnedRoomId, Need)>>(), vec![(
room_id,
Need::MESSAGES | Need::MEMBERS,
)],);
assert_eq!(
need_load.into_iter().collect::<Vec<(OwnedRoomId, Need)>>(),
vec![(room_id, Need::MESSAGES | Need::MEMBERS,)],
);
}

#[tokio::test]
Expand Down
54 changes: 41 additions & 13 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,8 +1052,10 @@ mod tests {
assert_eq!(res, vec![(act.into(), ctx.clone())]);

let res = cmds.input_cmd("room tag set u.irc", ctx.clone()).unwrap();
let act =
RoomAction::Set(RoomField::Tag(TagName::User("u.irc".parse().unwrap())), "".into());
let act = RoomAction::Set(
RoomField::Tag(TagName::User("u.irc".parse().unwrap())),
"".into(),
);
assert_eq!(res, vec![(act.into(), ctx.clone())]);

let res = cmds.input_cmd("room tag", ctx.clone());
Expand All @@ -1063,12 +1065,17 @@ mod tests {
assert_eq!(res, Err(CommandError::InvalidArgument));

let res = cmds.input_cmd("room tag set unknown", ctx.clone());
assert_eq!(res, Err(CommandError::Error("Invalid user tag name: unknown".into())));
assert_eq!(
res,
Err(CommandError::Error("Invalid user tag name: unknown".into()))
);

let res = cmds.input_cmd("room tag set needs-leading-u-dot", ctx.clone());
assert_eq!(
res,
Err(CommandError::Error("Invalid user tag name: needs-leading-u-dot".into()))
Err(CommandError::Error(
"Invalid user tag name: needs-leading-u-dot".into()
))
);
}

Expand Down Expand Up @@ -1114,7 +1121,9 @@ mod tests {
assert_eq!(res, vec![(act.into(), ctx.clone())]);

let res = cmds.input_cmd("room tag unset u.custom-tag", ctx.clone()).unwrap();
let act = RoomAction::Unset(RoomField::Tag(TagName::User("u.custom-tag".parse().unwrap())));
let act = RoomAction::Unset(RoomField::Tag(TagName::User(
"u.custom-tag".parse().unwrap(),
)));
assert_eq!(res, vec![(act.into(), ctx.clone())]);

let res = cmds.input_cmd("room tag unset u.irc", ctx.clone()).unwrap();
Expand All @@ -1128,12 +1137,17 @@ mod tests {
assert_eq!(res, Err(CommandError::InvalidArgument));

let res = cmds.input_cmd("room tag unset unknown", ctx.clone());
assert_eq!(res, Err(CommandError::Error("Invalid user tag name: unknown".into())));
assert_eq!(
res,
Err(CommandError::Error("Invalid user tag name: unknown".into()))
);

let res = cmds.input_cmd("room tag unset needs-leading-u-dot", ctx.clone());
assert_eq!(
res,
Err(CommandError::Error("Invalid user tag name: needs-leading-u-dot".into()))
Err(CommandError::Error(
"Invalid user tag name: needs-leading-u-dot".into()
))
);
}

Expand Down Expand Up @@ -1212,12 +1226,19 @@ mod tests {
let res = cmds.input_cmd(cmd, ctx.clone());
assert_eq!(
res,
Err(CommandError::Error("Multiple ++order arguments are not allowed".into()))
Err(CommandError::Error(
"Multiple ++order arguments are not allowed".into()
))
);

let cmd = "space child set !roomid:example.org !otherroom:example.org";
let res = cmds.input_cmd(cmd, ctx.clone());
assert_eq!(res, Err(CommandError::Error("Multiple room arguments are not allowed".into())));
assert_eq!(
res,
Err(CommandError::Error(
"Multiple room arguments are not allowed".into()
))
);

let cmd = "space child set ++foo=abcd !roomid:example.org";
let res = cmds.input_cmd(cmd, ctx.clone());
Expand All @@ -1233,11 +1254,17 @@ mod tests {

let cmd = "space child set foo";
let res = cmds.input_cmd(cmd, ctx.clone());
assert_eq!(res, Err(CommandError::Error("Invalid room id specified".into())));
assert_eq!(
res,
Err(CommandError::Error("Invalid room id specified".into()))
);

let cmd = "space child set";
let res = cmds.input_cmd(cmd, ctx.clone());
assert_eq!(res, Err(CommandError::Error("Must specify a room to add".into())));
assert_eq!(
res,
Err(CommandError::Error("Must specify a room to add".into()))
);
}

#[test]
Expand Down Expand Up @@ -1269,8 +1296,9 @@ mod tests {
assert_eq!(res, vec![(act.into(), ctx.clone())]);

let res = cmds.input_cmd("invite send @user:example.com", ctx.clone()).unwrap();
let act =
IambAction::Room(RoomAction::InviteSend(user_id!("@user:example.com").to_owned()));
let act = IambAction::Room(RoomAction::InviteSend(
user_id!("@user:example.com").to_owned(),
));
assert_eq!(res, vec![(act.into(), ctx.clone())]);

let res = cmds.input_cmd("invite", ctx.clone());
Expand Down
15 changes: 13 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ const VERSION: &str = match option_env!("VERGEN_GIT_SHA") {
#[clap(version = VERSION, about, long_about = None)]
#[clap(propagate_version = true)]
pub struct Iamb {
#[clap(long, value_parser)]
pub completions: Option<clap_complete::Shell>,

#[clap(short = 'P', long, value_parser)]
pub profile: Option<String>,

Expand Down Expand Up @@ -1029,7 +1032,12 @@ impl ApplicationSettings {
self.tunables
.users
.get(user_id)
.map(|user| (user.color.as_ref().map(|c| c.0), user.name.clone().map(Cow::Owned)))
.map(|user| {
(
user.color.as_ref().map(|c| c.0),
user.name.clone().map(Cow::Owned),
)
})
.unwrap_or_default()
}

Expand Down Expand Up @@ -1294,7 +1302,10 @@ mod tests {

#[test]
fn test_parse_notify_via() {
assert_eq!(NotifyVia { bell: false, desktop: true }, NotifyVia::default());
assert_eq!(
NotifyVia { bell: false, desktop: true },
NotifyVia::default()
);
assert_eq!(
NotifyVia { bell: false, desktop: true },
serde_json::from_str(r#""desktop""#).unwrap()
Expand Down
24 changes: 20 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::time::{Duration, Instant};

use clap::Parser;
use clap::{CommandFactory, Parser};
use matrix_sdk::crypto::encrypt_room_key_export;
use matrix_sdk::ruma::api::client::error::ErrorKind;
use matrix_sdk::ruma::OwnedUserId;
Expand Down Expand Up @@ -689,7 +689,10 @@ impl Application {
.await
.map_err(IambError::from)?;

let msg = format!("Imported {} of {} keys", res.imported_count, res.total_count);
let msg = format!(
"Imported {} of {} keys",
res.imported_count, res.total_count
);

Ok(Some(msg.into()))
},
Expand Down Expand Up @@ -880,7 +883,10 @@ async fn check_import_keys(
let keys = sled_export::export_room_keys(&settings.sled_dir).await?;
let passphrase = gen_passphrase();

println!("* Encrypting {} room keys with the passphrase {passphrase:?}...", keys.len());
println!(
"* Encrypting {} room keys with the passphrase {passphrase:?}...",
keys.len()
);

let encrypted = match encrypt_room_key_export(&keys, &passphrase, 500000) {
Ok(encrypted) => encrypted,
Expand Down Expand Up @@ -986,7 +992,12 @@ fn setup_tty(settings: &ApplicationSettings, enable_enhanced_keys: bool) -> std:
crossterm::execute!(stdout(), EnableMouseCapture)?;
}

crossterm::execute!(stdout(), EnableBracketedPaste, EnableFocusChange, SetTitle(title))
crossterm::execute!(
stdout(),
EnableBracketedPaste,
EnableFocusChange,
SetTitle(title)
)
}

// Do our best to reverse what we did in setup_tty() when we exit or crash.
Expand Down Expand Up @@ -1078,6 +1089,11 @@ fn main() -> IambResult<()> {
// Parse command-line flags.
let iamb = Iamb::parse();

if let Some(shell) = iamb.completions {
clap_complete::generate(shell, &mut Iamb::command(), "iamb", &mut std::io::stdout());
return Ok(());
}

// Load configuration and set up the Matrix SDK.
let settings = ApplicationSettings::load(iamb).unwrap_or_else(print_exit);

Expand Down
32 changes: 26 additions & 6 deletions src/message/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ impl SlashCommand {
MessageType::new("io.element.effect.hearts", input.into(), Default::default())?
},
SlashCommand::Rainfall => {
MessageType::new("io.element.effect.rainfall", input.into(), Default::default())?
MessageType::new(
"io.element.effect.rainfall",
input.into(),
Default::default(),
)?
},
SlashCommand::Snowfall => {
MessageType::new("io.element.effect.snowfall", input.into(), Default::default())?
MessageType::new(
"io.element.effect.snowfall",
input.into(),
Default::default(),
)?
},
SlashCommand::SpaceInvaders => {
MessageType::new(
Expand Down Expand Up @@ -214,17 +222,26 @@ pub mod tests {
let input = "**bold**\n";
let content = text_to_message_content(input.into());
assert_eq!(content.body, input);
assert_eq!(content.formatted.unwrap().body, "<p><strong>bold</strong></p>\n");
assert_eq!(
content.formatted.unwrap().body,
"<p><strong>bold</strong></p>\n"
);

let input = "*emphasis*\n";
let content = text_to_message_content(input.into());
assert_eq!(content.body, input);
assert_eq!(content.formatted.unwrap().body, "<p><em>emphasis</em></p>\n");
assert_eq!(
content.formatted.unwrap().body,
"<p><em>emphasis</em></p>\n"
);

let input = "`code`\n";
let content = text_to_message_content(input.into());
assert_eq!(content.body, input);
assert_eq!(content.formatted.unwrap().body, "<p><code>code</code></p>\n");
assert_eq!(
content.formatted.unwrap().body,
"<p><code>code</code></p>\n"
);

let input = "```rust\nconst A: usize = 1;\n```\n";
let content = text_to_message_content(input.into());
Expand All @@ -250,7 +267,10 @@ pub mod tests {
let input = "line 1\nline ~~2~~\n";
let content = text_to_message_content(input.into());
assert_eq!(content.body, input);
assert_eq!(content.formatted.unwrap().body, "<p>line 1<br />\nline <del>2</del></p>\n");
assert_eq!(
content.formatted.unwrap().body,
"<p>line 1<br />\nline <del>2</del></p>\n"
);

let input = "# Heading\n## Subheading\n\ntext\n";
let content = text_to_message_content(input.into());
Expand Down
15 changes: 12 additions & 3 deletions src/message/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,10 @@ pub mod tests {
Line::from(vec![Span::raw("world"), Span::raw("!"), Span::raw(" ")])
);
assert_eq!(text.lines[2], Line::from(vec![Span::raw(" ")]));
assert_eq!(text.lines[3], Line::from(vec![Span::raw("Content"), Span::raw(" ")]));
assert_eq!(
text.lines[3],
Line::from(vec![Span::raw("Content"), Span::raw(" ")])
);
assert_eq!(text.lines[4], Line::from(vec![Span::raw(" ")]));
assert_eq!(
text.lines[5],
Expand Down Expand Up @@ -1406,8 +1409,14 @@ pub mod tests {
let tree = parse_matrix_html(s);
let text = tree.to_text(7, Style::default(), true, &settings);
assert_eq!(text.lines.len(), 3);
assert_eq!(text.lines[0], Line::from(vec![Span::raw("Hello"), Span::raw(" "),]));
assert_eq!(text.lines[1], Line::from(vec![Span::raw("World"), Span::raw(" "),]));
assert_eq!(
text.lines[0],
Line::from(vec![Span::raw("Hello"), Span::raw(" "),])
);
assert_eq!(
text.lines[1],
Line::from(vec![Span::raw("World"), Span::raw(" "),])
);
assert_eq!(text.lines[2], Line::from(vec![Span::raw("Goodbye")]),);
}

Expand Down
Loading