Skip to content
Snippets Groups Projects
Commit e5ecda2a authored by vjrj's avatar vjrj
Browse files

Add new Contacts to ContactsCache. Comparison of contacts

parent e26abf5c
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart'; ...@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart'; import 'package:hydrated_bloc/hydrated_bloc.dart';
import '../../g1/g1_helper.dart'; import '../../g1/g1_helper.dart';
import '../../ui/contacts_cache.dart';
import '../../ui/ui_helpers.dart'; import '../../ui/ui_helpers.dart';
import 'contact.dart'; import 'contact.dart';
import 'contact_sort_type.dart'; import 'contact_sort_type.dart';
...@@ -42,6 +43,7 @@ class ContactsCubit extends HydratedCubit<ContactsState> { ...@@ -42,6 +43,7 @@ class ContactsCubit extends HydratedCubit<ContactsState> {
filteredContacts: updatedFilteredContacts, filteredContacts: updatedFilteredContacts,
)); ));
} }
ContactsCache().addContact(contact);
} }
void removeContact(Contact contact) { void removeContact(Contact contact) {
...@@ -94,6 +96,7 @@ class ContactsCubit extends HydratedCubit<ContactsState> { ...@@ -94,6 +96,7 @@ class ContactsCubit extends HydratedCubit<ContactsState> {
} }
return c; return c;
}).toList(); }).toList();
ContactsCache().addContact(contact);
emit(state.copyWith(contacts: contacts, filteredContacts: fcontacts)); emit(state.copyWith(contacts: contacts, filteredContacts: fcontacts));
} }
...@@ -197,6 +200,11 @@ class ContactsCubit extends HydratedCubit<ContactsState> { ...@@ -197,6 +200,11 @@ class ContactsCubit extends HydratedCubit<ContactsState> {
@override @override
String get id => 'contacts'; String get id => 'contacts';
bool isContact(String pubKey) => bool isContact(String pubKey) => state.contacts.any(
state.contacts.any((Contact c) => c.pubKey == pubKey); (Contact c) => extractPublicKey(c.pubKey) == extractPublicKey(pubKey));
Contact? getContact(String pubKey) => isContact(pubKey)
? state.contacts.firstWhere(
(Contact c) => extractPublicKey(c.pubKey) == extractPublicKey(pubKey))
: null;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment