Skip to content

Commit

Permalink
feat(llc, core, ui, localization): threads v2
Browse files Browse the repository at this point in the history
  • Loading branch information
xsahil03x committed Jan 2, 2025
1 parent 3e08ed8 commit 06ed934
Show file tree
Hide file tree
Showing 62 changed files with 2,356 additions and 349 deletions.
38 changes: 33 additions & 5 deletions packages/stream_chat/lib/src/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class StreamChatClient {

StreamSubscription<ConnectionStatus>? _connectionStatusSubscription;

final _eventController = BehaviorSubject<Event>();
final _eventController = PublishSubject<Event>();

/// Stream of [Event] coming from [_ws] connection
/// Listen to this or use the [on] method to filter specific event types
Expand Down Expand Up @@ -491,10 +491,12 @@ class StreamChatClient {
final previousState = wsConnectionStatus;
final currentState = _wsConnectionStatus = status;

handleEvent(Event(
type: EventType.connectionChanged,
online: status == ConnectionStatus.connected,
));
if (previousState != currentState) {
handleEvent(Event(
type: EventType.connectionChanged,
online: status == ConnectionStatus.connected,
));
}

if (currentState == ConnectionStatus.connected &&
previousState != ConnectionStatus.connected) {
Expand Down Expand Up @@ -1213,6 +1215,32 @@ class StreamChatClient {
messageId,
);

/// Mark the thread with [threadId] in the channel with [channelId] of type
/// [channelType] as read.
Future<EmptyResponse> markThreadRead(
String channelId,
String channelType,
String threadId,
) =>
_chatApi.channel.markThreadRead(
channelId,
channelType,
threadId,
);

/// Mark the thread with [threadId] in the channel with [channelId] of type
/// [channelType] as unread.
Future<EmptyResponse> markThreadUnread(
String channelId,
String channelType,
String threadId,
) =>
_chatApi.channel.markThreadUnread(
channelId,
channelType,
threadId,
);

/// Creates a new Poll
Future<CreatePollResponse> createPoll(Poll poll) =>
_chatApi.polls.createPoll(poll);
Expand Down
26 changes: 26 additions & 0 deletions packages/stream_chat/lib/src/core/api/channel_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,32 @@ class ChannelApi {
return EmptyResponse.fromJson(response.data);
}

/// Mark the provided [threadId] of the channel as read.
Future<EmptyResponse> markThreadRead(
String channelId,
String channelType,
String threadId,
) async {
final response = await _client.post(
'${_getChannelUrl(channelId, channelType)}/read',
data: {'thread_id': threadId},
);
return EmptyResponse.fromJson(response.data);
}

/// Mark the provided [threadId] of the channel as unread.
Future<EmptyResponse> markThreadUnread(
String channelId,
String channelType,
String threadId,
) async {
final response = await _client.post(
'${_getChannelUrl(channelId, channelType)}/unread',
data: {'thread_id': threadId},
);
return EmptyResponse.fromJson(response.data);
}

/// Stop watching the channel
Future<EmptyResponse> stopWatching(
String channelId,
Expand Down
8 changes: 7 additions & 1 deletion packages/stream_chat/lib/src/core/api/requests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,17 @@ class PartialUpdateUserRequest extends Equatable {
class ThreadOptions extends Equatable {
/// {@macro threadOptions}
const ThreadOptions({
this.watch = true,
this.replyLimit = 2,
this.participantLimit = 100,
this.memberLimit = 100,
});

/// If true, the client will watch for changes in the thread.
///
/// Defaults to true.
final bool watch;

/// The number of most recent replies to return per thread.
///
/// Defaults to 2.
Expand All @@ -239,5 +245,5 @@ class ThreadOptions extends Equatable {
Map<String, dynamic> toJson() => _$ThreadOptionsToJson(this);

@override
List<Object?> get props => [replyLimit, participantLimit, memberLimit];
List<Object?> get props => [watch, replyLimit, participantLimit, memberLimit];
}
51 changes: 22 additions & 29 deletions packages/stream_chat/lib/src/core/api/requests.g.dart

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

63 changes: 28 additions & 35 deletions packages/stream_chat/lib/src/core/models/attachment.g.dart

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

13 changes: 11 additions & 2 deletions packages/stream_chat/lib/src/core/models/channel_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:stream_chat/src/core/models/channel_config.dart';
import 'package:stream_chat/src/core/models/member.dart';
import 'package:stream_chat/src/core/models/user.dart';
import 'package:stream_chat/src/core/util/serializer.dart';

Expand All @@ -22,6 +23,7 @@ class ChannelModel {
DateTime? updatedAt,
this.deletedAt,
this.memberCount = 0,
this.members,
Map<String, Object?> extraData = const {},
this.team,
this.cooldown = 0,
Expand Down Expand Up @@ -101,6 +103,10 @@ class ChannelModel {
@JsonKey(includeToJson: false)
final int memberCount;

/// The list of this channel members
@JsonKey(includeToJson: false)
final List<Member>? members;

/// The number of seconds in a cooldown
@JsonKey(includeIfNull: false)
final int cooldown;
Expand Down Expand Up @@ -143,13 +149,13 @@ class ChannelModel {
'updated_at',
'deleted_at',
'member_count',
'members',
'team',
'cooldown',
];

/// Shortcut for channel name
String get name =>
extraData.containsKey('name') ? extraData['name']! as String : cid;
String? get name => extraData['name'] as String?;

/// Serialize to json
Map<String, dynamic> toJson() => Serializer.moveFromExtraDataToRoot(
Expand All @@ -170,6 +176,7 @@ class ChannelModel {
DateTime? updatedAt,
DateTime? deletedAt,
int? memberCount,
List<Member>? members,
Map<String, Object?>? extraData,
String? team,
int? cooldown,
Expand All @@ -190,6 +197,7 @@ class ChannelModel {
updatedAt: updatedAt ?? this.updatedAt,
deletedAt: deletedAt ?? this.deletedAt,
memberCount: memberCount ?? this.memberCount,
members: members ?? this.members,
extraData: extraData ?? this.extraData,
team: team ?? this.team,
cooldown: cooldown ?? this.cooldown,
Expand Down Expand Up @@ -220,6 +228,7 @@ class ChannelModel {
updatedAt: other.updatedAt,
deletedAt: other.deletedAt,
memberCount: other.memberCount,
members: other.members,
extraData: other.extraData,
team: other.team,
cooldown: other.cooldown,
Expand Down
3 changes: 3 additions & 0 deletions packages/stream_chat/lib/src/core/models/channel_model.g.dart

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

Loading

0 comments on commit 06ed934

Please sign in to comment.