/soc/2012/michael/android: 0437d5133423: Commented conversation ...

Michael Zangl michael at soc.pidgin.im
Mon Aug 20 10:15:53 EDT 2012


Changeset: 0437d51334239deda23a07f5a16553eaa5aacd2f
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-08-20 15:33 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/0437d5133423

Description:

Commented conversation classes

diffstat:

 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationListener.java |  22 +++-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java  |  70 +++++++--
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleConversation.java   |  64 ++++++++-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleMessage.java        |  50 ++++++-
 4 files changed, 179 insertions(+), 27 deletions(-)

diffs (truncated from 362 to 300 lines):

diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationListener.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationListener.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationListener.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationListener.java
@@ -1,8 +1,28 @@
 package im.pidgin.libpurple.conversation;
 
+/**
+ * This interface allows you to listen to conversations
+ *
+ * @author michael
+ */
 public interface ConversationListener {
 
-	void messageReceived(PurpleConversation purpleConversation, PurpleMessage message);
+	/**
+	 * Called when a message was received on a conversation.
+	 *
+	 * @param purpleConversation
+	 *            The conversation with that message.
+	 * @param message
+	 *            The message that was received.
+	 */
+	void messageReceived(PurpleConversation purpleConversation,
+	        PurpleMessage message);
 
+	/**
+	 * Called when the typing state of the buddy we are talking with changed.
+	 *
+	 * @param purpleConversation
+	 *            The conversation in which the buddy changed the typing state.
+	 */
 	void updateTypingState(PurpleConversation purpleConversation);
 }
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java
@@ -9,10 +9,22 @@ import im.pidgin.libpurple.peering.PeerG
 import java.util.Date;
 import java.util.Hashtable;
 
+/**
+ * This is the main conversation manager. It handles conversation object
+ * creation and destruction and event handling. This class is not accessible in
+ * the public API.
+ *
+ * @author michael
+ */
 public class ConversationManager extends AbstractPurpleManaged implements
