Skip to content

Commit daa03dd

Browse files
authored
Merge branch 'main' into focused-notify
2 parents b3e5954 + cb44556 commit daa03dd

13 files changed

+214
-54
lines changed

Cargo.lock

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ unicode-segmentation = "^1.7"
6161
unicode-width = "0.1.10"
6262
url = {version = "^2.2.2", features = ["serde"]}
6363
edit = "0.1.4"
64+
humansize = "2.0.0"
6465

6566
[dependencies.modalkit]
6667
version = "0.0.19"

README.md

+27-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
</div>
1313

14-
1514
## About
1615

1716
`iamb` is a Matrix client for the terminal that uses Vim keybindings. It includes support for:
@@ -40,8 +39,25 @@ Install Rust (1.70.0 or above) and Cargo, and then run:
4039
cargo install --locked iamb
4140
```
4241

42+
### Arch Linux
43+
44+
On Arch Linux a [package](https://aur.archlinux.org/packages/iamb-git) is available in the
45+
Arch User Repositories (AUR). To install it simply run with your favorite AUR helper:
46+
47+
```
48+
paru iamb-git
49+
```
50+
4351
See [Configuration](#configuration) for getting a profile set up.
4452

53+
### FreeBSD
54+
55+
On FreeBSD a package is available from the official repositories. To install it simply run:
56+
57+
```
58+
pkg install iamb
59+
```
60+
4561
### NetBSD
4662

4763
On NetBSD a package is available from the official repositories. To install it simply run:
@@ -50,26 +66,27 @@ On NetBSD a package is available from the official repositories. To install it s
5066
pkgin install iamb
5167
```
5268

53-
### Arch Linux
69+
### macOS
5470

