Compare commits
11 Commits
#MSG01/Imp
...
master
Author | SHA1 | Date |
---|---|---|
|
2d20012fc3 | 2 years ago |
|
5d51df9ca9 | 2 years ago |
![]() |
dfb73d42ff | 2 years ago |
|
41d1e8dbb3 | 2 years ago |
|
ab1c306f5b | 2 years ago |
|
da7fb93d90 | 2 years ago |
|
56e5cd28a4 | 2 years ago |
|
24771535f9 | 2 years ago |
|
52ec509b3d | 2 years ago |
|
a063418d88 | 2 years ago |
|
f3c678c23f | 2 years ago |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 18 KiB |
@ -1,4 +1,4 @@
|
|||||||
avnadmin
|
postgres
|
||||||
AVNS_MA4OWhqM3cOMSwKXlzw
|
mdpDaflBd
|
||||||
pg-206a2fcd-the-3c42.aivencloud.com
|
89.83.54.48
|
||||||
Bd-DaflMusic
|
BD-DaflMusic
|
@ -1,69 +0,0 @@
|
|||||||
// 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,35 +1,8 @@
|
|||||||
import 'user.dart';
|
import 'user.dart';
|
||||||
|
|
||||||
class Message {
|
class Message {
|
||||||
String idSender;
|
String senderId;
|
||||||
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']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,80 +0,0 @@
|
|||||||
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