Skip to content

Commit 4881014

Browse files
Merge pull request #72 from SAMA-Communications/development
Release 0.11.0
2 parents 9a62b71 + c7220b8 commit 4881014

31 files changed

Lines changed: 455 additions & 147 deletions

CHANGELOG.md

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

3+
## 0.11.0
4+
5+
### Features:
6+
- Implemented the Draft feature to locally save unsent messages
7+
- Added support for Programmable Chat
8+
- Added support for verifying that a user belongs to a specific organization
9+
10+
### Fixes:
11+
- Improved real-time updates for Online status to enhance compatibility with the web app
12+
313
## 0.10.0
414

515
### Features:

lib/objectbox-model.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
},
214214
{
215215
"id": "13:9106374520578572502",
216-
"lastPropertyId": "15:8834178211781701775",
216+
"lastPropertyId": "16:8214829155225431382",
217217
"name": "ConversationModel",
218218
"properties": [
219219
{
@@ -295,6 +295,14 @@
295295
"id": "15:8834178211781701775",
296296
"name": "isEncrypted",
297297
"type": 1
298+
},
299+
{
300+
"id": "16:8214829155225431382",
301+
"name": "draftMessageBindId",
302+
"type": 11,
303+
"flags": 520,
304+
"indexId": "38:1718185030575189588",
305+
"relationTarget": "MessageModel"
298306
}
299307
],
300308
"relations": [
@@ -307,7 +315,7 @@
307315
}
308316
],
309317
"lastEntityId": "13:9106374520578572502",
310-
"lastIndexId": "37:873959491954871870",
318+
"lastIndexId": "38:1718185030575189588",
311319
"lastRelationId": "5:7785256265115248397",
312320
"lastSequenceId": "0:0",
313321
"modelVersion": 5,

lib/objectbox.g.dart

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

lib/src/api/chats/messages_api.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import '../connection/connection.dart';
2-
import '../conversations/models/models.dart';
3-
import 'realtime/models/models.dart';
1+
import '../api.dart';
42

53
const String messageRequestName = 'message';
64
const String messageEditRequestName = 'message_edit';
@@ -10,7 +8,7 @@ const String messagesDeleteRequestName = 'message_delete';
108

119
const messageRequestTimeout = Duration(seconds: 5);
1210

