onUserPresenceChanged method
Function which gets called for the event 'user.presence.changed' and EventType.userUpdated.
This event is fired when a user's presence changes or gets updated.
By default, this updates the channel member with the event user.
Implementation
void onUserPresenceChanged(
Event event,
StreamChannelListController controller,
) {
final user = event.user;
if (user == null) return;
final channels = [...controller.currentItems];
final updatedChannels = channels.map((channel) {
final members = [...channel.state!.members];
final memberIndex = members.indexWhere(
(it) => user.id == (it.userId ?? it.user?.id),
);
if (memberIndex < 0) return channel;
members[memberIndex] = members[memberIndex].copyWith(user: user);
final updatedState = ChannelState(members: [...members]);
channel.state!.updateChannelState(updatedState);
return channel;
});
controller.channels = [...updatedChannels];
}