diff --git a/melos.yaml b/melos.yaml index 697f842..ca743d9 100644 --- a/melos.yaml +++ b/melos.yaml @@ -15,6 +15,9 @@ scripts: get: run: melos exec -c 1 -- "flutter pub get" + upgrade: + run: melos exec -c 1 -- "flutter pub upgrade" + analyze: run: | melos exec -c 1 -- \ diff --git a/packages/flutter_community_chat/lib/flutter_community_chat.dart b/packages/flutter_community_chat/lib/flutter_community_chat.dart index f367dbe..1fd5684 100644 --- a/packages/flutter_community_chat/lib/flutter_community_chat.dart +++ b/packages/flutter_community_chat/lib/flutter_community_chat.dart @@ -134,6 +134,7 @@ class _CommunityChatState extends State { chats: widget.dataProvider.getChatsStream(), onPressStartChat: () => _onPressStartChat(context), onPressChat: (chat) => _onPressChat(context, chat), + onDeleteChat: (ChatModel chat) => widget.dataProvider.deleteChat(chat), options: widget.options, translations: widget.translations, ); diff --git a/packages/flutter_community_chat/pubspec.lock b/packages/flutter_community_chat/pubspec.lock index 7e98a8f..ab559d6 100644 --- a/packages/flutter_community_chat/pubspec.lock +++ b/packages/flutter_community_chat/pubspec.lock @@ -179,7 +179,7 @@ packages: description: path: "packages/flutter_community_chat_interface" ref: HEAD - resolved-ref: adc7d063039e44e5a76275bed48d336b18271f3d + resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 url: "https://github.com/Iconica-Development/flutter_community_chat.git" source: git version: "0.0.1" @@ -188,7 +188,7 @@ packages: description: path: "packages/flutter_community_chat_view" ref: HEAD - resolved-ref: d10857d28905114c481753cd6193d685b713f028 + resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 url: "https://github.com/Iconica-Development/flutter_community_chat.git" source: git version: "0.0.1" @@ -305,7 +305,7 @@ packages: name: lints url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" logging: dependency: transitive description: diff --git a/packages/flutter_community_chat_firebase/lib/flutter_community_chat_firebase.dart b/packages/flutter_community_chat_firebase/lib/flutter_community_chat_firebase.dart index bc0579b..5682e30 100644 --- a/packages/flutter_community_chat_firebase/lib/flutter_community_chat_firebase.dart +++ b/packages/flutter_community_chat_firebase/lib/flutter_community_chat_firebase.dart @@ -74,4 +74,8 @@ class FirebaseCommunityChatDataProvider extends CommunityChatInterface { @override Future setChat(ChatModel chat) async => await _messageService.setChat(chat); + + @override + Future deleteChat(ChatModel chat) async => + await _chatService.deleteChat(chat); } diff --git a/packages/flutter_community_chat_firebase/lib/service/firebase_chat_service.dart b/packages/flutter_community_chat_firebase/lib/service/firebase_chat_service.dart index 3d7ead6..c6e514b 100644 --- a/packages/flutter_community_chat_firebase/lib/service/firebase_chat_service.dart +++ b/packages/flutter_community_chat_firebase/lib/service/firebase_chat_service.dart @@ -172,15 +172,7 @@ class FirebaseChatService { .collection('chats') .snapshots() .listen((snapshot) { - List chatIds = []; - - for (var chatDoc in snapshot.docs) { - var chatData = chatDoc.data(); - - if (chatData['id'] != null) { - chatIds.add(chatData['id']); - } - } + List chatIds = snapshot.docs.map((chat) => chat.id).toList(); if (chatIds.isNotEmpty) { chatsSubscription = _getSpecificChatsStream(chatIds).listen( @@ -207,12 +199,10 @@ class FirebaseChatService { for (var element in chatCollection.docs) { var data = element.data(); - if (data.containsKey('id') && - data.containsKey('users') && - data['users'] is List) { + if (data.containsKey('users') && data['users'] is List) { if (data['users'].contains(user.id)) { return PersonalChatModel( - id: data['id'], + id: element.id, user: user, ); } @@ -221,4 +211,31 @@ class FirebaseChatService { return null; } + + Future deleteChat(ChatModel chat) async { + var chatCollection = await db + .collection(options.chatsCollectionName) + .doc(chat.id) + .withConverter( + fromFirestore: (snapshot, _) => + FirebaseChatDocument.fromJson(snapshot.data()!, snapshot.id), + toFirestore: (chat, _) => chat.toJson(), + ) + .get(); + + var chatData = chatCollection.data(); + + if (chatData != null) { + for (var userId in chatData.users) { + db + .collection(options.usersCollectionName) + .doc(userId) + .collection('chats') + .doc(chat.id) + .delete(); + } + + await db.collection(options.chatsCollectionName).doc(chat.id).delete(); + } + } } diff --git a/packages/flutter_community_chat_firebase/lib/service/firebase_message_service.dart b/packages/flutter_community_chat_firebase/lib/service/firebase_message_service.dart index 7fec591..e83ae0f 100644 --- a/packages/flutter_community_chat_firebase/lib/service/firebase_message_service.dart +++ b/packages/flutter_community_chat_firebase/lib/service/firebase_message_service.dart @@ -197,7 +197,8 @@ class FirebaseMessageService { .collection(options.usersCollectionName) .doc(userId) .collection('chats') - .add({'id': reference.id, 'users': userIds}); + .doc(reference.id) + .set({'users': userIds}); } chat.id = reference.id; diff --git a/packages/flutter_community_chat_firebase/pubspec.lock b/packages/flutter_community_chat_firebase/pubspec.lock index 77e8892..95b8c68 100644 --- a/packages/flutter_community_chat_firebase/pubspec.lock +++ b/packages/flutter_community_chat_firebase/pubspec.lock @@ -84,7 +84,7 @@ packages: name: cloud_firestore url: "https://pub.dartlang.org" source: hosted - version: "3.2.0" + version: "3.5.1" cloud_firestore_platform_interface: dependency: transitive description: @@ -182,7 +182,7 @@ packages: name: firebase_core_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "4.5.1" + version: "4.5.2" firebase_core_web: dependency: transitive description: @@ -203,7 +203,7 @@ packages: name: firebase_storage_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "4.1.18" + version: "4.1.19" firebase_storage_web: dependency: transitive description: @@ -228,7 +228,7 @@ packages: description: path: "packages/flutter_community_chat_interface" ref: HEAD - resolved-ref: adc7d063039e44e5a76275bed48d336b18271f3d + resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 url: "https://github.com/Iconica-Development/flutter_community_chat.git" source: git version: "0.0.1" @@ -278,7 +278,7 @@ packages: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.1" + version: "4.0.2" intl: dependency: transitive description: @@ -299,7 +299,7 @@ packages: name: lints url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" logging: dependency: transitive description: diff --git a/packages/flutter_community_chat_interface/lib/src/community_chat_interface.dart b/packages/flutter_community_chat_interface/lib/src/community_chat_interface.dart index b29c9f0..f80ff1e 100644 --- a/packages/flutter_community_chat_interface/lib/src/community_chat_interface.dart +++ b/packages/flutter_community_chat_interface/lib/src/community_chat_interface.dart @@ -18,4 +18,5 @@ abstract class CommunityChatInterface extends DataInterface { Stream> getMessagesStream(); Stream> getChatsStream(); Future> getChatUsers(); + Future deleteChat(ChatModel chat); } diff --git a/packages/flutter_community_chat_interface/pubspec.lock b/packages/flutter_community_chat_interface/pubspec.lock index 3a232f5..dc431b3 100644 --- a/packages/flutter_community_chat_interface/pubspec.lock +++ b/packages/flutter_community_chat_interface/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "49.0.0" + version: "50.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "5.1.0" + version: "5.2.0" args: dependency: transitive description: @@ -28,14 +28,14 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.9.0" + version: "2.10.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" build: dependency: transitive description: @@ -56,7 +56,7 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.4.1" + version: "8.4.2" characters: dependency: transitive description: @@ -84,7 +84,7 @@ packages: name: convert url: "https://pub.dartlang.org" source: hosted - version: "3.0.2" + version: "3.1.1" crypto: dependency: transitive description: @@ -123,7 +123,7 @@ packages: description: path: "." ref: master - resolved-ref: e348c921d5e621975e4f06d3eeff8e8a89dda109 + resolved-ref: "500ed1d08095b33387ae3aa4ed1a2ad4d2fb2ac3" url: "https://github.com/Iconica-Development/flutter_data_interface.git" source: git version: "1.0.0" @@ -147,7 +147,7 @@ packages: name: lints url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" logging: dependency: transitive description: @@ -161,7 +161,7 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.12" + version: "0.12.13" material_color_utilities: dependency: transitive description: @@ -203,7 +203,7 @@ packages: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" sky_engine: dependency: transitive description: flutter @@ -215,7 +215,7 @@ packages: name: source_gen url: "https://pub.dartlang.org" source: hosted - version: "1.2.5" + version: "1.2.6" source_span: dependency: transitive description: @@ -229,7 +229,7 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: @@ -243,7 +243,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.1" + version: "1.2.0" term_glyph: dependency: transitive description: @@ -257,7 +257,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.14" + version: "0.4.16" typed_data: dependency: transitive description: @@ -278,7 +278,7 @@ packages: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" yaml: dependency: transitive description: diff --git a/packages/flutter_community_chat_view/example/pubspec.lock b/packages/flutter_community_chat_view/example/pubspec.lock index ee6f49d..5711407 100644 --- a/packages/flutter_community_chat_view/example/pubspec.lock +++ b/packages/flutter_community_chat_view/example/pubspec.lock @@ -186,7 +186,7 @@ packages: description: path: "packages/flutter_community_chat_interface" ref: HEAD - resolved-ref: adc7d063039e44e5a76275bed48d336b18271f3d + resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 url: "https://github.com/Iconica-Development/flutter_community_chat.git" source: git version: "0.0.1" @@ -252,7 +252,7 @@ packages: name: lints url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" logging: dependency: transitive description: diff --git a/packages/flutter_community_chat_view/lib/src/config/chat_translations.dart b/packages/flutter_community_chat_view/lib/src/config/chat_translations.dart index 4bdc3d2..82b428d 100644 --- a/packages/flutter_community_chat_view/lib/src/config/chat_translations.dart +++ b/packages/flutter_community_chat_view/lib/src/config/chat_translations.dart @@ -12,11 +12,13 @@ class ChatTranslations { this.cancelImagePickerBtn = 'Cancel', this.messagePlaceholder = 'Write your message here...', this.imageUploading = 'Image is uploading...', + this.deleteChatButton = 'Delete', }); final String chatsTitle; final String newChatButton; final String newChatTitle; + final String deleteChatButton; final String image; final String searchPlaceholder; final String cancelImagePickerBtn; diff --git a/packages/flutter_community_chat_view/lib/src/screens/chat_screen.dart b/packages/flutter_community_chat_view/lib/src/screens/chat_screen.dart index 385bce6..372be88 100644 --- a/packages/flutter_community_chat_view/lib/src/screens/chat_screen.dart +++ b/packages/flutter_community_chat_view/lib/src/screens/chat_screen.dart @@ -13,6 +13,7 @@ class ChatScreen extends StatefulWidget { required this.chats, required this.onPressStartChat, required this.onPressChat, + required this.onDeleteChat, this.translations = const ChatTranslations(), super.key, }); @@ -21,6 +22,7 @@ class ChatScreen extends StatefulWidget { final ChatTranslations translations; final Stream> chats; final VoidCallback? onPressStartChat; + final void Function(ChatModel chat) onDeleteChat; final void Function(ChatModel chat) onPressChat; @override @@ -39,37 +41,56 @@ class _ChatScreenState extends State { children: [ Expanded( child: ListView( - padding: const EdgeInsets.only( - top: 15.0, - ), + padding: const EdgeInsets.only(top: 15.0), children: [ StreamBuilder>( stream: widget.chats, builder: (BuildContext context, snapshot) => Column( children: [ for (ChatModel chat in snapshot.data ?? []) - GestureDetector( - onTap: () => widget.onPressChat(chat), - child: widget.options.chatRowContainerBuilder( - ChatRow( - image: chat is PersonalChatModel - ? chat.user.imageUrl - : (chat as GroupChatModel).imageUrl, - title: chat is PersonalChatModel - ? chat.user.name ?? '' - : (chat as GroupChatModel).title, - subTitle: chat.lastMessage != null - ? chat.lastMessage is ChatTextMessageModel - ? (chat.lastMessage! - as ChatTextMessageModel) - .text - : '📷 ${widget.translations.image}' - : null, - lastUsed: chat.lastUsed != null - ? _dateFormatter.format( - date: chat.lastUsed!, - ) - : null, + Builder( + builder: (context) => Dismissible( + onDismissed: (_) => widget.onDeleteChat(chat), + background: Container( + color: Colors.red, + child: Align( + alignment: Alignment.centerRight, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text( + widget.translations.deleteChatButton, + ), + ), + ), + ), + key: Key( + chat.id.toString(), + ), + child: GestureDetector( + onTap: () => widget.onPressChat(chat), + child: widget.options.chatRowContainerBuilder( + ChatRow( + image: chat is PersonalChatModel + ? chat.user.imageUrl + : (chat as GroupChatModel).imageUrl, + title: chat is PersonalChatModel + ? chat.user.name ?? '' + : (chat as GroupChatModel).title, + subTitle: chat.lastMessage != null + ? chat.lastMessage + is ChatTextMessageModel + ? (chat.lastMessage! + as ChatTextMessageModel) + .text + : '📷 ${widget.translations.image}' + : null, + lastUsed: chat.lastUsed != null + ? _dateFormatter.format( + date: chat.lastUsed!, + ) + : null, + ), + ), ), ), ), diff --git a/packages/flutter_community_chat_view/pubspec.lock b/packages/flutter_community_chat_view/pubspec.lock index bd3f55b..569316c 100644 --- a/packages/flutter_community_chat_view/pubspec.lock +++ b/packages/flutter_community_chat_view/pubspec.lock @@ -179,7 +179,7 @@ packages: description: path: "packages/flutter_community_chat_interface" ref: HEAD - resolved-ref: adc7d063039e44e5a76275bed48d336b18271f3d + resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 url: "https://github.com/Iconica-Development/flutter_community_chat.git" source: git version: "0.0.1" @@ -238,7 +238,7 @@ packages: name: lints url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" logging: dependency: transitive description: