Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/stream_core/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
targets:
$default:
builders:
json_serializable:
options:
explicit_to_json: true
field_rename: snake
1 change: 1 addition & 0 deletions packages/stream_core/lib/src/models.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'models/pagination_result.dart';
27 changes: 27 additions & 0 deletions packages/stream_core/lib/src/models/pagination_result.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:equatable/equatable.dart';

class PaginationResult<T> {
const PaginationResult({
required this.items,
required this.pagination,
});

final List<T> items;
final PaginationData pagination;
}

class PaginationData extends Equatable {
const PaginationData({
this.next,
this.previous,
});

/// Item id of where to start searching from for next [results]
final String? next;

/// Item id of where to start searching from for previous [results]
final String? previous;

@override
List<Object?> get props => [next, previous];
}
3 changes: 3 additions & 0 deletions packages/stream_core/lib/src/user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'user/connect_user_details_request.dart';
export 'user/user.dart';
export 'user/ws_auth_message_request.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:json_annotation/json_annotation.dart';

part 'connect_user_details_request.g.dart';

@JsonSerializable()
class ConnectUserDetailsRequest {
final String id;
final String? image;
final bool? invisible;
final String? language;
final String? name;
final Map<String, dynamic>? customData;

const ConnectUserDetailsRequest({
required this.id,
this.image,
this.invisible,
this.language,
this.name,
this.customData,
});

Map<String, dynamic> toJson() => _$ConnectUserDetailsRequestToJson(this);
static ConnectUserDetailsRequest fromJson(Map<String, dynamic> json) =>
_$ConnectUserDetailsRequestFromJson(json);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions packages/stream_core/lib/src/user/user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//
// Copyright © 2025 Stream.io Inc. All rights reserved.
//

import 'package:meta/meta.dart';

/// Model for the user's info.
@immutable
class User {
/// Creates a user with the provided id.
const User({
required this.id,
String? name,
this.imageUrl,
this.role = 'user',
this.type = UserAuthType.regular,
Map<String, dynamic>? customData,
}) : originalName = name,
customData = customData ?? const {};

/// Creates a guest user with the provided id.
/// - Parameter userId: the id of the user.
/// - Returns: a guest `User`.
const User.guest(String userId)
: this(id: userId, name: userId, type: UserAuthType.guest);

/// Creates an anonymous user.
/// - Returns: an anonymous `User`.
const User.anonymous() : this(id: '!anon', type: UserAuthType.anonymous);

/// The user's id.
final String id;

/// The user's image URL.
final String? imageUrl;

/// The user's role.
final String role;

/// The user authorization type.
final UserAuthType type;

/// The user's custom data.
final Map<String, dynamic> customData;

/// User's name that was provided when the object was created. It will be used when communicating
/// with the API and in cases where it doesn't make sense to override `null` values with the
/// `non-null` id.
final String? originalName;

/// A computed property that can be used for UI elements where you need to display user's identifier.
/// If a `name` value was provided on initialisation it will return it. Otherwise returns the `id`.
String get name => originalName ?? id;

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is User &&
other.id == id &&
other.imageUrl == imageUrl &&
other.role == role &&
other.type == type &&
other.originalName == originalName &&
_mapEquals(other.customData, customData);
}

bool _mapEquals(Map<String, dynamic>? a, Map<String, dynamic>? b) {
if (a == null && b == null) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;
for (final key in a.keys) {
if (!b.containsKey(key) || a[key] != b[key]) return false;
}
return true;
}

@override
int get hashCode {
return Object.hash(
id,
imageUrl,
role,
type,
originalName,
Object.hashAll(customData.entries),
);
}

@override
String toString() {
return 'User(id: $id, name: $name, imageURL: $imageUrl, role: $role, type: $type, customData: $customData)';
}
}

/// The user authorization type.
enum UserAuthType {
/// A regular user.
regular,

/// An anonymous user.
anonymous,

/// A guest user.
guest,
}
29 changes: 29 additions & 0 deletions packages/stream_core/lib/src/user/ws_auth_message_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'dart:convert';

import 'package:json_annotation/json_annotation.dart';

import '../user.dart';
import '../ws/events/sendable_event.dart';

part 'ws_auth_message_request.g.dart';

@JsonSerializable()
class WsAuthMessageRequest implements SendableEvent {
const WsAuthMessageRequest({
this.products,
required this.token,
this.userDetails,
});

final List<String>? products;
final String token;
final ConnectUserDetailsRequest? userDetails;

Map<String, dynamic> toJson() => _$WsAuthMessageRequestToJson(this);

static WsAuthMessageRequest fromJson(Map<String, dynamic> json) =>
_$WsAuthMessageRequestFromJson(json);

@override
Object toSerializedData() => json.encode(toJson());
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/stream_core/lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export 'utils/network_monitor.dart';
export 'utils/result.dart';
export 'utils/shared_emitter.dart';
5 changes: 5 additions & 0 deletions packages/stream_core/lib/src/ws.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export 'ws/client/connection_recovery_handler.dart';
export 'ws/client/default_connection_recovery_handler.dart';
export 'ws/client/web_socket_client.dart' show WebSocketClient;
export 'ws/client/web_socket_connection_state.dart';
export 'ws/events/ws_event.dart';
Loading
Loading