[Zope] ZRTChat: Logged in users indicator

Jim Washington jwashin@vt.edu
Wed, 19 Jan 2000 13:43:19 +0000


Hi, Brendon

Assuming I am seeing your site right and your folders look something
like the following:

/
/News
/Messages
/Chat
/Chat/My_Chat

Presuming you want something in your /News SquishDot or /Messages Folder
to say something about My_Chat, something like the following should
work:

<dtml-with Chat>
  <dtml-with My_Chat>
  <dtml-with "objectItems('ChatItem')[-1]"> 
      <dtml-if "(ZopeTime() -  5.0/60.0/24.0) <
_['bobobase_modification_time']">
         <dtml-var chat_going_img>
      <dtml-else>
         <dtml-var chat_not_going_img>
      </dtml-if>
  </dtml-with>
  </dtml-with>
</dtml-with>

What it does, following the statements in order:

go to the Chat folder (using 'with' you can get there from News or
Messages)
  go to My_Chat in the Chat folder ('with' gets you there from Chat)
  go the last ChatItem object (I think they are already in chronological
order) This uses the [-1] python trick to get the last item of a list.
      if the object's current datetime minus 5m/60m/24h is earlier than
the mod time (using 'ugly' syntax around bobo..time because it works),
        show the chat_is_going image
      else
        show the chat_not_going image
then close all the above tags

This could be optimized a bit.  That will be left as an exercise for the
reader...

Hope this helps.   I'm posting this back to the Zope list.

-- Jim Washington

 
> Thanks Jim,
> 
> Not being a programmer, it would help if you could give me a few tips as to
> how to accomplish the suggested code. Particularly how to get hold of the
> bobo_mod_time for the last chatitem from a different part of Zope i.e. a
> Squishdot news section.
> 
> Thanks
> Brendon
> 
> Jim Washington wrote:
> 
> > Good question.
> >
> > It's tough to know who or whether someone is actually there because
> > logouts are not enforced.  Any kind of non-time-based counting or
> > listing algorithm would end up with zombies really quick.
> >
> > However, for what you seem to need,  you could compare the latest chat
> > item's bobobase_modification_time with the current ZopeTime().  Then you
> > could say, for example, that someone has posted in the last five minutes
> > or so.
> >
> > I think that's how I would do it.  Let me know what you figure out.  I
> > may add a notifier like that into the next version.
> >
> > -- Jim Washington
> >
> > "Brendon Grunewald (70South)" wrote:
> > >
> > > I would like to put an image or different text at several places in the
> > > site when ever there is at least one person logged into the ZRTChat
> > > chatroom. i.e. a light on the front page to indicate that there is a
> > > chat session presently underway in the chatroom.
> > > Question:
> > > How can I accomplish the following algorithm,
> > > <If logged in users exist>
> > >    display image or text a
> > > <else>
> > >    display image or text b
> > > <fi>
> > >
> > > Basically I need to know how I can access a variable or other data type
> > > that will tell me whether there is anyone logged on when the page in
> > > question is requested. If no such variable exists, is there some other
> > > way of accomplishing this!
> > >
> > > Thanks
> > > Brendon