2010-03-10 03:32:20 -05:00
|
|
|
/*
|
|
|
|
Yaaic - Yet Another Android IRC Client
|
|
|
|
|
|
|
|
Copyright 2009 Sebastian Kaspari
|
|
|
|
|
|
|
|
This file is part of Yaaic.
|
|
|
|
|
|
|
|
Yaaic is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Yaaic is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.yaaic.model;
|
|
|
|
|
2010-03-11 17:41:31 -05:00
|
|
|
import java.util.Collections;
|
2010-03-10 03:32:20 -05:00
|
|
|
import java.util.LinkedList;
|
2010-03-11 17:41:31 -05:00
|
|
|
import java.util.List;
|
2010-03-10 03:32:20 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for conversations
|
|
|
|
*
|
|
|
|
* A conversation can be a channel, a query or server messages
|
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
|
|
|
*/
|
|
|
|
public abstract class Conversation
|
|
|
|
{
|
2010-03-10 19:10:21 -05:00
|
|
|
public static final String TAG = "Yaaic/Conversation";
|
|
|
|
|
2010-03-10 03:37:31 -05:00
|
|
|
public static final int TYPE_CHANNEL = 1;
|
|
|
|
public static final int TYPE_QUERY = 2;
|
|
|
|
public static final int TYPE_SERVER = 3;
|
|
|
|
|
2010-03-10 03:32:20 -05:00
|
|
|
private static final int HISTORY_SIZE = 30;
|
|
|
|
|
2010-03-11 17:41:31 -05:00
|
|
|
private List<Message> buffer;
|
|
|
|
private List<Message> history;
|
2010-03-10 03:32:20 -05:00
|
|
|
private String name;
|
|
|
|
|
2010-03-10 03:37:31 -05:00
|
|
|
/**
|
|
|
|
* Get the type of conversation (channel, query, ..)
|
|
|
|
*
|
|
|
|
* @return See the constants: Conversation.TYPE_*
|
|
|
|
*/
|
|
|
|
public abstract int getType();
|
|
|
|
|
2010-03-10 03:32:20 -05:00
|
|
|
/**
|
|
|
|
* Create a new conversation with the given name
|
|
|
|
*
|
|
|
|
* @param name The name of the conversation (channel, user)
|
|
|
|
*/
|
|
|
|
public Conversation(String name)
|
|
|
|
{
|
2010-03-11 17:41:31 -05:00
|
|
|
this.buffer = Collections.synchronizedList(new LinkedList<Message>());
|
|
|
|
this.history = Collections.synchronizedList(new LinkedList<Message>());
|
2010-03-10 03:32:20 -05:00
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get name of the conversation (channel, user)
|
|
|
|
*/
|
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a message to the channel
|
|
|
|
*/
|
|
|
|
public void addMessage(Message message)
|
|
|
|
{
|
2010-03-11 17:41:31 -05:00
|
|
|
buffer.add(0, message);
|
|
|
|
history.add(message);
|
2010-03-10 03:32:20 -05:00
|
|
|
|
|
|
|
if (history.size() > HISTORY_SIZE) {
|
2010-03-11 17:41:31 -05:00
|
|
|
history.remove(0);
|
2010-03-10 03:32:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-11 17:46:11 -05:00
|
|
|
* Get size of the current history
|
|
|
|
*/
|
|
|
|
public int getHistorySize()
|
|
|
|
{
|
|
|
|
return history.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get message of the history at the given position
|
2010-03-10 03:32:20 -05:00
|
|
|
*
|
2010-03-11 17:46:11 -05:00
|
|
|
* @param position
|
|
|
|
* @return The message at the given position
|
2010-03-10 03:32:20 -05:00
|
|
|
*/
|
2010-03-11 17:46:11 -05:00
|
|
|
public Message getHistoryMessage(int position)
|
2010-03-10 03:32:20 -05:00
|
|
|
{
|
2010-03-11 17:46:11 -05:00
|
|
|
return history.get(position);
|
2010-03-10 03:32:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get last buffered message
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Message pollBufferedMessage()
|
|
|
|
{
|
2010-03-11 17:41:31 -05:00
|
|
|
Message message = buffer.get(buffer.size() - 1);
|
|
|
|
buffer.remove(buffer.size() - 1);
|
2010-03-10 03:32:20 -05:00
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the channel have buffered messages?
|
|
|
|
*/
|
|
|
|
public boolean hasBufferedMessages()
|
|
|
|
{
|
|
|
|
return buffer.size() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the message buffer
|
|
|
|
*/
|
|
|
|
public void clearBuffer()
|
|
|
|
{
|
|
|
|
buffer.clear();
|
|
|
|
}
|
|
|
|
}
|