55-
On Arch Linux a [package](https://aur.archlinux.org/packages/iamb-git) is available in the
56-
Arch User Repositories (AUR). To install it simply run with your favorite AUR helper:
71+
On macOS a [package](https://formulae.brew.sh/formula/iamb#default) is availabe in Homebrew's
72+
repository. To install it simply run:
5773

5874
```
59-
paru iamb-git
75+
brew install iamb
6076
```
61-
### openSUSE Tumbleweed
6277

63-
On openSUSE Tumbleweed a [package](https://build.opensuse.org/package/show/home%3Asmolsheep/iamb) is available from openSUSE Build Service (OBS). To install just use OBS Package Installer:
78+
### Nix / NixOS (flake)
6479

6580
```
66-
opi iamb
81+
nix profile install "github:ulyssa/iamb"
6782
```
6883

69-
### Nix / NixOS (flake)
84+
### openSUSE Tumbleweed
85+
86+
On openSUSE Tumbleweed a [package](https://build.opensuse.org/package/show/openSUSE:Factory/iamb) is available from the official repositories. To install it simply run:
7087

7188
```
72-
nix profile install "github:ulyssa/iamb"
89+
zypper install iamb
7390
```
7491

7592
### Snap

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
};
2828
nativeBuildInputs = [ pkg-config ];
2929
buildInputs = [ openssl ] ++ lib.optionals stdenv.isDarwin
30-
(with darwin.apple_sdk.frameworks; [ AppKit Security ]);
30+
(with darwin.apple_sdk.frameworks; [ AppKit Security Cocoa]);
3131
};
3232

3333
devShell = mkShell {

src/base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1350,9 +1350,7 @@ impl ChatStore {
13501350

13511351
/// Get a joined room.
13521352
pub fn get_joined_room(&self, room_id: &RoomId) -> Option<MatrixRoom> {
1353-
let Some(room) = self.worker.client.get_room(room_id) else {
1354-
return None;
1355-
};
1353+
let room = self.worker.client.get_room(room_id)?;
13561354

13571355
if room.state() == MatrixRoomState::Joined {
13581356
Some(room)

src/commands.rs

+3
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ fn iamb_open(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
515515
fn iamb_logout(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
516516
let args = desc.arg.strings()?;
517517

518+
if args.is_empty() {
519+
return Result::Err(CommandError::Error("Missing username".to_string()));
520+
}
518521
if args.len() != 1 {
519522
return Result::Err(CommandError::InvalidArgument);
520523
}

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ mod tests {
11731173
let j = "j".parse::<TerminalKey>().unwrap();
11741174
let esc = "<Esc>".parse::<TerminalKey>().unwrap();
11751175

1176-
let jj = Keys(vec![j.clone(), j], "jj".into());
1176+
let jj = Keys(vec![j, j], "jj".into());
11771177
let run = mapped.get(&jj).unwrap();
11781178
let exp = Keys(vec![esc], "<Esc>".into());
11791179
assert_eq!(run, &exp);

src/message/html.rs

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ pub enum StyleTreeNode {
260260
Anchor(Box<StyleTreeNode>, char, Url),
261261
Blockquote(Box<StyleTreeNode>),
262262
Break,
263+
#[allow(dead_code)]
263264
Code(Box<StyleTreeNode>, Option<String>),
264265
Header(Box<StyleTreeNode>, usize),
265266
Image(Option<String>),

src/message/mod.rs

+122-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use std::collections::hash_map::DefaultHasher;
55
use std::collections::hash_set;
66
use std::collections::BTreeMap;
77
use std::convert::TryFrom;
8+
use std::fmt::{self, Display};
89
use std::hash::{Hash, Hasher};
910
use std::ops::{Deref, DerefMut};
1011

1112
use chrono::{DateTime, Local as LocalTz, NaiveDateTime, TimeZone};
1213
use comrak::{markdown_to_html, ComrakOptions};
14+
use humansize::{format_size, DECIMAL};
1315
use serde_json::json;
1416
use unicode_width::UnicodeWidthStr;
1517

@@ -509,6 +511,27 @@ impl MessageEvent {
509511
}
510512
}
511513

514+
/// Macro rule converting a File / Image / Audio / Video to its text content with the shape:
515+
/// `[Attached <type>: <content>[ (<human readable file size>)]]`
516+
macro_rules! display_file_to_text {
517+
( $msgtype:ident, $content:expr ) => {
518+
return Cow::Owned(format!(
519+
"[Attached {}: {}{}]",
520+
stringify!($msgtype),
521+
$content.body,
522+
$content
523+
.info
524+
.as_ref()
525+
.map(|info| {
526+
info.size
527+
.map(|s| format!(" ({})", format_size(u64::from(s), DECIMAL)))
528+
.unwrap_or_else(String::new)
529+
})
530+
.unwrap_or_else(String::new)
531+
))
532+
};
533+
}
534+
512535
fn body_cow_content(content: &RoomMessageEventContent) -> Cow<'_, str> {
513536
let s = match &content.msgtype {
514537
MessageType::Text(content) => content.body.as_str(),
@@ -518,16 +541,16 @@ fn body_cow_content(content: &RoomMessageEventContent) -> Cow<'_, str> {
518541
MessageType::ServerNotice(content) => content.body.as_str(),
519542

520543
MessageType::Audio(content) => {
521-
return Cow::Owned(format!("[Attached Audio: {}]", content.body));
544+
display_file_to_text!(Audio, content);
522545
},
523546
MessageType::File(content) => {
524-
return Cow::Owned(format!("[Attached File: {}]", content.body));
547+
display_file_to_text!(File, content);
525548
},
526549
MessageType::Image(content) => {
527-
return Cow::Owned(format!("[Attached Image: {}]", content.body));
550+
display_file_to_text!(Image, content);
528551
},
529552
MessageType::Video(content) => {
530-
return Cow::Owned(format!("[Attached Video: {}]", content.body));
553+
display_file_to_text!(Video, content);
531554
},
532555
_ => {
533556
return Cow::Owned(format!("[Unknown message type: {:?}]", content.msgtype()));
@@ -1122,14 +1145,27 @@ impl From<RoomMessageEvent> for Message {
11221145
}
11231146
}
11241147

1125-
impl ToString for Message {
1126-
fn to_string(&self) -> String {
1127-
self.event.body().into_owned()
1148+
impl Display for Message {
1149+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1150+
write!(f, "{}", self.event.body())
11281151
}
11291152
}
11301153

11311154
#[cfg(test)]
11321155
pub mod tests {
1156+
use matrix_sdk::ruma::events::room::{
1157+
message::{
1158+
AudioInfo,
1159+
AudioMessageEventContent,
1160+
FileInfo,
1161+
FileMessageEventContent,
1162+
ImageMessageEventContent,
1163+
VideoInfo,
1164+
VideoMessageEventContent,
1165+
},
1166+
ImageInfo,
1167+
};
1168+
11331169
use super::*;
11341170
use crate::tests::*;
11351171

@@ -1379,4 +1415,83 @@ pub mod tests {
13791415
)
13801416
);
13811417
}
1418+
1419+
#[test]
1420+
fn test_display_attachment_size() {
1421+
assert_eq!(
1422+
body_cow_content(&RoomMessageEventContent::new(MessageType::Image(
1423+
ImageMessageEventContent::plain(
1424+
"Alt text".to_string(),
1425+
"mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into()
1426+
)
1427+
.info(Some(Box::default()))
1428+
))),
1429+
"[Attached Image: Alt text]".to_string()
1430+
);
1431+
1432+
let mut info = ImageInfo::default();
1433+
info.size = Some(442630_u32.into());
1434+
assert_eq!(
1435+
body_cow_content(&RoomMessageEventContent::new(MessageType::Image(
1436+
ImageMessageEventContent::plain(
1437+
"Alt text".to_string(),
1438+
"mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into()
1439+
)
1440+
.info(Some(Box::new(info)))
1441+
))),
1442+
"[Attached Image: Alt text (442.63 kB)]".to_string()
1443+
);
1444+
1445+
let mut info = ImageInfo::default();
1446+
info.size = Some(12_u32.into());
1447+
assert_eq!(
1448+
body_cow_content(&RoomMessageEventContent::new(MessageType::Image(
1449+
ImageMessageEventContent::plain(
1450+
"Alt text".to_string(),
1451+
"mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into()
1452+
)
1453+
.info(Some(Box::new(info)))
1454+
))),
1455+
"[Attached Image: Alt text (12 B)]".to_string()
1456+
);
1457+
1458+
let mut info = AudioInfo::default();
1459+
info.size = Some(4294967295_u32.into());
1460+
assert_eq!(
1461+
body_cow_content(&RoomMessageEventContent::new(MessageType::Audio(
1462+
AudioMessageEventContent::plain(
1463+
"Alt text".to_string(),
1464+
"mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into()
1465+
)
1466+
.info(Some(Box::new(info)))
1467+
))),
1468+
"[Attached Audio: Alt text (4.29 GB)]".to_string()
1469+
);
1470+
1471+
let mut info = FileInfo::default();
1472+
info.size = Some(4426300_u32.into());
1473+
assert_eq!(
1474+
body_cow_content(&RoomMessageEventContent::new(MessageType::File(
1475+
FileMessageEventContent::plain(
1476+
"Alt text".to_string(),
1477+
"mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into()
1478+
)
1479+
.info(Some(Box::new(info)))
1480+
))),
1481+
"[Attached File: Alt text (4.43 MB)]".to_string()
1482+
);
1483+
1484+
let mut info = VideoInfo::default();
1485+
info.size = Some(44000_u32.into());
1486+
assert_eq!(
1487+
body_cow_content(&RoomMessageEventContent::new(MessageType::Video(
1488+
VideoMessageEventContent::plain(
1489+
"Alt text".to_string(),
1490+
"mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into()
1491+
)
1492+
.info(Some(Box::new(info)))
1493+
))),
1494+
"[Attached Video: Alt text (44 kB)]".to_string()
1495+
);
1496+
}
13821497
}

src/notifications.rs

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ fn send_notification_desktop(summary: String, body: Option<String>) {
8282
desktop_notification
8383
.summary(&summary)
8484
.appname("iamb")
85-
.timeout(notify_rust::Timeout::Milliseconds(3000))
8685
.action("default", "default");
8786

8887
if let Some(body) = body {

0 commit comments

Comments
 (0)