post merge commit
This commit is contained in:
@@ -25,17 +25,28 @@ class MessagingProviders extends ChangeNotifier {
|
||||
late final Account account;
|
||||
late final Databases database;
|
||||
late final Storage storage;
|
||||
late final Realtime realtime;
|
||||
late final RealtimeSubscription? subscription;
|
||||
|
||||
// Auth Status
|
||||
AuthStatus? status;
|
||||
late model.User? user;
|
||||
|
||||
static MessagingProviders instance = MessagingProviders();
|
||||
|
||||
|
||||
MessagingProviders() {
|
||||
_init();
|
||||
_loadUser();
|
||||
subscribe();
|
||||
}
|
||||
|
||||
subscribe() {
|
||||
subscription = realtime.subscribe(
|
||||
[
|
||||
'database.${Constants.instance.databaseId}.chats',
|
||||
'database.${Constants.instance.databaseId}.conversations'
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_init() {
|
||||
@@ -46,6 +57,7 @@ class MessagingProviders extends ChangeNotifier {
|
||||
account = Account(client);
|
||||
database = Databases(client);
|
||||
storage = Storage(client);
|
||||
realtime = Realtime(client);
|
||||
}
|
||||
|
||||
_loadUser() async {
|
||||
@@ -215,7 +227,7 @@ class MessagingProviders extends ChangeNotifier {
|
||||
for (var _document in _documentList.documents) {
|
||||
_returnValue.add(User.fromData(_document));
|
||||
}
|
||||
_returnValue.sort((a,b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
_returnValue.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
return _returnValue;
|
||||
},
|
||||
);
|
||||
@@ -256,39 +268,48 @@ class MessagingProviders extends ChangeNotifier {
|
||||
// }
|
||||
}
|
||||
|
||||
Future<List<Conversations>> getUserConversations(String userId) async {
|
||||
List<dynamic> _chatId = [];
|
||||
List<dynamic> _details = [];
|
||||
List<dynamic> _lastModified = [];
|
||||
List<Conversations> _returnValue = [];
|
||||
|
||||
// Stream<List<Conversations>> getUserConversations(String userId) async* {
|
||||
// //
|
||||
// // while (true) {
|
||||
// List<dynamic> _chatId = [];
|
||||
// List<dynamic> _details = [];
|
||||
// List<dynamic> _lastModified = [];
|
||||
// List<Conversations> _returnValue = [];
|
||||
var _document = await database.getDocument(
|
||||
databaseId: Constants.instance.databaseId,
|
||||
collectionId: Constants.instance.convCollectionId,
|
||||
documentId: userId.trim(),
|
||||
);
|
||||
|
||||
// var _conversationData = await database.getDocument(
|
||||
// databaseId: Constants.instance.databaseId,
|
||||
// collectionId: Constants.instance.convCollectionId,
|
||||
// documentId: userId.trim(),
|
||||
// );
|
||||
_chatId = _document.data['chatId'];
|
||||
_details = _document.data['details'];
|
||||
_lastModified = _document.data['lastModified'];
|
||||
|
||||
// yield _conversationData.toMap map(
|
||||
// (_snapshot) {
|
||||
// _chatId = _snapshot.data['chatId'];
|
||||
// _details = _snapshot.data['details'];
|
||||
// _lastModified = _snapshot.data['lastModified'];
|
||||
for (int i = 0; i < _chatId.length; i++) {
|
||||
_returnValue.add(
|
||||
Conversations.fromData(_chatId[i], _details[i], _lastModified[i]));
|
||||
}
|
||||
_returnValue.sort((a, b) => b.lastModified!.compareTo(a.lastModified!));
|
||||
|
||||
// for (int i = 0; i < _chatId.length; i++) {
|
||||
// _returnValue.add(Conversations.fromData(
|
||||
// _chatId[i], _details[i], _lastModified[i]));
|
||||
// }
|
||||
// _returnValue.sort((a, b) => b.lastModified!.compareTo(a.lastModified!));
|
||||
// return _returnValue;
|
||||
// },
|
||||
// );
|
||||
// // }
|
||||
// }
|
||||
return _returnValue;
|
||||
// .then((document) {
|
||||
// _chatId = document.data['chatId'];
|
||||
// _details = document.data['details'];
|
||||
// _lastModified = document.data['lastModified'];
|
||||
|
||||
// for (int i = 0; i < _chatId.length; i++) {
|
||||
// _returnValue.add(
|
||||
// Conversations.fromData(_chatId[i], _details[i], _lastModified[i]));
|
||||
// }
|
||||
// _returnValue.sort((a, b) => b.lastModified!.compareTo(a.lastModified!));
|
||||
|
||||
// //conversationsController.add(_returnValue);
|
||||
// }).catchError((error) {
|
||||
// _returnValue;
|
||||
// // conversationsController.addError(error);
|
||||
// });
|
||||
|
||||
// return Future.delayed(Duration(microseconds: 300));
|
||||
}
|
||||
|
||||
Stream<Chats> getMessage(String _chatId) async* {
|
||||
//
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:messaging_app/service/snackbar_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class ConversationsPage extends StatefulWidget {
|
||||
ConversationsPage({
|
||||
super.key,
|
||||
|
||||
@@ -26,16 +26,36 @@ class RecentConverstationsPage extends StatefulWidget {
|
||||
|
||||
class _RecentConverstationsPageState extends State<RecentConverstationsPage> {
|
||||
late MessagingProviders _auth;
|
||||
List<Conversations> streamData = [];
|
||||
|
||||
final myController = StreamController<List<Conversations>>.broadcast();
|
||||
Stream<List<Conversations>> get messageStream => myController.stream;
|
||||
|
||||
void messager() {
|
||||
MessagingProviders.instance.getUserConversation(_auth.user!.$id);
|
||||
// To listen to the conversations stream
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
loadStream();
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
myController.close();
|
||||
loadStream() async {
|
||||
streamData =
|
||||
await MessagingProviders.instance.getUserConversations(_auth.user!.$id);
|
||||
}
|
||||
|
||||
subscribe() {
|
||||
MessagingProviders.instance.subscription!.stream.listen((data) {
|
||||
final event = data.events.first;
|
||||
if (event.endsWith('.create')) {
|
||||
streamData.add(data.payload['']);
|
||||
} else if (event.endsWith('.update')) {}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
MessagingProviders.instance.subscription!.stream.listen((data) {
|
||||
final event = data.events.first;
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:messaging_app/service/navigation_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class SearchPage extends StatefulWidget {
|
||||
SearchPage({
|
||||
super.key,
|
||||
|
||||
Reference in New Issue
Block a user