1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-26 02:42:16 -05:00

Do something sane for private messages where the sender is our nick

As of now, private messages where the sender is our nick end up in
a query window targeted at us.  Show these messages in the query window
of the target instead, which is probably what we want.

This is useful for use with irssi proxy, which will send messages sent
by another client attached to the proxy to us in this way.

(Note that this patch makes a change to PircBot to pass the target of a
private message to the onPrivateMessage handler.)
This commit is contained in:
Steven Luo 2011-05-29 17:49:01 -07:00 committed by Sebastian Kaspari
parent 159cb8195d
commit 9a8bf44d63
2 changed files with 40 additions and 32 deletions

View File

@ -991,7 +991,8 @@ public abstract class PircBot implements ReplyConstants {
}
else if (command.equals("PRIVMSG")) {
// This is a private message to us.
this.onPrivateMessage(sourceNick, sourceLogin, sourceHostname, line.substring(line.indexOf(" :") + 2));
// XXX PircBot patch to pass target info to privmsg callback
this.onPrivateMessage(sourceNick, sourceLogin, sourceHostname, target, line.substring(line.indexOf(" :") + 2));
}
else if (command.equals("JOIN")) {
// Someone is joining a channel.
@ -1305,7 +1306,8 @@ public abstract class PircBot implements ReplyConstants {
* @param hostname The hostname of the person who sent the private message.
* @param message The actual message.
*/
protected void onPrivateMessage(String sender, String login, String hostname, String message) {}
// XXX PircBot patch to pass target info to privmsg callback
protected void onPrivateMessage(String sender, String login, String hostname, String target, String message) {}
/**

View File

@ -208,19 +208,23 @@ public class IRCConnection extends PircBot
Message message = new Message(sender + " " + action);
message.setIcon(R.drawable.action);
if (target.equals(this.getNick())) {
String queryNick = target;
if (queryNick.equals(this.getNick())) {
// We are the target - this is an action in a query
conversation = server.getConversation(sender);
queryNick = sender;
}
conversation = server.getConversation(queryNick);
if (conversation == null) {
// Open a query if there's none yet
conversation = new Query(sender);
conversation = new Query(queryNick);
server.addConversation(conversation);
conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_NEW,
server.getId(),
sender
queryNick
);
service.sendBroadcast(intent);
} else {
@ -229,21 +233,14 @@ public class IRCConnection extends PircBot
Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE,
server.getId(),
sender
queryNick
);
service.sendBroadcast(intent);
}
} else {
// A action in a channel
conversation = server.getConversation(target);
conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE,
server.getId(),
target
);
service.sendBroadcast(intent);
if (sender.equals(this.getNick())) {
// Don't notify for something sent in our name
return;
}
boolean mentioned = isMentioned(action);
@ -584,22 +581,26 @@ public class IRCConnection extends PircBot
* On Private Message
*/
@Override
protected void onPrivateMessage(String sender, String login, String hostname, String text)
protected void onPrivateMessage(String sender, String login, String hostname, String target, String text)
{
Message message = new Message("<" + sender + "> " + text);
String queryNick = sender;
Conversation conversation = server.getConversation(sender);
if (queryNick.equals(this.getNick())) {
queryNick = target;
}
Conversation conversation = server.getConversation(queryNick);
if (conversation == null) {
// Open a query if there's none yet
conversation = new Query(sender);
conversation = new Query(queryNick);
conversation.addMessage(message);
server.addConversation(conversation);
Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_NEW,
server.getId(),
sender
queryNick
);
service.sendBroadcast(intent);
} else {
@ -608,11 +609,16 @@ public class IRCConnection extends PircBot
Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE,
server.getId(),
sender
queryNick
);
service.sendBroadcast(intent);
}
if (sender.equals(this.getNick())) {
// Don't notify for something sent in our name
return;
}
service.updateNotification(
"<" + sender + "> " + text,
service.getSettings().isVibrateHighlightEnabled(),