X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=js%2FpageMinichat.js;h=637ff21416a6d9e8f030f6d0dc87e3a2c2cc04e5;hb=f6158580ec307685d5ac2075ff7a58f205335690;hp=3e3055430bbfd0a169f9d463f0343c8e93d4e7cc;hpb=0b34258466c58a805a2cbfe7ef134385b26fed94;p=euphorik.git
diff --git a/js/pageMinichat.js b/js/pageMinichat.js
index 3e30554..637ff21 100755
--- a/js/pageMinichat.js
+++ b/js/pageMinichat.js
@@ -147,7 +147,9 @@ PageMinichat.prototype.envoyerMessage = function(pseudo, message)
{
this.util.messageDialogue("login impossible")
return
- }
+ }
+
+ this.client.pseudo = pseudo
;;; dumpObj(this.getJSONMessage(pseudo, message, repondA))
jQuery.ajax(
@@ -208,11 +210,12 @@ function Reponse(id, pseudo, login)
* @param pseudo
* @param contenu
*/
-function Message(id, date, pseudo, contenu)
+function Message(id, date, pseudo, login, contenu)
{
this.id = id
this.date = date
this.pseudo = pseudo
+ this.login = login
this.contenu = contenu
this.appartientAuClient = false
@@ -283,7 +286,7 @@ Message.prototype.getConversation = function(messages)
* @param numConv le numéro (appelé id) de la conversation
* @param formateur outil permettant la mise en forme du texte des messages
*/
-function Conversation(num, util, formateur)
+function Conversation(num, util, formateur, client)
{
var thisConversation = this
@@ -292,6 +295,9 @@ function Conversation(num, util, formateur)
this.messageOver = null // le message sur lequel se trouve le curseur
this.util = util
this.formateur = formateur
+ this.client = client
+ this.idDernierMessageAffiche = 0
+
this.messages = new Array()
this.messagesParId = new Object()
@@ -398,6 +404,7 @@ Conversation.prototype.ajouterMessage = function(message)
Conversation.prototype.viderMessages = function()
{
this.messages = new Array()
+ this.idDernierMessageAffiche = 0
jQuery("#conversations #" + this.getId() + " .message").remove()
}
@@ -410,21 +417,23 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv)
{
var thisConversation = this
- var idDernierMessageAffiche = jQuery("#conversations #" + this.getId() + " div:first").attr("id")
- idDernierMessageAffiche = (idDernierMessageAffiche == undefined ? 0 : parseInt(idDernierMessageAffiche, 36))
-
// est-ce que le prochain message est pair ? (permet d'alterner le style des messages)
- var messagePair = (idDernierMessageAffiche == 0 ? true :
+ var messagePair = (this.idDernierMessageAffiche == 0 ? true :
(jQuery("#conversations #" + this.getId() + " div:first").attr("class").search("messagePair") == -1)
)
// construction de l'XHTML des messages
var XHTML = ""
for (var i = this.messages.length - 1; i >= 0; i--)
- if (this.messages[i].id > idDernierMessageAffiche)
- {
+ if (this.messages[i].id > this.idDernierMessageAffiche)
+ {
var message = this.messages[i]
+ // construit l'identifiant de la personne
+ var identifiant =
+ this.client.nickFormat == "nick" ? message.pseudo :
+ (this.client.nickFormat == "login" ? message.login : message.pseudo + "(" + message.login +")" )
+
var XHTMLrepondA = ""
for (var id in message.repondA)
XHTMLrepondA += this.formateur.traitementComplet(message.repondA[id].pseudo) + "> "
@@ -439,7 +448,7 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv)
"\">" +
"
" +
"[" + message.date + "]" +
- "" + this.formateur.traitementComplet(message.pseudo) + ":" +
+ "" + this.formateur.traitementComplet(identifiant) + ":" +
XHTMLrepondA +
"" + (message.systeme ? this.formateur.remplacerBalisesHTML(message.contenu) : this.formateur.traitementComplet(message.contenu, message.pseudo)) + "" +
""
@@ -460,7 +469,7 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv)
jQuery("#conversations #" + this.getId() + " .message").slice(this.nbMessageMax, nbMessagesAffiche).empty()
// Ajoute les événements liés à chaque message
- jQuery("#conversations #" + this.getId() + " .message").filter(function(){return parseInt(jQuery(this).attr("id"), 36) > idDernierMessageAffiche}).each(
+ jQuery("#conversations #" + this.getId() + " .message").filter(function(){return parseInt(jQuery(this).attr("id"), 36) > thisConversation.idDernierMessageAffiche}).each(
function()
{
jQuery(".lienConv", this).click(
@@ -510,6 +519,9 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv)
)
}
)
+
+ if (this.messages.length > 0)
+ this.idDernierMessageAffiche = this.messages[this.messages.length-1].id
}
/**
@@ -521,6 +533,7 @@ Conversation.prototype.afficherConversation = function(element)
{
// cherche le message selectionné
var id = parseInt(jQuery(element).attr("id"), 36)
+
var message = this.messagesParId[id]
if (message == undefined) return
@@ -563,7 +576,8 @@ function Messages(client, formateur, util)
this.conversations = new Array() // les conversations, la première représente la conversation principale
this.nouvelleConversation(0)
- this.idDernierMessage = null // l'id du dernier message connu
+// Obsolète
+ //this.idDernierMessage = null // l'id du dernier message connu
// l'objet JSONHttpRequest représentant la connexion d'attente
this.attenteCourante = null
@@ -579,15 +593,28 @@ Messages.prototype.getJSONrafraichirMessages = function()
"page" : "chat",
"message_count" : conf.nbMessageAffiche,
"main_page" : this.client.pagePrincipale,
- "conversations" : this.client.getJSONConversations()
+ "conversations" : this.getJSONConversations()
}
if (this.client.cookie != null) mess["cookie"] = this.client.cookie;
- if (this.idDernierMessage != null) mess["last_message_id"] = this.idDernierMessage
+ mess["last_message_id"] = this.conversations[0].idDernierMessageAffiche
+
+ // obsolète
+ //if (this.idDernierMessage != null) mess["last_message_id"] = this.idDernierMessage
return mess
}
+Messages.prototype.getJSONConversations = function()
+{
+ var clientConv = this.client.getJSONConversations()
+ for (var i = 1; i < this.conversations.length; i++)
+ {
+ clientConv[i-1]["last_message_id"] = this.conversations[i].idDernierMessageAffiche
+ }
+ return clientConv
+}
+
/**
* Ajoute un ensemble de messages puis les affiches.
* @param elements un tableau d'éléments JSON représentant les messages, voir protocole.txt
@@ -613,13 +640,15 @@ Messages.prototype.ajouterMessage = function(element, numConversation)
// pas d'utilisation de jquery pour des raisons de performance
var id = element["id"]
- if (this.idDernierMessage == null || id > this.idDernierMessage)
- this.idDernierMessage = id
+ // Obsolète
+ /*if (this.idDernierMessage == null || id > this.idDernierMessage)
+ this.idDernierMessage = id*/
var message = new Message(
id,
element["date"],
element["nick"],
+ element["login"],
element["content"]
)
@@ -654,7 +683,7 @@ Messages.prototype.nouvelleConversation = function(num, funFermer, funLien)
{
var thisMessages = this
- this.conversations[num] = new Conversation(num, this.util, this.formateur)
+ this.conversations[num] = new Conversation(num, this.util, this.formateur, this.client)
if (funFermer != undefined)
this.conversations[num].eventFermer(funFermer)
if (funLien != undefined)
@@ -744,7 +773,8 @@ Messages.prototype.flush = function(numConv)
Messages.prototype.viderMessages = function()
{
- this.idDernierMessage = null
+ // Obsolète
+ //this.idDernierMessage = null
for (var i = 0; i < this.conversations.length; i++)
this.conversations[i].viderMessages()
@@ -773,8 +803,11 @@ Messages.prototype.rafraichirMessages = function(vider)
this.stopAttenteCourante()
+ /*if (vider)
+ this.idDernierMessage = null*/
if (vider)
- this.idDernierMessage = null
+ for (var i = 0; i < this.conversations.length; i++)
+ this.conversations[i].idDernierMessageAffiche = 0
dumpObj(this.getJSONrafraichirMessages())
this.attenteCourante = jQuery.ajax({
@@ -790,9 +823,12 @@ Messages.prototype.rafraichirMessages = function(vider)
if (vider)
thisMessages.viderMessages()
- // ajoute les messages reçu à leur conversation respective
+ // ajoute les messages reçus à leur conversation respective
for (var numConv = 0; numConv < data["conversations"].length; numConv++)
{
+ // ya pas de nouveaux message -> on passe à la prochaine conversation
+ if (data["conversations"][numConv]["messages"].length == 0) continue
+
thisMessages.ajouterMessages(data["conversations"][numConv], numConv)
// définit les événements liés à la conversation