esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vdic...@apache.org
Subject svn commit: r805620 - in /incubator/esme/trunk/server/src/main: scala/org/apache/esme/actor/ scala/org/apache/esme/api/ scala/org/apache/esme/comet/ scala/org/apache/esme/model/ scala/org/apache/esme/snippet/ webapp/templates-hidden/
Date Tue, 18 Aug 2009 23:00:52 GMT
Author: vdichev
Date: Tue Aug 18 23:00:51 2009
New Revision: 805620

URL: http://svn.apache.org/viewvc?rev=805620&view=rev
Log:
Resend messages only once.

Modified:
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/PopStatsActor.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/UserActor.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagCloud.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/Timeline.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Mailbox.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserSnip.scala
    incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/PopStatsActor.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/PopStatsActor.scala?rev=805620&r1=805619&r2=805620&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/PopStatsActor.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/actor/PopStatsActor.scala Tue
Aug 18 23:00:51 2009
@@ -56,9 +56,9 @@
           queue += StatEvent(id, now)
           stats += (id -> (stats.getOrElse(id,0) + 1))
         case Top(n) =>
-          val topList = stats.toList.sort{ (t1, t2) =>
-            val ((_,freq1),(_,freq2)) = (t1, t2)
-            freq2 < freq1
+          val topList = stats.toList.sort{
+            case ((_,freq1),(_,freq2)) =>
+              freq2 < freq1
           }.take(n)
           reply(topList)
         case Expire => {

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=805620&r1=805619&r2=805620&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 Tue Aug
18 23:00:51 2009
@@ -51,8 +51,8 @@
   private[actor] case class TestForTracking(msg: Message)
   private[actor] case class UpdateTracking(ttype: Distributor.TrackingType)
   private[actor] case class AllowPool(poolId: Long)
-  private[actor] case class Resend(msgId: Long)
   
+  case class Resend(msgId: Long)
   case class MessageReceived(msg: Message, reason: MailboxReason)
   
   val logger: Logger = Logger.getLogger("org.apache.esme.actor")
@@ -72,7 +72,7 @@
 
   private var perform: List[PerformMatcher] = Nil
   
-  private var _mailbox: Array[(Long,MailboxReason)] = Array()
+  private var _mailbox: Array[(Long,MailboxReason,Boolean)] = Array()
   
   private var pools: Set[Long] = Set()
 
@@ -99,7 +99,7 @@
         foreach(u => userTimezone = TimeZone.getTimeZone(u.timezone))
 
         _mailbox = Mailbox.mostRecentMessagesFor(userId, 500).
-        map(m => (m._1.id.is, m._2) ).toArray
+        map{case (msg, reason, resent) => (msg.id.is, reason, resent) }.toArray
         
         pools = Privilege.findViewablePools(userId)
 
@@ -195,6 +195,12 @@
         for (msg <- Message.find(msgId)) {
           if (!msg.pool.defined_?)
             PopStatsActor ! PopStatsActor.IncrStats(ResendStat, msgId)
+            
+          Mailbox.find(By(Mailbox.message, msg),
+                       By(Mailbox.user, userId)).foreach { m =>
+                         m.resent(true).save
+                         listeners.foreach(_ ! Resend(msgId))
+                       }
           for (id <- followers)
             Distributor !
             Distributor.AddMessageToMailbox(id, msg, ResendReason(userId))
@@ -231,7 +237,7 @@
         }
         mb.saveMe
           
-        _mailbox = ((msg.id.is, reason) :: _mailbox.toList).take(500).toArray
+        _mailbox = ((msg.id.is, reason, false) :: _mailbox.toList).take(500).toArray
 
         listeners.foreach(_ ! MessageReceived(msg, reason))
             

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala?rev=805620&r1=805619&r2=805620&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala Tue Aug 18
23:00:51 2009
@@ -324,7 +324,7 @@
     val r: Box[NodeSeq] = 
     t or (for (user <- calcUser ?~ "User not found";
                val lst = Mailbox.mostRecentMessagesFor(user.id, 40))
-          yield lst.flatMap{ case (msg, why) => msg.toXml % why.attr})
+          yield lst.flatMap{ case (msg, why, _) => msg.toXml % why.attr})
     
     r
   }

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala?rev=805620&r1=805619&r2=805620&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala Tue Aug
18 23:00:51 2009
@@ -178,7 +178,7 @@
   def friendsTimeline(): Box[TwitterResponse] = {
     calcUser map { user => 
       val statusList =
-        for ((msg, why) <- Mailbox.mostRecentMessagesFor(user.id, 20))
+        for ((msg, why, _) <- Mailbox.mostRecentMessagesFor(user.id, 20))
           yield { msgData(msg) }
       Right(Map("statuses" -> ("status", statusList) ))
     }

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagCloud.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagCloud.scala?rev=805620&r1=805619&r2=805620&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagCloud.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/TagCloud.scala Tue Aug
18 23:00:51 2009
@@ -45,7 +45,7 @@
     for (user <- User.currentUser) {
       Distributor ! Distributor.Listen(user.id, this)
       Distributor !? (2000, Distributor.LatestMessages(user.id, 40)) match {
-        case Some(msg: List[(Long,MailboxReason)]) => messages = msg map {_._1}
+        case Some(msg: List[(Long,MailboxReason,Boolean)]) => messages = msg map {_._1}
         case x =>
       }
     }

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/Timeline.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/Timeline.scala?rev=805620&r1=805619&r2=805620&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/Timeline.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/comet/Timeline.scala Tue Aug
18 23:00:51 2009
@@ -37,14 +37,14 @@
 import java.text._
 
 class Timeline extends CometActor {
-  private var messages: List[(Long,MailboxReason)] = Nil
+  private var messages: List[(Long,MailboxReason,Boolean)] = Nil
   
   override def localSetup() {
     super.localSetup()
     for (user <- User.currentUser) {
       Distributor ! Distributor.Listen(user.id, this)
       Distributor !? (2000, Distributor.LatestMessages(user.id, 40)) match {
-        case Some(msg: List[(Long,MailboxReason)]) => messages = msg
+        case Some(msg: List[(Long,MailboxReason,Boolean)]) => messages = msg
         case x =>
       }
     }
@@ -60,19 +60,28 @@
   def render = {
     val msgMap = Message.findMessages(messages map {_._1})
     val toDisplay =
-      for ((id, reason) <- messages;
+      for ((id, reason, resent) <- messages;
            msg <- msgMap.get(id))
-      yield (msg, reason)
+      yield (msg, reason, resent)
     val jsId = "timeline_messages";
 
     OnLoad(JsCrVar(jsId, JsArray(
-        toDisplay.map(m => JsObj(("message",m._1.asJs),("reason",m._2.asJs))) :_*)) &
+        toDisplay.map{case (msg, reason, resent) =>
+                  JsObj(("message",msg.asJs),("reason",reason.asJs), ("resent",resent))
+                  } :_*)) &
     JsFunc("displayMessages", JsVar(jsId), jsId).cmd)
   }
   
   override def lowPriority = {
     case UserActor.MessageReceived(msg, r) =>
-      messages = ( (msg.id.is,r) :: messages).take(40)
+      messages = ( (msg.id.is,r,false) :: messages).take(40)
+      reRender(false)
+      
+    case UserActor.Resend(msgId) =>
+      messages = messages.map {
+        case (`msgId`, r, _) => (msgId, r, true)
+        case x => x
+      }
       reRender(false)
       
     case Distributor.UserUpdated(_) =>

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Mailbox.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Mailbox.scala?rev=805620&r1=805619&r2=805620&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Mailbox.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Mailbox.scala Tue Aug
18 23:00:51 2009
@@ -33,7 +33,7 @@
   override def dbTableName = "mailbox" // define the DB table name
 
   def mostRecentMessagesFor(userId: Long, cnt: Int):
-  List[(Message, MailboxReason)] = {
+  List[(Message, MailboxReason, Boolean)] = {
     val mb = findAll(By(user, userId), OrderBy(id, Descending),
                      MaxRows(cnt))
 
@@ -41,7 +41,7 @@
 
     val map = Message.findMessages(msgToFind)
 
-    mb.flatMap(m => map.get(m.message).map(msg => (msg, m.reason)))
+    mb.flatMap(m => map.get(m.message).map(msg => (msg, m.reason, m.resent.is)))
   }
     
   override def dbIndexes = Index(user, message) :: super.dbIndexes
@@ -58,6 +58,7 @@
   object directlyFrom extends MappedLongForeignKey(this, User)
   object conversation extends MappedLongForeignKey(this, Message)
   object resentBy extends MappedLongForeignKey(this, User)
+  object resent extends MappedBoolean(this)
 
   lazy val reason: MailboxReason =
   viaTrack.can.map(TrackReason) or directlyFrom.can.map(DirectReason)  or

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserSnip.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserSnip.scala?rev=805620&r1=805619&r2=805620&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserSnip.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/snippet/UserSnip.scala Tue
Aug 18 23:00:51 2009
@@ -182,8 +182,8 @@
             <tbody>
             {
               val msgMap = Message.findMessages(l.map(_._1))
-              l.map{ stat =>
-                val (msgId, freq) = stat
+              l.map{
+                case (msgId, freq) =>
                 (for (m <- msgMap.get(msgId)) yield {
                   <tr>
                     <td>{freq}</td>
@@ -211,8 +211,8 @@
             </thead>
             <tbody>
             {
-              l.map{ stat =>
-                val (linkId, freq) = stat
+              l.map{
+                case (linkId, freq) =>
                 (for (u <- UrlStore.find(linkId)) yield {
                   <tr>
                     <td>{freq}</td> <td>{u.url.is}</td>

Modified: incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html?rev=805620&r1=805619&r2=805620&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html (original)
+++ incubator/esme/trunk/server/src/main/webapp/templates-hidden/message.html Tue Aug 18 23:00:51
2009
@@ -41,6 +41,7 @@
           // Marshall the data from the Comet-supplied message
           var cometMsg = msgArray[msgIndex].message;
           var cometReason = msgArray[msgIndex].reason;
+          var cometResent = msgArray[msgIndex].resent;
           var msgId = "message_"+cometMsg.id;
 
           // Only do this if the message is not already in the table
@@ -83,9 +84,14 @@
             newMsg.find('#reason').text(msgReason);
             newMsg.find('#when').text(msgDateStr);
             var id = cometMsg.id;
-            newMsg.find('#resend').attr('id', 'resend_' + id).
-              attr('onclick', 'javascript:resend_msg(' + id + ');' +
-                                         'clearResend("resend_' + id + '")');
+            var resendButton = newMsg.find('#resend');
+            if (cometResent) {
+              resendButton.css("display", "none");
+            } else {
+              resendButton.attr('id', 'resend_' + id).
+                attr('onclick', 'javascript:resend_msg(' + id + ');' +
+                                           'clearResend("resend_' + id + '")');
+            }
             for (var tagIndex=0; tagIndex < msgTags.length; tagIndex++) {
               var newTag = tagTemplate.clone(true).attr('id',msgTags[tagIndex]);
               newTag.find('a')



Mime
View raw message