Chat cleanup in 1.5

Chat cleanup in 1.5

by Petr Skoda -
Number of replies: 15
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Hi!

I have cleaned up the Chat module a bit and fixed some problems. It is now in CVS HEAD but should also work in latest 1.4.3+ You can try it tomorrow.

The changes are not visible, but the chat should be more scalable with less bugs.

DO NOT INSTALL ON PRODUCTION SITES!

Changes in standard:
  • message pane refreshed immediately after sending new message (javascript from insert.php reloads jsupdate.php)
  • user pane is reloaded only if somebody enters or exits, idle time is updated by javascript from jsupdate.php - hence very few reloads!
  • fixed encoding problems
  • general speedup - removed some database calls, added two cacheing fields to chat_user table (lang and course)
  • page reload (F5) works!! - user can rejoin chat without new entering - recycling of chat_sid
  • after joining you see some message history (needed for F5, but IMO good when entering too)
  • lots of other small fixes

Changes in chat daemon:
  • maybe fixed repetitive sending, empty pages, etc. - at least I hope so, the problem was that the server did not read comple http request but only first 512 bytes
  • other small changes outside chatd.php

I am not finished yet, there is still some cleanup work left in lib.php and lots of work in chat daemon.

skodak

PS: I did forget to mention that it is compatible with register_globals off smile
PS2: the chat daemon works in Windows too...
Average of ratings: -
In reply to Petr Skoda

Re: Chat cleanup in 1.5

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Uhm,

sounds really cool. I hope it works! wink big grin tongueout

Ciao smile
In reply to Eloy Lafuente (stronk7)

Re: Chat cleanup in 1.5

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
WFM in Fireforox, IE6 and Opera big grin

I will correct the update syntax in scripts - it works but I agree that I should not depend on default function parameters because of the code readability.

How it works internally?
  1. before entering chat user is assigned unique chat_sid
  2. other pages use this token to verify user only in chat_users table - chat_users table alone contains all needed about user (user is "logged-in" and session created only during entering)
  3. language is determined only once and is cached in chat_users - you would have to login user, find course, etc. (anyway it is not possible in chat daemon)
  4. course ID is cached also in chat_users to eliminate some database requests and simplify coding
  5. active user list is reloaded only when needed (on message 'exit' and 'enter' or when there is a loong silence in room)


I tried to make less database calls, but at the right time when user expects there should be some update/change wink
In reply to Petr Skoda

Re: Chat cleanup in 1.5

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
I may have found some bugs in lib.php when deleting and uninstalling chats or module itself - I will find out more about it later...

I will also add some code to upgrade script to delete all active users from chat_users before upgrade.
In reply to Petr Skoda

Re: Chat cleanup in 1.5

by John Papaioannou -
Lines 534-547 in chatd.php (user has entered the chat message broadcast) have been commented out. Are you in the middle of doing something there or was that accidental?

Jon
In reply to John Papaioannou

Re: Chat cleanup in 1.5

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Sure, I moved that to chat_login_user() from lib.php, the reason was to enable page reloading (F5) - it is not finished yet sad

Other plans with chatd:
  • I am planning to remove groupid page parameter too, already cached in chat_users
  • I want to use the new cached lang and course too, the old code does not seem correct to me and it does not set page encoding
  • I would also like to move some functionality to lib.php to share it in the two implementations - such as exit message
  • user panel - IMO we could also limit the reloading a bit with some javascript tricks
In reply to Petr Skoda

Re: Chat cleanup in 1.5

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Now chatd stopped working on my Win32 test box - CPU load 99% and everything stops, it worked for 3 day without problems...

grrrrr, I hate windoze - enough is enough, I am going to install some real OS now angry

I am going to revert the unfinished code in chatd.php, it looks like it will take some time to install BSD and get productive again sad
In reply to Petr Skoda

Re: Chat cleanup in 1.5

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
hmmm, works again. I have corrected gui_sockets/chatinput.php - there was a typo in it sad

Chatd still needs a lot of work to catch up with normal chat wink First of all I should solve the reloading issues...
In reply to Petr Skoda

Re: Chat cleanup in 1.5

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
I have tried to enable page reloading when using chatd, it is possible, but quite difficult. There are 3 alternatives now:
  1. patch current code to support reloading in browser (F5)
  2. leave it the way it is now - only minor cleanup/speedup
  3. rewrite chat deamon - enable mixed clients, move user panel out of chatd

3/ Chatd rewrite
I was thinking most of the time about the third possibility - chatd would only send messages to clients. New messages would be inserted into database and chatd would poll it once per second and distribute new messages to all chatd clients. User panel reloading could be solved the same way as in normal chat.

database access:
  • once per second reading of all new messages - only in chatd
  • (SID and users) * number of users on each 'enter' and 'exit' - from user panel (already in normal chat)
  • refreshing of last access time of connected users - once per several seconds, user panel idle times can be refresh by javascript from the user panel
  • deleting of timed out users - should wait some time before deleting user to enable page reloading

positive effects:
  • easier to code and maintain (much smaller chatd)
  • multiple chat deamons possible
  • mixed clients - normal, chatd, Java(??)
  • several messages before entering could shown to new chatters

I am not sure which way to go, any ideas? I am going to clean the present chatd code a bit during the weekend, maybe when I know it better I will see other possibilities...

skodak
In reply to Petr Skoda

Re: Chat cleanup in 1.5

by John Papaioannou -
IMHO option 2 would be the better choice for two reasons: 1) chatd isn't the most important part of Moodle I can think of, 2) I have some ideas about a unified messaging/chat architecture in 1.6. It might be good to discuss that before anyone starts doing heavy coding.

But first, 1.5 has to come out... argh.
In reply to John Papaioannou

Re: Chat cleanup in 1.5

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Thanks for answer.

 I agree and will do only cleanup work for now wink
In reply to Petr Skoda

Re: Chat cleanup in 1.5

by Janne Mikkonen -
Hi guys!

Just a wild thought: what if we'd make a javascript client that uses XMLHttpRequest() calls?

Pro's
  1. No flashing pages refreshing
  2. Lightweight (lighter than java)
Con's
  1. Browser based, possibly IE and Gecko based only...
  2. Security???
- Janne -
In reply to Janne Mikkonen

Re: Chat cleanup in 1.5

by John Papaioannou -
That's exactly the idea! big grin

BTW, I have made a working simple demo illustrating it in action. Anyone who wants it drop me a line. wink

As for the cons,
  1. Gmail works in Safari (gecko) and many other browsers in general (don't exactly remember). So there should be an easy choice for a supported browser for everyone no matter what the operating system. Basically the only browsers that wouldn't be supported are khtml-engine based (Konqueror and?).
  2. It's not any less secure than javascript-based chat and chatd. They all use HTTP as the communication protocol, so it's exactly the same...

In reply to John Papaioannou

Re: Chat cleanup in 1.5

by Janne Mikkonen -
Please do send me the demo smile

As for con 2. I didn't mean that kind of security wink but ...