13-
Future<bool> sendMessage({
11+
Future<(bool, Message?)> sendMessage({
1412
required Message message,
1513
}) {
1614
var dataToSend = {
@@ -23,7 +21,7 @@ Future<bool> sendMessage({
2321

2422
if (SamaConnectionService.instance.connectionState !=
2523
ConnectionState.connected) {
26-
return Future.value(false);
24+
return Future.value((false, null));
2725
}
2826

2927
return SamaConnectionService.instance
@@ -32,11 +30,16 @@ Future<bool> sendMessage({
3230
.timeout(messageRequestTimeout)
3331
.then((response) {
3432
if (message.id == response['mid']) {
35-
return true;
33+
if (response['bot_message'] != null) {
34+
return (true, Message.fromJson(response['bot_message']));
35+
} else if (response['modified'] != null) {
36+
var msg = message.copyWith(
37+
body: response['modified']['body'], extension: {'modified': true});
38+
return (true, msg);
39+
}
40+
return (true, null);
3641
}
37-
return false;
38-
}).catchError((onError) {
39-
return false;
42+
return (false, null);
4043
});
4144
}
4245

lib/src/api/chats/realtime/models/message_statuses.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,25 @@ class PendingMessageStatus implements MessageSendStatus {
3333
class SentMessageStatus implements MessageSendStatus {
3434
final String messageId; // mid
3535
final String serverMessageId; // server_mid
36-
final DateTime time; // t
36+
final int time; // t
3737

3838
SentMessageStatus.fromJson(Map<String, dynamic> json)
3939
: messageId = json['mid'],
4040
serverMessageId = json['server_mid'],
41-
time = DateTime.parse(json['t'].toString());
41+
time = json['t'];
4242
}
4343

4444
class ReadMessagesStatus extends MessageStatus implements MessageSendStatus {
4545
ReadMessagesStatus.fromJson(super.json) : super.fromJson();
4646
}
4747

48+
class FailedMessagesStatus implements MessageSendStatus {
49+
final String messageId;
50+
51+
FailedMessagesStatus.fromJson(Map<String, dynamic> json)
52+
: messageId = json['mid'];
53+
}
54+
4855
class EditMessageStatus {
4956
final String messageId; // id
5057
final String newBody; // body

lib/src/api/connection/http_request.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Future<Map<String, dynamic>> sendHTTPRequest(
1313
String requestName, dynamic requestData,
1414
[Map? requestHeaders]) async {
1515
final url = 'https://${await SecureStorage.instance.getEnvironmentUrl()}';
16+
final orgId = await SecureStorage.instance.getEnvironmentOrgId();
17+
requestData['organization_id'] = orgId;
1618
var urlQuery = buildQueryUrl(url, [requestName]);
1719
var body = jsonEncode(requestData);
1820
Map<String, String> headers = Map.of(_headers);

lib/src/api/conversations/models/message.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,32 @@ class Message extends Equatable {
4949
't': createdAt,
5050
};
5151

52+
Message copyWith({
53+
String? id,
54+
String? from,
55+
String? cid,
56+
String? rawStatus,
57+
String? body,
58+
List<Attachment>? attachments,
59+
int? t,
60+
DateTime? createdAt,
61+
Map<String, dynamic>? extension,
62+
}) {
63+
return Message(
64+
id: id ?? this.id,
65+
from: from ?? this.from,
66+
cid: cid ?? this.cid,
67+
rawStatus: rawStatus ?? this.rawStatus,
68+
body: body ?? this.body,
69+
attachments: attachments ?? this.attachments,
70+
t: t ?? this.t,
71+
createdAt: createdAt ?? this.createdAt,
72+
extension: extension ?? this.extension,
73+
);
74+
}
75+
5276
@override
53-
List<Object?> get props => [
54-
id, rawStatus, attachments, body
55-
];
77+
List<Object?> get props => [id, rawStatus, attachments, body];
5678

5779
static const empty = Message();
5880
}

lib/src/api/users/realtime/users_manager.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ class UsersManager {
1515

1616
StreamSubscription<Map<String, dynamic>>? _dataListener;
1717

18-
final StreamController<Map<String, dynamic>> _lastActivityController =
18+
final StreamController<Map<String, int>> _lastActivityController =
1919
StreamController.broadcast();
2020

21-
Stream<Map<String, dynamic>> get lastActivityControllerStream =>
21+
Stream<Map<String, int>> get lastActivityControllerStream =>
2222
_lastActivityController.stream;
2323

2424
_init() {
2525
if (_dataListener != null) return;
2626

2727
_dataListener = SamaConnectionService.instance.dataStream.listen((data) {
2828
if (data['last_activity'] != null) {
29-
_processLastActivity(data['last_activity'].cast<String, dynamic>());
29+
_processLastActivity(data['last_activity'].cast<String, int>());
3030
}
3131
});
3232
}
3333

34-
void _processLastActivity(Map<String, dynamic> data) {
34+
void _processLastActivity(Map<String, int> data) {
3535
_lastActivityController.add(data);
3636
}
3737

lib/src/api/users/users_api.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ Future<User> createUser({
3030
String? lastName,
3131
String? email,
3232
String? phone,
33-
}) {
33+
}) async {
3434
return SamaConnectionService.instance.sendRequest(userCreateRequestName, {
3535
'login': login,
3636
'password': password,
3737
'device_id': deviceId,
38+
'organization_id': await SecureStorage.instance.getEnvironmentOrgId(),
3839
if (email != null) 'email': email,
3940
if (phone != null) 'phone': phone,
4041
if (firstName != null) 'first_name': firstName,
@@ -188,7 +189,7 @@ Future<List<User>> searchUsersByKeyword(String keyword,
188189
});
189190
}
190191

191-
Future<dynamic> subscribeUserLastActivity(String id) {
192+
Future<int> subscribeUserLastActivity(String id) {
192193
return SamaConnectionService.instance
193194
.sendRequest(userLastActivitySubscribe, {'id': id}).then((response) {
194195
var status = response['last_activity'][id];

lib/src/api/utils/config.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const String apiProdUrl = 'api.samacloud.io';
2-
const String apiDevUrl = 'api-dev.samacloud.io';
1+
const String _apiProdUrl = 'api.samacloud.io';
2+
const String _apiDevUrl = 'api-dev.samacloud.io';
3+
4+
const String _organizationIdProd = '6821d147b2bb04e5fe564c73';
5+
const String _organizationIdDev = '6821d147b2bb04e5fe564c73';
36

47
enum EnvType {
5-
dev(apiDevUrl),
6-
prod(apiProdUrl);
8+
prod(_apiProdUrl, _organizationIdProd),
9+
dev(_apiDevUrl, _organizationIdDev);
710

811
final String url;
12+
final String organizationId;
913

10-
const EnvType(this.url);
11-
12-
factory EnvType.fromUrl(String url) {
13-
return values.firstWhere((e) => e.url == url);
14-
}
14+
const EnvType(this.url, this.organizationId);
1515
}

0 commit comments

Comments
 (0)