incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esjew...@apache.org
Subject svn commit: r1023299 - in /incubator/esme/trunk/server/src/main/scala: bootstrap/liftweb/ org/apache/esme/lib/ org/apache/esme/snippet/
Date Sat, 16 Oct 2010 14:47:54 GMT
Author: esjewett
Date: Sat Oct 16 14:47:54 2010
New Revision: 1023299

URL: http://svn.apache.org/viewvc?rev=1023299&view=rev
Log:
Refactoring a bit to make the snippets used in User and Tag displays separate. These will
probably get blown away entirely when we switch to a canonical timeline view, but I only figured
that out after I'd done the refactoring.

Added:
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/MessageUtils.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserDisplay.scala
Modified:
    incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ConversationMgr.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/TagDisplay.scala

Modified: incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala?rev=1023299&r1=1023298&r2=1023299&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala Sat Oct 16 14:47:54
2010
@@ -171,7 +171,7 @@ class Boot {
     // Build SiteMap
     val entries = Menu(Loc("Home", List("index"), "Home")) ::
         Menu(Loc("user", List("info_view", "user"), "User Info", ifIsLoggedIn,
-          Loc.Snippet("user_info", TagDisplay.userInfo))) ::
+          Loc.Snippet("user_info", UserDisplay.userInfo))) ::
         logLevel.menu  ::
         Menu(Loc("tag", List("info_view", "tag"), "Tag", ifIsLoggedIn,
           Loc.Snippet("tag_display", TagDisplay.display))) ::

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ConversationMgr.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ConversationMgr.scala?rev=1023299&r1=1023298&r2=1023299&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ConversationMgr.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/ConversationMgr.scala Sat
Oct 16 14:47:54 2010
@@ -85,8 +85,6 @@ object ConversationMgr {
 
       val jsId = "timeline_messages"                  
 
-      val cid = S.param("cid").map(toLong).openOr(-1L)
-
       val msgs = Message.findAndPrime(By(Message.conversation, cid),
                                       OrderBy(Message.id, Descending))
 

Added: incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/MessageUtils.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/MessageUtils.scala?rev=1023299&view=auto
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/MessageUtils.scala (added)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/MessageUtils.scala Sat
Oct 16 14:47:54 2010
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.esme.lib
+
+import org.apache.esme._
+import model._
+import org.apache.esme.actor._
+
+import net.liftweb._
+import http._
+import SHtml._
+import js._
+import JsCmds._
+import JE._
+import util._
+import common._
+import Helpers._
+
+import mapper._
+
+import scala.xml.{NodeSeq, Text}
+import java.util.Date
+
+object MessageUtils {
+  def bindMessages(messageList: List[Message])(in: NodeSeq): NodeSeq =
+    messageList.flatMap{m =>
+      val nickname = m.author.obj.map(_.nickname.is) openOr ""
+      bind("item", in,
+           "author" -> <a href={"/user/"+urlEncode(nickname)}>{nickname}</a>,
+           "body" -> m.digestedXHTML,
+           "date" -> Text(new Date(m.when.is).toString))
+    }          
+}
\ No newline at end of file

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/TagDisplay.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/TagDisplay.scala?rev=1023299&r1=1023298&r2=1023299&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/TagDisplay.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/TagDisplay.scala Sat
Oct 16 14:47:54 2010
@@ -20,7 +20,8 @@
 package org.apache.esme.snippet
 
 import org.apache.esme._
-import model._
+import model._    
+import lib.MessageUtils
 import org.apache.esme.actor._
 
 import net.liftweb._
@@ -39,48 +40,6 @@ import scala.xml.{NodeSeq, Text}
 import java.util.Date
 
 object TagDisplay {
-  def userInfo(in: NodeSeq): NodeSeq = {
-    val user: User = S.param("uid").flatMap(User.findFromWeb) openOr {
-      S.error(S.?("base_ui_no_user_found"))
-      S.redirectTo(S.referer openOr "/")
-    }
-   
-    def updateFollow: JsCmd = SetHtml("following", followOrNot)
-
-    def followOrNot: NodeSeq = {
-      User.currentUser match {
-        case Full(u) if u != user =>
-          if (u.following_?(user))
-          ajaxButton(S.?("base_ui_unfollow"), () => {u.unfollow(user); updateFollow})
-          else ajaxButton(S.?("base_ui_follow"), () => {u.follow(user); updateFollow})
-
-        case _ => <xml:group> <div class="thatsyou">{S.?("base_user_thats_you")}</div></xml:group>

-      }
-    }
-
-
-     bind("user", in,
-         "nicename" -> user.niceName,
-         "lastName" -> user.lastName,
-         "firstName" -> user.firstName,
-          "image" -> user.image_url,
-         "followButton" -> followOrNot,
-         "timeline" -> bindTag(Mailbox.mostRecentMessagesFor(user.id, 50).map(_._1)) _,
-         "messages" -> bindTag(Message.findAll(By(Message.author, user), OrderBy(Message.id,
Descending), MaxRows(50))) _,
-         AttrBindParam("userId", Text(user.id.toString),"userId")
-    )
-
-  
-  }
-
-  private def bindTag(tagList: List[Message])(in: NodeSeq): NodeSeq =
-    tagList.flatMap{m =>
-      val nickname = m.author.obj.map(_.nickname.is) openOr ""
-      bind("item", in,
-           "author" -> <a href={"/user/"+urlEncode(nickname)}>{nickname}</a>,
-           "body" -> m.digestedXHTML,
-           "date" -> Text(new Date(m.when.is).toString))
-    }
 
   def display(in: NodeSeq): NodeSeq = {  
   
@@ -89,7 +48,7 @@ object TagDisplay {
     val tag = Tag.findAll(By(Tag.name, name))
     val user = User.currentUser
 
-    val tagList: List[Message] =
+    val messageList: List[Message] =
     for {
       t <- tag
       item <- t.findMessages()
@@ -121,8 +80,8 @@ object TagDisplay {
     def updateFollow: JsCmd = SetHtml("following", followOrUnfollow)
 
     bind("tag", in, "name" -> name,
-         "each" -> bindTag(tagList) _,
+         "each" -> MessageUtils.bindMessages(messageList) _,
          "followButton" -> followOrUnfollow )
 
-  }  
+  }       
 }

Added: incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserDisplay.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserDisplay.scala?rev=1023299&view=auto
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserDisplay.scala (added)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserDisplay.scala Sat
Oct 16 14:47:54 2010
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.esme.snippet
+
+import org.apache.esme._
+import model._    
+import lib.MessageUtils
+import org.apache.esme.actor._
+
+import net.liftweb._
+import http._
+import SHtml._
+import js._
+import JsCmds._
+import JE._
+import util._
+import common._
+import Helpers._
+
+import mapper._
+
+import scala.xml.{NodeSeq, Text}
+import java.util.Date
+
+object UserDisplay {
+  def userInfo(in: NodeSeq): NodeSeq = {
+    val user: User = S.param("uid").flatMap(User.findFromWeb) openOr {
+      S.error(S.?("base_ui_no_user_found"))
+      S.redirectTo(S.referer openOr "/")
+    }
+   
+    def updateFollow: JsCmd = SetHtml("following", followOrNot)
+
+    def followOrNot: NodeSeq = {
+      User.currentUser match {
+        case Full(u) if u != user =>
+          if (u.following_?(user))
+          ajaxButton(S.?("base_ui_unfollow"), () => {u.unfollow(user); updateFollow})
+          else ajaxButton(S.?("base_ui_follow"), () => {u.follow(user); updateFollow})
+
+        case _ => <xml:group> <div class="thatsyou">{S.?("base_user_thats_you")}</div></xml:group>

+      }
+    }
+
+
+     bind("user", in,
+         "nicename" -> user.niceName,
+         "lastName" -> user.lastName,
+         "firstName" -> user.firstName,
+          "image" -> user.image_url,
+         "followButton" -> followOrNot,
+         "timeline" -> MessageUtils.bindMessages(Mailbox.mostRecentMessagesFor(user.id,
50).map(_._1)) _,
+         "messages" -> MessageUtils.bindMessages(Message.findAll(
+            By(Message.author, user), 
+            OrderBy(Message.id, Descending), 
+            MaxRows(50))) _,
+         AttrBindParam("userId", Text(user.id.toString),"userId")
+    )
+ 
+  }
+}
\ No newline at end of file



Mime
View raw message