X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2FpageMinichat%2Fconversations.js;h=90e59434e7a11927d4e715dcf244e9d7ecf143cd;hp=ada8a24382bc09f8cf3c20e5b0cea8ebedf7bf17;hb=4aa85a2e80963b73773e748fd4402fab2ad852ce;hpb=217c4d7a0d5f9fee3a8ef0a05ab8506c7f39d5e5 diff --git a/js/pageMinichat/conversations.js b/js/pageMinichat/conversations.js index ada8a24..90e5943 100644 --- a/js/pageMinichat/conversations.js +++ b/js/pageMinichat/conversations.js @@ -99,7 +99,7 @@ euphorik.Conversations.prototype.enleverMessageRepond = function(mess) { * Définit un message comme y répondant. */ euphorik.Conversations.prototype.ajouterMessageRepond = function(mess) { - var thisMessages = this; + var thisConversations = this; // est-ce que le message fait partie de la même conversation que les autres messages ? // TODO : solution plus élégante pour prendre un mess parmis messagesRepond !? @@ -126,7 +126,7 @@ euphorik.Conversations.prototype.ajouterMessageRepond = function(mess) { $("#" + mess.getId(this.prefixIdMessage)).click( function() { $(this).fadeOut("normal", function() { - thisMessages.enleverMessageRepond(mess); + thisConversations.enleverMessageRepond(mess); $("form#posterMessage #repondA .messages").hide(); }); } @@ -218,9 +218,14 @@ euphorik.Conversations.prototype.ajouterMessages = function(elements, numConvers if (!elements.messages.length) { return this.conversations[numConversation] !== undefined; } - + for (var i = 0; i < elements.messages.length; i++) { - this.ajouterMessage(elements.messages[i], numConversation) + if (this.ajouterMessage(elements.messages[i], numConversation)) { + // si une nouvelle conversation a été créée alors on lui donne la racine + // TODO : ce block ne devrait pas se trouver ici mais dans "nouvelleConversation" + this.conversations[numConversation].setRacine(elements.first); + this.mettreAJourFragment(); + } } this.flush(numConversation); @@ -241,9 +246,7 @@ euphorik.Conversations.prototype.ajouterMessages = function(elements, numConvers * @param numConversation le numéro de la conversation, 0 = principale * @return true si une nouvelle conversation a été créée sinon false */ -euphorik.Conversations.prototype.ajouterMessage = function(element, numConversation) { - var thisConversations = this; - +euphorik.Conversations.prototype.ajouterMessage = function(element, numConversation) { var message = new euphorik.Message( this.client, @@ -255,56 +258,30 @@ euphorik.Conversations.prototype.ajouterMessage = function(element, numConversat if (!this.conversations[numConversation]) { nouvelleConversation = true; - this.nouvelleConversation( - numConversation, - message, // si une nouvelle conversation a été créée alors on lui donne la racine qui correspond au premier message - function(num) { // fermeture de la conversation - thisConversations.supprimerConversation(num); - }, - function(num) { // insertion du lien vers la conversation - thisPage.util.replaceSelection( - $("form#posterMessage input.message")[0], - "{" + thisConversations.client.conversations[num-1].root.toString(36) + "}" - ); - } - ); + this.nouvelleConversation(numConversation); } this.conversations[numConversation].ajouterMessage(message); return nouvelleConversation; }; -euphorik.Conversations.prototype.nouvelleConversation = function(num, racine, funFermer, funLien) -{ - var thisMessages = this; +euphorik.Conversations.prototype.nouvelleConversation = function(num) { + var thisConversations = this; this.conversations[num] = new euphorik.Conversation(this, num); - - if (racine) { - this.conversations[num].racine = racine; - this.mettreAJourFragment(); - } - - if (funFermer) { - this.conversations[num].eventFermer(funFermer); - } - - if (funLien) { - this.conversations[num].eventLien(funLien); - } - + this.conversations[num].setFunPage( function(num) { // page suivante - thisMessages.client.pageSuivante(num - 1); - thisMessages.rafraichirMessages(true); + thisConversations.client.pageSuivante(num - 1); + thisConversations.rafraichirMessages(true); }, function(num) { // page précédente - thisMessages.client.pagePrecedente(num - 1); - thisMessages.rafraichirMessages(true); + thisConversations.client.pagePrecedente(num - 1); + thisConversations.rafraichirMessages(true); }, function(num) { // retour à la page une - if (thisMessages.client.goPremierePage(num - 1)) { - thisMessages.rafraichirMessages(true); + if (thisConversations.client.goPremierePage(num - 1)) { + thisConversations.rafraichirMessages(true); } } ); @@ -385,7 +362,7 @@ euphorik.Conversations.prototype.viderMessages = function() { * @param vider vide tous les messages avant d'afficher les nouveaux */ euphorik.Conversations.prototype.rafraichirMessages = function(vider) { - var thisMessages = this; + var thisConversations = this; vider = vider || false; @@ -396,14 +373,14 @@ euphorik.Conversations.prototype.rafraichirMessages = function(vider) { } this.comet.waitEvent( - function() { return thisMessages.getJSONrafraichirMessages(); }, + function() { return thisConversations.getJSONrafraichirMessages(); }, { "new_troll" : - function(data) { - thisMessages.trollIdCourant = data.troll_id; - $("#trollCourant .troll").html(thisMessages.formateur.traitementComplet(data.content)).unbind("click").click( + function(data) { + thisConversations.trollIdCourant = data.troll_id; + $("#trollCourant .troll").html(thisConversations.formateur.traitementComplet(data.content)).unbind("click").click( function() { - thisMessages.ouvrirConversation(data.message_id); + thisConversations.ouvrirConversation(data.message_id); } ); @@ -412,19 +389,19 @@ euphorik.Conversations.prototype.rafraichirMessages = function(vider) { "new_messages" : function(data) { if (vider) { - thisMessages.viderMessages(); + thisConversations.viderMessages(); } // ajoute les messages reçus à leur conversation respective data.conversations.each(function(numConv, conv) { - if (!thisMessages.ajouterMessages(conv, numConv)) { - thisMessages.util.messageDialogue("La conversation {" + thisMessages.client.conversations[numConv - 1].root.toString(36) + "} n'existe pas"); - thisMessages.client.supprimerConversation(numConv - 1); + if (!thisConversations.ajouterMessages(conv, numConv)) { + thisConversations.util.messageDialogue("La conversation {" + thisConversations.client.conversations[numConv - 1].root.toString(36) + "} n'existe pas"); + thisConversations.client.supprimerConversation(numConv - 1); } }); if (vider) { - thisMessages.afficherMessagesRepondConversations(); + thisConversations.afficherMessagesRepondConversations(); } vider = false;