Skip to content

Commit

Permalink
Fix showing PRIVMSGs when target is not us
Browse files Browse the repository at this point in the history
This case can happen when using bouncers, see inline comments and #271.

Fixes #271
  • Loading branch information
osa1 committed Nov 21, 2020
1 parent d52029f commit 62a4deb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
helpful message on how to enable it. Previously `/notify` would behave as if
desktop notification support is enabled but notifications would not work.
(#270)
- Fixed a bug when showing messages relayed by bouncers. (#271)

# 2020/09/20: 0.7.0

Expand Down
67 changes: 48 additions & 19 deletions tiny/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,29 +186,58 @@ fn handle_irc_msg(ui: &dyn UI, client: &Client, msg: wire::Msg) {
}
}
wire::MsgTarget::User(target) => {
// Message is sent to the user. If the sender is a server we show the message
// in the server tab, otherwise we show it in a private tab. In case of an
// ambiguity we again show in a private tab, as some bouncers send PRIVMSGs
// from users with ambiguous prefix without a `user@host` part. See #247.
let msg_target = {
match pfx {
Server(_) => MsgTarget::Server { serv },
User { ref nick, .. } | Ambiguous(ref nick) => {
// Show NOTICE messages in server tabs if we don't have a tab for
// the sender already (see #21)
if is_notice && !ui.user_tab_exists(serv, nick) {
MsgTarget::Server { serv }
} else {
MsgTarget::User { serv, nick }
if target == client.get_nick() {
// Message is sent to us. If the sender is a server we show the message in
// the server tab, otherwise we show it in a private tab. In case of an
// ambiguity we again show in a private tab, as some bouncers send PRIVMSGs
// from users with ambiguous prefix without a `user@host` part. See #247.
let msg_target = {
match pfx {
Server(_) => MsgTarget::Server { serv },
User { ref nick, .. } | Ambiguous(ref nick) => {
// Show NOTICE messages in server tabs if we don't have a tab for
// the sender already (see #21)
if is_notice && !ui.user_tab_exists(serv, nick) {
MsgTarget::Server { serv }
} else {
MsgTarget::User { serv, nick }
}
}
}
}
};
ui.add_privmsg(sender, &msg, ts, &msg_target, false, is_action);
if target == client.get_nick() {
};
ui.add_privmsg(sender, &msg, ts, &msg_target, false, is_action);
ui.set_tab_style(TabStyle::Highlight, &msg_target);
} else {
// Not sure if this case can happen
// PRIVMSG not sent to us. This case can happen when using a bouncer, see
// #271. When multiple clients connect to the same bouncer and one of them
// sends a PRIVMSG, the message is relayed to the other clients. E.g.
//
// PRIVMSG <our_nick> <target> :...
//
// When this happens the prefix should be our nick. We check this below:
if log_enabled!(log::Level::Warn) {
match pfx {
Server(_) => {
warn!(
"PRIVMSG target is not us, but prefix is server: {:?}",
msg
);
}
User { ref nick, .. } | Ambiguous(ref nick) => {
if *nick != client.get_nick() {
warn!("PRIVMSG sender or target is not us: {:?}", msg);
}
}
}
}
let msg_target = MsgTarget::User {
serv,
nick: &target,
};
ui.add_privmsg(&client.get_nick(), &msg, ts, &msg_target, false, is_action);
// Don't highlight the tab as `Highlight`: the message was sent by us so
// the tab probably doesn't need that much attention. Highlight as `NewMsg`
// instead.
ui.set_tab_style(TabStyle::NewMsg, &msg_target);
}
}
Expand Down

0 comments on commit 62a4deb

Please sign in to comment.