Compare commits
33 Commits
master
...
#MSG01/Imp
Author | SHA1 | Date |
---|---|---|
![]() |
9fa0510a87 | 2 years ago |
![]() |
d4a6daf4d2 | 2 years ago |
![]() |
d3cc32a0b8 | 2 years ago |
|
b99d407c91 | 2 years ago |
![]() |
b61f9d6f07 | 2 years ago |
![]() |
a029de17c9 | 2 years ago |
![]() |
b53f683da7 | 2 years ago |
![]() |
48e868084a | 2 years ago |
|
fee30256cc | 2 years ago |
|
a2ee5b35a5 | 2 years ago |
|
6f59204361 | 2 years ago |
|
7a77591c11 | 2 years ago |
|
ae00ce8b76 | 2 years ago |
|
1e5e6f997a | 2 years ago |
|
79e56d12ba | 2 years ago |
|
407bd19f4a | 2 years ago |
![]() |
7880edf861 | 2 years ago |
![]() |
d2b9ca3547 | 2 years ago |
![]() |
d77b18503a | 2 years ago |
|
4f1436fc5b | 2 years ago |
![]() |
a9dd2cd336 | 2 years ago |
![]() |
98afc0967e | 2 years ago |
![]() |
f320c8e113 | 2 years ago |
|
29a513a484 | 2 years ago |
![]() |
a8df8e214e | 2 years ago |
|
67df69604b | 2 years ago |
|
9497713be4 | 2 years ago |
|
dc951b015e | 2 years ago |
|
cee8a2fd80 | 2 years ago |
|
7f35484e2c | 2 years ago |
|
d3afd5714f | 2 years ago |
![]() |
e7402aa914 | 2 years ago |
|
b9a9f72d0c | 2 years ago |
After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 20 KiB |
@ -1,4 +1,4 @@
|
|||||||
postgres
|
avnadmin
|
||||||
mdpDaflBd
|
AVNS_MA4OWhqM3cOMSwKXlzw
|
||||||
89.83.54.48
|
pg-206a2fcd-the-3c42.aivencloud.com
|
||||||
BD-DaflMusic
|
Bd-DaflMusic
|
@ -0,0 +1,69 @@
|
|||||||
|
// File generated by FlutterFire CLI.
|
||||||
|
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
|
||||||
|
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
|
||||||
|
import 'package:flutter/foundation.dart'
|
||||||
|
show defaultTargetPlatform, kIsWeb, TargetPlatform;
|
||||||
|
|
||||||
|
/// Default [FirebaseOptions] for use with your Firebase apps.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// ```dart
|
||||||
|
/// import 'firebase_options.dart';
|
||||||
|
/// // ...
|
||||||
|
/// await Firebase.initializeApp(
|
||||||
|
/// options: DefaultFirebaseOptions.currentPlatform,
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
|
class DefaultFirebaseOptions {
|
||||||
|
static FirebaseOptions get currentPlatform {
|
||||||
|
if (kIsWeb) {
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions have not been configured for web - '
|
||||||
|
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
switch (defaultTargetPlatform) {
|
||||||
|
case TargetPlatform.android:
|
||||||
|
return android;
|
||||||
|
case TargetPlatform.iOS:
|
||||||
|
return ios;
|
||||||
|
case TargetPlatform.macOS:
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions have not been configured for macos - '
|
||||||
|
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||||
|
);
|
||||||
|
case TargetPlatform.windows:
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions have not been configured for windows - '
|
||||||
|
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||||
|
);
|
||||||
|
case TargetPlatform.linux:
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions have not been configured for linux - '
|
||||||
|
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions are not supported for this platform.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const FirebaseOptions android = FirebaseOptions(
|
||||||
|
apiKey: 'AIzaSyBODcBh2wlcYBc0QCQKLKXA46uE64veSvA',
|
||||||
|
appId: '1:743783838712:android:34e4356470b8125ee51c0d',
|
||||||
|
messagingSenderId: '743783838712',
|
||||||
|
projectId: 'daflmusic-b36d2',
|
||||||
|
storageBucket: 'daflmusic-b36d2.appspot.com',
|
||||||
|
);
|
||||||
|
|
||||||
|
static const FirebaseOptions ios = FirebaseOptions(
|
||||||
|
apiKey: 'AIzaSyD2E7KNx6BNyn6U7FqDq65m-i66WXVyjYA',
|
||||||
|
appId: '1:743783838712:ios:d69f49090eb60fb9e51c0d',
|
||||||
|
messagingSenderId: '743783838712',
|
||||||
|
projectId: 'daflmusic-b36d2',
|
||||||
|
storageBucket: 'daflmusic-b36d2.appspot.com',
|
||||||
|
iosClientId: '743783838712-eqfakrghgk4grboprkebadoqe09k0002.apps.googleusercontent.com',
|
||||||
|
iosBundleId: 'com.example.daflProjectFlutter',
|
||||||
|
);
|
||||||
|
}
|
@ -1,8 +1,35 @@
|
|||||||
import 'user.dart';
|
import 'user.dart';
|
||||||
|
|
||||||
class Message {
|
class Message {
|
||||||
String senderId;
|
String idSender;
|
||||||
|
String idReceiver;
|
||||||
String content;
|
String content;
|
||||||
|
String timestamp;
|
||||||
|
|
||||||
Message(this.senderId, this.content);
|
|
||||||
}
|
Message({required this.idSender,
|
||||||
|
required this.idReceiver,
|
||||||
|
required this.content,
|
||||||
|
required this.timestamp
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, dynamic> toHashMap() {
|
||||||
|
return {
|
||||||
|
'idSender': idSender,
|
||||||
|
'idReceiver': idReceiver,
|
||||||
|
'content': content,
|
||||||
|
'timestamp' : timestamp
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
factory Message.fromMap(Map<String, dynamic> data){
|
||||||
|
return Message(
|
||||||
|
idSender: data['idSender'],
|
||||||
|
idReceiver: data['idReceiver'],
|
||||||
|
content: data['content'],
|
||||||
|
timestamp: data['timestamp']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
import 'package:dafl_project_flutter/model/message.dart';
|
||||||
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class MessageDatabaseService{
|
||||||
|
// Make an unique chat ID between 2 client. Look like 'User1-User2'
|
||||||
|
String _getChatId(String idSender, String idReceiver) {
|
||||||
|
// Test to always have the same id
|
||||||
|
if (idSender.hashCode <= idReceiver.hashCode)
|
||||||
|
return '$idSender-${idReceiver}';
|
||||||
|
else
|
||||||
|
return '${idReceiver}-$idSender';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Send a message from an user to an other
|
||||||
|
void sendMessage(Message message, String idSender, String idReceiver) {
|
||||||
|
String chatId = _getChatId(idSender, idReceiver);
|
||||||
|
|
||||||
|
// Get a message from a snapshot Firestore
|
||||||
|
var documentReference = FirebaseFirestore.instance
|
||||||
|
.collection('messages')
|
||||||
|
.doc(chatId)
|
||||||
|
.collection(chatId)
|
||||||
|
.doc(DateTime
|
||||||
|
.now()
|
||||||
|
.millisecondsSinceEpoch
|
||||||
|
.toString());
|
||||||
|
|
||||||
|
FirebaseFirestore.instance.runTransaction((transaction) async {
|
||||||
|
transaction.set(documentReference, message.toHashMap());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Message _getMessage(DocumentSnapshot<Map<String, dynamic>> snapshot) {
|
||||||
|
var data = snapshot.data();
|
||||||
|
if (data == null)
|
||||||
|
throw Exception("no data in database");
|
||||||
|
|
||||||
|
return Message.fromMap(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a list of messages from Firestore
|
||||||
|
List<Message> _getAllMessages(QuerySnapshot<Map<String, dynamic>> snapshot) {
|
||||||
|
return snapshot.docs.map((doc) {
|
||||||
|
return _getMessage(doc);
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the massages from Firestore
|
||||||
|
Stream<List<Message>> getMessage(String idSender, String idReceiver) {
|
||||||
|
String chatId = _getChatId(idSender, idReceiver);
|
||||||
|
return FirebaseFirestore.instance
|
||||||
|
.collection('messages')
|
||||||
|
.doc(chatId)
|
||||||
|
.collection(chatId)
|
||||||
|
.orderBy('timestamp', descending: true)
|
||||||
|
.snapshots().map(_getAllMessages);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void addMessagingUser(String idSender, String idReceiver) {
|
||||||
|
|
||||||
|
// Get a message from a snapshot Firestore
|
||||||
|
var documentReference = FirebaseFirestore.instance
|
||||||
|
.collection('users')
|
||||||
|
.doc(idSender)
|
||||||
|
.collection(idSender)
|
||||||
|
.doc(DateTime
|
||||||
|
.now()
|
||||||
|
.millisecondsSinceEpoch
|
||||||
|
.toString());
|
||||||
|
|
||||||
|
Map<String, dynamic> receiver = { 'user' : idReceiver };
|
||||||
|
|
||||||
|
FirebaseFirestore.instance.runTransaction((transaction) async {
|
||||||
|
transaction.set(documentReference, receiver);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue