Skip to content

Commit

Permalink
fix(llc): when removing current user from channel check for null in t…
Browse files Browse the repository at this point in the history
…he callback

Closes #1753
  • Loading branch information
esarbanis committed Nov 24, 2023
1 parent 0ddab63 commit 89b1b0f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
update message with `type: reply`.
- [[#1724]](https://github.com/GetStream/stream-chat-flutter/issues/1724) Fixed sendFile error
on `AttachmentFile` with `bytes` and no `name`.
- [[#1753]](https://github.com/GetStream/stream-chat-flutter/issues/1753) Fixed Unhandled null
check operator exception when user is removed from a channel.

## 6.8.0

Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat/lib/src/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ class ClientState {
)
.listen((event) async {
final isCurrentUser = event.user!.id == currentUser!.id;
if (isCurrentUser) {
if (isCurrentUser && event.channel != null) {
final eventChannel = event.channel!;
await _client.chatPersistenceClient
?.deleteChannels([eventChannel.cid]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';

import 'package:stream_chat_flutter_example/debug/error_dialog.dart';

class DebugAddUser extends StatelessWidget {
const DebugAddUser({
super.key,
required this.client,
required this.channel,
});

final StreamChatClient client;
final Channel channel;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: TextField(
decoration: const InputDecoration(
labelText: 'Add User',
hintText: 'User Id',
isDense: true,
border: OutlineInputBorder(),
),
onSubmitted: (value) async {
final userId = value.trim();
try {
debugPrint('[addUser] userId: $userId');
final result = await client.addChannelMembers(
channel.id!,
channel.type,
[userId],
);
debugPrint('[addUser] result: $result');
} catch (e) {
debugPrint('[addUser] failed: $e');
showErrorDialog(context, e, 'Add User');
}
},
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';

import 'package:stream_chat_flutter_example/debug/error_dialog.dart';

class DebugRemoveUser extends StatelessWidget {
const DebugRemoveUser({
super.key,
required this.client,
required this.channel,
});

final StreamChatClient client;
final Channel channel;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: TextField(
decoration: const InputDecoration(
labelText: 'Remove User',
hintText: 'User Id',
isDense: true,
border: OutlineInputBorder(),
),
onSubmitted: (value) async {
final userId = value.trim();
try {
debugPrint('[removeUser] userId: $userId');
final result = await client.removeChannelMembers(
channel.id!,
channel.type,
[userId],
);
debugPrint('[removeUser] result: $result');
} catch (e) {
debugPrint('[removeUser] failed: $e');
showErrorDialog(context, e, 'Remove User');
}
},
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat_flutter_example/debug/actions/add_user.dart';
import 'package:stream_chat_flutter_example/debug/actions/ban_user.dart';
import 'package:stream_chat_flutter_example/debug/actions/mute_user.dart';
import 'package:stream_chat_flutter_example/debug/actions/remove_shadow_ban.dart';
import 'package:stream_chat_flutter_example/debug/actions/remove_user.dart';
import 'package:stream_chat_flutter_example/debug/actions/shadow_ban.dart';
import 'package:stream_chat_flutter_example/debug/actions/unban_user.dart';
import 'package:stream_chat_flutter_example/debug/actions/unmute_user.dart';
Expand Down Expand Up @@ -82,6 +84,10 @@ class _DebugChannelPageState extends State<DebugChannelPage> {
DebugShadowBan(client: _channel.client),
const SizedBox(height: 8),
DebugRemoveShadowBan(client: _channel.client),
const SizedBox(height: 8),
DebugAddUser(client: _channel.client, channel: _channel),
const SizedBox(height: 8),
DebugRemoveUser(client: _channel.client, channel: _channel),
],
),
),
Expand Down

0 comments on commit 89b1b0f

Please sign in to comment.