// Firefox extension enabling the use of Gmail chat across multiple tabs. // Copyright (C) 2007 Jack Wootton . // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . function Conversation() { this._chatEntries = []; this._mostRecentTemp = -1; this._lastSender = ""; this.chatEntryLength = function() { return this._chatEntries.length; } this.getChatEntry = function(aIndex) { return this._chatEntries[aIndex]; } this.addChatEntry = function(aChatEntry) { var added = false; this._chatEntries[this._chatEntries.length] = aChatEntry; added = true; if (aChatEntry.hasSender()) this._lastSender = aChatEntry.getSender(); /* * Make the removal of temporary chat message quicker, * by storing the position of the most recent temporary * message. This works since there should only ever be one * temporary message at any time during a conversation. */ if (aChatEntry.getType() == Utility.MSG_TEMPORARY) { this._mostRecentTemp = this._chatEntries.length-1; } else { // A non-temporary Chat Entry has been added. // Any temporary Chat Entrys should be moved // to the end of the collection of Chat Entry // objects so that the temporary message does // not appear behind any non-temporary messages. // We need to do this because temporary // Chat Entrys are moved the the 'end' of the // conversation in functions which run when the // RCF is visible. // // If the RCF is not visible (for example the User // has closed the RCF) // the temporary nodes are moved to the 'end' // of the conversation here, so that when the entire // conversation is re-displayed upon a page reload, the // message 'Jane Doe is typing' (for example) will be // displayed at the end of the conversation. if (this._mostRecentTemp >= 0) { var tempCeArray = this._chatEntries.splice(this._mostRecentTemp,1); for (var i = 0; i < tempCeArray.length; i++) { this._chatEntries[this._chatEntries.length] = tempCeArray[i]; this._mostRecentTemp = this._chatEntries.length-1; } } } return added; } this.removeTemporaryChatEntry = function() { if (this._mostRecentTemp >= 0) { var itemsRemoved = this._chatEntries.splice(this._mostRecentTemp,1); this._mostRecentTemp = -1; for(var k = 0; k < itemsRemoved.length; k ++) itemsRemoved[k] = null; } } this.reset = function() { this._chatEntries = []; this._mostRecentTemp = -1; this._lastSender = ""; } this.expunge = function() { if (this._chatEntries == null) return; var chatEntryArray = []; while (this._chatEntries.length > 0) { chatEntryArray = this._chatEntries.splice(i,1); for (var k = 0; k < chatEntryArray.length; k++) { chatEntryArray[k].expunge(); chatEntryArray[k] = null; } } } }