On May 15, 2015, at 9:41 AM, Mirko Saiu <mirko...@gmail.com> wrote:We have this kind of incomprehensible problem and we even don't know how exactly reproduce it. We just stop using the comet chat for a while keeping the web browser page open, then when we try to use the chat again , it doesn't works. It will works again only if you logout and login.Jetty version is 8.1.17Lift version is 2.6Can someone help us?Here some code..The chat snippet:
class chatin extends Loggable {var message = ""var idExperience = S.param("key").map(_.toString) openOr("nudda")var meeting: Meeting = _var usr: User = _User.currentUser.map{ x =>usr = xmeeting = Meeting.findByStringIdActive(idExperience).getOrElse{S.redirectTo("/404")}if (!meeting.belongsToUser(usr.id.toString())) S.redirectTo("/404")GMRConfig.sessionVars.last_meetingExp.set(idExperience)usr.last_meeting(idExperience).save} getOrElse({logger.error("Meeting, no user is logged")})def doSubmit() : JsCmd = {println("CHAT dosubmit 1")User.currentUser.map({ usr =>Meeting.findByStringId(idExperience).map({println("CHAT dosubmit 2 message: " + message)mp => mp.addChatMessage(usr, message)})SetValById("chat_in", "") & // clear the input boxCall("scrollChat").cmd}) openOr {logger.error("user not logged in") }}def bindchat(xhtml: NodeSeq) = {var chatlist = <ul id="main_ul_id"><li id="main_li_id"><div name="fumetto"><img name="img" class="triang"/><div name="body">{ChatMessage.where(_.meeting eqs GMRConfig.sessionVars.last_meetingExp.get).orderDesc(_.time).fetch.foreach(x=> line(x))}</div></div><div class="clear-both"></div></li></ul>var html =<div id="divChat" class="chat-box box" data-lift={"comet?type=Chat;name=" + idExperience + ";ul_id=main_ul_id;li_id=main_li_id"}><div class="message-list">{chatlist}</div><div class="form-input"><form class="lift:form.ajax">{SHtml.textarea("", message = _, "id" -> "chat_in")}{SHtml.ajaxSubmit(S.?("send"), doSubmit, "id" -> "send")}</form></div></div>bind("print", xhtml, "chat" -> html)}def line(c: ChatMessage) = {if (c.userEmail.get != User.currentUser.get.email.get){("name=fumetto [class]" #> "fumetto-destinatario pull-left clear-both" &"name=img [src]" #> "/img/triang_conv_sx.png" &"name=body" #> c.message.get)}else{( "name=fumetto [class]" #> "fumetto-mittente pull-right clear-both" &"name=img [src]" #> "/img/triang_conv_dx.png" &"name=body" #> c.message.get )}}}
The CometActor and the LiftActor:
class Chat extends CometActor with CometListener with Loggable{private lazy val li = liId.flatMap(Helpers.findId(defaultHtml, _)) openOr NodeSeq.Emptyprivate val ulId = S.attr("ul_id") openOr "some_ul_id"private val liId = S.attr("li_id")var meetingID = S.param("key").getOrElse("nudda")var chats: List[ChatMessage] = ChatMessage.where(_.meeting eqs meetingID).orderDesc(_.time).fetchdef updateChats(list: List[ChatMessage]) = {chats = list}override def exceptionHandler = {case e => logger.error(e.getStackTraceString)}override def lowPriority = {case x: ChatMessage => if(meetingID == x.meeting.get && !chats.contains(x)) {println("CHAT lowPriority: " + x.message.get)chats = x::chatsval update = CmdPair(AppendHtml(ulId, line(x)),Call("scrollChat").cmd)partialUpdate(update)}}// register this componentdef registerWith = ChatServer// render the whole list of chatsoverride def render = {("#" + ulId + " *") #> {displayList}}// display a list of chatsprivate def displayList: NodeSeq = chats.reverse.flatMap(line)// display a lineprivate def line(c: ChatMessage) = {("name=fumetto [class]" #> "fumetto-destinatario pull-left clear-both" &"name=li [class]" #> "fumetto-sinistra pull-right clear-both" &"name=img [src]" #> "/img/triang_conv_sx.png" &"name=body" #> c.message.is)(li)}else{( "name=fumetto [class]" #> "fumetto-mittente pull-right clear-both" &"name=li [class]" #> "fumetto-destra pull-right clear-both" &"name=img [src]" #> "/img/triang_conv_dx.png" &"name=body" #> c.message.is)(li)}}}object ChatServer extends LiftActor with ListenerManager with Loggable{//variablie che viene aggiornata aad ogni meering page apertavar chat: ChatMessage = _override protected def exceptionHandler = {case e => logger.error(e.getStackTraceString)}override def lowPriority = {case v: ChatMessage =>chat = vupdateListeners()case _ =>}def createUpdate = chatdef toHtml(msg: String): NodeSeq = <div>{msg}</div>}--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<div data-lift="Snippet1">
<div data-lift="ChatSnippet"></div>
</div>
<div data-lift="ChatSnippet"></div>
<div data-lift="Snippet1"></div>