Skip to content

Commit 8879e04

Browse files
Merge pull request #65 from SAMA-Communications/development
Release 0.9.0
2 parents 635dccb + 96604c5 commit 8879e04

47 files changed

Lines changed: 684 additions & 340 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
API_KEY_ANDROID=YOUR_API_KEY
2+
APP_ID_ANDROID=YOUR_APP_ID
3+
MESSAGING_SENDER_ID_ANDROID=YOUR_MESSAGING_SENDER_ID
4+
PROJECT_ID_ANDROID=YOUR_PROJECT_ID
5+
STORAGE_BUCKET_ANDROID=YOUR_STORAGE_BUCKET
6+
7+
API_KEY_IOS=YOUR_API_KEY
8+
APP_ID_IOS=YOUR_APP_ID
9+
MESSAGING_SENDER_ID_IOS=YOUR_MESSAGING_SENDER_ID
10+
PROJECT_ID_IOS=YOUR_PROJECT_ID
11+
STORAGE_BUCKET_IOS=YOUR_STORAGE_BUCKET
12+
IOS_BUNDLE_ID_IOS=YOUR_IOS_BUNDLE_ID

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pubspec.lock
1212
doc/api/
1313

1414
# dotenv environment variables file
15-
.env*
15+
.env
1616

1717
# Avoid committing generated Javascript files:
1818
*.dart.js

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 0.9.0
4+
5+
### Features:
6+
- Implemented offline mode for chats
7+
- Implemented offline mode for messages
8+
- Improved message attachments caching
9+
310
## 0.8.0
411

512
### Features:

lib/firebase_options.dart

Lines changed: 0 additions & 68 deletions
This file was deleted.

lib/main.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import 'package:firebase_core/firebase_core.dart';
22
import 'package:firebase_messaging/firebase_messaging.dart';
3-
import 'firebase_options.dart';
43
import 'package:flutter/material.dart';
54
import 'package:flutter_bloc/flutter_bloc.dart';
65