-		PeerGenerator<PurpleConversation> {
+        PeerGenerator<PurpleConversation> {
 
-	private final Hashtable<Long, PurpleConversation> conversations = new Hashtable<Long, PurpleConversation>();
+	/**
+	 * A hashtable of conversations that we know of. TODO: We can use ui_data
+	 * here.
+	 */
+	private final Hashtable<Long, PurpleConversation> conversations =
+	        new Hashtable<Long, PurpleConversation>();
 
 	public ConversationManager(CoreManager manager) {
 		super(manager);
@@ -27,34 +39,58 @@ public class ConversationManager extends
 
 	private native void register_native();
 
+	/**
+	 * Starts a new conversation with a buddy.
+	 *
+	 * @param buddy
+	 *            The buddy to start a conversation with.
+	 * @return
+	 */
 	public PurpleConversation newConversation(PurpleBuddy buddy) {
-		PurpleConversation conversation = PurpleConversation.newConversation(
-				buddy, getManager());
+		PurpleConversation conversation =
+		        PurpleConversation.newConversation(buddy, getManager());
 		conversations.put(conversation.getNativePointer(), conversation);
 		return conversation;
 	}
-	
-	protected void createConversation(long conv) { 
-		//PurpleConversation conversation = getPeer(conv);
-		//conversations.put(conversation.getNativePointer(), conversation);
+
+	/**
+	 * Called on a conversation created event.
+	 *
+	 * @param conv
+	 *            The conversation that was created.
+	 */
+	protected void createConversation(long conv) {
+		// PurpleConversation conversation = getPeer(conv);
+		// conversations.put(conversation.getNativePointer(), conversation);
 	}
 
-	protected void destroyConversation(long conv) { 
+	/**
+	 * Called when a conversation was destroyed.
+	 *
+	 * @param conv
+	 *            The conversation that was destroyed.
+	 */
+	protected void destroyConversation(long conv) {
 		PurpleConversation conversation = getPeer(conv);
+		conversation.nativeObjectFreed();
 		conversations.remove(conversation.getNativePointer());
 		conversation.nativeObjectFreed();
 	}
-	
-	protected void writeIm(long conv, String who, String message, int flags, long mtime) { 
-		
+
+	/* signal / ui ops callbacks */
+
+	protected void writeIm(long conv, String who, String message, int flags,
+	        long mtime) {
+
 		Date time = new Date(mtime);
 		PurpleConversation conversation = getPeer(conv);
-		conversation.notifyMessageReceived(new PurpleMessage(who, message, flags, time));
+		conversation.notifyMessageReceived(new PurpleMessage(who, message,
+		        flags, time));
 	}
 
 	protected void updateBuddyTyping(long accountPointer, String who) {
-		PurpleAccount account = getManager().getAccountList().getPeer(
-				accountPointer);
+		PurpleAccount account =
+		        getManager().getAccountList().getPeer(accountPointer);
 		PurpleConversation conversation = findImWithAccount(who, account);
 		if (conversation == null) {
 			return;
@@ -64,7 +100,7 @@ public class ConversationManager extends
 	}
 
 	private PurpleConversation findImWithAccount(String who,
-			PurpleAccount account) {
+	        PurpleAccount account) {
 		long account_native = findImWithAccount_native(who, account);
 		if (account_native == 0) {
 			return null;
@@ -74,7 +110,7 @@ public class ConversationManager extends
 	}
 
 	private native long findImWithAccount_native(String who,
-			PurpleAccount account);
+	        PurpleAccount account);
 
 	@Override
 	public PurpleConversation getPeer(long pointer) {
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleConversation.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleConversation.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleConversation.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleConversation.java
@@ -6,29 +6,63 @@ import im.pidgin.libpurple.core.PeeredPu
 
 import java.util.LinkedList;
 
+/**
+ * This is a conversation with some buddy. Currently, this only represents an IM
+ * buddy.
+ *
+ * @author michael
+ */
 public class PurpleConversation extends PeeredPurpleManaged {
 
+	/**
+	 * Creates a new conversation.
+	 *
+	 * @param buddy
+	 *            The buddy to conversate with.
+	 * @param manager
+	 *            The manager
+	 * @return A new conversation that was just created.
+	 */
 	protected static PurpleConversation newConversation(PurpleBuddy buddy,
-			CoreManager manager) {
+	        CoreManager manager) {
 		long nativePointer = newConversation_native(buddy);
 		return new PurpleConversation(nativePointer, manager);
 	}
 
 	private static native long newConversation_native(PurpleBuddy buddy);
 
-	private final LinkedList<ConversationListener> conversationListeners = new LinkedList<ConversationListener>();
+	/**
+	 * This is a list of listeners that listen to this conversation.
+	 */
+	private final LinkedList<ConversationListener> conversationListeners =
+	        new LinkedList<ConversationListener>();
+	/**
+	 * The mutex to synchronize the conversation listeners.
+	 */
 	private final Object conversationListenerMutex = new Object();
 
 	private PurpleConversation(long nativePointer, CoreManager manager) {
 		super(nativePointer, manager);
 	}
 
+	/**
+	 * Adds a listener to this conversation.
+	 *
+	 * @param l
+	 *            The listener to add.
+	 */
 	public void addConversationListener(ConversationListener l) {
 		synchronized (conversationListenerMutex) {
 			conversationListeners.add(l);
 		}
 	}
 
+	/**
+	 * Removes a listener from this conversation if it was previously added.
+	 *
+	 * @param l
+	 *            The listener to remove.
+	 */
 	public void removeConversationListener(ConversationListener l) {
 		synchronized (conversationListenerMutex) {
 			conversationListeners.remove(l);
@@ -51,6 +85,13 @@ public class PurpleConversation extends 
 		}
 	}
 
+	/**
+	 * Enables or disables logging for this conversation.
+	 *
+	 * @param logging
+	 *            <code>true</code> if logging should be enabled, or
+	 *            <code>false</code> otherwise.
+	 */
 	public synchronized void setLogging(boolean logging) {
 		ensureNotDestroyed();
 		setLogging_native(logging);
@@ -58,6 +99,12 @@ public class PurpleConversation extends 
 
 	private native void setLogging_native(boolean logging);
 
+	/**
+	 * Returns whether or not logging is enabled for this conversation.
+	 *
+	 * @return <code>true</code> if logging is enabled, or <code>false</code>
+	 *         otherwise.
+	 */
 	public synchronized boolean isLogging() {
 		ensureNotDestroyed();
 		return isLogging_native();
@@ -65,6 +112,12 @@ public class PurpleConversation extends 
 
 	private native boolean isLogging_native();
 
+	/**
+	 * Sends a message to the buddy in this conversation.
+	 *
+	 * @param message
+	 *            The message to send.
+	 */
 	public synchronized void send(String message) {
 		ensureNotDestroyed();
 		send_native(message);
@@ -81,7 +134,12 @@ public class PurpleConversation extends 
 	protected synchronized void nativeObjectFreed() {
 		super.nativeObjectFreed();
 	}
-	
+
+	/**
+	 * Gets the typing state of the opponent.
+	 *
+	 * @return true if the other buddy is typing. TODO: Change this to an enum.
+	 */
 	public synchronized boolean getTypingState() {
 		ensureNotDestroyed();
 		return getTypingState_native();
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleMessage.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleMessage.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleMessage.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleMessage.java
@@ -4,6 +4,11 @@ import im.pidgin.libpurple.constants.Con
 
 import java.util.Date;
 
+/**
+ * This is a message that was sent on a conversation.
+ *
+ * @author michael
+ */
 public class PurpleMessage {
 
 	private final String who;
@@ -11,33 +16,66 @@ public class PurpleMessage {
 	private final int flags;
 	private final Date time;
 
-	public PurpleMessage(String who, String message, int flags, Date time) {
+	/**
+	 * Creates a new message object.
+	 *
+	 * @param who
+	 * @param message
+	 * @param flags



More information about the Commits mailing list