Skip to content

Commit

Permalink
Visually highlight /me action when mentioned
Browse files Browse the repository at this point in the history
  • Loading branch information
englut committed Dec 16, 2024
1 parent 4533b80 commit 1c5dad6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
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
21 changes: 15 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 @@ -726,14 +735,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 @@ -770,7 +779,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
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
23 changes: 20 additions & 3 deletions src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,42 @@ 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| match user {
Some(user) => match our_nick {
Some(nick)
if message::references_user(
user.nickname(),
nick,
message,
) =>
{
theme::container::highlight(theme)
}
_ => Default::default(),
},
_ => Default::default(),
});

Some(
container(
row![]
.push_maybe(timestamp)
.push_maybe(prefixes)
.push(marker)
.push(space)
.push(message),
.push(text_container),
)
.into(),
)
Expand Down
2 changes: 1 addition & 1 deletion src/buffer/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn view<'a>(
.into(),
)
}
message::Source::Action => {
message::Source::Action(_) => {
let marker = message_marker(max_nick_width, theme::selectable_text::action);

let message = message_content(
Expand Down

0 comments on commit 1c5dad6

Please sign in to comment.