Bug 1662033 - Remove uuid property from nsIAbDirectory. r=mkmelin

Differential Revision: https://phabricator.services.mozilla.com/D88756

--HG--
extra : rebase_source : 50da1f8ac62fc16707ee4e5ee387b5b731fddfb6
This commit is contained in:
Geoff Lankow 2020-08-28 21:09:39 +12:00
Родитель 588fafebdf
Коммит 5627183c5b
19 изменённых файлов: 46 добавлений и 114 удалений

Просмотреть файл

@ -193,11 +193,9 @@ function getContainingDirectory() {
// If the source directory is "All Address Books", find the parent
// address book of the card being edited and reflect the changes in it.
if (directory.URI == kAllDirectoryRoot + "?") {
let dirId = gEditCard.card.directoryId.substring(
0,
gEditCard.card.directoryId.indexOf("&")
directory = MailServices.ab.getDirectoryFromUID(
gEditCard.card.directoryUID
);
directory = MailServices.ab.getDirectoryFromId(dirId);
}
return directory;
}

Просмотреть файл

@ -567,8 +567,7 @@ function AbEditCard(card) {
if (card.isMailList) {
goEditListDialog(card, card.mailListURI);
} else {
let dirId = card.directoryId.split("&")[0];
let directory = MailServices.ab.getDirectoryFromId(dirId);
let directory = MailServices.ab.getDirectoryFromUID(card.directoryUID);
goEditCardDialog(directory.URI, card);
}
}

Просмотреть файл

@ -301,11 +301,7 @@ var abDirTreeObserver = {
} else {
let srcDirectory = null;
if (srcURI == kAllDirectoryRoot + "?" && actionIsMoving) {
let dirId = card.directoryId.substring(
0,
card.directoryId.indexOf("&")
);
srcDirectory = MailServices.ab.getDirectoryFromId(dirId);
srcDirectory = MailServices.ab.getDirectoryFromUID(card.directoryUID);
}
directory.dropCard(card, needToCopyCard);

Просмотреть файл

@ -61,23 +61,22 @@ ABView.prototype = {
this.selection.getRangeAt(i, start, finish);
for (let j = start.value; j <= finish.value; j++) {
let card = this.getCardFromRow(j);
let directoryId = card.directoryId.split("&")[0];
let cardSet = directoryMap.get(directoryId);
let cardSet = directoryMap.get(card.directoryUID);
if (!cardSet) {
cardSet = new Set();
directoryMap.set(directoryId, cardSet);
directoryMap.set(card.directoryUID, cardSet);
}
cardSet.add(card);
}
}
for (let [directoryId, cardSet] of directoryMap) {
for (let [directoryUID, cardSet] of directoryMap) {
let directory;
if (this.directory && this.directory.isMailList) {
// Removes cards from the list instead of deleting them.
directory = this.directory;
} else {
directory = MailServices.ab.getDirectoryFromId(directoryId);
directory = MailServices.ab.getDirectoryFromUID(directoryUID);
}
cardSet = [...cardSet];
@ -321,8 +320,9 @@ function abViewCard(card, directoryHint) {
if (directoryHint) {
this._directory = directoryHint;
} else {
let directoryId = this.card.directoryId.split("&")[0];
this._directory = MailServices.ab.getDirectoryFromId(directoryId);
this._directory = MailServices.ab.getDirectoryFromUID(
this.card.directoryUID
);
}
}
abViewCard.prototype = {

Просмотреть файл

@ -16,7 +16,7 @@ ChromeUtils.defineModuleGetter(
* @implements {nsIAbCard}
*/
function AddrBookCard() {
this._directoryId = "";
this._directoryUID = "";
this._properties = new Map([
["PreferMailFormat", Ci.nsIAbPreferMailFormat.unknown],
["PopularityIndex", 0],
@ -62,11 +62,11 @@ AddrBookCard.prototype = {
return result;
},
get directoryId() {
return this._directoryId;
get directoryUID() {
return this._directoryUID;
},
set directoryId(value) {
this._directoryId = value;
set directoryUID(value) {
this._directoryUID = value;
},
get UID() {
if (!this._uid) {

Просмотреть файл

@ -247,7 +247,7 @@ class AddrBookDirectory {
_getCard(uid) {
let card = new AddrBookCard();
card.directoryId = this.uuid;
card.directoryUID = this.UID;
card._uid = uid;
card._properties = this._loadCardProperties(uid);
return card.QueryInterface(Ci.nsIAbCard);
@ -444,7 +444,6 @@ class AddrBookDirectory {
set dirName(value) {
this.setLocalizedStringValue("description", value);
this._dirName = value;
this._uuid = null;
Services.obs.notifyObservers(this, "addrbook-directory-updated", "DirName");
}
get dirType() {
@ -470,12 +469,6 @@ class AddrBookDirectory {
get position() {
return this._prefBranch.getIntPref("position", 1);
}
get uuid() {
if (!this._uuid) {
this._uuid = `${this.dirPrefId}&${this.dirName}`;
}
return this._uuid;
}
get childNodes() {
let lists = Array.from(
this._lists.values(),
@ -777,7 +770,7 @@ class AddrBookDirectory {
}
let newCard = new AddrBookCard();
newCard.directoryId = this.uuid;
newCard.directoryUID = this.UID;
newCard._uid = needToCopyCard ? newUID() : card.UID;
if (this.hasOwnProperty("_cards")) {

Просмотреть файл

@ -186,8 +186,8 @@ AddrBookMailingList.prototype = {
return `${self._parent.URI}/${self._uid}`;
},
get directoryId() {
return self._parent.uuid;
get directoryUID() {
return self._parent.UID;
},
get firstName() {
return "";

Просмотреть файл

@ -475,9 +475,6 @@ AddrBookManager.prototype = {
}
return false;
},
generateUUID(directoryId, localId) {
return `${directoryId}#${localId}`;
},
/* nsICommandLineHandler */

Просмотреть файл

@ -19,10 +19,6 @@ interface nsIAbPreferMailFormat : nsISupports {
/**
* An interface representing an address book card.
*
* The UUID of a card is a composition of a directory ID and a per-directory ID.
* The per-directory ID is reflected in the localId property. If either of these
* properties change, the UUID will change correspondingly.
*
* None of these IDs will be reflected in the property collection. Neither
* nsIAbCard::properties, nsIAbCard::deleteProperty, nor any of the property
* getters and setters are able to interact with these properties.
@ -102,7 +98,7 @@ interface nsIAbCard : nsISupports {
[optional] in nsIStringBundle aBundle);
/**
* The UUID for the nsIAbDirectory containing this card.
* The UID for the nsIAbDirectory containing this card.
*
* The directory considered to contain this card is the directory which
* produced this card (e.g., through nsIAbDirectory::getCardForProperty) or
@ -117,7 +113,7 @@ interface nsIAbCard : nsISupports {
* Consumers of this interface outside of directory implementations SHOULD
* NOT, in general, modify this property.
*/
attribute AUTF8String directoryId;
attribute AUTF8String directoryUID;
/**
* A 128-bit unique identifier for this card. This can only be set if it is not

Просмотреть файл

@ -42,29 +42,9 @@ interface nsISimpleEnumerator;
* the SQLite-based address book type is:
*
* @mozilla.org/addressbook/directory;1?type=jsaddrbook
*
* The UUID of an nsIAbDirectory is its preference ID and its name, concatenated
* together.
*/
[scriptable, uuid(72dc868b-db5b-4daa-b6c6-071be4a05d02)]
interface nsIAbDirectory : nsISupports {
/**
* A universally-unique identifier for this item.
*
* If this item cannot be associated with a UUID for some reason, it MUST
* return the empty string. The empty string MUST NOT be a valid UUID for any
* item. Under no circumstances may this function throw an error.
*
* It is STRONGLY RECOMMENDED that implementations guarantee that this UUID
* will not change between two different sessions of the application and that,
* if this item is deleted, the UUID will not be reused.
*
* The format of the UUID for a generic nsIAbDirectory is purposefully left
* undefined, although any item contained by an nsIAbDirectory SHOULD use
* nsIAbManager::generateUUID to generate the UUID.
*/
readonly attribute AUTF8String uuid;
/**
* Returns true if this collection is read-only.
*/

Просмотреть файл

@ -94,16 +94,4 @@ interface nsIAbManager : nsISupports
* @return True if a directory called name already exists.
*/
boolean directoryNameExists(in wstring name);
/**
* Generates a UUID from a (directory ID, local ID) tuple.
*
* Use of this method is preferred in such cases, since it is designed to work
* with other methods of this interface.
*
* @param directoryId The directory ID.
* @param localId The per-directory ID.
* @return A string to use for the UUID.
*/
AUTF8String generateUUID(in AUTF8String directoryId, in AUTF8String localId);
};

Просмотреть файл

@ -109,13 +109,13 @@ nsAbCardProperty::~nsAbCardProperty(void) {}
NS_IMPL_ISUPPORTS(nsAbCardProperty, nsIAbCard)
NS_IMETHODIMP nsAbCardProperty::GetDirectoryId(nsACString& dirId) {
dirId = m_directoryId;
NS_IMETHODIMP nsAbCardProperty::GetDirectoryUID(nsACString& dirUID) {
dirUID = m_directoryUID;
return NS_OK;
}
NS_IMETHODIMP nsAbCardProperty::SetDirectoryId(const nsACString& aDirId) {
m_directoryId = aDirId;
NS_IMETHODIMP nsAbCardProperty::SetDirectoryUID(const nsACString& aDirUID) {
m_directoryUID = aDirUID;
return NS_OK;
}
@ -319,19 +319,19 @@ NS_IMETHODIMP nsAbCardProperty::SetUID(const nsACString& aUID) {
rv = SetPropertyAsAString(kUIDProperty, NS_ConvertUTF8toUTF16(aUID));
NS_ENSURE_SUCCESS(rv, rv);
if (m_directoryId.IsEmpty()) {
if (m_directoryUID.IsEmpty()) {
return NS_OK;
}
int ampIndex = m_directoryId.FindChar('&');
const nsACString& directoryId = Substring(m_directoryId, 0, ampIndex);
int ampIndex = m_directoryUID.FindChar('&');
const nsACString& directoryUID = Substring(m_directoryUID, 0, ampIndex);
nsCOMPtr<nsIAbManager> abManager =
do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbDirectory> directory = nullptr;
rv = abManager->GetDirectoryFromId(directoryId, getter_AddRefs(directory));
rv = abManager->GetDirectoryFromId(directoryUID, getter_AddRefs(directory));
NS_ENSURE_SUCCESS(rv, rv);
if (!directory) {

Просмотреть файл

@ -42,7 +42,7 @@ class nsAbCardProperty : public nsIAbCard {
// Store most of the properties here
nsInterfaceHashtable<nsCStringHashKey, nsIVariant> m_properties;
nsCString m_directoryId;
nsCString m_directoryUID;
private:
nsresult AppendSection(const AppendItem* aArray, int16_t aCount,

Просмотреть файл

@ -46,17 +46,6 @@ nsAbDirProperty::~nsAbDirProperty(void) {
NS_IMPL_ISUPPORTS(nsAbDirProperty, nsIAbDirectory, nsISupportsWeakReference)
NS_IMETHODIMP nsAbDirProperty::GetUuid(nsACString& uuid) {
// XXX: not all directories have a dirPrefId...
nsresult rv = GetDirPrefId(uuid);
NS_ENSURE_SUCCESS(rv, rv);
uuid.Append('&');
nsString dirName;
GetDirName(dirName);
uuid.Append(NS_ConvertUTF16toUTF8(dirName));
return rv;
}
NS_IMETHODIMP nsAbDirProperty::GetPropertiesChromeURI(nsACString& aResult) {
aResult.AssignLiteral(
"chrome://messenger/content/addressbook/abAddressBookNameDialog.xhtml");

Просмотреть файл

@ -309,7 +309,7 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::DoQuery(
if (!mConnection || !mDirectoryUrl) {
mDirectoryUrl = currentUrl;
aDirectory->GetUuid(mDirectoryId);
aDirectory->GetUID(mDirectoryUID);
mCurrentLogin = login;
mCurrentMechanism = saslMechanism;
mCurrentProtocolVersion = protocolVersion;
@ -321,7 +321,7 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::DoQuery(
if (!equal) {
mDirectoryUrl = currentUrl;
aDirectory->GetUuid(mDirectoryId);
aDirectory->GetUID(mDirectoryUID);
mCurrentLogin = login;
mCurrentMechanism = saslMechanism;
mCurrentProtocolVersion = protocolVersion;
@ -507,7 +507,7 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::StopQuery(int32_t contextID) {
}
NS_IMETHODIMP nsAbLDAPDirectoryQuery::OnQueryFoundCard(nsIAbCard* aCard) {
aCard->SetDirectoryId(mDirectoryId);
aCard->SetDirectoryUID(mDirectoryUID);
for (int32_t i = 0; i < mListeners.Count(); ++i)
mListeners[i]->OnSearchFoundCard(aCard);

Просмотреть файл

@ -31,7 +31,7 @@ class nsAbLDAPDirectoryQuery : public nsIAbDirectoryQuery,
virtual ~nsAbLDAPDirectoryQuery();
nsCOMPtr<nsILDAPConnection> mConnection;
nsCOMPtr<nsILDAPURL> mDirectoryUrl;
nsCString mDirectoryId;
nsCString mDirectoryUID;
nsCOMArray<nsIAbDirSearchListener> mListeners;
nsCString mCurrentLogin;
nsCString mCurrentMechanism;

Просмотреть файл

@ -286,9 +286,6 @@ nsAbOSXDirectory::Init(const char* aUri) {
cardList = m_AddressList;
}
nsAutoCString ourUuid;
GetUuid(ourUuid);
unsigned int nbCards = [cards count];
nsCOMPtr<nsIAbCard> card;
nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
@ -562,9 +559,9 @@ nsresult nsAbOSXDirectory::AssertDirectory(nsIAbManager* aManager, nsIAbDirector
}
nsresult nsAbOSXDirectory::AssertCard(nsIAbManager* aManager, nsIAbCard* aCard) {
nsAutoCString ourUuid;
GetUuid(ourUuid);
aCard->SetDirectoryId(ourUuid);
nsAutoCString ourUID;
GetUID(ourUID);
aCard->SetDirectoryUID(ourUID);
nsresult rv =
m_IsMailList ? m_AddressList->AppendElement(aCard) : mCardList->AppendElement(aCard);

Просмотреть файл

@ -261,7 +261,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(
for (auto card : aCards) {
retCode = ExtractCardEntry(card, entryString);
if (NS_SUCCEEDED(retCode) && !entryString.IsEmpty()) {
card->SetDirectoryId(EmptyCString());
card->SetDirectoryUID(EmptyCString());
cardEntry.Assign(entryString);
if (!mapiAddBook->DeleteEntry(*mMapiData, cardEntry)) {
@ -953,8 +953,8 @@ nsresult nsAbOutlookDirectory::GetChildCards(nsIMutableArray* aCards,
return NS_ERROR_FAILURE;
}
nsAutoCString ourUuid;
GetUuid(ourUuid);
nsAutoCString ourUID;
GetUID(ourUID);
nsAutoCString entryId;
nsAutoCString uriName;
@ -968,7 +968,7 @@ nsresult nsAbOutlookDirectory::GetChildCards(nsIMutableArray* aCards,
rv = OutlookCardForURI(uriName, getter_AddRefs(childCard));
NS_ENSURE_SUCCESS(rv, rv);
childCard->SetDirectoryId(ourUuid);
childCard->SetDirectoryUID(ourUID);
aCards->AppendElement(childCard);
}
@ -1156,9 +1156,9 @@ nsresult nsAbOutlookDirectory::CreateCard(nsIAbCard* aData,
retCode = OutlookCardForURI(uri, getter_AddRefs(newCard));
NS_ENSURE_SUCCESS(retCode, retCode);
nsAutoCString ourUuid;
GetUuid(ourUuid);
newCard->SetDirectoryId(ourUuid);
nsAutoCString ourUID;
GetUID(ourUID);
newCard->SetDirectoryUID(ourUID);
if (!didCopy) {
retCode = newCard->Copy(aData);

Просмотреть файл

@ -132,7 +132,6 @@ add_task(async function createAddressBook() {
observer.checkEvents(["addrbook-directory-created", book]);
// Check nsIAbDirectory properties.
equal(book.uuid, "ldap_2.servers.newbook&new book");
ok(!book.readOnly);
ok(!book.isRemote);
ok(!book.isSecure);
@ -200,7 +199,7 @@ add_task(async function createContact() {
ok(childCards[0].equals(contact));
// Check nsIAbCard properties.
equal(contact.directoryId, book.uuid);
equal(contact.directoryUID, book.UID);
equal(contact.UID.length, 36);
equal(contact.firstName, "new");
equal(contact.lastName, "contact");