Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYNC-CONTACT-V2] Update UI for new contact
Browse files Browse the repository at this point in the history
nqhhdev committed Jan 20, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent cce694e commit a239a93
Showing 15 changed files with 178 additions and 117 deletions.
8 changes: 4 additions & 4 deletions lib/di/global/get_it_initializer.dart
Original file line number Diff line number Diff line change
@@ -277,6 +277,9 @@ class GetItInitializer {
getIt.registerFactory<PhonebookContactInteractor>(
() => PhonebookContactInteractor(),
);
getIt.registerFactory<PhonebookContactInteractorV2>(
() => PhonebookContactInteractorV2(),
);
getIt.registerSingleton<DownloadFileForPreviewInteractor>(
DownloadFileForPreviewInteractor(),
);
@@ -320,6 +323,7 @@ class GetItInitializer {
ContactsManager(
getTomContactsInteractor: getIt.get<GetTomContactsInteractor>(),
phonebookContactInteractor: getIt.get<PhonebookContactInteractor>(),
phonebookContactInteractorV2: getIt.get<PhonebookContactInteractorV2>(),
),
);
getIt.registerLazySingleton<SaveLanguageInteractor>(
@@ -355,10 +359,6 @@ class GetItInitializer {
getIt.registerFactory<VerifyNameInteractor>(
() => VerifyNameInteractor(),
);

getIt.registerFactory<PhonebookContactInteractorV2>(
() => PhonebookContactInteractorV2(),
);
}

void _bindingControllers() {
2 changes: 1 addition & 1 deletion lib/domain/app_state/contact/get_contacts_state.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:fluffychat/app_state/failure.dart';
import 'package:fluffychat/app_state/initial.dart';
import 'package:fluffychat/app_state/success.dart';
import 'package:fluffychat/domain/model/contact/contact.dart';
import 'package:fluffychat/domain/model/contact/contact_new.dart';

class ContactsInitial extends Initial {
const ContactsInitial() : super();
43 changes: 30 additions & 13 deletions lib/domain/app_state/contact/get_phonebook_contact_state_v2.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
import 'package:fluffychat/app_state/failure.dart';
import 'package:fluffychat/app_state/initial.dart';
import 'package:fluffychat/app_state/success.dart';
import 'package:fluffychat/domain/model/contact/contact_v2.dart';
import 'package:fluffychat/domain/model/contact/contact_new.dart';

class GetPhonebookContactsInitial extends Initial {
const GetPhonebookContactsInitial() : super();
class GetPhonebookContactsV2Initial extends Initial {
const GetPhonebookContactsV2Initial() : super();

@override
List<Object?> get props => [];
}

class GetPhonebookContactsLoading extends Success {
class GetPhonebookContactsV2Loading extends Success {
final int progress;

const GetPhonebookContactsLoading({required this.progress});
const GetPhonebookContactsV2Loading({required this.progress});

@override
List<Object?> get props => [progress];
}

class GetPhonebookContactsSuccess extends Success {
class GetPhonebookContactsV2Success extends Success {
final int progress;
final List<Contact> foundContacts;
final List<Contact> notFoundContacts;
final int totalProgress;
final List<Contact> contacts;

const GetPhonebookContactsSuccess({
const GetPhonebookContactsV2Success({
required this.progress,
required this.foundContacts,
required this.notFoundContacts,
required this.totalProgress,
required this.contacts,
});

@override
List<Object?> get props => [
progress,
foundContacts,
notFoundContacts,
contacts,
totalProgress,
];
}

class GetPhonebookContactsV2IsEmpty extends Failure {
const GetPhonebookContactsV2IsEmpty();

@override
List<Object?> get props => [];
}

class GetPhonebookContactsV2Failure extends Failure {
final dynamic exception;

const GetPhonebookContactsV2Failure({required this.exception});

@override
List<Object?> get props => [exception];
}
25 changes: 15 additions & 10 deletions lib/domain/model/extensions/contact/contacts_extension.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fluffychat/domain/model/contact/contact.dart';
import 'package:fluffychat/domain/model/contact/contact_new.dart';
import 'package:fluffychat/utils/string_extension.dart';

extension ContactsExtension on Iterable<Contact> {
@@ -9,20 +9,25 @@ extension ContactsExtension on Iterable<Contact> {
final contactsMatched = where((contact) {
final supportedFields = [
contact.displayName,
contact.matrixId,
contact.email,
];
final plainTextContains = supportedFields.any(
(field) =>
field?.toLowerCase().contains(keyword.toLowerCase()) ?? false,
);
final phoneNumberContains = keyword.msisdnSanitizer().isNotEmpty
? contact.phoneNumber
?.msisdnSanitizer()
.contains(keyword.msisdnSanitizer()) ??
false
: false;
return plainTextContains || phoneNumberContains;

final matrixIdInPhoneNumber = contact.phoneNumbers?.any((phoneNumber) {
return phoneNumber.number
.msisdnSanitizer()
.contains(keyword.msisdnSanitizer());
}) ??
false;

final matrixInEmail = contact.emails?.any((email) {
return email.address.contains(keyword);
}) ??
false;

return plainTextContains || matrixIdInPhoneNumber || matrixInEmail;
});
return contactsMatched;
}
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ class GetTomContactsInteractor {
if (response.isEmpty) {
yield const Left(GetContactsIsEmpty());
} else {
yield Right(GetContactsSuccess(contacts: response));
// yield Right(GetContactsSuccess(contacts: response));
}
} catch (e) {
yield Left(GetContactsFailure(keyword: '', exception: e));
6 changes: 5 additions & 1 deletion lib/pages/chat_draft/draft_chat_adaptive_scaffold.dart
Original file line number Diff line number Diff line change
@@ -48,7 +48,11 @@ class DraftChatAdaptiveScaffold extends StatelessWidget {
if (extra.isNotEmpty) {
return PresentationContact(
matrixId: extra[PresentationContactConstant.receiverId],
email: extra[PresentationContactConstant.email],
emails: {
PresentationEmail(
address: extra[PresentationContactConstant.email] ?? '',
),
},
displayName: extra[PresentationContactConstant.displayName],
);
} else {
2 changes: 1 addition & 1 deletion lib/pages/contacts_tab/contacts_tab.dart
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ class ContactsTabController extends State<ContactsTab>
'/$path/draftChat',
extra: {
PresentationContactConstant.receiverId: contact.matrixId ?? '',
PresentationContactConstant.email: contact.email ?? '',
PresentationContactConstant.email: contact.emails ?? '',
PresentationContactConstant.displayName: contact.displayName ?? '',
PresentationContactConstant.status: '',
},
14 changes: 11 additions & 3 deletions lib/pages/contacts_tab/contacts_tab_body_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:fluffychat/app_state/success.dart';
import 'package:fluffychat/domain/app_state/contact/get_contacts_state.dart';
import 'package:fluffychat/domain/app_state/contact/get_phonebook_contacts_state.dart';
import 'package:fluffychat/domain/app_state/contact/get_phonebook_contact_state_v2.dart';
import 'package:fluffychat/domain/model/contact/contact_type.dart';
import 'package:fluffychat/pages/contacts_tab/contacts_tab.dart';
import 'package:fluffychat/pages/contacts_tab/contacts_tab_view_style.dart';
@@ -70,6 +70,9 @@ class _SliverPhonebookList extends StatelessWidget {
return ValueListenableBuilder(
valueListenable: controller.presentationPhonebookContactNotifier,
builder: (context, phonebookContactState, child) {
debugPrint(
'DEBUG::_SliverPhonebookList: phonebookContactState: $phonebookContactState',
);
return phonebookContactState.fold(
(failure) {
if (!PlatformInfos.isMobile) {
@@ -256,7 +259,7 @@ class _SliverContactsList extends StatelessWidget {
);
}

if (success is PresentationExternalContactSuccess) {
if (success is PresentationExternalContactV2Success) {
final externalContact = success.contact;
return _SilverExternalContact(
controller: controller,
@@ -334,7 +337,12 @@ class _SliverPhonebookLoading extends StatelessWidget {
valueListenable: controller.presentationPhonebookContactNotifier,
builder: (context, phonebookContactState, child) {
final loading = phonebookContactState
.getSuccessOrNull<GetPhonebookContactsLoading>();
.getSuccessOrNull<GetPhonebookContactsV2Success>();

debugPrint(
'DEBUG::_SliverPhonebookLoading: _SliverPhonebookLoading: $loading',
);

if (loading == null) {
return const SliverToBoxAdapter();
}
2 changes: 1 addition & 1 deletion lib/pages/new_private_chat/new_private_chat.dart
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ class NewPrivateChatController extends State<NewPrivateChat>
path: 'rooms',
contactPresentationSearch: ContactPresentationSearch(
matrixId: contact.matrixId,
email: contact.email,
email: contact.emails?.first.address ?? '',
displayName: contact.displayName,
),
);
63 changes: 32 additions & 31 deletions lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import 'package:fluffychat/presentation/model/contact/presentation_contact.dart'
import 'package:fluffychat/pages/new_private_chat/widget/contact_status_widget.dart';
import 'package:fluffychat/utils/display_name_widget.dart';
import 'package:fluffychat/widgets/avatar/avatar.dart';
import 'package:fluffychat/widgets/highlight_text.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/twake_components/twake_chip.dart';
import 'package:flutter/material.dart';
@@ -95,36 +94,38 @@ class ExpansionContactListTile extends StatelessWidget {
],
),
),
if (contact.matrixId != null &&
(contact.email == null ||
contact.phoneNumber == null))
HighlightText(
text: contact.matrixId!,
searchWord: highlightKeyword,
style: ListItemStyle.subtitleTextStyle(
fontFamily: 'Inter',
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
if (contact.email != null)
HighlightText(
text: contact.email!,
searchWord: highlightKeyword,
style: ListItemStyle.subtitleTextStyle(
fontFamily: 'Inter',
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
if (contact.phoneNumber != null)
HighlightText(
text: contact.phoneNumber!,
searchWord: highlightKeyword,
style: ListItemStyle.subtitleTextStyle(
fontFamily: 'Inter',
),
),

/// TODO: Uncomment the following code snippet
// if (contact.matrixId != null &&
// (contact.email == null ||
// contact.phoneNumber == null))
// HighlightText(
// text: contact.matrixId!,
// searchWord: highlightKeyword,
// style: ListItemStyle.subtitleTextStyle(
// fontFamily: 'Inter',
// ),
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// ),
// if (contact.email != null)
// HighlightText(
// text: contact.email!,
// searchWord: highlightKeyword,
// style: ListItemStyle.subtitleTextStyle(
// fontFamily: 'Inter',
// ),
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// ),
// if (contact.phoneNumber != null)
// HighlightText(
// text: contact.phoneNumber!,
// searchWord: highlightKeyword,
// style: ListItemStyle.subtitleTextStyle(
// fontFamily: 'Inter',
// ),
// ),
],
),
),
2 changes: 1 addition & 1 deletion lib/pages/search/search_external_contact.dart
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ class SearchExternalContactWidget extends StatelessWidget {
searchController.onSearchItemTap(
ContactPresentationSearch(
matrixId: newContact.matrixId,
email: newContact.email,
email: newContact.emails?.first.address ?? '',
displayName: newContact.displayName,
),
);
Loading

0 comments on commit a239a93

Please sign in to comment.