You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@esme.apache.org by rh...@apache.org on 2011/07/23 17:43:44 UTC
svn commit: r1150127 -
/esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala
Author: rhirsch
Date: Sat Jul 23 15:43:44 2011
New Revision: 1150127
URL: http://svn.apache.org/viewvc?rev=1150127&view=rev
Log:
[ESME-292] Implement API2 methods for Tag/Conversation follow/unfollow
Modified:
esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala
Modified: esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala?rev=1150127&r1=1150126&r2=1150127&view=diff
==============================================================================
--- esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala (original)
+++ esme/trunk/server/src/main/scala/org/apache/esme/api/API2.scala Sat Jul 23 15:43:44 2011
@@ -104,6 +104,11 @@ object API2 extends ApiHelper with XmlHe
case Req("api2" :: "tags" :: tag :: "messages" :: Nil, _, GetRequest)
=> () => allTagMsgs(tag)
+
+ case Req("api2" :: "tags" :: tag :: "followers" :: Nil, _, PostRequest) => ()
+ => followTag(Box(List(tag)))
+ case Req("api2" :: "tags" :: tag :: "followers" :: Nil, _, DeleteRequest) => ()
+ => unfollowTag(Box(List(tag)))
case Req("api2" :: "user" :: "followees" :: Nil, _, GetRequest) => allFollowees
case Req("api2" :: "user" :: "followees" :: Nil, _, PostRequest) => addFollowee
@@ -137,6 +142,11 @@ object API2 extends ApiHelper with XmlHe
case Req("api2" :: "conversations" :: conversationId :: Nil, _, GetRequest) => ()
=> getConversation(Box(List(conversationId)))
+
+ case Req("api2" :: "conversations" :: conversationId :: "followers" :: Nil, _, PostRequest) => ()
+ => followConversation(Box(List(conversationId)))
+ case Req("api2" :: "conversations" :: conversationId :: "followers" :: Nil, _, DeleteRequest) => ()
+ => unfollowConversation(Box(List(conversationId)))
}
def allSessions(): LiftResponse = {
@@ -721,6 +731,104 @@ object API2 extends ApiHelper with XmlHe
r
}
+
+ def followTag(tagId: Box[String]): LiftResponse = {
+ val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+ for (user <- User.currentUser)
+ yield {
+ val tagList = Tag.findAll(By(Tag.name, tagId.openOr("")))
+ val tag = tagList.head
+
+ if (!tag.followers.contains(user)) {
+ tag.followers += user
+ tag.save
+ }
+ if(tagList.length == 0)
+ (404,Map(),Empty)
+ else
+ (200,Map(),Empty)
+ }
+
+ val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+ if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+ r
+ }
+
+ def unfollowTag(tagId: Box[String]): LiftResponse = {
+ val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+ for (user <- User.currentUser)
+ yield {
+ val tagList = Tag.findAll(By(Tag.name, tagId.openOr("")))
+ val tag = tagList.head
+
+ if (tag.followers.contains(user)) {
+ tag.followers -= user
+ tag.save
+ }
+ if(tagList.length == 0)
+ (404,Map(),Empty)
+ else
+ (200,Map(),Empty)
+ }
+
+ val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+ if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+ r
+ }
+
+
+
+ def followConversation(conversationId: Box[String]): LiftResponse = {
+ val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+ for (user <- User.currentUser;
+ id <- conversationId.map(toLong))
+ yield {
+
+ val messages = Message.findMessages(List(id))
+
+ val m = messages.values.toList.head
+ if (!m.followers.contains(user)) {
+ m.followers += user
+ m.save
+ }
+ if(messages.isEmpty)
+ (404,Map(),Empty)
+ else
+ (200,Map(),Empty)
+ }
+
+ val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+ if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+ r
+ }
+
+ def unfollowConversation(conversationId: Box[String]): LiftResponse = {
+ val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+ for (user <- User.currentUser;
+ id <- conversationId.map(toLong))
+ yield {
+
+ val messages = Message.findMessages(List(id))
+
+ val m = messages.values.toList.head
+ if (m.followers.contains(user)) {
+ m.followers -= user
+ m.save
+ }
+ if(messages.isEmpty)
+ (404,Map(),Empty)
+ else
+ (200,Map(),Empty)
+ }
+
+ val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+ if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+ r
+ }
def unAuthorized(): LiftResponse = {
Full((403,Map.empty[String, String],Empty))