6+
import 'sama_firebase_options.dart';
77
import 'src/api/api.dart';
88
import 'src/db/db_service.dart';
9+
import 'src/db/local/attachment_local_datasource.dart';
910
import 'src/db/local/conversation_local_datasource.dart';
1011
import 'src/db/local/message_local_datasource.dart';
1112
import 'src/db/local/user_local_datasource.dart';
@@ -18,6 +19,7 @@ import 'src/repository/messages/messages_repository.dart';
1819
import 'src/repository/user/user_repository.dart';
1920
import 'src/shared/auth/bloc/auth_bloc.dart';
2021
import 'src/shared/connection/bloc/connection_bloc.dart';
22+
import 'src/shared/messages_collector/messages_collector.dart';
2123
import 'src/shared/push_notifications/bloc/push_notifications_bloc.dart';
2224
import 'src/shared/secure_storage.dart';
2325
import 'src/shared/sharing/bloc/sharing_intent_bloc.dart';
@@ -29,7 +31,7 @@ final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
2931
Future<void> main() async {
3032
WidgetsFlutterBinding.ensureInitialized();
3133
await Firebase.initializeApp(
32-
options: DefaultFirebaseOptions.currentPlatform,
34+
options: await SamaFirebaseOptions.currentPlatform,
3335
);
3436
FirebaseMessaging.onBackgroundMessage(onBackgroundMessage);
3537
DatabaseService.instance.init();
@@ -53,6 +55,7 @@ class _AppState extends State<App> {
5355
late final MessageLocalDatasource _messageLocalDatasource;
5456
late final AttachmentsRepository _attachmentsRepository;
5557
late final UserLocalDataSource _userLocalDataSource;
58+
late final AttachmentLocalDatasource _attachmentLocalDatasource;
5659

5760
@override
5861
void initState() {
@@ -61,26 +64,30 @@ class _AppState extends State<App> {
6164
_conversationLocalDatasource = ConversationLocalDatasource();
6265
_messageLocalDatasource = MessageLocalDatasource();
6366
_userLocalDataSource = UserLocalDataSource();
67+
_attachmentLocalDatasource = AttachmentLocalDatasource();
6468
_userRepository = UserRepository(localDataSource: _userLocalDataSource);
6569
_authenticationRepository = AuthenticationRepository(_userRepository);
6670
_messagesRepository = MessagesRepository(
6771
localDatasource: _messageLocalDatasource,
6872
userRepository: _userRepository);
69-
_attachmentsRepository = AttachmentsRepository();
73+
_attachmentsRepository = AttachmentsRepository(_attachmentLocalDatasource);
7074
_conversationRepository = ConversationRepository(
7175
localDatasource: _conversationLocalDatasource,
7276
userRepository: _userRepository,
7377
messagesRepository: _messagesRepository);
7478
_globalSearchRepository = GlobalSearchRepository(
7579
conversationRepository: _conversationRepository,
7680
userRepository: _userRepository);
81+
MessagesCollector.instance
82+
.init(_conversationRepository, _messagesRepository);
7783
}
7884

7985
@override
8086
void dispose() {
8187
_authenticationRepository.dispose();
8288
_messagesRepository.dispose();
8389
_conversationRepository.dispose();
90+
MessagesCollector.instance.destroy();
8491
DatabaseService.instance.close();
8592
super.dispose();
8693
}
@@ -113,7 +120,10 @@ class _AppState extends State<App> {
113120
create: (context) => AuthenticationBloc(
114121
authenticationRepository: _authenticationRepository),
115122
),
116-
BlocProvider(create: (context) => ConnectionBloc(), lazy: false),
123+
BlocProvider(
124+
create: (context) => ConnectionBloc(
125+
authenticationRepository: _authenticationRepository),
126+
lazy: false),
117127
BlocProvider(create: (context) => SharingIntentBloc()),
118128
BlocProvider(
119129
create: (context) => PushNotificationsBloc(

lib/objectbox-model.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"entities": [
66
{
77
"id": "8:6709400528399140612",
8-
"lastPropertyId": "4:2743437583742703683",
8+
"lastPropertyId": "5:5717160279142175066",
99
"name": "AttachmentModel",
1010
"properties": [
1111
{
@@ -18,8 +18,8 @@
1818
"id": "2:747399038920962484",
1919
"name": "fileId",
2020
"type": 9,
21-
"flags": 34848,
22-
"indexId": "15:626623788693270148"
21+
"flags": 2080,
22+
"indexId": "37:873959491954871870"
2323
},
2424
{
2525
"id": "3:768953523524252804",
@@ -30,6 +30,11 @@
3030
"id": "4:2743437583742703683",
3131
"name": "fileBlurHash",
3232
"type": 9
33+
},
34+
{
35+
"id": "5:5717160279142175066",
36+
"name": "url",
37+
"type": 9
3338
}
3439
],
3540
"relations": []
@@ -302,7 +307,7 @@
302307
}
303308
],
304309
"lastEntityId": "13:9106374520578572502",
305-
"lastIndexId": "35:2642777293408708995",
310+
"lastIndexId": "37:873959491954871870",
306311
"lastRelationId": "5:7785256265115248397",
307312
"lastSequenceId": "0:0",
308313
"modelVersion": 5,
@@ -323,7 +328,9 @@
323328
8590772032330868498,
324329
8137762055088700512,
325330
7050184320199163165,
326-
5813459946923529345
331+
5813459946923529345,
332+
626623788693270148,
333+
6221333517652902864
327334
],
328335
"retiredPropertyUids": [
329336
5244948909752663107,

lib/objectbox.g.dart

Lines changed: 24 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/sama_firebase_options.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:firebase_core/firebase_core.dart';
2+
import 'package:flutter/foundation.dart';
3+
import 'package:flutter_dotenv/flutter_dotenv.dart';
4+
5+
class SamaFirebaseOptions {
6+
static Future<FirebaseOptions> get currentPlatform async {
7+
try {
8+
await dotenv.load(fileName: ".env");
9+
} catch (e) {
10+
print('Error loading .env file: $e');
11+
}
12+
switch (defaultTargetPlatform) {
13+
case TargetPlatform.android:
14+
return android;
15+
case TargetPlatform.iOS:
16+
return ios;
17+
default:
18+
throw UnsupportedError(
19+
'SamaFirebaseOptions are not supported for this platform.',
20+
);
21+
}
22+
}
23+
24+
static FirebaseOptions android = FirebaseOptions(
25+
apiKey: dotenv.env['API_KEY_ANDROID'] ?? '',
26+
appId: dotenv.env['APP_ID_ANDROID'] ?? '',
27+
messagingSenderId: dotenv.env['MESSAGING_SENDER_ID_ANDROID'] ?? '',
28+
projectId: dotenv.env['PROJECT_ID_ANDROID'] ?? '',
29+
storageBucket: dotenv.env['STORAGE_BUCKET_ANDROID'] ?? '',
30+
);
31+
32+
static FirebaseOptions ios = FirebaseOptions(
33+
apiKey: dotenv.env['API_KEY_IOS'] ?? '',
34+
appId: dotenv.env['APP_ID_IOS'] ?? '',
35+
messagingSenderId: dotenv.env['MESSAGING_SENDER_ID_IOS'] ?? '',
36+
projectId: dotenv.env['PROJECT_ID_IOS'] ?? '',
37+
storageBucket: dotenv.env['STORAGE_BUCKET_IOS'] ?? '',
38+
iosBundleId: dotenv.env['IOS_BUNDLE_ID_IOS'] ?? '',
39+
);
40+
}

lib/src/api/chats/messages_api.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ Future<bool> sendMessage({
2121
if (message.attachments != null) 'attachments': message.attachments,
2222
};
2323

24+
if (SamaConnectionService.instance.connectionState !=
25+
ConnectionState.connected) {
26+
return Future.value(false);
27+
}
28+
2429
return SamaConnectionService.instance
25-
.sendRequest(messageRequestName, dataToSend, retryRequestId: message.id)
30+
.sendRequest(messageRequestName, dataToSend,
31+
retryRequestId: message.id, shouldRetry: false)
2632
.timeout(messageRequestTimeout)
2733
.then((response) {
2834
if (message.id == response['mid']) {

0 commit comments

Comments
 (0)