reply rendering
This commit is contained in:
parent
a453114c17
commit
2a4525a78f
6 changed files with 226 additions and 109 deletions
|
|
@ -14,6 +14,7 @@ import "package:nexus/controllers/current_room_controller.dart";
|
|||
import "package:nexus/controllers/room_chat_controller.dart";
|
||||
import "package:nexus/helpers/extension_helper.dart";
|
||||
import "package:nexus/helpers/launch_helper.dart";
|
||||
import "package:nexus/widgets/top_widget.dart";
|
||||
import "package:nexus/widgets/room_avatar.dart";
|
||||
|
||||
class RoomChat extends HookConsumerWidget {
|
||||
|
|
@ -86,16 +87,11 @@ class RoomChat extends HookConsumerWidget {
|
|||
required bool isSentByMe,
|
||||
MessageGroupStatus? groupStatus,
|
||||
}) => kDebugMode
|
||||
? FlyerChatTextMessage(
|
||||
message: TextMessage(
|
||||
id: message.id,
|
||||
authorId: message.authorId,
|
||||
text:
|
||||
"Unsupported message type: ${message.metadata?["eventType"]}",
|
||||
? Text(
|
||||
"${message.authorId} sent ${message.metadata?["eventType"]}",
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: Colors.grey,
|
||||
),
|
||||
receivedBackgroundColor: Colors.red,
|
||||
sentBackgroundColor: Colors.red,
|
||||
index: index,
|
||||
)
|
||||
: SizedBox.shrink(),
|
||||
textMessageBuilder:
|
||||
|
|
@ -114,31 +110,9 @@ class RoomChat extends HookConsumerWidget {
|
|||
SizedBox(height: 8),
|
||||
|
||||
FlyerChatTextMessage(
|
||||
topWidget: Padding(
|
||||
padding: EdgeInsets.only(bottom: 12),
|
||||
child: InkWell(
|
||||
onTap: () => showAboutDialog(
|
||||
context: context,
|
||||
), // TODO: Show user profile
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 8,
|
||||
children: [
|
||||
Avatar(
|
||||
userId: message.authorId,
|
||||
headers: headers,
|
||||
),
|
||||
Text(
|
||||
message.metadata?["displayName"] ??
|
||||
message.authorId,
|
||||
style: theme.textTheme.titleMedium
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
topWidget: TopWidget(
|
||||
message,
|
||||
headers: headers,
|
||||
),
|
||||
message: message.copyWith(
|
||||
text: message.text.replaceAllMapped(
|
||||
|
|
@ -188,6 +162,7 @@ class RoomChat extends HookConsumerWidget {
|
|||
required bool isSentByMe,
|
||||
MessageGroupStatus? groupStatus,
|
||||
}) => FlyerChatImageMessage(
|
||||
topWidget: TopWidget(message, headers: headers),
|
||||
message: message,
|
||||
index: index,
|
||||
headers: headers,
|
||||
|
|
@ -204,6 +179,7 @@ class RoomChat extends HookConsumerWidget {
|
|||
context: context,
|
||||
), // TODO: Download
|
||||
child: FlyerChatFileMessage(
|
||||
topWidget: TopWidget(message, headers: headers),
|
||||
message: message,
|
||||
index: index,
|
||||
),
|
||||
|
|
|
|||
107
lib/widgets/top_widget.dart
Normal file
107
lib/widgets/top_widget.dart
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
import "dart:math";
|
||||
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_chat_core/flutter_chat_core.dart";
|
||||
import "package:flutter_chat_ui/flutter_chat_ui.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/message_controller.dart";
|
||||
import "package:nexus/helpers/extension_helper.dart";
|
||||
|
||||
class TopWidget extends ConsumerWidget {
|
||||
final Message message;
|
||||
final Map<String, String> headers;
|
||||
const TopWidget(this.message, {required this.headers, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (message.replyToMessageId != null) ...[
|
||||
ref
|
||||
.watch(MessageController.provider(message.replyToMessageId!))
|
||||
.betterWhen(
|
||||
loading: SizedBox.shrink,
|
||||
data: (replyMessage) {
|
||||
if (replyMessage == null) return SizedBox.shrink();
|
||||
final replyText = message is TextMessage
|
||||
? replyMessage.text.substring(
|
||||
0,
|
||||
min(
|
||||
max(
|
||||
min(
|
||||
(message as TextMessage).text.length - 20,
|
||||
replyMessage.text.length,
|
||||
),
|
||||
40,
|
||||
),
|
||||
replyMessage.text.length,
|
||||
),
|
||||
)
|
||||
: replyMessage.text;
|
||||
return InkWell(
|
||||
onTap: () => showAboutDialog(
|
||||
context: context,
|
||||
), // TODO: Scroll to message
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
left: BorderSide(
|
||||
width: 4,
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 8),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 8,
|
||||
children: [
|
||||
Avatar(
|
||||
userId: replyMessage.authorId,
|
||||
headers: headers,
|
||||
size: 16,
|
||||
),
|
||||
Text(
|
||||
replyMessage.metadata?["displayName"] ??
|
||||
replyMessage.authorId,
|
||||
style: Theme.of(context).textTheme.labelMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
replyText,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
],
|
||||
InkWell(
|
||||
onTap: () =>
|
||||
showAboutDialog(context: context), // TODO: Show user profile
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 8,
|
||||
children: [
|
||||
Avatar(userId: message.authorId, headers: headers),
|
||||
Text(
|
||||
message.metadata?["displayName"] ?? message.authorId,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
],
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue