|
1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: message container class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cimcvenginemessagecontainer.h" |
|
19 #include "mimcvenginemessageobserver.h" |
|
20 #include "mimcvenginechatinterface.h" // KSendBufferId |
|
21 #include "cimcvenginemessagebase.h" |
|
22 #include <escapeutils.h> |
|
23 #include "imcvuiliterals.h" |
|
24 #include "imcvlogger.h" |
|
25 #include <collate.h> |
|
26 #include "mimcvenginebuffermemoryhandler.h" |
|
27 #include "mimcvenginenewmsgobserver.h" |
|
28 |
|
29 // needed to skip domains in domain-neutral comparison (TUint version) |
|
30 const TUint KAtUInt( '@' ); |
|
31 |
|
32 // general colon needed in various places |
|
33 _LIT( KColon, ":" ); |
|
34 |
|
35 // general slash needed in various places |
|
36 _LIT( KSlash, "/" ); |
|
37 |
|
38 // needed to skip domains in domain-neutral comparison |
|
39 _LIT( KAt, "@" ); |
|
40 |
|
41 //----------------------------------------------------------------------------- |
|
42 // CIMCVEngineMessageContainer::CIMCVEngineMessageContainer |
|
43 // ( Other items commented in header ) |
|
44 //----------------------------------------------------------------------------- |
|
45 CIMCVEngineMessageContainer::CIMCVEngineMessageContainer( |
|
46 MIMCVEngineBufferMemoryHandler& aMemoryHandler ) |
|
47 : iMemoryHandler( aMemoryHandler ) |
|
48 { |
|
49 } |
|
50 |
|
51 //----------------------------------------------------------------------------- |
|
52 // CIMCVEngineMessageContainer::~CIMCVEngineMessageContainer |
|
53 // ( Other items commented in header ) |
|
54 //----------------------------------------------------------------------------- |
|
55 CIMCVEngineMessageContainer::~CIMCVEngineMessageContainer() |
|
56 { |
|
57 |
|
58 |
|
59 for( TInt a( 0 ); a < iMessageContainer.Count(); ++a ) |
|
60 { |
|
61 if( iMessageContainer[ a ]->DecreaseOwnerCount() ) |
|
62 { |
|
63 delete iMessageContainer[ a ]; |
|
64 } |
|
65 } |
|
66 iMessageContainer.Reset(); |
|
67 |
|
68 |
|
69 delete iTargetId; |
|
70 delete iBuddyDisplayName; |
|
71 delete iDecodedTargetId; |
|
72 delete iEditerMessge; |
|
73 delete iContactLink; |
|
74 } |
|
75 |
|
76 //----------------------------------------------------------------------------- |
|
77 // CIMCVEngineMessageContainer::NewL |
|
78 // ( Other items commented in header ) |
|
79 //----------------------------------------------------------------------------- |
|
80 CIMCVEngineMessageContainer* CIMCVEngineMessageContainer::NewL( |
|
81 TInt aServiceId, |
|
82 const TDesC& aTargetId, |
|
83 const TDesC& aDisplayName, |
|
84 const TDesC8& aContactLink, |
|
85 MIMCVEngineBufferMemoryHandler& aMemoryHandler, |
|
86 TContainerType aType ) |
|
87 { |
|
88 CIMCVEngineMessageContainer* self = CIMCVEngineMessageContainer::NewLC( |
|
89 aServiceId, |
|
90 aTargetId, |
|
91 aDisplayName, |
|
92 aContactLink, |
|
93 aMemoryHandler, |
|
94 aType ); |
|
95 CleanupStack::Pop( self ); |
|
96 return self; |
|
97 } |
|
98 |
|
99 //----------------------------------------------------------------------------- |
|
100 // CIMCVEngineMessageContainer::NewLC |
|
101 // ( Other items commented in header ) |
|
102 //----------------------------------------------------------------------------- |
|
103 CIMCVEngineMessageContainer* CIMCVEngineMessageContainer::NewLC( |
|
104 TInt aServiceId, |
|
105 const TDesC& aTargetId, |
|
106 const TDesC& aDisplayName, |
|
107 const TDesC8& aContactLink, |
|
108 MIMCVEngineBufferMemoryHandler& aMemoryHandler, |
|
109 TContainerType aType ) |
|
110 { |
|
111 CIMCVEngineMessageContainer* self = |
|
112 new ( ELeave ) CIMCVEngineMessageContainer( aMemoryHandler ); |
|
113 CleanupStack::PushL( self ); |
|
114 self->ConstructL( aServiceId, aTargetId,aDisplayName,aContactLink, aType ); |
|
115 return self; |
|
116 } |
|
117 |
|
118 //----------------------------------------------------------------------------- |
|
119 // CIMCVEngineMessageContainer::ConstructL |
|
120 // ( Other items commented in header ) |
|
121 //----------------------------------------------------------------------------- |
|
122 void CIMCVEngineMessageContainer::ConstructL( |
|
123 TInt /*aServiceId*/, |
|
124 const TDesC& aTargetId, |
|
125 const TDesC& aDisplayName, |
|
126 const TDesC8& aContactLink, |
|
127 TContainerType aType ) |
|
128 { |
|
129 iTargetId = aTargetId.AllocL(); |
|
130 iBuddyDisplayName = aDisplayName.AllocL(); |
|
131 iContactLink = aContactLink.Alloc(); |
|
132 iDecodedTargetId = EscapeUtils::EscapeDecodeL( *iTargetId ); |
|
133 ResolveType( aType ); |
|
134 |
|
135 } |
|
136 |
|
137 //----------------------------------------------------------------------------- |
|
138 // CIMCVEngineMessageContainer::UnreadCount |
|
139 // ( Other items commented in header ) |
|
140 //----------------------------------------------------------------------------- |
|
141 TInt CIMCVEngineMessageContainer::UnreadCount( |
|
142 MIMCVEngineMessageReadInterface::TUnreadFilter aUnreadFilter ) const |
|
143 { |
|
144 TInt countOfAll = iMessageContainer.Count(); |
|
145 TInt unreadCount = countOfAll - iUnreadOffset; |
|
146 if( aUnreadFilter != EUnreadAll ) |
|
147 { |
|
148 for( TInt a = countOfAll - 1; a >= iUnreadOffset; --a ) |
|
149 { |
|
150 if( iMessageContainer[ a ]->MessagerType() == MIMCVEngineMessage::EMessageSent ) |
|
151 { |
|
152 unreadCount--; |
|
153 } |
|
154 } |
|
155 } |
|
156 return unreadCount; |
|
157 } |
|
158 |
|
159 //----------------------------------------------------------------------------- |
|
160 // CIMCVEngineMessageContainer::StoreEditerMessageL |
|
161 // ( Other items commented in header ) |
|
162 //----------------------------------------------------------------------------- |
|
163 void CIMCVEngineMessageContainer::StoreEditerMessageL(const TDesC& aEditorMessage ) |
|
164 { |
|
165 if( iEditerMessge) |
|
166 { |
|
167 delete iEditerMessge; |
|
168 iEditerMessge = NULL; |
|
169 } |
|
170 iEditerMessge = aEditorMessage.AllocL(); |
|
171 } |
|
172 |
|
173 //----------------------------------------------------------------------------- |
|
174 // CIMCVEngineMessageContainer::GetEditerMessage |
|
175 // ( Other items commented in header ) |
|
176 //----------------------------------------------------------------------------- |
|
177 |
|
178 const TDesC& CIMCVEngineMessageContainer::GetEditerMessage() |
|
179 { |
|
180 if( iEditerMessge) |
|
181 { |
|
182 return *iEditerMessge; |
|
183 } |
|
184 return KNullDesC; |
|
185 } |
|
186 |
|
187 //----------------------------------------------------------------------------- |
|
188 // CIMCVEngineMessageContainer::MessageCount |
|
189 // ( Other items commented in header ) |
|
190 //----------------------------------------------------------------------------- |
|
191 TInt CIMCVEngineMessageContainer::MessageCount() const |
|
192 { |
|
193 // Offset is index to first unread message. It is exatly same as count of |
|
194 // read messages. |
|
195 return iUnreadOffset; |
|
196 } |
|
197 //----------------------------------------------------------------------------- |
|
198 // CIMCVEngineMessageContainer::Read |
|
199 // ( Other items commented in header ) |
|
200 //----------------------------------------------------------------------------- |
|
201 void CIMCVEngineMessageContainer::Read( TReadType aReadType, TInt aAmount /* = 0 */ ) |
|
202 { |
|
203 TInt messageCount( iMessageContainer.Count() ); |
|
204 TInt originalUnreadCount = UnreadCount( ); |
|
205 |
|
206 switch( aReadType ) |
|
207 { |
|
208 case EReadAll: |
|
209 iUnreadOffset = messageCount; |
|
210 break; |
|
211 case EReadAmount: |
|
212 iUnreadOffset+= aAmount; |
|
213 break; |
|
214 case EReadOne: |
|
215 ++iUnreadOffset; |
|
216 break; |
|
217 default: |
|
218 return; |
|
219 } |
|
220 |
|
221 // Cannot be more than messageCount |
|
222 if( iUnreadOffset > messageCount ) |
|
223 { |
|
224 iUnreadOffset = messageCount; |
|
225 } |
|
226 |
|
227 // Inform observers only if unreadcount is changed. |
|
228 if( originalUnreadCount != UnreadCount() ) |
|
229 { |
|
230 if (( iChatObserver ) && (!iActiveChat)) |
|
231 { |
|
232 TRAP_IGNORE( iChatObserver->HandleChatEventL( |
|
233 MIMCVEngineNewMsgObserver::EUnreadCountChanged ) ); |
|
234 } |
|
235 } |
|
236 |
|
237 } |
|
238 |
|
239 //----------------------------------------------------------------------------- |
|
240 // CIMCVEngineMessageContainer::Message |
|
241 // ( Other items commented in header ) |
|
242 //----------------------------------------------------------------------------- |
|
243 MIMCVEngineMessage& CIMCVEngineMessageContainer::Message( TInt aIndex ) const |
|
244 { |
|
245 //__CHAT_ASSERT_DEBUG( aIndex >= 0 && aIndex < MessageCount() ); |
|
246 return *iMessageContainer[ aIndex ]; |
|
247 } |
|
248 |
|
249 //----------------------------------------------------------------------------- |
|
250 // CIMCVEngineMessageContainer::ReadNextUnread |
|
251 // ( Other items commented in header ) |
|
252 //----------------------------------------------------------------------------- |
|
253 MIMCVEngineMessage& CIMCVEngineMessageContainer::ReadNextUnread() |
|
254 { |
|
255 //__CHAT_ASSERT_DEBUG( UnreadCount() != 0 ); |
|
256 Read( EReadOne ); |
|
257 return *iMessageContainer[ MessageCount() - 1 ]; |
|
258 } |
|
259 |
|
260 //----------------------------------------------------------------------------- |
|
261 // CIMCVEngineMessageContainer::ReadUnreadFromIndex |
|
262 // ( Other items commented in header ) |
|
263 //----------------------------------------------------------------------------- |
|
264 MIMCVEngineMessage& CIMCVEngineMessageContainer::ReadUnreadFromIndex( TInt aIndex ) |
|
265 { |
|
266 //__CHAT_ASSERT_DEBUG( UnreadCount() != 0 ); |
|
267 //__CHAT_ASSERT_DEBUG( aIndex >= 0 && aIndex < iMessageContainer.Count() ); |
|
268 Read( EReadOne ); |
|
269 return *iMessageContainer[aIndex]; |
|
270 } |
|
271 |
|
272 //----------------------------------------------------------------------------- |
|
273 // CIMCVEngineMessageContainer::SetObserver |
|
274 // ( Other items commented in header ) |
|
275 //----------------------------------------------------------------------------- |
|
276 void CIMCVEngineMessageContainer::SetObserver( MIMCVEngineMessageObserver* aObserver ) |
|
277 { |
|
278 iObserver = aObserver; |
|
279 } |
|
280 |
|
281 //----------------------------------------------------------------------------- |
|
282 // CIMCVEngineMessageContainer::SetObserver |
|
283 // ( Other items commented in header ) |
|
284 //----------------------------------------------------------------------------- |
|
285 TPtrC CIMCVEngineMessageContainer::Name() const |
|
286 { |
|
287 IM_CV_LOGS(TXT("CIMCVEngineMessageContainer::Name Start")); |
|
288 if( iBuddyDisplayName && iBuddyDisplayName->Length()) |
|
289 { |
|
290 IM_CV_LOGS(TXT("to_del CIMCVEngineMessageContainer::Name iBuddyDisplayName= %S"),&(*iBuddyDisplayName) ); |
|
291 //IM_CV_LOGS(TXT("to_del CIMCVEngineMessageContainer::Name iBuddyDisplayName length = %d"),iBuddyDisplayName->Length() ); |
|
292 return *iBuddyDisplayName; |
|
293 } |
|
294 if( iTargetId ) |
|
295 { |
|
296 IM_CV_LOGS(TXT("to_del CIMCVEngineMessageContainer::target iTargetId= %S"), &(*iTargetId)); |
|
297 return DisplayId( *iTargetId ); |
|
298 } |
|
299 return KNullDesC(); |
|
300 } |
|
301 //----------------------------------------------------------------------------- |
|
302 // CIMCVEngineMessageContainer::DisplayName |
|
303 // ( Other items commented in header ) |
|
304 //----------------------------------------------------------------------------- |
|
305 TDesC CIMCVEngineMessageContainer::DisplayName() const |
|
306 { |
|
307 IM_CV_LOGS(TXT("CIMCVEngineMessageContainer::DisplayName Start" )); |
|
308 if( iBuddyDisplayName && iBuddyDisplayName->Length()) |
|
309 { |
|
310 IM_CV_LOGS(TXT("CIMCVEngineMessageContainer::DisplayName EChatContainer: %s"), &(*iBuddyDisplayName)); |
|
311 return *iBuddyDisplayName; |
|
312 } |
|
313 return KNullDesC(); |
|
314 } |
|
315 //----------------------------------------------------------------------------- |
|
316 // CIMCVEngineMessageContainer::SetName |
|
317 // ( Other items commented in header ) |
|
318 //----------------------------------------------------------------------------- |
|
319 void CIMCVEngineMessageContainer::SetNameL(const TDesC& aDisplayName) |
|
320 { |
|
321 IM_CV_LOGS(TXT("CIMCVEngineMessageContainer::SetNameL Start")); |
|
322 //if the iBuddydisplayName is same as aDisplayName |
|
323 // then no need to set it again. |
|
324 if(iBuddyDisplayName && (aDisplayName.Compare(*iBuddyDisplayName)!=0)) |
|
325 { |
|
326 delete iBuddyDisplayName; |
|
327 iBuddyDisplayName = NULL; |
|
328 IM_CV_LOGS(TXT("CIMCVEngineMessageContainer::SetName=%S"),&aDisplayName); |
|
329 iBuddyDisplayName = aDisplayName.AllocL(); |
|
330 } |
|
331 } |
|
332 //----------------------------------------------------------------------------- |
|
333 // CIMCVEngineMessageContainer::SetName |
|
334 // ( Other items commented in header ) |
|
335 //----------------------------------------------------------------------------- |
|
336 void CIMCVEngineMessageContainer::SetLinkL(const TDesC8& aContactLink) |
|
337 { |
|
338 IM_CV_LOGS(TXT(" CIMCVEngineMessageContainer::SetLinkL Start")); |
|
339 //if the iContactLink is same as aContactLink |
|
340 // then no need to set it again. |
|
341 if(iContactLink && (aContactLink.Compare(*iContactLink)!=0)) |
|
342 { |
|
343 delete iContactLink; |
|
344 iContactLink = NULL; |
|
345 IM_CV_LOGS(TXT(" CIMCVEngineMessageContainer::SetLinkL=%S"),&aContactLink); |
|
346 iContactLink = aContactLink.AllocL(); |
|
347 } |
|
348 |
|
349 } |
|
350 //----------------------------------------------------------------------------- |
|
351 // CIMCVEngineMessageContainer::ContactLink |
|
352 // ( Other items commented in header ) |
|
353 //----------------------------------------------------------------------------- |
|
354 |
|
355 TPtrC8 CIMCVEngineMessageContainer::ContactLink() const |
|
356 { |
|
357 return *iContactLink; |
|
358 } |
|
359 |
|
360 //----------------------------------------------------------------------------- |
|
361 // CIMCVEngineMessageContainer::DeleteMessage |
|
362 // ( Other items commented in header ) |
|
363 //----------------------------------------------------------------------------- |
|
364 void CIMCVEngineMessageContainer::DeleteMessage( TInt aIndex ) |
|
365 { |
|
366 MIMCVEngineMessage* target = &Message( aIndex ); |
|
367 iMessageContainer.Remove( aIndex ); |
|
368 iContainerSizeInBytes -= target->SizeInBytes(); |
|
369 --iUnreadOffset; |
|
370 |
|
371 if( iObserver ) |
|
372 { |
|
373 iObserver->HandleMessageEvent( MIMCVEngineMessageObserver::EMessageDeleted, |
|
374 aIndex ); |
|
375 } |
|
376 |
|
377 if( target->DecreaseOwnerCount() ) |
|
378 { |
|
379 delete target; |
|
380 } |
|
381 } |
|
382 |
|
383 //----------------------------------------------------------------------------- |
|
384 // CIMCVEngineMessageContainer::AppendL |
|
385 // ( Other items commented in header ) |
|
386 //----------------------------------------------------------------------------- |
|
387 void CIMCVEngineMessageContainer::AppendL( MIMCVEngineMessage* aMessage, TBool aSharedOwnership ) |
|
388 { |
|
389 if( !aMessage ) |
|
390 { |
|
391 User::Leave( KErrArgument ); |
|
392 } |
|
393 |
|
394 if( !aSharedOwnership ) |
|
395 { |
|
396 CleanupDeletePushL( aMessage ); |
|
397 } |
|
398 |
|
399 // Check memory status |
|
400 // if failes, leave with KErrNoMemory |
|
401 if( !iMemoryHandler.FreeMemoryIfNeededL( aMessage->SizeInBytes() ) ) |
|
402 { |
|
403 User::Leave( KErrNoMemory ); |
|
404 } |
|
405 |
|
406 iMessageContainer.AppendL( aMessage ); |
|
407 iContainerSizeInBytes += aMessage->SizeInBytes(); |
|
408 |
|
409 if( !aSharedOwnership ) |
|
410 { |
|
411 CleanupStack::Pop( aMessage ); |
|
412 } |
|
413 |
|
414 aMessage->IncreaseOwnerCount(); |
|
415 |
|
416 aMessage->SetContainerInfo( this ); |
|
417 |
|
418 IM_CV_LOGS(TXT( "Sender %s, Recipient %s" ), |
|
419 &aMessage->Sender(), |
|
420 &aMessage->Recipient() ); |
|
421 |
|
422 |
|
423 if( iObserver ) |
|
424 { |
|
425 iObserver->HandleMessageEvent( MIMCVEngineMessageObserver::ENewMessage ); |
|
426 } |
|
427 |
|
428 if ( ( iChatObserver ) && (!iActiveChat) ) |
|
429 { |
|
430 iChatObserver->HandleChatEventL( MIMCVEngineNewMsgObserver::EUnreadCountChanged, |
|
431 aMessage ); |
|
432 } |
|
433 } |
|
434 |
|
435 //----------------------------------------------------------------------------- |
|
436 // CIMCVEngineMessageContainer::ServerAddress |
|
437 // ( Other items commented in header ) |
|
438 //----------------------------------------------------------------------------- |
|
439 // |
|
440 TTime CIMCVEngineMessageContainer::Time() |
|
441 { |
|
442 TTime time = Time::NullTTime(); |
|
443 TInt count = iMessageContainer.Count(); |
|
444 if( count == 0 ) |
|
445 { |
|
446 // no messages, return null |
|
447 return time; |
|
448 } |
|
449 return iMessageContainer[count - 1]->TimeStamp(); |
|
450 } |
|
451 |
|
452 |
|
453 |
|
454 //----------------------------------------------------------------------------- |
|
455 // CIMCVEngineMessageContainer::Target |
|
456 // ( Other items commented in header ) |
|
457 //----------------------------------------------------------------------------- |
|
458 const TDesC& CIMCVEngineMessageContainer::Target() const |
|
459 { |
|
460 if( !iTargetId ) |
|
461 { |
|
462 return KNullDesC; |
|
463 } |
|
464 return *iTargetId; |
|
465 } |
|
466 |
|
467 |
|
468 //----------------------------------------------------------------------------- |
|
469 // CIMCVEngineMessageContainer::OrderUid |
|
470 // ( Other items commented in header ) |
|
471 //----------------------------------------------------------------------------- |
|
472 TInt CIMCVEngineMessageContainer::OrderUid( const CIMCVEngineMessageContainer& aSourceA, |
|
473 const CIMCVEngineMessageContainer& aSourceB ) |
|
474 { |
|
475 |
|
476 // points to user part of id |
|
477 TPtrC ptrId1( aSourceA.ComparableTarget() ); |
|
478 TPtrC ptrId2( aSourceB.ComparableTarget() ); |
|
479 |
|
480 // find out if we have domains in the ids |
|
481 TInt domainPos1( ptrId1.Locate( KAtUInt ) ); |
|
482 TInt domainPos2( ptrId2.Locate( KAtUInt ) ); |
|
483 |
|
484 TBool domainIn1( KErrNotFound != domainPos1 ); |
|
485 TBool domainIn2( KErrNotFound != domainPos2 ); |
|
486 |
|
487 // points to domains in the neutral id |
|
488 TPtrC ptrDom1( KNullDesC ); |
|
489 TPtrC ptrDom2( KNullDesC ); |
|
490 |
|
491 // points to user parts in the neutral id |
|
492 TPtrC ptrUid1( ptrId1 ); |
|
493 TPtrC ptrUid2( ptrId2 ); |
|
494 |
|
495 // separate user id parts and domain parts |
|
496 if ( domainIn1 ) |
|
497 { |
|
498 ptrDom1.Set( ptrId1.Mid( domainPos1 + 1) ); |
|
499 ptrUid1.Set( ptrId1.Mid( 0, domainPos1 ) ); |
|
500 } |
|
501 |
|
502 if ( domainIn2 ) |
|
503 { |
|
504 ptrDom2.Set( ptrId2.Mid( domainPos2 + 1) ); |
|
505 ptrUid2.Set( ptrId2.Mid( 0, domainPos2 ) ); |
|
506 } |
|
507 |
|
508 // Create custom collation method to ignore punctuations |
|
509 // index 0 gets the default method |
|
510 TCollationMethod collation = |
|
511 *Mem::CollationMethodByIndex( 0 ); |
|
512 collation.iFlags |= TCollationMethod::EIgnoreNone; |
|
513 |
|
514 // domains are compared only when it is really needed |
|
515 // check if userid part is the same in both ids |
|
516 TInt idResult = ptrUid1.CompareC( ptrUid2, KCollationLevel, &collation ); |
|
517 |
|
518 if( idResult != 0 ) |
|
519 { |
|
520 return idResult; |
|
521 } |
|
522 |
|
523 // id part is same, we have to compare domain |
|
524 |
|
525 // If domain comparison is neutral and one id is without domain |
|
526 // -> Domains are same. Other situation domainResult stays valid. |
|
527 if ( domainIn1 ^ domainIn2 ) |
|
528 { |
|
529 return 0; |
|
530 } |
|
531 else |
|
532 { |
|
533 return ptrDom1.CompareC( ptrDom2, KCollationLevel, &collation ); |
|
534 } |
|
535 } |
|
536 |
|
537 |
|
538 |
|
539 //----------------------------------------------------------------------------- |
|
540 // CIMCVEngineMessageContainer::ContainerType |
|
541 // ( Other items commented in header ) |
|
542 //----------------------------------------------------------------------------- |
|
543 MIMCVEngineMessageReadInterface::TContainerType CIMCVEngineMessageContainer::ContainerType() const |
|
544 { |
|
545 return iContainerType; |
|
546 } |
|
547 |
|
548 //----------------------------------------------------------------------------- |
|
549 // CIMCVEngineMessageContainer::ResolveType |
|
550 // ( Other items commented in header ) |
|
551 //----------------------------------------------------------------------------- |
|
552 void CIMCVEngineMessageContainer::SetChatObserver( MIMCVEngineNewMsgObserver* aObserver ) |
|
553 { |
|
554 iChatObserver = aObserver; |
|
555 } |
|
556 |
|
557 //----------------------------------------------------------------------------- |
|
558 // CIMCVEngineMessageContainer::ResolveType |
|
559 // ( Other items commented in header ) |
|
560 //----------------------------------------------------------------------------- |
|
561 void CIMCVEngineMessageContainer::ResolveType( TContainerType aType ) |
|
562 { |
|
563 if( aType != ENoneContainer ) |
|
564 { |
|
565 iContainerType = aType; |
|
566 } |
|
567 else if( iTargetId->Compare( KSendBufferId ) == 0 ) |
|
568 { |
|
569 iContainerType = ESendContainer; |
|
570 } |
|
571 else |
|
572 { |
|
573 iContainerType = EChatContainer; |
|
574 } |
|
575 } |
|
576 |
|
577 |
|
578 |
|
579 // ----------------------------------------------------------------------------- |
|
580 // CIMCVEngineMessageContainer::TargetId |
|
581 // ( Other items commented in header ) |
|
582 // ----------------------------------------------------------------------------- |
|
583 // |
|
584 MIMCVEngineMessageContainerInfo& CIMCVEngineMessageContainer::TargetId() |
|
585 { |
|
586 return *this; |
|
587 } |
|
588 |
|
589 // ----------------------------------------------------------------------------- |
|
590 // CIMCVEngineMessageContainer::Lock |
|
591 // locks messagecontainer if needed. |
|
592 // ----------------------------------------------------------------------------- |
|
593 // |
|
594 void CIMCVEngineMessageContainer::Lock( TBool aLocked ) |
|
595 { |
|
596 iLocked = aLocked; |
|
597 } |
|
598 |
|
599 // ----------------------------------------------------------------------------- |
|
600 // CIMCVEngineMessageContainer::ComparableTarget |
|
601 // ( Other items commented in header ) |
|
602 // ----------------------------------------------------------------------------- |
|
603 // |
|
604 const TDesC& CIMCVEngineMessageContainer::ComparableTarget() const |
|
605 { |
|
606 if ( !iDecodedTargetId ) |
|
607 { |
|
608 return KNullDesC; |
|
609 } |
|
610 return *iDecodedTargetId; |
|
611 } |
|
612 |
|
613 // ----------------------------------------------------------------------------- |
|
614 // CIMCVEngineMessageContainer::AllMessagesCount |
|
615 // ( Other items commented in header ) |
|
616 // ----------------------------------------------------------------------------- |
|
617 // |
|
618 TInt CIMCVEngineMessageContainer::AllMessagesCount() const |
|
619 { |
|
620 return iMessageContainer.Count(); |
|
621 } |
|
622 |
|
623 // ----------------------------------------------------------------------------- |
|
624 // CCABufferManager::NotifyContactForPending |
|
625 // ( Other items commented in header ) |
|
626 // ----------------------------------------------------------------------------- |
|
627 // |
|
628 MIMCVEngineMessage& CIMCVEngineMessageContainer::MessageFromAll( TInt aIndex ) const |
|
629 { |
|
630 //__CHAT_ASSERT_DEBUG( aIndex >= 0 && aIndex < AllMessagesCount() ); |
|
631 return *iMessageContainer[ aIndex ]; |
|
632 } |
|
633 |
|
634 //----------------------------------------------------------------------------- |
|
635 // CIMCVEngineMessageContainer::DeleteMessageFromAll |
|
636 // ( Other items commented in header ) |
|
637 //----------------------------------------------------------------------------- |
|
638 // |
|
639 void CIMCVEngineMessageContainer::DeleteMessageFromAll( TInt aIndex ) |
|
640 { |
|
641 MIMCVEngineMessage* target = &MessageFromAll( aIndex ); |
|
642 iMessageContainer.Remove( aIndex ); |
|
643 iContainerSizeInBytes -= target->SizeInBytes(); |
|
644 if( iUnreadOffset > aIndex ) |
|
645 { |
|
646 --iUnreadOffset; |
|
647 } |
|
648 |
|
649 if( iObserver ) |
|
650 { |
|
651 iObserver->HandleMessageEvent( MIMCVEngineMessageObserver::EMessageDeleted, |
|
652 aIndex ); |
|
653 } |
|
654 |
|
655 if( target->DecreaseOwnerCount() ) |
|
656 { |
|
657 delete target; |
|
658 } |
|
659 } |
|
660 |
|
661 //----------------------------------------------------------------------------- |
|
662 // CIMCVEngineMessageContainer::IsLocked |
|
663 // ( Other items commented in header ) |
|
664 //----------------------------------------------------------------------------- |
|
665 // |
|
666 TBool CIMCVEngineMessageContainer::IsLocked() const |
|
667 { |
|
668 return iLocked ; |
|
669 } |
|
670 |
|
671 //----------------------------------------------------------------------------- |
|
672 // CIMCVEngineMessageContainer::ContainerSizeInBytes |
|
673 // ( Other items commented in header ) |
|
674 //----------------------------------------------------------------------------- |
|
675 // |
|
676 TInt CIMCVEngineMessageContainer::ContainerSizeInBytes() const |
|
677 { |
|
678 return iContainerSizeInBytes; |
|
679 } |
|
680 |
|
681 |
|
682 //----------------------------------------------------------------------------- |
|
683 // CIMCVEngineMessageContainer::SetActive |
|
684 // ( Other items commented in header ) |
|
685 //----------------------------------------------------------------------------- |
|
686 // |
|
687 void CIMCVEngineMessageContainer::SetActive( TBool aActiveChat ) |
|
688 { |
|
689 iActiveChat = aActiveChat; |
|
690 } |
|
691 |
|
692 |
|
693 //----------------------------------------------------------------------------- |
|
694 // CIMCVEngineMessageContainer::IsActive |
|
695 // ( Other items commented in header ) |
|
696 //----------------------------------------------------------------------------- |
|
697 // |
|
698 TBool CIMCVEngineMessageContainer::IsActive() |
|
699 { |
|
700 return iActiveChat; |
|
701 } |
|
702 |
|
703 |
|
704 |
|
705 // ----------------------------------------------------------------------------- |
|
706 // CIMCVEngineMessageContainer::DisplayId |
|
707 // ----------------------------------------------------------------------------- |
|
708 // |
|
709 TPtrC CIMCVEngineMessageContainer::DisplayId( const TDesC& aId, TBool aDomainHiding ) |
|
710 { |
|
711 TPtrC ret( aId ); |
|
712 |
|
713 // locate ":" for userid, groupid. |
|
714 // locate "/" for list id. |
|
715 TInt pos = aId.FindC( aDomainHiding ? KSlash : KColon ); |
|
716 |
|
717 if ( ( pos != KErrNotFound) && ( pos != aId.Length()-1) ) |
|
718 { |
|
719 // contains the special character, and it is not the last char |
|
720 // remove everything before the special char (including the char) |
|
721 ret.Set( aId.Mid( pos + 1 ) ); |
|
722 } |
|
723 if( aDomainHiding) |
|
724 { |
|
725 // remove also the domain part |
|
726 TInt domainPos = ret.FindC( KAt ); |
|
727 if ( ( domainPos != KErrNotFound ) && ( domainPos != 0 ) ) |
|
728 { |
|
729 ret.Set( ret.Mid( 0, domainPos ) ); |
|
730 } |
|
731 |
|
732 } |
|
733 |
|
734 return ret; |
|
735 } |
|
736 |
|
737 |
|
738 // end of file |