fix some miscategorization of messages when grouped by age due to gmt offset, fixed a memory leak, and handled the case where messages arrived out of date order, sr=mscott 263678
git-svn-id: svn://10.0.0.236/branches/AVIARY_1_0_20040515_BRANCH@163736 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -160,10 +160,12 @@ nsHashKey *nsMsgGroupView::AllocHashKeyForHdr(nsIMsgDBHdr *msgHdr)
|
||||
}
|
||||
case nsMsgViewSortType::byDate:
|
||||
{
|
||||
PRUint32 ageBucket;
|
||||
PRUint32 ageBucket = 1;
|
||||
PRTime dateOfMsg;
|
||||
PRUint32 dateOfMsgInSeconds, currentTimeInSeconds;
|
||||
|
||||
nsresult rv = msgHdr->GetDate(&dateOfMsg);
|
||||
(void) msgHdr->GetDateInSeconds(&dateOfMsgInSeconds);
|
||||
|
||||
PRTime currentTime = PR_Now();
|
||||
PRExplodedTime explodedCurrentTime;
|
||||
@@ -171,6 +173,8 @@ nsHashKey *nsMsgGroupView::AllocHashKeyForHdr(nsIMsgDBHdr *msgHdr)
|
||||
PRExplodedTime explodedMsgTime;
|
||||
PR_ExplodeTime(dateOfMsg, PR_LocalTimeParameters, &explodedMsgTime);
|
||||
|
||||
dateOfMsgInSeconds -= explodedMsgTime.tm_params.tp_gmt_offset;
|
||||
|
||||
if (explodedCurrentTime.tm_year == explodedMsgTime.tm_year &&
|
||||
explodedCurrentTime.tm_month == explodedMsgTime.tm_month &&
|
||||
explodedCurrentTime.tm_mday == explodedMsgTime.tm_mday)
|
||||
@@ -183,50 +187,54 @@ nsHashKey *nsMsgGroupView::AllocHashKeyForHdr(nsIMsgDBHdr *msgHdr)
|
||||
{
|
||||
// some constants for calculation
|
||||
static PRInt64 microSecondsPerSecond;
|
||||
static PRInt64 secondsPerDay;
|
||||
static PRInt64 microSecondsPerDay;
|
||||
static PRInt64 microSecondsPer6Days;
|
||||
static PRInt64 microSecondsPer13Days;
|
||||
|
||||
static PRBool bGotConstants = PR_FALSE;
|
||||
if ( !bGotConstants )
|
||||
{
|
||||
// seeds
|
||||
PRInt64 secondsPerDay;
|
||||
|
||||
LL_I2L ( microSecondsPerSecond, PR_USEC_PER_SEC );
|
||||
LL_UI2L ( secondsPerDay, 60 * 60 * 24 );
|
||||
|
||||
// derivees
|
||||
LL_MUL( microSecondsPerDay, secondsPerDay, microSecondsPerSecond );
|
||||
LL_MUL( microSecondsPer6Days, microSecondsPerDay, 6 );
|
||||
LL_MUL( microSecondsPer13Days, microSecondsPerDay, 13 );
|
||||
|
||||
bGotConstants = PR_TRUE;
|
||||
}
|
||||
|
||||
// the most recent midnight, counting from current time
|
||||
PRInt64 todaysMicroSeconds, mostRecentMidnight;
|
||||
LL_MOD( todaysMicroSeconds, currentTime, microSecondsPerDay );
|
||||
LL_SUB( mostRecentMidnight, currentTime, todaysMicroSeconds );
|
||||
PRInt64 yesterday;
|
||||
LL_SUB( yesterday, mostRecentMidnight, microSecondsPerDay );
|
||||
// most recent midnight minus 6 days
|
||||
PRInt64 mostRecentWeek;
|
||||
LL_SUB( mostRecentWeek, mostRecentMidnight, microSecondsPer6Days );
|
||||
const PRUint32 secondsPerDay = 60 * 60 * 24;
|
||||
const PRUint32 secondsPer6Days = 60 * 60 * 24 * 6;
|
||||
const PRUint32 secondsPer13Days = 60 * 60 * 24 * 13;
|
||||
PRInt64 temp;
|
||||
PRUint32 mostRecentMidnightSeconds;
|
||||
|
||||
LL_DIV(temp, currentTime, microSecondsPerSecond);
|
||||
LL_L2UI(currentTimeInSeconds, temp);
|
||||
|
||||
PRUint32 nowSeconds;
|
||||
LL_L2UI(nowSeconds, temp);
|
||||
|
||||
nowSeconds -= explodedCurrentTime.tm_params.tp_gmt_offset;
|
||||
|
||||
PRUint32 todaysSeconds = (nowSeconds % (60 * 60 * 24));
|
||||
mostRecentMidnightSeconds = currentTimeInSeconds - todaysSeconds;
|
||||
PRUint32 mostRecentWeekSeconds = mostRecentMidnightSeconds - secondsPer6Days;
|
||||
PRUint32 yesterdayInSeconds = mostRecentMidnightSeconds - secondsPerDay;
|
||||
|
||||
// was the message sent yesterday?
|
||||
if ( LL_CMP( dateOfMsg, >=, yesterday ) )
|
||||
if (dateOfMsgInSeconds >= yesterdayInSeconds)
|
||||
{ // yes ....
|
||||
ageBucket = 2;
|
||||
}
|
||||
else if (LL_CMP(dateOfMsg, >=, mostRecentWeek))
|
||||
else if (dateOfMsgInSeconds >= mostRecentWeekSeconds)
|
||||
{
|
||||
ageBucket = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRInt64 lastTwoWeeks;
|
||||
LL_SUB( lastTwoWeeks, mostRecentMidnight, microSecondsPer13Days);
|
||||
ageBucket = LL_CMP(dateOfMsg, >=, lastTwoWeeks) ? 4 : 5;
|
||||
PRUint32 lastTwoWeeks = mostRecentMidnightSeconds - secondsPer13Days;
|
||||
ageBucket = (dateOfMsgInSeconds >= lastTwoWeeks) ? 4 : 5;
|
||||
}
|
||||
}
|
||||
return new nsPRUint32Key(ageBucket);
|
||||
@@ -248,7 +256,7 @@ nsMsgGroupThread *nsMsgGroupView::AddHdrToThread(nsIMsgDBHdr *msgHdr)
|
||||
// msgKey = ((nsPRUint32Key *) hashKey)->GetValue();
|
||||
nsMsgGroupThread *foundThread = nsnull;
|
||||
if (hashKey)
|
||||
foundThread = (nsMsgGroupThread *) m_groupsTable.Get(hashKey);
|
||||
foundThread = (nsMsgGroupThread *) m_groupsTable.Get(hashKey);
|
||||
PRBool newThread = !foundThread;
|
||||
nsMsgViewIndex viewIndexOfThread;
|
||||
if (!foundThread)
|
||||
@@ -284,7 +292,11 @@ nsMsgGroupThread *nsMsgGroupView::AddHdrToThread(nsIMsgDBHdr *msgHdr)
|
||||
foundThread->AddChild(msgHdr, nsnull, PR_FALSE, nsnull /* announcer */);
|
||||
// check if new hdr became thread root
|
||||
if (!newThread && foundThread->m_keys[0] == msgKey)
|
||||
{
|
||||
m_keys.SetAt(viewIndexOfThread, msgKey);
|
||||
if (m_sortType == nsMsgViewSortType::byDate)
|
||||
foundThread->m_keys.SetAt(1, msgKey); // replace the old duplicate dummy header.
|
||||
}
|
||||
|
||||
return foundThread;
|
||||
}
|
||||
@@ -475,12 +487,9 @@ NS_IMETHODIMP nsMsgGroupView::GetCellText(PRInt32 aRow, const PRUnichar *aColID,
|
||||
formattedCountString.AppendInt(numChildren);
|
||||
aValue.Assign(formattedCountString);
|
||||
}
|
||||
delete hashKey;
|
||||
return NS_OK;
|
||||
}
|
||||
// XXX fix me by making Fetch* take an nsAString& parameter
|
||||
nsXPIDLString valueText;
|
||||
nsCOMPtr <nsIMsgThread> thread;
|
||||
|
||||
return nsMsgDBView::GetCellText(aRow, aColID, aValue);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user