-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-1551: Add test for
combineDuplicateContactAndChat
func
- Loading branch information
Showing
4 changed files
with
835 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:fluffychat/presentation/model/search/presentation_search.dart'; | ||
|
||
mixin SearchMixin { | ||
List<PresentationSearch> combineDuplicateContactAndChat({ | ||
required List<PresentationSearch> contacts, | ||
required List<PresentationSearch> recentChat, | ||
}) { | ||
final Map<String, PresentationSearch> distinctContactsAndChatsMap = {}; | ||
|
||
for (final contact in contacts) { | ||
distinctContactsAndChatsMap[contact.id] = contact; | ||
} | ||
|
||
for (final chat in recentChat) { | ||
final isContactHasChat = | ||
distinctContactsAndChatsMap[chat.directChatMatrixID ?? chat.id] != | ||
null; | ||
if (!isContactHasChat) { | ||
distinctContactsAndChatsMap[chat.id] = chat; | ||
} | ||
} | ||
|
||
return distinctContactsAndChatsMap.values.toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.