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