Skip to content

Commit

Permalink
Merge pull request #17 from takenet/feature/999999-blue-messenger
Browse files Browse the repository at this point in the history
feat: version upgrade
  • Loading branch information
leonardogbr authored Dec 20, 2024
2 parents 6b21ce9 + 22d15ac commit cc9f1a3
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 239 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.7.8'
flutter-version: '3.27.0'
- name: Install dependencies
run: flutter pub get
- name: Run tests
Expand All @@ -95,7 +95,7 @@ jobs:
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.7.8'
flutter-version: '3.27.0'
- name: Check Publish Warnings
run: dart pub publish --dry-run
- name: Publish
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.7.8'
flutter-version: '3.27.0'
- name: Install dependencies
run: flutter pub get
- name: Run tests
Expand Down
65 changes: 33 additions & 32 deletions lib/lime.dart
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
library lime;
library;

export 'src/protocol/guid.dart' show guid;
export 'src/protocol/extensions/string.extension.dart' show StringExtension;
export 'src/protocol/extensions/notification_event.extension.dart'
show NotificationEventExtension;
export 'package:lime/src/protocol/extensions/authentication_schema.extension.dart'
show AuthenticationSchemaExtension;

export 'src/protocol/client/client_channel.dart' show ClientChannel;
export 'src/protocol/command.dart' show Command;
export 'src/protocol/document.dart' show Document;
export 'src/protocol/envelope.dart' show Envelope;
export 'src/protocol/lime_uri.dart' show LimeUri;
export 'src/protocol/media_type.dart' show MediaType;
export 'src/protocol/message.dart' show Message;
export 'src/protocol/notification.dart' show Notification;
export 'src/protocol/plain_document.dart' show PlainDocument;
export 'src/protocol/reason_codes.dart' show ReasonCodes;
export 'src/protocol/reason.dart' show Reason;
export 'src/protocol/enums/command_method.enum.dart' show CommandMethod;
export 'src/protocol/enums/command_status.enum.dart' show CommandStatus;
export 'src/protocol/enums/notification_event.enum.dart' show NotificationEvent;
export 'src/protocol/enums/presence_status.enum.dart' show PresenceStatus;
export 'src/protocol/enums/routing_rule.enum.dart' show RoutingRule;
export 'src/protocol/enums/session_compression.enum.dart'
show SessionCompression;
export 'src/protocol/enums/session_encryption.enum.dart' show SessionEncryption;
export 'src/protocol/enums/session_state.enum.dart' show SessionState;
export 'src/protocol/enums/presence_status.enum.dart' show PresenceStatus;
export 'src/protocol/enums/routing_rule.enum.dart' show RoutingRule;
export 'src/protocol/envelope.dart' show Envelope;
export 'src/protocol/exceptions/insecure_socket.exception.dart'
show InsecureSocketException;
export 'src/protocol/exceptions/lime.exception.dart' show LimeException;
export 'src/protocol/extensions/envelope.extension.dart' show EnvelopeExtension;
export 'src/protocol/types/composite_types.dart' show CompositeTypes;
export 'src/protocol/types/discrete_types.dart' show DiscreteTypes;
export 'src/protocol/types/sub_types.dart' show SubTypes;
export 'src/protocol/node.dart' show Node;
export 'src/protocol/extensions/notification_event.extension.dart'
show NotificationEventExtension;
export 'src/protocol/extensions/string.extension.dart' show StringExtension;
export 'src/protocol/guid.dart' show guid;
export 'src/protocol/identity.dart' show Identity;
export 'src/protocol/session.dart' show Session;
export 'src/protocol/lime_uri.dart' show LimeUri;
export 'src/protocol/media_type.dart' show MediaType;
export 'src/protocol/message.dart' show Message;
export 'src/protocol/network/transport.dart' show Transport;
export 'src/protocol/network/web_socket_transport.dart' show WebSocketTransport;
export 'src/protocol/node.dart' show Node;
export 'src/protocol/notification.dart' show Notification;
export 'src/protocol/plain_document.dart' show PlainDocument;
export 'src/protocol/presence.dart' show Presence;
export 'src/protocol/reason.dart' show Reason;
export 'src/protocol/reason_codes.dart' show ReasonCodes;
export 'src/protocol/security/authentication.dart' show Authentication;
export 'src/protocol/security/enums/authentication_scheme.enum.dart'
show AuthenticationScheme;
export 'src/protocol/security/external_authentication.dart'
show ExternalAuthentication;
export 'src/protocol/security/guest_authentication.dart'
show GuestAuthentication;
export 'src/protocol/security/key_authentication.dart' show KeyAuthentication;
export 'src/protocol/security/external_authentication.dart'
show ExternalAuthentication;
export 'src/protocol/security/plain_authentication.dart'
show PlainAuthentication;
export 'src/protocol/security/transport_authentication.dart'
show TransportAuthentication;
export 'src/protocol/security/enums/authentication_scheme.enum.dart'
show AuthenticationScheme;
export 'package:lime/src/protocol/extensions/authentication_schema.extension.dart'
show AuthenticationSchemaExtension;
export 'src/protocol/client/client_channel.dart' show ClientChannel;
export 'src/protocol/network/transport.dart' show Transport;
export 'src/protocol/network/web_socket_transport.dart' show WebSocketTransport;
export 'src/protocol/exceptions/lime.exception.dart' show LimeException;
export 'src/protocol/exceptions/insecure_socket.exception.dart'
show InsecureSocketException;
export 'src/protocol/session.dart' show Session;
export 'src/protocol/types/composite_types.dart' show CompositeTypes;
export 'src/protocol/types/discrete_types.dart' show DiscreteTypes;
export 'src/protocol/types/sub_types.dart' show SubTypes;
6 changes: 2 additions & 4 deletions lib/src/protocol/client/client_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import 'channel.dart';
class ClientChannel extends Channel {
ClientChannel(
Transport transport, {
final bool autoReplyPings = true,
final bool autoNotifyReceipt = false,
super.autoReplyPings = true,
super.autoNotifyReceipt = false,
}) : super(
transport: transport,
autoReplyPings: autoReplyPings,
autoNotifyReceipt: autoNotifyReceipt,
);

/// Exposes a [StreamController] to allow listening when a new [Notification] is received by the channel
Expand Down
27 changes: 13 additions & 14 deletions lib/src/protocol/command.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:flutter/foundation.dart';
import 'guid.dart';
import 'enums/command_method.enum.dart';
import 'enums/command_status.enum.dart';
import 'envelope.dart';
import 'guid.dart';
import 'message.dart';
import 'node.dart';
import 'reason.dart';
import 'enums/command_method.enum.dart';
import 'enums/command_status.enum.dart';

/// Allows the manipulation of node resources, like server session parameters or information related to the network nodes.
class Command extends Envelope {
Expand Down Expand Up @@ -37,24 +35,24 @@ class Command extends Envelope {
/// Initializes a new instance of the Command class.
Command({
final String? id,
final Node? from,
final Node? to,
final Node? pp,
final Map<String, dynamic>? metadata,
super.from,
super.to,
super.pp,
super.metadata,
this.uri,
required this.method,
this.reason,
this.resource,
this.status,
this.type,
}) : super(id: id ?? guid(), from: from, to: to, pp: pp, metadata: metadata);
}) : super(id: id ?? guid());

/// Allows converting a [Command] object to a [Map] collection of key/value pairs
Map<String, dynamic> toJson() {
Map<String, dynamic> command = {};

command[Envelope.idKey] = id;
command[methodKey] = describeEnum(method);
command[methodKey] = method.name;

if (from != null) {
command[Envelope.fromKey] = from.toString();
Expand All @@ -73,7 +71,7 @@ class Command extends Envelope {
}

if (status != null) {
command[statusKey] = describeEnum(status!);
command[statusKey] = status!.name;
}

if (uri != null) {
Expand Down Expand Up @@ -106,7 +104,7 @@ class Command extends Envelope {
pp: envelope.pp,
metadata: envelope.metadata,
method: json[methodKey] != null
? CommandMethod.values.firstWhere((e) => describeEnum(e) == json[methodKey])
? CommandMethod.values.firstWhere((e) => e.name == json[methodKey])
: CommandMethod.unknown,
);

Expand All @@ -115,7 +113,8 @@ class Command extends Envelope {
}

if (json.containsKey(statusKey)) {
command.status = CommandStatus.values.firstWhere((e) => describeEnum(e) == json[statusKey]);
command.status =
CommandStatus.values.firstWhere((e) => e.name == json[statusKey]);
}

if (json.containsKey(uriKey)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/protocol/enums/notification_event.enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ enum NotificationEvent {
/// A problem occurred during the processing of the message.
failed,

/// The message is being sent
sending,

/// The message format was validated by the server.
@Deprecated("This specific event should not be sent anymore")
validated,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:lime/lime.dart';

extension AuthenticationSchemaExtension on AuthenticationScheme {
AuthenticationScheme getValue(String? value) =>
AuthenticationScheme.values.firstWhere((e) => describeEnum(e) == value,
AuthenticationScheme.values.firstWhere((e) => e.name == value,
orElse: () => AuthenticationScheme.unknown);
}
19 changes: 10 additions & 9 deletions lib/src/protocol/extensions/notification_event.extension.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import 'package:flutter/foundation.dart';

import '../enums/notification_event.enum.dart';

extension NotificationEventExtension on NotificationEvent {
NotificationEvent getValue(String? value) =>
NotificationEvent.values.firstWhere((e) => describeEnum(e) == value, orElse: () => NotificationEvent.unknown);
NotificationEvent.values.firstWhere((e) => e.name == value,
orElse: () => NotificationEvent.unknown);

bool isLowerThan(NotificationEvent? other) {
const events = {
NotificationEvent.accepted: 0,
NotificationEvent.dispatched: 1,
NotificationEvent.received: 2,
NotificationEvent.consumed: 3,
NotificationEvent.failed: 4,
NotificationEvent.sending: 0,
NotificationEvent.accepted: 1,
NotificationEvent.dispatched: 2,
NotificationEvent.received: 3,
NotificationEvent.consumed: 4,
NotificationEvent.failed: 5,
NotificationEvent.unknown: 99,
};

return (events[this] ?? 99) < (events[other ?? NotificationEvent.unknown] ?? 99);
return (events[this] ?? 99) <
(events[other ?? NotificationEvent.unknown] ?? 99);
}
}
11 changes: 5 additions & 6 deletions lib/src/protocol/message.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'envelope.dart';
import 'guid.dart';
import 'node.dart';

/// Provides the transport of a content between nodes in a network.
class Message extends Envelope {
Expand All @@ -10,13 +9,13 @@ class Message extends Envelope {
/// Initializes a new instance of the Message class.
Message({
final String? id,
final Node? from,
final Node? to,
final Node? pp,
Map<String, dynamic>? metadata,
super.from,
super.to,
super.pp,
super.metadata,
this.content,
this.type,
}) : super(id: id ?? guid(), from: from, to: to, pp: pp, metadata: metadata);
}) : super(id: id ?? guid());

/// MIME declaration of the content type of the message.
String? type;
Expand Down
34 changes: 25 additions & 9 deletions lib/src/protocol/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import 'interfaces/inode.dart';
/// Represents an element of a network.
class Node extends Identity implements INode {
/// Initializes a new instance of the node class.
Node({String? name, String? domain, this.instance}) : super(name: name, domain: domain);
Node({
super.name,
super.domain,
this.instance,
});

/// The name of the instance used by the node to connect to the network.
@override
Expand All @@ -20,19 +24,27 @@ class Node extends Identity implements INode {

@override
String toString() {
return instance == null ? super.toString() : '${super.toString()}/$instance';
return instance == null
? super.toString()
: '${super.toString()}/$instance';
}

bool _equals(other) {
final node = other as Node?;
final stringNode = other?.toString();

final node = tryParse(stringNode) ? parse(stringNode) : null;

if (node == null) return false;

return ((name == null && node.name == null) || (name != null && name?.toLowerCase() == node.name?.toLowerCase())) &&
return ((name == null && node.name == null) ||
(name != null &&
name?.toLowerCase() == node.name?.toLowerCase())) &&
((domain == null && node.domain == null) ||
(domain != null && domain?.toLowerCase() == node.domain?.toLowerCase())) &&
(domain != null &&
domain?.toLowerCase() == node.domain?.toLowerCase())) &&
((instance == null && node.instance == null) ||
(instance != null && instance?.toLowerCase() == node.instance?.toLowerCase()));
(instance != null &&
instance?.toLowerCase() == node.instance?.toLowerCase()));
}

/// Parses the string to a valid Node.
Expand All @@ -47,12 +59,14 @@ class Node extends Identity implements INode {
return Node(
name: identity.name,
domain: identity.domain,
instance: s!.length > identityString.length ? s.substring(identityString.length + 1) : null);
instance: s!.length > identityString.length
? s.substring(identityString.length + 1)
: null);
}

/// Tries to parse the string to a valid Node.
static bool tryParse(
String s,
String? s,
) {
try {
parse(s);
Expand All @@ -69,6 +83,8 @@ class Node extends Identity implements INode {

/// Indicates if the node is a complete representation,
bool isComplete() {
return !['', null].contains(name) && !['', null].contains(domain) && !['', null].contains(instance);
return !['', null].contains(name) &&
!['', null].contains(domain) &&
!['', null].contains(instance);
}
}
16 changes: 7 additions & 9 deletions lib/src/protocol/notification.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/foundation.dart';
import 'enums/notification_event.enum.dart';
import 'envelope.dart';
import 'guid.dart';
import 'node.dart';
import 'reason.dart';

/// Transports information about events associated to a message in a session.
Expand All @@ -13,13 +11,13 @@ class Notification extends Envelope {

Notification({
final String? id,
final Node? from,
final Node? to,
final Node? pp,
final Map<String, dynamic>? metadata,
super.from,
super.to,
super.pp,
super.metadata,
this.event,
this.reason,
}) : super(id: id ?? guid(), from: from, to: to, pp: pp, metadata: metadata);
}) : super(id: id ?? guid());

/// Related event to the notification
NotificationEvent? event;
Expand Down Expand Up @@ -50,7 +48,7 @@ class Notification extends Envelope {
}

if (event != null) {
notification[eventKey] = describeEnum(event!);
notification[eventKey] = event!.name;
}

if (reason != null) {
Expand All @@ -77,7 +75,7 @@ class Notification extends Envelope {
}
if (json.containsKey(eventKey)) {
notification.event = NotificationEvent.values
.firstWhere((e) => describeEnum(e) == json[eventKey]);
.firstWhere((e) => e.name == json[eventKey]);
}

return notification;
Expand Down
Loading

0 comments on commit cc9f1a3

Please sign in to comment.