1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-22 17:02:21 -05:00

Send channel name as extra on CHANNEL_MESSAGE broadcast

This commit is contained in:
Sebastian Kaspari 2010-03-02 20:28:32 +01:00
parent 4414f5ab7c
commit a361f957db
6 changed files with 62 additions and 15 deletions

View File

@ -80,7 +80,10 @@ public class IRCConnection extends PircBot
debug("Action", target + " " + sender + " " + action);
server.getChannel(target).addMessage("* " + sender + " " + action);
service.sendBroadcast(new Intent(Broadcast.CHANNEL_MESSAGE));
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
}
/**
@ -133,7 +136,10 @@ public class IRCConnection extends PircBot
service.sendBroadcast(new Intent(Broadcast.CHANNEL_NEW));
} else {
server.getChannel(target).addMessage(sender + " joined");
service.sendBroadcast(new Intent(Broadcast.CHANNEL_MESSAGE));
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
}
}
@ -151,7 +157,10 @@ public class IRCConnection extends PircBot
service.sendBroadcast(new Intent(Broadcast.CHANNEL_REMOVE));
} else {
server.getChannel(target).addMessage(kickerNick + " kicked " + recipientNick);
service.sendBroadcast(new Intent(Broadcast.CHANNEL_MESSAGE));
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
}
}
@ -164,7 +173,10 @@ public class IRCConnection extends PircBot
debug("Message", target + " " + sender + " " + message);
server.getChannel(target).addMessage("<" + sender + ">" + message);
service.sendBroadcast(new Intent(Broadcast.CHANNEL_MESSAGE));
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
}
/**
@ -176,7 +188,10 @@ public class IRCConnection extends PircBot
debug("Mode", target + " " + sourceNick + " " + mode);
server.getChannel(target).addMessage(sourceNick + " sets mode " + mode);
service.sendBroadcast(new Intent(Broadcast.CHANNEL_MESSAGE));
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
}
/**
@ -206,7 +221,10 @@ public class IRCConnection extends PircBot
debug("Op", target + " " + recipient + "(" + sourceNick + ")");
server.getChannel(target).addMessage(sourceNick + " oped " + recipient);
service.sendBroadcast(new Intent(Broadcast.CHANNEL_MESSAGE));
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
}
/**
@ -223,7 +241,10 @@ public class IRCConnection extends PircBot
service.sendBroadcast(new Intent(Broadcast.CHANNEL_REMOVE));
} else {
server.getChannel(target).addMessage(sender + " parted");
service.sendBroadcast(new Intent(Broadcast.CHANNEL_MESSAGE));
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
}
}
@ -259,7 +280,9 @@ public class IRCConnection extends PircBot
server.getChannel(target).addMessage("Topic: " + topic);
}
service.sendBroadcast(new Intent(Broadcast.CHANNEL_MESSAGE));
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent);
}
/**

View File

@ -22,7 +22,7 @@ package org.yaaic.listener;
public interface ChannelListener
{
public void onChannelMessage();
public void onChannelMessage(String target);
public void onNewChannel();
public void onRemoveChannel();
}

View File

@ -27,4 +27,6 @@ public class Broadcast
public static final String CHANNEL_MESSAGE = "org.yaaic.channel.message";
public static final String CHANNEL_NEW = "org.yaaic.channel.new";
public static final String CHANNEL_REMOVE = "org.yaaic.channel.remove";
public static final String EXTRA_CHANNEL = "channel";
}

View File

@ -57,10 +57,30 @@ public class Channel
*/
public void addMessage(String message)
{
messages.add(message);
messages.addFirst(message);
if (messages.size() > BUFFER_SIZE) {
messages.removeFirst();
messages.removeLast();
}
}
/**
* Get all messages
*
* @return
*/
public LinkedList<String> getMessages()
{
return messages;
}
/**
* Get last message
*
* @return
*/
public String pollMessage()
{
return messages.poll();
}
}

View File

@ -42,7 +42,7 @@ public class ChannelReceiver extends BroadcastReceiver
String action = intent.getAction();
if (action.equals(Broadcast.CHANNEL_MESSAGE)) {
listener.onChannelMessage();
listener.onChannelMessage(intent.getExtras().getString(Broadcast.EXTRA_CHANNEL));
}
}
}

View File

@ -20,8 +20,6 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.view;
import java.util.Iterator;
import org.yaaic.R;
import org.yaaic.Yaaic;
import org.yaaic.irc.IRCBinder;
@ -53,6 +51,7 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;
/**
@ -187,8 +186,11 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
/**
* On channel message
*/
public void onChannelMessage()
public void onChannelMessage(String target)
{
String message = server.getChannel(target).pollMessage();
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
/**