This commit is contained in:
Christien Rioux 2023-08-08 23:33:31 -07:00
parent d965f674fc
commit e76e3cf0ba
11 changed files with 148 additions and 66 deletions

View file

@ -14,6 +14,7 @@ import '../providers/account.dart';
import '../providers/chat.dart';
import '../providers/conversation.dart';
import '../tools/theme_service.dart';
import '../tools/widget_helpers.dart';
import '../veilid_support/veilid_support.dart';
class ChatComponent extends ConsumerStatefulWidget {
@ -32,7 +33,6 @@ class ChatComponent extends ConsumerStatefulWidget {
}
class ChatComponentState extends ConsumerState<ChatComponent> {
List<types.Message> _messages = [];
final _unfocusNode = FocusNode();
late final types.User _localUser;
late final types.User _remoteUser;
@ -52,8 +52,6 @@ class ChatComponentState extends ConsumerState<ChatComponent> {
widget.activeChatContact.identityPublicKey)
.toString(),
firstName: widget.activeChatContact.remoteProfile.name);
unawaited(_loadMessages());
}
@override
@ -62,29 +60,6 @@ class ChatComponentState extends ConsumerState<ChatComponent> {
super.dispose();
}
externalize messages so they auto refresh and fix speed.
Future<void> _loadMessages() async {
final localConversationRecordKey = proto.TypedKeyProto.fromProto(
widget.activeChatContact.localConversationRecordKey);
final remoteIdentityPublicKey = proto.TypedKeyProto.fromProto(
widget.activeChatContact.identityPublicKey);
final protoMessages = await getLocalConversationMessages(
activeAccountInfo: widget.activeAccountInfo,
localConversationRecordKey: localConversationRecordKey,
remoteIdentityPublicKey: remoteIdentityPublicKey);
if (protoMessages == null) {
return;
}
setState(() {
_messages = [];
for (final protoMessage in protoMessages) {
final message = protoMessageToMessage(protoMessage);
_messages.insert(0, message);
}
});
}
types.Message protoMessageToMessage(proto.Message message) {
final isLocal = message.author ==
widget.activeAccountInfo.localAccount.identityMaster
@ -107,9 +82,9 @@ class ChatComponentState extends ConsumerState<ChatComponent> {
final message = protoMessageToMessage(protoMessage);
setState(() {
_messages.insert(0, message);
});
// setState(() {
// _messages.insert(0, message);
// });
// Now add the message to the conversation messages
final localConversationRecordKey = proto.TypedKeyProto.fromProto(
@ -122,6 +97,8 @@ class ChatComponentState extends ConsumerState<ChatComponent> {
localConversationRecordKey: localConversationRecordKey,
remoteIdentityPublicKey: remoteIdentityPublicKey,
message: protoMessage);
ref.invalidate(activeConversationMessagesProvider);
}
Future<void> _handleSendPressed(types.PartialText message) async {
@ -149,6 +126,17 @@ class ChatComponentState extends ConsumerState<ChatComponent> {
final textTheme = Theme.of(context).textTheme;
final contactName = widget.activeChatContact.editedProfile.name;
final protoMessages =
ref.watch(activeConversationMessagesProvider).asData?.value;
if (protoMessages == null) {
return waitingPage(context);
}
final messages = <types.Message>[];
for (final protoMessage in protoMessages) {
final message = protoMessageToMessage(protoMessage);
messages.insert(0, message);
}
return DefaultTextStyle(
style: textTheme.bodySmall!,
child: Align(
@ -185,7 +173,7 @@ class ChatComponentState extends ConsumerState<ChatComponent> {
decoration: const BoxDecoration(),
child: Chat(
theme: chatTheme,
messages: _messages,
messages: messages,
//onAttachmentPressed: _handleAttachmentPressed,
//onMessageTap: _handleMessageTap,
//onPreviewDataFetched: _handlePreviewDataFetched,

View file

@ -1,5 +1,6 @@
import 'dart:async';
import 'package:awesome_extensions/awesome_extensions.dart';
import 'package:basic_utils/basic_utils.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@ -76,13 +77,12 @@ class ContactInvitationDisplayDialogState
final textTheme = theme.textTheme;
final signedContactInvitationBytesV = ref.watch(_generateFutureProvider);
final cardsize = MediaQuery.of(context).size.shortestSide - 24;
final cardsize = MediaQuery.of(context).size.shortestSide - 48;
return Dialog(
backgroundColor: Colors.white,
child: SizedBox(
width: cardsize,
height: cardsize,
child: FittedBox(
fit: BoxFit.scaleDown,
child: signedContactInvitationBytesV.when(
loading: () => waitingPage(context),
data: (data) {
@ -96,16 +96,16 @@ class ContactInvitationDisplayDialogState
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FittedBox(
fit: BoxFit.scaleDown,
child: Text(
translate(
'send_invite_dialog.contact_invitation'),
style: textTheme.headlineMedium!
.copyWith(color: Colors.black)))
.paddingAll(8),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(
translate(
'send_invite_dialog.contact_invitation'),
style: textTheme.headlineMedium!
.copyWith(color: Colors.black))),
ConstrainedBox(
constraints: const BoxConstraints(
minWidth: 300, minHeight: 300),
child: QrImageView.withQr(
size: 300,
qr: QrCode.fromUint8List(
@ -113,11 +113,12 @@ class ContactInvitationDisplayDialogState
errorCorrectLevel:
QrErrorCorrectLevel.L))),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(widget.message,
softWrap: true,
style: textTheme.headlineSmall!
.copyWith(color: Colors.black))),
fit: BoxFit.scaleDown,
child: Text(widget.message,
softWrap: true,
style: textTheme.headlineSmall!
.copyWith(color: Colors.black)))
.paddingAll(8),
ElevatedButton.icon(
icon: const Icon(Icons.copy),
label: Text(translate(
@ -131,7 +132,7 @@ class ContactInvitationDisplayDialogState
text:
makeTextInvite(widget.message, data)));
},
),
).paddingAll(8),
]));
},
error: (e, s) {

View file

@ -114,9 +114,12 @@ class ContactInvitationItemWidget extends ConsumerWidget {
));
}
},
subtitle: Text(contactInvitationRecord.message.isEmpty
? translate('contact_list.invitation')
: contactInvitationRecord.message),
title: Text(
contactInvitationRecord.message.isEmpty
? translate('contact_list.invitation')
: contactInvitationRecord.message,
softWrap: true,
),
iconColor: scale.tertiaryScale.background,
textColor: scale.tertiaryScale.text,
//Text(Timestamp.fromInt64(contactInvitationRecord.expiration) / ),

View file

@ -143,7 +143,7 @@ class SendInviteDialogState extends ConsumerState<SendInviteDialog> {
TextField(
controller: _messageTextController,
inputFormatters: [
LengthLimitingTextInputFormatter(256),
LengthLimitingTextInputFormatter(128),
],
decoration: InputDecoration(
border: const OutlineInputBorder(),