From 7e76d6bc2ccd165730addd3337656b479f9d95d4 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 12 May 2008 21:16:44 +0000 Subject: [PATCH] =?utf8?q?ADD=20un=20objet=20permettant=20l'attente=20des?= =?utf8?q?=20=C3=A9v=C3=A9nements.=20Utilis=C3=A9=20pour=20la=20page=20'ch?= =?utf8?q?at'=20et=20le=20sera=20pour=20'admin'?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- js/euphorik.js | 79 +++++++++++++++++++++++++++--- js/pageMinichat.js | 59 +++++----------------- modules/erl/euphorik_protocole.erl | 6 +-- sessions/js.session | 15 ++---- 4 files changed, 92 insertions(+), 67 deletions(-) diff --git a/js/euphorik.js b/js/euphorik.js index 929a35c..8aaf875 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -350,8 +350,8 @@ Formateur.prototype.getShort = function(url) { var estUneImage = false var versionShort = null - var rechercheImg = this.regexImg.exec(url) - //alert(url) + var rechercheImg = this.regexImg.exec(url) + if (rechercheImg != null) { versionShort = rechercheImg[1].toLowerCase() @@ -599,7 +599,6 @@ Client.prototype.authentifie = function() Client.prototype.setStatut = function(statut) { - //alert(statut) // conversation en "enum" si en "string" if (typeof(statut) == "string") { @@ -745,7 +744,6 @@ Client.prototype.majMenu = function() // TODO : à virer : ne plus changer de style de display ... spa beau .. ou trouver une autre méthode var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client - alert(this.ekMaster) $("#menu .admin").css("display", this.ekMaster ? "inline" : "none") // met à jour le menu @@ -769,7 +767,6 @@ Client.prototype.majMenu = function() } } - Client.prototype.slap = function(userId, raison) { var thisClient = this @@ -794,7 +791,6 @@ Client.prototype.slap = function(userId, raison) }) } - Client.prototype.ban = function(userId, raison, minutes) { var thisClient = this @@ -831,6 +827,77 @@ Client.prototype.kick = function(userId, raison) /////////////////////////////////////////////////////////////////////////////////////////////////// +/** + * classe permettant de gérer les événements (push serveur). + * @page la page + */ +function PageEvent(page, util) +{ + this.page = page + this.util = util + + // l'objet JSONHttpRequest représentant la connexion d'attente + this.attenteCourante = null +} + +/** + * Arrête l'attente courante s'il y en a une. + */ +PageEvent.prototype.stopAttenteCourante = function() +{ + if (this.attenteCourante != null) + this.attenteCourante.abort() +} + +/** + * Attend un événement lié à la page. + * @funSend une fonction renvoyant les données json à envoyer + * @funReceive une fonction qui accepte un paramètre correspondant au données reçues + */ +PageEvent.prototype.waitEvent = function(funSend, funReceive) +{ + var thisPageEvent = this + + this.stopAttenteCourante() + + // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veux dans l'ordre définit dans le protocole) + // TODO : ya pas mieux ? + var dataToSend = + { + "action" : "wait_event", + "page" : this.page + } + var poulpe = funSend() + for (v in poulpe) + dataToSend[v] = poulpe[v] + + ;;; dumpObj(dataToSend) + this.attenteCourante = jQuery.ajax({ + type: "POST", + url: "request", + dataType: "json", + data: this.util.jsonVersAction(dataToSend), + success: + function(data) + { + ;;; dumpObj(data) + + funReceive(data) + + // rappel de la fonction dans 100 ms + setTimeout(function(){ thisPageEvent.waitEvent(funSend, funReceive) }, 100); + }, + error: + function(XMLHttpRequest, textStatus, errorThrown) + { + setTimeout(function(){ thisPageEvent.rafraichirMessages(funSend, funReceive) }, 1000); + } + }) + +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + function initialiserListeStyles(client) { $("#menuCss").change( diff --git a/js/pageMinichat.js b/js/pageMinichat.js index 80cd013..ed0321c 100755 --- a/js/pageMinichat.js +++ b/js/pageMinichat.js @@ -150,8 +150,7 @@ PageMinichat.prototype.charger = function() PageMinichat.prototype.decharger = function() { - //alert(this.attenteCourante) - this.messages.stopAttenteCourante() + this.messages.pageEvent.stopAttenteCourante() $("body #smiles").remove() $("body #outilsBan").remove() @@ -672,8 +671,7 @@ function Messages(client, formateur, util) this.conversations = new Array() // les conversations, la première représente la conversation principale this.nouvelleConversation(0) - // l'objet JSONHttpRequest représentant la connexion d'attente - this.attenteCourante = null + this.pageEvent = new PageEvent("chat", this.util) } /** @@ -682,8 +680,6 @@ function Messages(client, formateur, util) Messages.prototype.getJSONrafraichirMessages = function() { var mess = { - "action" : "wait_event", - "page" : "chat", "message_count" : conf.nbMessageAffiche, "main_page" : this.client.pagePrincipale, "conversations" : this.getJSONConversations() @@ -692,9 +688,6 @@ Messages.prototype.getJSONrafraichirMessages = function() if (this.client.cookie != null) mess["cookie"] = this.client.cookie; mess["last_message_id"] = this.conversations[0].idDernierMessageAffiche - // obsolète - //if (this.idDernierMessage != null) mess["last_message_id"] = this.idDernierMessage - return mess } @@ -877,22 +870,10 @@ Messages.prototype.ouvrirConversation = function(racine) Messages.prototype.viderMessages = function() { - // Obsolète - //this.idDernierMessage = null - for (var i = 0; i < this.conversations.length; i++) this.conversations[i].viderMessages() } -/** - * Arrete l'attente courante s'il y en a une. - */ -Messages.prototype.stopAttenteCourante = function() -{ - if (this.attenteCourante != null) - this.attenteCourante.abort() -} - /** * Met à jour les messages de manière continue. * (AJAX-Comet-style proof) @@ -900,30 +881,24 @@ Messages.prototype.stopAttenteCourante = function() */ Messages.prototype.rafraichirMessages = function(vider) { - var thisMessages = this // caisupair javacrypte + var thisMessages = this if (vider == undefined) vider = false - - this.stopAttenteCourante() if (vider) for (var i = 0; i < this.conversations.length; i++) - this.conversations[i].idDernierMessageAffiche = 0 - - ;;; dumpObj(this.getJSONrafraichirMessages()) - this.attenteCourante = jQuery.ajax({ - type: "POST", - url: "request", - dataType: "json", - data: this.util.jsonVersAction(this.getJSONrafraichirMessages()), - success: - function(data) - { - ;;; dumpObj(data) + this.conversations[i].idDernierMessageAffiche = 0 + this.pageEvent.waitEvent( + function() { return thisMessages.getJSONrafraichirMessages() }, + function(data) + { if (vider) + { thisMessages.viderMessages() + vider = false + } // ajoute les messages reçus à leur conversation respective for (var numConv = 0; numConv < data["conversations"].length; numConv++) @@ -934,14 +909,6 @@ Messages.prototype.rafraichirMessages = function(vider) thisMessages.client.supprimerConversation(numConv - 1) } } - - // rappel de la fonction dans 100 ms - setTimeout(function(){ thisMessages.rafraichirMessages() }, 100); - }, - error: - function(XMLHttpRequest, textStatus, errorThrown) - { - setTimeout(function(){ thisMessages.rafraichirMessages() }, 1000); - } - }) + } + ) } diff --git a/modules/erl/euphorik_protocole.erl b/modules/erl/euphorik_protocole.erl index 5c8d6d8..24569de 100755 --- a/modules/erl/euphorik_protocole.erl +++ b/modules/erl/euphorik_protocole.erl @@ -304,7 +304,7 @@ ban( if User2#user.login =:= [] -> ""; true -> "(" ++ User2#user.login ++ ")" end, if Duration =< 15 -> "kické"; true -> "banni" end, format_minutes(Duration), - if Reason =/= [] -> " Raison: " ++ Reason; true -> "" end ++ "." + if Reason =/= [] -> " - Raison: " ++ Reason; true -> "" end ++ "." ] ))), json_reponse_ok(); @@ -333,7 +333,7 @@ slap( euphorik_bd:nouveau_message_sys(lists:flatten(io_lib:format("~s s'auto slap~s.", [ User1#user.pseudo, - if Reason =/= [] -> " Raison: " ++ Reason; true -> "" end + if Reason =/= [] -> " - Raison: " ++ Reason; true -> "" end ] ))); {ok, User2 = #user{ek_master = false}} -> @@ -341,7 +341,7 @@ slap( [ User2#user.pseudo, User1#user.pseudo, - if Reason =/= [] -> " Raison: " ++ Reason; true -> "" end ++ "." + if Reason =/= [] -> " - Raison: " ++ Reason; true -> "" end ++ "." ] ))), json_reponse_ok(); diff --git a/sessions/js.session b/sessions/js.session index 14853bd..5eab12e 100755 --- a/sessions/js.session +++ b/sessions/js.session @@ -5,7 +5,6 @@ buffer.1.position=22818 buffer.2.path=/home/gburri/projets/euphorik/js/pageMinichat.js buffer.2.position=7496 -buffer.2.current=1 buffer.3.path=/home/gburri/projets/euphorik/js/pageProfile.js buffer.3.position=1 @@ -13,17 +12,9 @@ buffer.3.position=1 buffer.4.path=/home/gburri/projets/euphorik/js/pageRegister.js buffer.4.position=1 -buffer.5.path=/home/gburri/projets/euphorik/js/debug.js +buffer.5.path=/home/gburri/projets/euphorik/js/pageAbout.js buffer.5.position=1 -buffer.6.path=/home/gburri/projets/euphorik/css/1/euphorik.css +buffer.6.path=/home/gburri/projets/euphorik/js/pageAdmin.js buffer.6.position=1 - -buffer.7.path=/home/gburri/projets/euphorik/css/1/pageAbout.css -buffer.7.position=1 - -buffer.8.path=/home/gburri/projets/euphorik/css/1/pageMinichat.css -buffer.8.position=1 - -buffer.9.path=/home/gburri/projets/euphorik/css/1/pageProfileRegister.css -buffer.9.position=164 +buffer.6.current=1 -- 2.43.0