Add method to calIItemBase to compare items by id, regardless of whether either or both are proxy items and change some code to use this new method (bug 328011). Thanks to <daniel.boelzle@sun.com> for the patch; r=dmose

This commit is contained in:
dmose%mozilla.org 2006-03-03 06:27:42 +00:00
parent 6b1a8e840d
commit 08e541e3ee
3 changed files with 19 additions and 4 deletions

View File

@ -207,8 +207,7 @@
<parameter name="aItem"/>
<body><![CDATA[
for each (ed in this.mItemData) {
if (ed.item == aItem ||
(ed.item.id == aItem.id && ed.item.recurrence_id == aItem.recurrence_id))
if (aItem.sameId(ed.item))
{
return;
}
@ -251,8 +250,7 @@
var origLen = this.mItemData.length;
this.mItemData = this.mItemData.filter(
function(itd) {
if (itd.item == aItem ||
(itd.item.id == aItem.id && itd.item.recurrence_id == aItem.recurrence_id))
if (aItem.sameId(itd.item))
{
deleted.push(itd);
return false;

View File

@ -78,6 +78,16 @@ interface calIItemBase : nsISupports
// clone always returns a mutable event
calIItemBase clone();
/**
* Checks whether the argument object refers the same calendar item as
* this one, by testing both the id and recurrenceId property. This
*
* @arg aItem the item to compare against this one
*
* @return true if both ids match, false otherwise
*/
boolean hasSameIds(in calIItemBase aItem);
//
// the generation number of this item; 0 means
// that it's never been stored in a store

View File

@ -157,6 +157,13 @@ calItemBase.prototype = {
this.mImmutable = true;
},
hasSameIds: function(that) {
return (that && this.id == that.id &&
(this.recurrenceId == that.recurrenceId || // both null
(this.recurrenceId && that.recurrenceId &&
this.recurrenceId.compare(that.recurrenceId) == 0)));
},
// initialize this class's members
initItemBase: function () {
var now = new Date();