Fix message limit removal

[skip ci]
This commit is contained in:
tommyxchow 2021-11-23 20:03:54 -05:00
parent cbf4994dfc
commit 6af80f5462
3 changed files with 109 additions and 109 deletions

View file

@ -21,79 +21,82 @@ class _ChatState extends State<Chat> {
future: widget.chatStore.getAssets(),
builder: (_, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Column(
children: [
Expanded(
child: Stack(
alignment: AlignmentDirectional.bottomCenter,
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Column(
children: [
Expanded(
child: Stack(
alignment: AlignmentDirectional.bottomCenter,
children: [
Observer(
builder: (_) {
return ListView.builder(
addAutomaticKeepAlives: false,
addRepaintBoundaries: false,
itemCount: widget.chatStore.messages.length,
controller: widget.chatStore.scrollController,
itemBuilder: (context, index) {
return widget.chatStore.renderChatMessage(widget.chatStore.messages[index], context);
},
);
},
),
Observer(
builder: (_) {
return Visibility(
visible: !widget.chatStore.autoScroll,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
width: double.infinity,
child: ElevatedButton(
onPressed: widget.chatStore.resumeScroll,
child: const Text('Resume Scroll'),
),
),
);
},
),
],
),
),
Row(
children: [
Observer(
builder: (_) {
return ListView.builder(
addAutomaticKeepAlives: false,
addRepaintBoundaries: false,
itemCount: widget.chatStore.messages.length,
controller: widget.chatStore.scrollController,
itemBuilder: (context, index) {
return widget.chatStore.renderChatMessage(widget.chatStore.messages[index], context);
IconButton(
icon: const Icon(Icons.stacked_bar_chart),
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) {
return ChatStats(
chatStore: widget.chatStore,
);
},
);
},
),
Observer(
builder: (_) {
return Visibility(
visible: !widget.chatStore.autoScroll,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
width: double.infinity,
child: ElevatedButton(
onPressed: widget.chatStore.resumeScroll,
child: const Text('Resume Scroll'),
if (context.read<AuthStore>().isLoggedIn)
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0),
child: TextField(
decoration: const InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
hintText: 'Send a message',
),
controller: widget.chatStore.textController,
onSubmitted: (string) => widget.chatStore.sendMessage(string),
),
);
},
),
],
),
),
Row(
children: [
IconButton(
icon: const Icon(Icons.stacked_bar_chart),
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) {
return ChatStats(
chatStore: widget.chatStore,
);
},
);
},
),
if (context.read<AuthStore>().isLoggedIn)
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0),
child: TextField(
decoration: const InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
hintText: 'Send a message',
),
controller: widget.chatStore.textController,
onSubmitted: (string) => widget.chatStore.sendMessage(string),
),
),
),
],
)
],
],
)
],
),
);
}
return const Center(

View file

@ -180,7 +180,7 @@ abstract class _ChatStoreBase with Store {
if (_autoScroll) {
// If there are more messages than the limit, remove around 10% of them from the oldest.
if (messages.length > settings.messageLimit && settings.messageLimit != 1000) {
messages.removeRange(0, (messages.length - settings.messageLimit * 0.1).ceil());
messages.removeRange(0, (settings.messageLimit - settings.messageLimit * 0.1).ceil());
}
// After the end of the frame, scroll to the bottom of the chat.

View file

@ -26,55 +26,52 @@ class VideoChat extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Column(
children: [
Observer(
builder: (_) {
if (context.read<SettingsStore>().videoEnabled) {
return AspectRatio(
aspectRatio: 16 / 9,
child: Video(
title: title,
userName: userName,
userLogin: userLogin,
videoStore: VideoStore(),
),
);
}
return AppBar(
title: Text(
userName,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
child: Column(
children: [
Observer(
builder: (_) {
if (context.read<SettingsStore>().videoEnabled) {
return AspectRatio(
aspectRatio: 16 / 9,
child: Video(
title: title,
userName: userName,
userLogin: userLogin,
videoStore: VideoStore(),
),
actions: [
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) {
return Settings(settingsStore: context.read<SettingsStore>());
},
);
},
),
],
);
},
),
Expanded(
child: Chat(
chatStore: ChatStore(
auth: context.read<AuthStore>(),
settings: context.read<SettingsStore>(),
channelName: userLogin,
}
return AppBar(
title: Text(
userName,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
actions: [
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) {
return Settings(settingsStore: context.read<SettingsStore>());
},
);
},
),
],
);
},
),
Expanded(
child: Chat(
chatStore: ChatStore(
auth: context.read<AuthStore>(),
settings: context.read<SettingsStore>(),
channelName: userLogin,
),
),
],
),
),
],
),
),
);