Skip to content

Commit

Permalink
fix: 🐛 prevent actions if receiver is not capable of dealing with them
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbadstuebner committed Jun 18, 2024
1 parent 08da145 commit c9439b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
send message not working when user start texting after newLine.
* **Fix**: [191](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/191) Fix
error when using `BuildContext` or `State` extensions when not mounted.
* **Fix**: [192](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/192) Fix
send to closed socket or animate on `ScrollController` without clients.

## [1.3.1]

Expand Down
25 changes: 17 additions & 8 deletions lib/src/controller/chat_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class ChatController {
/// Used to add message in message list.
void addMessage(Message message) {
initialMessageList.add(message);
messageStreamController.sink.add(initialMessageList);
if (!messageStreamController.isClosed) {
messageStreamController.sink.add(initialMessageList);
}
}

/// Used to add reply suggestions.
Expand Down Expand Up @@ -134,24 +136,31 @@ class ChatController {
messageType: message.messageType,
status: message.status,
);
messageStreamController.sink.add(initialMessageList);
if (!messageStreamController.isClosed) {
messageStreamController.sink.add(initialMessageList);
}
}

/// Function to scroll to last messages in chat view
void scrollToLastMessage() => Timer(
const Duration(milliseconds: 300),
() => scrollController.animateTo(
scrollController.position.minScrollExtent,
curve: Curves.easeIn,
duration: const Duration(milliseconds: 300),
),
() {
if (!scrollController.hasClients) return;
scrollController.animateTo(
scrollController.position.minScrollExtent,
curve: Curves.easeIn,
duration: const Duration(milliseconds: 300),
);
},
);

/// Function for loading data while pagination.
void loadMoreData(List<Message> messageList) {
/// Here, we have passed 0 index as we need to add data before first data
initialMessageList.insertAll(0, messageList);
messageStreamController.sink.add(initialMessageList);
if (!messageStreamController.isClosed) {
messageStreamController.sink.add(initialMessageList);
}
}

/// Function for getting ChatUser object from user id
Expand Down

0 comments on commit c9439b6

Please sign in to comment.