r7189 - dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive



Author: otaylor
Date: 2008-01-11 10:28:22 -0600 (Fri, 11 Jan 2008)
New Revision: 7189

Added:
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/ChatMessagesIQHandler.java
Modified:
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/HippoPlugin.java
Log:
Add a data model IQ for adding a chat message

Added: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/ChatMessagesIQHandler.java
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/ChatMessagesIQHandler.java	2008-01-11 16:04:22 UTC (rev 7188)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/ChatMessagesIQHandler.java	2008-01-11 16:28:22 UTC (rev 7189)
@@ -0,0 +1,51 @@
+package com.dumbhippo.jive;
+
+import java.util.Date;
+
+import javax.ejb.EJB;
+
+import org.xmpp.packet.IQ;
+
+import com.dumbhippo.identity20.Guid;
+import com.dumbhippo.jive.annotations.IQHandler;
+import com.dumbhippo.jive.annotations.IQMethod;
+import com.dumbhippo.persistence.Sentiment;
+import com.dumbhippo.server.ChatRoomInfo;
+import com.dumbhippo.server.ChatSystem;
+import com.dumbhippo.server.NotFoundException;
+import com.dumbhippo.server.views.UserViewpoint;
+import com.dumbhippo.tx.RetryException;
+
+ IQHandler(namespace=ChatMessagesIQHandler.CHAT_MESSAGES_NAMESPACE)
+public class ChatMessagesIQHandler extends AnnotatedIQHandler {
+	static final String CHAT_MESSAGES_NAMESPACE = "http://mugshot.org/p/chatMessages";; 
+	
+	@EJB
+	private ChatSystem chatSystem;
+	
+	public ChatMessagesIQHandler() {
+		super("Mugshot Chat Messages IQ Handler");
+	}
+	
+	@IQMethod(name="addMessage", type=IQ.Type.set)
+	@IQParams({ "chatId", "text", "sentiment" })
+	public void addChatMessage(UserViewpoint viewpoint, Guid chatId, String text, String sentiment) throws IQException, RetryException {
+		Sentiment sentimentValue;
+		try {
+			sentimentValue = Sentiment.valueOf(sentiment);
+		} catch (IllegalArgumentException e) {
+			throw IQException.createBadRequest("Bad value for sentiment");
+		}
+		
+		ChatRoomInfo info;
+		try {
+			info = chatSystem.getChatRoomInfo(chatId, false);
+			if (!chatSystem.canJoinChat(info.getChatId(), info.getKind(), viewpoint))
+				throw new NotFoundException("Chatroom not visible");
+		} catch (NotFoundException e) {
+			throw IQException.createBadRequest("No such chatroom");
+		}
+		
+		chatSystem.addChatRoomMessage(info.getChatId(), info.getKind(), viewpoint, text, sentimentValue, new Date());
+	}
+}

Modified: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/HippoPlugin.java
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/HippoPlugin.java	2008-01-11 16:04:22 UTC (rev 7188)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/HippoPlugin.java	2008-01-11 16:28:22 UTC (rev 7189)
@@ -83,6 +83,7 @@
 			addIQHandler(new SystemIQHandler());
 			addIQHandler(new ApplicationsIQHandler());
 			addIQHandler(new LegacyApplicationsIQHandler());
+			addIQHandler(new ChatMessagesIQHandler());
 			addIQHandler(new ClientInfoIQHandler());
 			addIQHandler(new MySpaceIQHandler());					
 			addIQHandler(new MusicIQHandler());



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]