Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-1772: Prevent infinity contact loop #1782

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/config/first_column_inner_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:fluffychat/pages/new_group/new_group.dart';
import 'package:fluffychat/pages/new_group/new_group_chat_info.dart';
import 'package:fluffychat/pages/new_private_chat/new_private_chat.dart';
import 'package:fluffychat/pages/search/search.dart';
import 'package:fluffychat/presentation/model/presentation_contact.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/cupertino.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'package:fluffychat/pages/story/story_page.dart';
import 'package:fluffychat/pages/twake_welcome/twake_welcome.dart';
import 'package:fluffychat/presentation/model/chat/chat_router_input_argument.dart';
import 'package:fluffychat/presentation/model/forward/forward_argument.dart';
import 'package:fluffychat/presentation/model/presentation_contact.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
import 'package:fluffychat/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ class TomContactRepositoryImpl implements ContactRepository {
TomContactRepositoryImpl();

@override
Stream<List<Contact>> fetchContacts({
Future<List<Contact>> fetchContacts({
required ContactQuery query,
int? limit,
int? offset,
}) async* {
final response = await datasource.fetchContacts(
}) async {
return datasource.fetchContacts(
query: query,
limit: limit,
offset: offset,
);

yield response;
}

@override
Expand Down
7 changes: 7 additions & 0 deletions lib/domain/app_state/contact/get_contacts_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class GetContactsSuccess extends Success {
List<Object?> get props => [contacts];
}

class GetContactsIsEmpty extends Failure {
const GetContactsIsEmpty();

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

class GetContactsFailure extends Failure {
final String keyword;
final dynamic exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class GetPhonebookContactsSuccess extends Success {
List<Object?> get props => [contacts];
}

class GetPhonebookContactsIsEmpty extends Failure {
const GetPhonebookContactsIsEmpty();

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

class GetPhonebookContactsFailure extends Failure {
final dynamic exception;

Expand Down
2 changes: 1 addition & 1 deletion lib/domain/repository/contact_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:fluffychat/domain/model/contact/contact_query.dart';
import 'package:fluffychat/domain/model/contact/lookup_mxid_request.dart';

abstract class ContactRepository {
Stream<List<Contact>> fetchContacts({
Future<List<Contact>> fetchContacts({
hoangdat marked this conversation as resolved.
Show resolved Hide resolved
required ContactQuery query,
int? limit,
int? offset,
Expand Down
16 changes: 8 additions & 8 deletions lib/domain/usecase/contacts/get_tom_contacts_interactor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ class GetTomContactsInteractor {
}) async* {
try {
yield const Right(ContactsLoading());
yield* contactRepository
.fetchContacts(
final response = await contactRepository.fetchContacts(
query: ContactQuery(keyword: ''),
limit: limit,
)
.map((contacts) {
return Right(
GetContactsSuccess(contacts: contacts),
);
});
);

if (response.isEmpty) {
yield const Left(GetContactsIsEmpty());
} else {
yield Right(GetContactsSuccess(contacts: response));
}
} catch (e) {
yield Left(GetContactsFailure(keyword: '', exception: e));
}
Expand Down
12 changes: 10 additions & 2 deletions lib/domain/usecase/contacts/phonebook_contact_interactor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ class PhonebookContactInteractor {
thirdPartyIdToHashMap.values.whereNotNull().slices(lookupChunkSize);

if (chunks.isEmpty) {
yield Right(GetPhonebookContactsSuccess(contacts: contacts));
if (contacts.isEmpty) {
yield const Left(GetPhonebookContactsIsEmpty());
} else {
yield Right(GetPhonebookContactsSuccess(contacts: contacts));
}
return;
}

Expand Down Expand Up @@ -85,7 +89,11 @@ class PhonebookContactInteractor {
return contact;
}).toList();

yield Right(GetPhonebookContactsSuccess(contacts: lookupContacts));
if (lookupContacts.isEmpty) {
yield const Left(GetPhonebookContactsIsEmpty());
} else {
yield Right(GetPhonebookContactsSuccess(contacts: lookupContacts));
}
} catch (e) {
Logs().e('PhonebookContactInteractor::error', e);
yield Left(GetPhonebookContactsFailure(exception: e));
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat_details/chat_details_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:fluffychat/pages/chat_details/chat_details.dart';
import 'package:fluffychat/pages/chat_details/chat_details_edit.dart';
import 'package:fluffychat/utils/platform_infos.dart';

import 'package:fluffychat/presentation/model/presentation_contact.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact.dart';
import 'package:flutter/material.dart';

class ChatDetailsRoutes {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat_draft/draft_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:fluffychat/presentation/mixins/common_media_picker_mixin.dart';
import 'package:fluffychat/presentation/mixins/media_picker_mixin.dart';
import 'package:fluffychat/presentation/mixins/send_files_mixin.dart';
import 'package:fluffychat/presentation/model/chat/chat_router_input_argument.dart';
import 'package:fluffychat/presentation/model/presentation_contact.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
import 'package:fluffychat/utils/network_connection_service.dart';
import 'package:fluffychat/utils/platform_infos.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/chat_draft/draft_chat_adaptive_scaffold.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:fluffychat/pages/chat_draft/draft_chat.dart';
import 'package:fluffychat/pages/chat_profile_info/chat_profile_info_navigator.dart';
import 'package:fluffychat/presentation/enum/chat/right_column_type_enum.dart';
import 'package:fluffychat/presentation/model/presentation_contact.dart';
import 'package:fluffychat/presentation/model/presentation_contact_constant.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact_constant.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat_profile_info/chat_profile_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:fluffychat/domain/app_state/contact/lookup_match_contact_state.d
import 'package:fluffychat/domain/usecase/contacts/lookup_match_contact_interactor.dart';
import 'package:fluffychat/pages/chat_profile_info/chat_profile_info_shared/chat_profile_info_shared.dart';
import 'package:fluffychat/pages/chat_profile_info/chat_profile_info_view.dart';
import 'package:fluffychat/presentation/model/presentation_contact.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/cupertino.dart';
import 'package:matrix/matrix.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/cupertino.dart';

import 'package:fluffychat/pages/chat_profile_info/chat_profile_info.dart';
import 'package:fluffychat/presentation/model/presentation_contact.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact.dart';

class ChatProfileInfoRoutes {
static const String profileInfo = '/profileInfo';
Expand Down
17 changes: 14 additions & 3 deletions lib/pages/contacts_tab/contacts_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/presentation/mixins/comparable_presentation_contact_mixin.dart';
import 'package:fluffychat/pages/contacts_tab/contacts_tab_view.dart';
import 'package:fluffychat/presentation/mixins/contacts_view_controller_mixin.dart';
import 'package:fluffychat/presentation/model/presentation_contact.dart';
import 'package:fluffychat/presentation/model/presentation_contact_constant.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact.dart';
import 'package:fluffychat/presentation/model/contact/presentation_contact_constant.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
import 'package:fluffychat/utils/string_extension.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/cupertino.dart';
import 'package:go_router/go_router.dart';
Expand All @@ -28,7 +31,15 @@ class ContactsTabController extends State<ContactsTab>

@override
void initState() {
initialFetchContacts();
SchedulerBinding.instance.addPostFrameCallback((_) async {
if (mounted) {
initialFetchContacts(
client: Matrix.of(context).client,
matrixLocalizations: MatrixLocals(L10n.of(context)!),
);
}
});

_listenFocusTextEditing();
super.initState();
}
Expand Down
Loading
Loading