Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight notifications for /me actions. #674

Merged
merged 5 commits into from
Dec 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion data/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Input {
.collect(),
),
Command::Me(target, action) => Some(vec![Message::sent(
to_target(&target, message::Source::Action)?,
to_target(&target, message::Source::Action(Some(user.clone())))?,
message::action_text(user.nickname(), Some(&action)),
)]),
_ => None,
Expand Down
22 changes: 16 additions & 6 deletions data/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Message {
matches!(self.direction, Direction::Received)
&& match self.target.source() {
Source::User(_) => true,
Source::Action => true,
Source::Action(_) => true,
Source::Server(Some(server)) => {
matches!(
server.kind(),
Expand Down Expand Up @@ -280,7 +280,7 @@ impl Message {
direction: Direction::Received,
target: Target::Query {
nick: from.clone(),
source: Source::Action,
source: Source::Action(None),
},
content,
id: None,
Expand All @@ -299,7 +299,7 @@ impl Message {
direction: Direction::Sent,
target: Target::Query {
nick: to.clone(),
source: Source::Action,
source: Source::Action(None),
},
content,
id: None,
Expand Down Expand Up @@ -347,6 +347,15 @@ impl Message {
channel,
source: Source::User(user),
},
Target::Channel {
channel,
source: Source::Action(user),
..
} => Target::Highlights {
server,
channel,
source: Source::Action(user),
},
_ => return None,
};

Expand Down Expand Up @@ -725,14 +734,14 @@ fn target(

Some(Target::Query {
nick: target.nickname().to_owned(),
source: Source::Action,
source: Source::Action(None),
})
}
Command::PRIVMSG(target, text) => {
let is_action = is_action(&text);
let source = |user| {
if is_action {
Source::Action
Source::Action(Some(user))
} else {
Source::User(user)
}
Expand Down Expand Up @@ -769,7 +778,7 @@ fn target(
let is_action = is_action(&text);
let source = |user| {
if is_action {
Source::Action
Source::Action(Some(user))
} else {
Source::User(user)
}
Expand Down Expand Up @@ -1239,6 +1248,7 @@ pub fn references_user_text(sender: NickRef, own_nick: NickRef, text: &str) -> b
sender != own_nick
&& text
.chars()
.filter(|&c| c != '\u{1}')
.group_by(|c| c.is_whitespace())
.into_iter()
.any(|(is_whitespace, chars)| {
Expand Down
2 changes: 1 addition & 1 deletion data/src/message/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use self::server::Server;
pub enum Source {
User(User),
Server(Option<Server>),
Action,
Action(Option<User>),
Internal(Internal),
}

Expand Down
30 changes: 19 additions & 11 deletions src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,14 @@ pub fn view<'a>(
.push(nick)
.push(space);

let text_container =
container(message_content).style(move |theme| match our_nick {
Some(nick)
if message::references_user(user.nickname(), nick, message) =>
{
theme::container::highlight(theme)
let text_container = container(message_content).style(move |theme| {
if let Some(nick) = our_nick {
if message::references_user(user.nickname(), nick, message) {
return theme::container::highlight(theme);
}
_ => Default::default(),
});
}
Default::default()
});

match &config.buffer.nickname.alignment {
data::buffer::Alignment::Left | data::buffer::Alignment::Right => Some(
Expand Down Expand Up @@ -203,25 +202,34 @@ pub fn view<'a>(
.into(),
)
}
message::Source::Action => {
message::Source::Action(user) => {
let marker = message_marker(max_nick_width, theme::selectable_text::action);

let message = message_content(
let message_content = message_content(
&message.content,
theme,
scroll_view::Message::Link,
theme::selectable_text::action,
config,
);

let text_container = container(message_content).style(move |theme| {
if let (Some(user), Some(nick)) = (user, our_nick) {
if message::references_user(user.nickname(), nick, message) {
return theme::container::highlight(theme);
}
}
Default::default()
});

Some(
container(
row![]
.push_maybe(timestamp)
.push_maybe(prefixes)
.push(marker)
.push(space)
.push(message),
.push(text_container),
)
.into(),
)
Expand Down
38 changes: 38 additions & 0 deletions src/buffer/highlights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,44 @@ pub fn view<'a>(
.into(),
)
}
message::Target::Highlights {
server,
channel,
source: message::Source::Action(_),
} => {
let timestamp =
config
.buffer
.format_timestamp(&message.server_time)
.map(|timestamp| {
selectable_text(timestamp).style(theme::selectable_text::timestamp)
});

let channel_text = selectable_rich_text::<_, _, (), _, _>(vec![
span(channel.as_str())
.color(theme.colors().buffer.url)
.link(message::Link::GoToMessage(
server.clone(),
channel.clone(),
message.hash,
)),
span(" "),
])
.on_link(scroll_view::Message::Link);

let text = message_content(
&message.content,
theme,
scroll_view::Message::Link,
theme::selectable_text::action,
config,
);

Some(
container(row![].push_maybe(timestamp).push(channel_text).push(text))
.into(),
)
}
_ => None,
},
)
Expand Down
31 changes: 25 additions & 6 deletions src/buffer/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub fn view<'a>(
let status = clients.status(server);
let buffer = &state.buffer;
let input = history.input(buffer);
let our_nick = clients.nickname(&state.server);

let chathistory_state = clients.get_chathistory_state(server, state.nick.as_ref());

Expand Down Expand Up @@ -74,7 +75,7 @@ pub fn view<'a>(
let nick = user_context::view(text, server, None, user, None, None)
.map(scroll_view::Message::UserContext);

let message = message_content::with_context(
let message_content = message_content::with_context(
&message.content,
theme,
scroll_view::Message::Link,
Expand All @@ -95,12 +96,21 @@ pub fn view<'a>(
let timestamp_nickname_row =
row![].push_maybe(timestamp).push(nick).push(space);

let text_container = container(message_content).style(move |theme| {
if let Some(nick) = our_nick {
if message::references_user(user.nickname(), nick, message) {
return theme::container::highlight(theme);
}
}
Default::default()
});

match &config.buffer.nickname.alignment {
data::buffer::Alignment::Left | data::buffer::Alignment::Right => {
Some(row![].push(timestamp_nickname_row).push(message).into())
Some(row![].push(timestamp_nickname_row).push(text_container).into())
}
data::buffer::Alignment::Top => {
Some(column![].push(timestamp_nickname_row).push(message).into())
Some(column![].push(timestamp_nickname_row).push(text_container).into())
}
}
}
Expand Down Expand Up @@ -130,24 +140,33 @@ pub fn view<'a>(
.into(),
)
}
message::Source::Action => {
message::Source::Action(user) => {
let marker = message_marker(max_nick_width, theme::selectable_text::action);

let message = message_content(
let message_content = message_content(
&message.content,
theme,
scroll_view::Message::Link,
theme::selectable_text::action,
config,
);

let text_container = container(message_content).style(move |theme| {
if let (Some(user), Some(nick)) = (user, our_nick) {
if message::references_user(user.nickname(), nick, message) {
return theme::container::highlight(theme);
}
}
Default::default()
});

Some(
container(
row![]
.push_maybe(timestamp)
.push(marker)
.push(space)
.push(message),
.push(text_container),
)
.into(),
)
Expand Down
Loading