diff --git a/mailnews/db/msgdb/public/nsIDBChangeListener.h b/mailnews/db/msgdb/public/nsIDBChangeListener.h index 1ff56d214c4..2174a177909 100644 --- a/mailnews/db/msgdb/public/nsIDBChangeListener.h +++ b/mailnews/db/msgdb/public/nsIDBChangeListener.h @@ -18,6 +18,10 @@ public: } NS_IMETHOD OnKeyChange(nsMsgKey aKeyChanged, int32 aFlags, nsIDBChangeListener * aInstigator) = 0; + NS_IMETHOD OnKeyDeleted(nsMsgKey aKeyChanged, int32 aFlags, + nsIDBChangeListener * aInstigator) = 0; + NS_IMETHOD OnKeyAdded(nsMsgKey aKeyChanged, int32 aFlags, + nsIDBChangeListener * aInstigator) = 0; NS_IMETHOD OnAnnouncerGoingAway(nsDBChangeAnnouncer * instigator) ; }; diff --git a/mailnews/db/msgdb/public/nsMsgDatabase.h b/mailnews/db/msgdb/public/nsMsgDatabase.h index 7adad162a21..203e303ce4d 100644 --- a/mailnews/db/msgdb/public/nsMsgDatabase.h +++ b/mailnews/db/msgdb/public/nsMsgDatabase.h @@ -52,6 +52,10 @@ public: // convenience routines to notify all our ChangeListeners void NotifyKeyChangeAll(nsMsgKey keyChanged, PRInt32 flags, nsIDBChangeListener *instigator); + void NotifyKeyAddedAll(nsMsgKey keyAdded, PRInt32 flags, + nsIDBChangeListener *instigator); + void NotifyKeyDeletedAll(nsMsgKey keyDeleted, PRInt32 flags, + nsIDBChangeListener *instigator); void NotifyAnnouncerGoingAway(nsDBChangeAnnouncer *instigator); }; @@ -109,8 +113,13 @@ public: virtual nsresult GetMsgHdrForKey(nsMsgKey key, nsMsgHdr **msgHdr); // create a new message header from a hdrStruct. Caller must release resulting header, // after adding any extra properties they want. - virtual nsresult CreateNewHdr(PRBool *newThread, MessageHdrStruct *hdrStruct, nsMsgHdr **newHdr, PRBool notify = FALSE); + virtual nsresult CreateNewHdrAndAddToDB(PRBool *newThread, MessageHdrStruct *hdrStruct, nsMsgHdr **newHdr, PRBool notify = FALSE); + + // Must call AddNewHdrToDB after creating. The idea is that you create + // a new header, fill in its properties, and then call AddNewHdrToDB. + // AddNewHdrToDB will send notifications to any listeners. virtual nsresult CreateNewHdr(nsMsgKey key, nsMsgHdr **newHdr); + virtual nsresult AddNewHdrToDB(nsMsgHdr *newHdr, PRBool notify); // extract info from an nsMsgHdr into a MessageHdrStruct virtual nsresult GetMsgHdrStructFromnsMsgHdr(nsMsgHdr *msgHdr, MessageHdrStruct &hdrStruct); diff --git a/mailnews/db/msgdb/public/nsMsgHdr.h b/mailnews/db/msgdb/public/nsMsgHdr.h index 87becd7172b..dd44c19b9ac 100644 --- a/mailnews/db/msgdb/public/nsMsgHdr.h +++ b/mailnews/db/msgdb/public/nsMsgHdr.h @@ -98,6 +98,7 @@ protected: PRUint32 m_flags; PRUint16 m_numReferences; // x-ref header for threading PRInt16 m_csID; // cs id of message + nsString m_charSet; // OK, charset of headers, since cs id's aren't supported. nsMsgPriority m_priority; // nsMsgHdrs will have to know what db and row they belong to, since they are really diff --git a/mailnews/db/msgdb/src/makefile.win b/mailnews/db/msgdb/src/makefile.win index d30c11aa398..c23e61565c6 100644 --- a/mailnews/db/msgdb/src/makefile.win +++ b/mailnews/db/msgdb/src/makefile.win @@ -37,7 +37,7 @@ CPP_OBJS= .\$(OBJDIR)\nsMsgDatabase.obj \ .\$(OBJDIR)\nsDBFolderInfo.obj\ .\$(OBJDIR)\nsMailDatabase.obj\ .\$(OBJDIR)\nsMsgHdr.obj\ - .\$(OBJDIR)\mdbstubs.obj\ +# .\$(OBJDIR)\mdbstubs.obj\ $(NULL) diff --git a/mailnews/db/msgdb/src/nsMailDatabase.cpp b/mailnews/db/msgdb/src/nsMailDatabase.cpp index 8a4a9d1ca5e..8e234b495ce 100644 --- a/mailnews/db/msgdb/src/nsMailDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMailDatabase.cpp @@ -468,24 +468,28 @@ nsresult nsMailDatabase::PrePopulate() newHdr->SetSubject("Why the Lakers suck"); newHdr->SetDate(resDate); newHdr->SetRecipients("riley@heat.com (Pat Riley)", FALSE); + AddNewHdrToDB (newHdr, PR_TRUE); newHdr->Release(); res = CreateNewHdr(2, &newHdr); newHdr->SetAuthor("shaq@brick.com (Shaquille O'Neal)"); newHdr->SetSubject("Anyone here know how to shoot free throws?"); newHdr->SetDate(resDate); + AddNewHdrToDB (newHdr, PR_TRUE); newHdr->Release(); res = CreateNewHdr(3, &newHdr); newHdr->SetAuthor("dj@celtics.com (Dennis Johnson)"); newHdr->SetSubject("Has anyone seen my jump shot?"); newHdr->SetDate(resDate); + AddNewHdrToDB (newHdr, PR_TRUE); newHdr->Release(); res = CreateNewHdr(4, &newHdr); newHdr->SetAuthor("sichting@celtics.com (Jerry Sichting)"); newHdr->SetSubject("Tips for fighting 7' 4\" guys"); newHdr->SetDate(resDate); + AddNewHdrToDB (newHdr, PR_TRUE); newHdr->Release(); return NS_OK; } diff --git a/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mailnews/db/msgdb/src/nsMsgDatabase.cpp index 4f8b4d34311..a9d1ab78fe3 100644 --- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -79,6 +79,29 @@ void nsDBChangeAnnouncer::NotifyKeyChangeAll(nsMsgKey keyChanged, PRInt32 flags, } } +void nsDBChangeAnnouncer::NotifyKeyDeletedAll(nsMsgKey keyDeleted, PRInt32 flags, + nsIDBChangeListener *instigator) +{ + + for (int i = 0; i < Count(); i++) + { + nsIDBChangeListener *changeListener = (nsIDBChangeListener *) ElementAt(i); + + changeListener->OnKeyDeleted(keyDeleted, flags, instigator); + } +} +void nsDBChangeAnnouncer::NotifyKeyAddedAll(nsMsgKey keyAdded, PRInt32 flags, + nsIDBChangeListener *instigator) +{ + + for (int i = 0; i < Count(); i++) + { + nsIDBChangeListener *changeListener = (nsIDBChangeListener *) ElementAt(i); + + changeListener->OnKeyAdded(keyAdded, flags, instigator); + } +} + void nsDBChangeAnnouncer::NotifyAnnouncerGoingAway(nsDBChangeAnnouncer *instigator) { if (instigator == NULL) @@ -582,7 +605,7 @@ nsresult nsMsgDatabase::DeleteHeader(nsMsgHdr *msgHdr, nsIDBChangeListener *inst if (notify) { PRUint32 flags; (void)msgHdr->GetFlags(&flags); - NotifyKeyChangeAll(key, flags, instigator); // tell listeners + NotifyKeyDeletedAll(key, flags, instigator); // tell listeners } // if (!onlyRemoveFromThread) // to speed up expiration, try this. But really need to do this in RemoveHeaderFromDB @@ -1179,14 +1202,30 @@ nsresult nsMsgDatabase::CreateNewHdr(nsMsgKey key, nsMsgHdr **pnewHdr) &allMsgHdrsTableOID, &hdrRow); if (err == NS_OK) { - err = m_mdbAllMsgHeadersTable->AddRow(GetEnv(), hdrRow); *pnewHdr = new nsMsgHdr(this, hdrRow); (*pnewHdr)->AddRef(); } return err; } -nsresult nsMsgDatabase::CreateNewHdr(PRBool *newThread, MessageHdrStruct *hdrStruct, nsMsgHdr **pnewHdr, PRBool notify /* = FALSE */) +nsresult nsMsgDatabase::AddNewHdrToDB(nsMsgHdr *newHdr, PRBool notify) +{ + nsresult err = m_mdbAllMsgHeadersTable->AddRow(GetEnv(), newHdr->GetMDBRow()); + if (notify) + { + nsMsgKey key; + PRUint32 flags; + + newHdr->GetMessageKey(&key); + newHdr->GetFlags(&flags); + + NotifyKeyAddedAll(key, flags, NULL); + } + + return err; +} + +nsresult nsMsgDatabase::CreateNewHdrAndAddToDB(PRBool *newThread, MessageHdrStruct *hdrStruct, nsMsgHdr **pnewHdr, PRBool notify /* = FALSE */) { nsresult err = NS_OK; nsIMdbRow *hdrRow;