You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@esme.apache.org by es...@apache.org on 2010/10/24 18:28:45 UTC
svn commit: r1026833 - in /incubator/esme/trunk/server/src/main:
scala/org/apache/esme/actor/ scala/org/apache/esme/comet/
scala/org/apache/esme/snippet/ webapp/info_view/ webapp/templates-hidden/
Author: esjewett
Date: Sun Oct 24 16:28:45 2010
New Revision: 1026833
URL: http://svn.apache.org/viewvc?rev=1026833&view=rev
Log:
[ESME-287] [ESME-289] Switch tag view timeline to the standard format and use comet, so new messages with a tag automagically show up on the page.
Added:
incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagTimeline.scala
incubator/esme/trunk/server/src/main/webapp/templates-hidden/timeline_tag.html
Modified:
incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/Distributor.scala
incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/TagDistributor.scala
incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/UserActor.scala
incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/TagDisplay.scala
incubator/esme/trunk/server/src/main/webapp/info_view/tag.html
Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/Distributor.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/Distributor.scala?rev=1026833&r1=1026832&r2=1026833&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/Distributor.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/Distributor.scala Sun Oct 24 16:28:45 2010
@@ -68,13 +68,14 @@ object Distributor extends LiftActor {
case ListenObject(listenable, who) => listenable match {
case u:User => findOrCreateUser(u.id) ! UserActor.Listen(who)
- case c:Message => ConvDistributor ! ConvDistributor.Listen(c,who)
- case x =>
+ case c:Message => ConvDistributor ! ConvDistributor.Listen(c,who)
+ case t:Tag => TagDistributor ! TagDistributor.Listen(t,who)
}
case UnlistenObject(listenable, who) => listenable match {
case u:User => findOrCreateUser(u.id) ! UserActor.Unlisten(who)
case c:Message => ConvDistributor ! ConvDistributor.Unlisten(c,who)
+ case t:Tag => TagDistributor ! TagDistributor.Unlisten(t,who)
}
case LatestMessages(user, cnt) =>
Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/TagDistributor.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/TagDistributor.scala?rev=1026833&r1=1026832&r2=1026833&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/TagDistributor.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/TagDistributor.scala Sun Oct 24 16:28:45 2010
@@ -23,7 +23,9 @@ import net.liftweb._
import actor._
import org.apache.esme._
-import model.{Tag, User, TagFollowReason}
+import model.{Tag, User, Message, TagFollowReason, NoReason, MailboxReason}
+
+import scala.collection.mutable.HashMap
object TagDistributor extends LiftActor {
@@ -34,13 +36,28 @@ object TagDistributor extends LiftActor
t.followers.refresh.map( u => {
Distributor ! Distributor.AddMessageToMailbox(u.id, msg, TagFollowReason(t.name));
})
+ listeners.getOrElse(t, List()).map(
+ _ ! MessageReceived(msg, NoReason)
+ )
})
})
}
+
+ case Listen(tag, who) =>
+ listeners.update(tag, who :: listeners.getOrElse(tag, List()))
+
+ case Unlisten(tag, who) =>
+ listeners.update(tag, listeners.getOrElse(tag, List()).filter( _ ne who))
}
def touch {
- }
+ }
+
+ private var listeners: HashMap[Tag,List[LiftActor]] = new HashMap
+
+ case class Listen(tag:Tag,who:LiftActor)
+ case class Unlisten(tag:Tag,who:LiftActor)
+ case class MessageReceived(msg: Message, reason: MailboxReason)
}
\ No newline at end of file
Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/UserActor.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/UserActor.scala?rev=1026833&r1=1026832&r2=1026833&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/UserActor.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/UserActor.scala Sun Oct 24 16:28:45 2010
@@ -154,7 +154,7 @@ class UserActor extends LiftActor {
Distributor ! Distributor.NewMessage(msg)
- reply(msg)
+ reply(msg)
}
case AddToMailbox(msg, reason) =>
Added: incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagTimeline.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagTimeline.scala?rev=1026833&view=auto
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagTimeline.scala (added)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagTimeline.scala Sun Oct 24 16:28:45 2010
@@ -0,0 +1,61 @@
+/**
+ * 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.comet
+
+import net.liftweb.common._
+import net.liftweb.mapper._
+import net.liftweb.http._
+import net.liftweb.util.Helpers.TimeSpan
+
+import org.apache.esme._
+import actor.{Distributor,UserActor,TagDistributor}
+import model._
+
+class TagTimeline extends Timeline {
+
+ val jsId = "tag_timeline_messages"
+ val tagName = (S.param("tag") openOr "").trim
+ val tag = Tag.findAll(By(Tag.name, tagName))
+
+ override def localSetup() {
+ super.localSetup()
+
+ for(t <- tag) {
+ Distributor ! Distributor.ListenObject(t, this)
+ messages = t.findMessages().map(m => (m.id.is, NoReason, false)).take(40)
+ }
+ }
+
+ override def localShutdown() {
+ super.localShutdown()
+ for(t <- tag) {
+ Distributor ! Distributor.UnlistenObject(t, this)
+ }
+ }
+
+ override def lifespan = Full(TimeSpan(300000))
+
+ override def lowPriority = {
+ case TagDistributor.MessageReceived(msg, r) =>
+ messages = ((msg.id.is,r,false) :: messages).take(40)
+ reRender(false)
+ }
+
+}
\ 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=1026833&r1=1026832&r2=1026833&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 Sun Oct 24 16:28:45 2010
@@ -45,19 +45,16 @@ object TagDisplay {
val name = (S.param("tag") openOr "N/A").trim
- val tag = Tag.findAll(By(Tag.name, name))
+ val tag = Tag.findAll(By(Tag.name, name)).headOption
val user = User.currentUser
- val messageList: List[Message] =
- for {
- t <- tag
- item <- t.findMessages()
- } yield item
+ val messageList: List[Message] =
+ {for(t <- tag) yield { t.findMessages() }}.getOrElse(List())
def followOrUnfollow: NodeSeq = {
val ret: Box[NodeSeq] = for {
u <- user
- t = tag.first
+ t <- tag
} yield {
if (!t.followers.contains(u)) {
ajaxButton("Follow tag", () => {
@@ -78,9 +75,14 @@ object TagDisplay {
}
def updateFollow: JsCmd = SetHtml("following", followOrUnfollow)
+
+ def cometTimeline:NodeSeq = { for(t <- tag) yield {
+ <lift:comet type="TagTimeline" name={"tag"+t.id.is} />
+ }}.getOrElse(Text(""))
bind("tag", in, "name" -> name,
- "each" -> MessageUtils.bindMessages(messageList) _,
+ "each" -> MessageUtils.bindMessages(messageList) _,
+ "cometTimeline" -> cometTimeline,
"followButton" -> followOrUnfollow )
}
Modified: incubator/esme/trunk/server/src/main/webapp/info_view/tag.html
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/webapp/info_view/tag.html?rev=1026833&r1=1026832&r2=1026833&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/webapp/info_view/tag.html (original)
+++ incubator/esme/trunk/server/src/main/webapp/info_view/tag.html Sun Oct 24 16:28:45 2010
@@ -16,46 +16,15 @@
specific language governing permissions and limitations *
under the License. *
-->
-<lift:surround with="base" at="left">
- <script type="text/javascript" src="../scripts/esme_table_sorter_tag.js"></script>
- <lift:TableSorterSnip/>
- <lift:tag_display>
-<div id="back-header">
- <h1><lift:loc>ui_tag_title</lift:loc><i> '<tag:name/>'</i></h1>
-<div class="container-settings">
- <span id="following"><tag:followButton/></span>
-
- <table id="esme-table" class="tablesorter">
- <thead>
- <tr>
- <th>
- <lift:loc>ui_tag_author</lift:loc>
- </th>
- <th>
- <lift:loc>ui_tag_message</lift:loc>
- </th>
- <th>
- <lift:loc>ui_tag_date</lift:loc>
- </th>
- </tr>
- </thead>
- <tbody>
- <tag:each>
- <tr>
- <td>
- <item:author/>
- </td>
- <td>
- <item:body/>
- </td>
- <td align="center">
- <item:date/>
- </td>
- </tr>
- </tag:each>
- </tbody>
- </table>
- </div>
- </div><!-- End demo -->
- </lift:tag_display>
+<lift:surround with="base" at="left">
+ <link rel="stylesheet" type="text/css" href="../style/style.css" />
+ <lift:tag_display>
+ <div id="back-header">
+ <h1><lift:loc>ui_tag_title</lift:loc> '<tag:name/>'</h1>
+ </div>
+ <div class="container-aux">
+ <span id="following"><tag:followButton/></span>
+ <lift:embed what="templates-hidden/timeline_tag"/>
+ </div>
+ </lift:tag_display>
</lift:surround>
\ No newline at end of file
Added: incubator/esme/trunk/server/src/main/webapp/templates-hidden/timeline_tag.html
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/webapp/templates-hidden/timeline_tag.html?rev=1026833&view=auto
==============================================================================
--- incubator/esme/trunk/server/src/main/webapp/templates-hidden/timeline_tag.html (added)
+++ incubator/esme/trunk/server/src/main/webapp/templates-hidden/timeline_tag.html Sun Oct 24 16:28:45 2010
@@ -0,0 +1,29 @@
+<!--
+ 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. *
+-->
+
+<div id="tag_timeline_messages">
+ <head>
+ <script src="../scripts/display_messages_top.js" type="text/javascript"/>
+ <script src="../scripts/pretty.js" type="text/javascript"/>
+ </head>
+ <lift:tag_display>
+ <tag:cometTimeline />
+ </lift:tag_display>
+ <lift:embed what="templates-hidden/message_core"/>
+</div>