Add better error handling, send messages early and update when delivered
This commit is contained in:
parent
8c7adbc9d3
commit
55ecbc3590
9 changed files with 111 additions and 74 deletions
|
|
@ -21,7 +21,7 @@ import "package:nexus/widgets/chat_page/room_appbar.dart";
|
|||
import "package:nexus/widgets/chat_page/wrappers/text_message_wrapper.dart";
|
||||
import "package:nexus/widgets/chat_page/reply_widget.dart";
|
||||
import "package:nexus/widgets/form_text_input.dart";
|
||||
// import "package:dynamic_polls/dynamic_polls.dart";
|
||||
import "package:nexus/main.dart";
|
||||
|
||||
class RoomChat extends HookConsumerWidget {
|
||||
final bool isDesktop;
|
||||
|
|
@ -108,11 +108,13 @@ class RoomChat extends HookConsumerWidget {
|
|||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
notifier.deleteMessage(
|
||||
message,
|
||||
reason: deleteReasonController.text,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
await notifier
|
||||
.deleteMessage(
|
||||
message,
|
||||
reason: deleteReasonController.text,
|
||||
)
|
||||
.onError(showError);
|
||||
},
|
||||
child: Text("Delete"),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import "package:flutter/material.dart";
|
|||
import "package:flutter_chat_core/flutter_chat_core.dart";
|
||||
import "package:nexus/widgets/chat_page/lazy_loading/message_avatar.dart";
|
||||
import "package:nexus/widgets/chat_page/lazy_loading/message_displayname.dart";
|
||||
import "package:timeago/timeago.dart";
|
||||
|
||||
class MessageWrapper extends StatelessWidget {
|
||||
final Message message;
|
||||
|
|
@ -10,41 +11,69 @@ class MessageWrapper extends StatelessWidget {
|
|||
const MessageWrapper(this.message, this.child, this.groupStatus, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
child: AnimatedContainer(
|
||||
padding: message.metadata?["flashing"] == true
|
||||
? EdgeInsets.all(8)
|
||||
: EdgeInsets.all(0),
|
||||
color: message.metadata?["flashing"] == true
|
||||
? Theme.of(context).colorScheme.onSurface.withAlpha(50)
|
||||
: Colors.transparent,
|
||||
duration: Duration(milliseconds: 250),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
groupStatus?.isFirst != false
|
||||
? MessageAvatar(message, height: 40)
|
||||
: SizedBox(width: 40),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 4,
|
||||
children: [
|
||||
if (groupStatus?.isFirst != false)
|
||||
MessageDisplayname(
|
||||
message,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final error = message.metadata?["error"];
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
child: AnimatedContainer(
|
||||
padding: message.metadata?["flashing"] == true
|
||||
? EdgeInsets.all(8)
|
||||
: EdgeInsets.all(0),
|
||||
color: message.metadata?["flashing"] == true
|
||||
? Theme.of(context).colorScheme.onSurface.withAlpha(50)
|
||||
: Colors.transparent,
|
||||
duration: Duration(milliseconds: 250),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
groupStatus?.isFirst != false
|
||||
? MessageAvatar(message, height: 40)
|
||||
: SizedBox(width: 40),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 4,
|
||||
children: [
|
||||
if (groupStatus?.isFirst != false)
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: MessageDisplayname(
|
||||
message,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (message.deliveredAt != null &&
|
||||
groupStatus?.isFirst == true)
|
||||
Tooltip(
|
||||
message: message.deliveredAt!.toString(),
|
||||
child: Text(
|
||||
format(message.deliveredAt!),
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child,
|
||||
],
|
||||
child,
|
||||
if (error != null && error != "not sent")
|
||||
Text(
|
||||
error,
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ class TextMessageWrapper extends StatelessWidget {
|
|||
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: isSentByMe
|
||||
? colorScheme.primaryContainer
|
||||
? (message.id.startsWith("~")
|
||||
? colorScheme.onPrimary
|
||||
: colorScheme.primaryContainer)
|
||||
: colorScheme.surfaceContainer,
|
||||
),
|
||||
child: Column(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue