-
-
Notifications
You must be signed in to change notification settings - Fork 310
In-game chat feature #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
In-game chat feature #339
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c66297a
Add the user interface for in-game chat
julien4215 655ee22
change bubble message color in light and dark mode
julien4215 17c7c85
add messages from server like "Draw offer sent"
julien4215 33ef47f
Fix in-game chat screen title
julien4215 8a289d9
-edit controller to receive and send messages
julien4215 92276ed
Improvements of chat bottom bar
julien4215 c2d6c68
-factoring code
julien4215 eb61bea
small improvements/fixs
julien4215 8d3b5f3
rename bottom bar class for message screen
julien4215 d074edf
refactor controller
julien4215 3a63d7d
fix test
julien4215 6b58cea
make chat controller more generic
julien4215 f7afd54
make message screen more generic
julien4215 d747d17
use AdaptiveTextField instead of TexFfield
julien4215 2f8ced5
use user full name widget
julien4215 b9f2452
replace ref.watch by ref.read outside build method
julien4215 9c32f31
Chat style improvements
veloce bd1902b
remove useless icon due to fullScreenDialog being true
julien4215 c6e5d05
Chat tweaks
veloce c913b69
Fix chat ListView padding on iOS
veloce 87ea390
Dismiss the keyboard on tap
veloce 8b6b666
More chat fixes
veloce 6a66311
Restore maxLines to 4 on chat input
veloce 336c02a
Tweak chat bubble and color
veloce f715d3e
Add little more contrast to android chat bubbles
veloce b091be8
Bind chat controller state to a context id
veloce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:fast_immutable_collections/fast_immutable_collections.dart'; | ||
| import 'package:freezed_annotation/freezed_annotation.dart'; | ||
| import 'package:lichess_mobile/src/model/auth/auth_socket.dart'; | ||
| import 'package:lichess_mobile/src/model/common/id.dart'; | ||
| import 'package:lichess_mobile/src/model/common/socket.dart'; | ||
| import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
|
||
| part 'chat_controller.freezed.dart'; | ||
| part 'chat_controller.g.dart'; | ||
|
|
||
| @riverpod | ||
| class ChatController extends _$ChatController { | ||
| StreamSubscription<SocketEvent>? _socketSubscription; | ||
|
|
||
| AuthSocket get _socket => ref.read(authSocketProvider); | ||
|
|
||
| @override | ||
| ChatState build(ID chatContext) { | ||
| _socketSubscription = _socket.stream.listen(_handleSocketTopic); | ||
|
|
||
| ref.onDispose(() { | ||
| _socketSubscription?.cancel(); | ||
| }); | ||
|
|
||
| return ChatState( | ||
| messages: IList(), | ||
| unreadMessages: 0, | ||
| ); | ||
| } | ||
|
|
||
| void setMessages(IList<Message> messages) { | ||
| state = ChatState( | ||
| messages: messages, | ||
| unreadMessages: 0, | ||
| ); | ||
| } | ||
|
|
||
| void onUserMessage(String message) { | ||
| _socket.send( | ||
| 'talk', | ||
| message, | ||
| ); | ||
| } | ||
|
|
||
| void resetUnreadMessages() { | ||
| state = state.copyWith(unreadMessages: 0); | ||
| } | ||
|
|
||
| void _handleSocketTopic(SocketEvent event) { | ||
| switch (event.topic) { | ||
| // Called when a message is received | ||
| case 'message': | ||
| final data = event.data as Map<String, dynamic>; | ||
| final message = data["t"] as String; | ||
| final username = data["u"] as String; | ||
| state = state.copyWith( | ||
| messages: state.messages.add( | ||
| Message( | ||
| message: message, | ||
| username: username, | ||
| ), | ||
| ), | ||
| unreadMessages: state.unreadMessages + 1, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @freezed | ||
| class ChatState with _$ChatState { | ||
| const ChatState._(); | ||
|
|
||
| const factory ChatState({ | ||
| required IList<Message> messages, | ||
| required int unreadMessages, | ||
| }) = _ChatState; | ||
| } | ||
|
|
||
| @immutable | ||
| class Message { | ||
| final String username; | ||
| final String message; | ||
|
|
||
| const Message({required this.username, required this.message}); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.