Skip to content

Commit

Permalink
Merge pull request #1167 from GetStream/feat/listen-channel-member-up…
Browse files Browse the repository at this point in the history
…dated

feat(llc): handle member.updated events in channel client
  • Loading branch information
imtoori authored May 19, 2022
2 parents f5786ce + 731db0c commit 715f70a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
- Added `PaginationParams.createdAtBefore` for message pagination.
- Added `PaginationParams.createdAtAround` for message pagination.
- Added support for `channel.membership` and `channel.membershipStream` in `Channel`.
- `Channel` now listens for `member.updated` events and updates the `Channel.members` accordingly.

🔄 Changed

- Deprecated `PaginationParams.before` and `PaginationParams.after`. Use `PaginationParams.limit` instead.
- Deprecated `PaginationParams.before` and `PaginationParams.after`. Use `PaginationParams.limit` instead.

## 4.1.0

Expand Down
14 changes: 14 additions & 0 deletions packages/stream_chat/lib/src/client/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,8 @@ class ChannelClientState {

_listenMemberRemoved();

_listenMemberUpdated();

_listenMemberBanned();

_listenMemberUnbanned();
Expand Down Expand Up @@ -1644,6 +1646,18 @@ class ChannelClientState {
}));
}

void _listenMemberUpdated() {
_subscriptions.add(_channel.on(EventType.memberUpdated).listen((Event e) {
final member = e.member;
final existingMembers = channelState.members ?? [];
updateChannelState(channelState.copyWith(
members: existingMembers
.map((m) => m.userId == member!.userId ? member : m)
.toList(growable: false),
));
}));
}

void _listenChannelUpdated() {
_subscriptions.add(_channel.on(EventType.channelUpdated).listen((Event e) {
final channel = e.channel!;
Expand Down
3 changes: 3 additions & 0 deletions packages/stream_chat/lib/src/event_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class EventType {
/// Event sent when a member is removed to a channel
static const String memberRemoved = 'member.removed';

/// Event sent when a member is updated in a channel
static const String memberUpdated = 'member.updated';

/// Event sent when a member is removed to a channel
static const String userBanned = 'user.banned';

Expand Down

0 comments on commit 715f70a

Please sign in to comment.