// MBRecentContact.cpp : implementation file
|
//
|
|
#include "stdafx.h"
|
#include "mbam.h"
|
#include "MBRecentContact.h"
|
|
|
// CMBRecentContact
|
|
CMBContactItem::CMBContactItem( )
|
{
|
m_strSubject = _T("");
|
m_strMsgDate =_T("");
|
m_nUnreadCount = 0;
|
}
|
|
CMBContactItem::~CMBContactItem( )
|
{
|
}
|
void CMBContactItem::operator = ( const CMBContactItem &Item )
|
{
|
m_nType = Item.m_nType;
|
m_strID = Item.m_strID;
|
m_strName = Item.m_strName;
|
m_strMsgDate = Item.m_strMsgDate;
|
m_strSubject = Item.m_strSubject;
|
m_nSortLevel = Item.m_nSortLevel;
|
m_bIsDelete = Item.m_bIsDelete;
|
m_strGener = Item.m_strGener;
|
m_strSName = Item.m_strSName;
|
}
|
|
CMBRecentContact::CMBRecentContact()
|
{
|
m_nLimitCount = LIMIT_COUNT;
|
m_bIsLoaded = FALSE;
|
m_listContact.RemoveAll();
|
}
|
|
CMBRecentContact::~CMBRecentContact()
|
{
|
CleanContact( );
|
}
|
|
void CMBRecentContact::CleanContact( )
|
{
|
POSITION pos;
|
CMBContactItem *pMember = NULL;
|
|
for ( pos = m_listContact.GetHeadPosition(); pos; )
|
{
|
pMember = (CMBContactItem *)m_listContact.GetNext( pos );
|
if ( pMember )
|
delete pMember;
|
}
|
m_listContact.RemoveAll();
|
m_bIsLoaded = FALSE;
|
}
|
|
void CMBRecentContact::SetAMLogin( CString strLogin )
|
{
|
m_strLogin = strLogin;
|
}
|
|
void CMBRecentContact::ProcessContact( )
|
{
|
POSITION pos, posOld;
|
CMBContactItem *pItem = NULL;
|
|
if(m_listContact.GetCount() > LIMIT_COUNT)
|
{
|
pos = m_listContact.FindIndex( LIMIT_COUNT + 1 );
|
for ( pos; pos; )
|
{
|
posOld = pos;
|
pItem = (CMBContactItem*)m_listContact.GetNext( pos );
|
m_listContact.RemoveAt( posOld );
|
if ( pItem )
|
{
|
delete pItem;
|
pItem = NULL;
|
}
|
}
|
}
|
}
|
void CMBRecentContact::AddContactItem( CString strID, CString strName,
|
int nType, CString strDate, CString strSubject )
|
{
|
if ( strID.CompareNoCase( m_strLogin ) == 0 )
|
return; // Èç¹ûÊÇAMʹÓÃÕß²»ÐèÒª¼ÓÈë
|
|
POSITION pos, posOld;
|
CMBContactItem *pItem = NULL;
|
CMBContactItem *pContactItem = NULL;
|
bool bHaveFind = false;
|
bool bFlag = false;
|
COleDateTime dtCurrent= COleDateTime::GetCurrentTime();
|
CString strCurrentTime = dtCurrent.Format(_T("%Y-%m-%d %H:%M:%S"));
|
pos = FindContactItem( strID, nType);
|
if ( pos )
|
{
|
pItem = (CMBContactItem*)m_listContact.GetAt( pos );
|
if ( !pItem )
|
m_listContact.RemoveAt( pos );
|
else
|
{
|
if(pItem->m_strMsgDate > strCurrentTime)
|
bFlag = true;
|
else if ( pItem->m_strMsgDate < strDate )
|
bFlag = true;
|
if (bFlag )
|
{
|
pItem->m_strMsgDate = strDate;
|
pItem->m_strSubject = strSubject;
|
bHaveFind = false;
|
m_listContact.RemoveAt( pos );
|
|
// ÒÆÎ»ÖÃ
|
for ( pos = m_listContact.GetHeadPosition( ); pos; )
|
{
|
posOld = pos;
|
pContactItem = (CMBContactItem*)m_listContact.GetNext( pos );
|
|
if ( pContactItem->m_strMsgDate < strDate )
|
{
|
bHaveFind = true;
|
m_listContact.InsertBefore( posOld, pItem );
|
break;
|
}
|
}
|
|
if ( !bHaveFind )
|
m_listContact.AddTail( pItem );
|
}
|
}
|
}
|
|
if ( !pItem )
|
{
|
bHaveFind = false;
|
for ( pos = m_listContact.GetHeadPosition( ); pos; )
|
{
|
posOld = pos;
|
pItem = (CMBContactItem*)m_listContact.GetNext( pos );
|
|
if ( pItem->m_strMsgDate < strDate )
|
{
|
pContactItem = new CMBContactItem;
|
pContactItem->m_strSubject = strSubject;
|
pContactItem->m_strID = strID;
|
pContactItem->m_strName = strName;
|
pContactItem->m_nType = (AMVIEWITEMTYPE)nType;
|
pContactItem->m_strMsgDate = strDate;
|
|
bHaveFind = true;
|
m_listContact.InsertBefore( posOld, pContactItem );
|
break;
|
}
|
}
|
|
if ( !bHaveFind )
|
{
|
pContactItem = new CMBContactItem;
|
|
pContactItem->m_strID = strID;
|
pContactItem->m_strName = strName;
|
pContactItem->m_nType = (AMVIEWITEMTYPE)nType;
|
pContactItem->m_strMsgDate = strDate;
|
pContactItem->m_strSubject = strSubject;
|
m_listContact.AddTail( pContactItem );
|
}
|
}
|
}
|
|
POSITION CMBRecentContact::FindContactItem( CString strID, int nType )
|
{
|
POSITION pos, posOld;
|
CMBContactItem *pItem = NULL;
|
|
int nCount = m_listContact.GetCount();
|
for ( pos = m_listContact.GetHeadPosition( ); pos; )
|
{
|
posOld = pos;
|
pItem = (CMBContactItem*)m_listContact.GetNext( pos );
|
|
if ( pItem && pItem->m_strID.CompareNoCase( strID ) == 0 && pItem->m_nType == nType)
|
return posOld;
|
}
|
|
return NULL;
|
}
|
void CMBRecentContact::DeleteContactItem( CString strID, int nType)
|
{
|
POSITION pos;
|
CMBContactItem *pItem = NULL;
|
CString strSQL;
|
|
int nCount = m_listContact.GetCount();
|
pos = FindContactItem( strID, nType);
|
if ( pos )
|
{
|
pItem = (CMBContactItem*)m_listContact.GetAt( pos );
|
m_listContact.RemoveAt(pos);
|
if(pItem)
|
delete pItem;
|
pItem = NULL;
|
|
}
|
}
|
void CMBRecentContact::SetLoaded(BOOL bIsLoaded)
|
{
|
m_bIsLoaded = bIsLoaded;
|
}
|
BOOL CMBRecentContact::IsLoaded()
|
{
|
return m_bIsLoaded;
|
}
|
BOOL CMBRecentContact::GetOldContactDate( CString &strDate)
|
{
|
POSITION pos;
|
CMBContactItem *pItem = NULL;
|
|
if(m_listContact.GetCount() < 30)
|
{
|
return FALSE;
|
}
|
else
|
{
|
pos = m_listContact.GetTailPosition();
|
if( !pos)
|
return FALSE;
|
pItem = (CMBContactItem*)m_listContact.GetAt(pos);
|
if( !pItem)
|
return FALSE;
|
strDate = pItem->m_strMsgDate;
|
return TRUE;
|
}
|
}
|
|
|
// CMBRecentContact member functions
|