1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-12-01 21:32:22 -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")) { else if (command.equals("PRIVMSG")) {
// This is a private message to us. // 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")) { else if (command.equals("JOIN")) {
// Someone is joining a channel. // 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 hostname The hostname of the person who sent the private message.
* @param message The actual 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,44 +208,41 @@ public class IRCConnection extends PircBot
Message message = new Message(sender + " " + action); Message message = new Message(sender + " " + action);
message.setIcon(R.drawable.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 // We are the target - this is an action in a query
conversation = server.getConversation(sender); queryNick = sender;
if (conversation == null) { }
// Open a query if there's none yet conversation = server.getConversation(queryNick);
conversation = new Query(sender);
server.addConversation(conversation);
conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent( if (conversation == null) {
Broadcast.CONVERSATION_NEW, // Open a query if there's none yet
server.getId(), conversation = new Query(queryNick);
sender server.addConversation(conversation);
); conversation.addMessage(message);
service.sendBroadcast(intent);
} else {
conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_NEW,
server.getId(), server.getId(),
sender queryNick
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
}
} else { } else {
// A action in a channel
conversation = server.getConversation(target);
conversation.addMessage(message); conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
target queryNick
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
} }
if (sender.equals(this.getNick())) {
// Don't notify for something sent in our name
return;
}
boolean mentioned = isMentioned(action); boolean mentioned = isMentioned(action);
if (mentioned || target.equals(this.getNick())) { if (mentioned || target.equals(this.getNick())) {
service.updateNotification( service.updateNotification(
@ -584,22 +581,26 @@ public class IRCConnection extends PircBot
* On Private Message * On Private Message
*/ */
@Override @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); 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) { if (conversation == null) {
// Open a query if there's none yet // Open a query if there's none yet
conversation = new Query(sender); conversation = new Query(queryNick);
conversation.addMessage(message); conversation.addMessage(message);
server.addConversation(conversation); server.addConversation(conversation);
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_NEW, Broadcast.CONVERSATION_NEW,
server.getId(), server.getId(),
sender queryNick
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
} else { } else {
@ -608,11 +609,16 @@ public class IRCConnection extends PircBot
Intent intent = Broadcast.createConversationIntent( Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE, Broadcast.CONVERSATION_MESSAGE,
server.getId(), server.getId(),
sender queryNick
); );
service.sendBroadcast(intent); service.sendBroadcast(intent);
} }
if (sender.equals(this.getNick())) {
// Don't notify for something sent in our name
return;
}
service.updateNotification( service.updateNotification(
"<" + sender + "> " + text, "<" + sender + "> " + text,
service.getSettings().isVibrateHighlightEnabled(), service.getSettings().isVibrateHighlightEnabled(),