Compare commits
6 Commits
master
...
#MSG01/cha
Author | SHA1 | Date |
---|---|---|
|
bd1e2efa2e | 2 years ago |
|
27e970a3b9 | 2 years ago |
|
77de0b8384 | 2 years ago |
|
974b046f72 | 2 years ago |
|
308bfd95cd | 2 years ago |
|
32dd6c986c | 2 years ago |
@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"project_info": {
|
||||||
|
"project_number": "943188299704",
|
||||||
|
"project_id": "daflmusic-b3b74",
|
||||||
|
"storage_bucket": "daflmusic-b3b74.appspot.com"
|
||||||
|
},
|
||||||
|
"client": [
|
||||||
|
{
|
||||||
|
"client_info": {
|
||||||
|
"mobilesdk_app_id": "1:943188299704:android:995199bd5229a330a9c94d",
|
||||||
|
"android_client_info": {
|
||||||
|
"package_name": "com.example.dafl_project_flutter"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "943188299704-qp12a784hmdo97v7qq78ekasgrfkmo52.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"api_key": [
|
||||||
|
{
|
||||||
|
"current_key": "AIzaSyBehHyqsXbBm1I7fBSG2bPOQvpDX-8Rm7I"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": {
|
||||||
|
"appinvite_service": {
|
||||||
|
"other_platform_oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "943188299704-qp12a784hmdo97v7qq78ekasgrfkmo52.apps.googleusercontent.com",
|
||||||
|
"client_type": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"configuration_version": "1"
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CLIENT_ID</key>
|
||||||
|
<string>943188299704-h4035qno57lll2km151rdh3bgbb22vk7.apps.googleusercontent.com</string>
|
||||||
|
<key>REVERSED_CLIENT_ID</key>
|
||||||
|
<string>com.googleusercontent.apps.943188299704-h4035qno57lll2km151rdh3bgbb22vk7</string>
|
||||||
|
<key>API_KEY</key>
|
||||||
|
<string>AIzaSyCnQnCeu7gdc1_uIOxXVNQT1pG8xjD_tB8</string>
|
||||||
|
<key>GCM_SENDER_ID</key>
|
||||||
|
<string>943188299704</string>
|
||||||
|
<key>PLIST_VERSION</key>
|
||||||
|
<string>1</string>
|
||||||
|
<key>BUNDLE_ID</key>
|
||||||
|
<string>com.example.daflProjectFlutter</string>
|
||||||
|
<key>PROJECT_ID</key>
|
||||||
|
<string>daflmusic-b3b74</string>
|
||||||
|
<key>STORAGE_BUCKET</key>
|
||||||
|
<string>daflmusic-b3b74.appspot.com</string>
|
||||||
|
<key>IS_ADS_ENABLED</key>
|
||||||
|
<false></false>
|
||||||
|
<key>IS_ANALYTICS_ENABLED</key>
|
||||||
|
<false></false>
|
||||||
|
<key>IS_APPINVITE_ENABLED</key>
|
||||||
|
<true></true>
|
||||||
|
<key>IS_GCM_ENABLED</key>
|
||||||
|
<true></true>
|
||||||
|
<key>IS_SIGNIN_ENABLED</key>
|
||||||
|
<true></true>
|
||||||
|
<key>GOOGLE_APP_ID</key>
|
||||||
|
<string>1:943188299704:ios:bd6866b329aebb64a9c94d</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"file_generated_by": "FlutterFire CLI",
|
||||||
|
"purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory",
|
||||||
|
"GOOGLE_APP_ID": "1:943188299704:ios:bd6866b329aebb64a9c94d",
|
||||||
|
"FIREBASE_PROJECT_ID": "daflmusic-b3b74",
|
||||||
|
"GCM_SENDER_ID": "943188299704"
|
||||||
|
}
|
@ -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: 'AIzaSyBehHyqsXbBm1I7fBSG2bPOQvpDX-8Rm7I',
|
||||||
|
appId: '1:943188299704:android:995199bd5229a330a9c94d',
|
||||||
|
messagingSenderId: '943188299704',
|
||||||
|
projectId: 'daflmusic-b3b74',
|
||||||
|
storageBucket: 'daflmusic-b3b74.appspot.com',
|
||||||
|
);
|
||||||
|
|
||||||
|
static const FirebaseOptions ios = FirebaseOptions(
|
||||||
|
apiKey: 'AIzaSyCnQnCeu7gdc1_uIOxXVNQT1pG8xjD_tB8',
|
||||||
|
appId: '1:943188299704:ios:bd6866b329aebb64a9c94d',
|
||||||
|
messagingSenderId: '943188299704',
|
||||||
|
projectId: 'daflmusic-b3b74',
|
||||||
|
storageBucket: 'daflmusic-b3b74.appspot.com',
|
||||||
|
iosClientId: '943188299704-h4035qno57lll2km151rdh3bgbb22vk7.apps.googleusercontent.com',
|
||||||
|
iosBundleId: 'com.example.daflProjectFlutter',
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
import 'package:dafl_project_flutter/model/message.dart';
|
||||||
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
|
||||||
|
class MessageDatabaseServices {
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
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());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a message from a snapshot Firestore
|
||||||
|
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)
|
||||||
|
.snapshots()
|
||||||
|
.map(_getAllMessages);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
|
|
||||||
|
class NotificationService {
|
||||||
|
static void initialize() {
|
||||||
|
FirebaseMessaging.instance.requestPermission();
|
||||||
|
|
||||||
|
FirebaseMessaging.onMessage.listen((event) {
|
||||||
|
print('A new onMessage event was published!');
|
||||||
|
});
|
||||||
|
|
||||||
|
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||||
|
print('A new onMessageOpenedApp event was published!');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String?> getToken() async {
|
||||||
|
return FirebaseMessaging.instance.getToken(
|
||||||
|
vapidKey:
|
||||||
|
"BOxfduRivQnT8TS1h9WRGEk4gV2IOzJpTCcoKxVTMgVWjxi6TUcQBng2mqM7fUfNy51esFrRGE68coa0XZaKdHc");
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,34 @@
|
|||||||
import 'user.dart';
|
import 'user.dart';
|
||||||
|
|
||||||
class Message {
|
class Message {
|
||||||
User sender;
|
String idSender;
|
||||||
|
String idReceiver;
|
||||||
String content;
|
String content;
|
||||||
|
|
||||||
Message(this.sender, this.content);
|
Message({
|
||||||
|
required this.idSender,
|
||||||
|
required this.idReceiver,
|
||||||
|
required this.content,
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, dynamic> toHashMap() {
|
||||||
|
return {
|
||||||
|
'idSender': idSender,
|
||||||
|
'idReceiver': idReceiver,
|
||||||
|
'content': content,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory Message.fromMap(Map<String, dynamic> data) {
|
||||||
|
return Message(
|
||||||
|
idSender: data['idSender'],
|
||||||
|
idReceiver: data['idReceiver'],
|
||||||
|
content: data['content'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return "idSender : $idSender " + "Content : $content \n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue