mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-05-16 13:12:43 -04:00
messages work
This commit is contained in:
parent
43dbf26cc0
commit
634543910b
47 changed files with 2206 additions and 123 deletions
|
@ -1,12 +1,17 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:async_tools/async_tools.dart';
|
||||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
|
||||
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../account_manager/account_manager.dart';
|
||||
import '../../chat_list/chat_list.dart';
|
||||
import '../../contacts/contacts.dart';
|
||||
import '../../proto/proto.dart' as proto;
|
||||
import '../../theme/theme.dart';
|
||||
|
@ -14,10 +19,19 @@ import '../../tools/tools.dart';
|
|||
import '../chat.dart';
|
||||
|
||||
class ChatComponent extends StatefulWidget {
|
||||
const ChatComponent({super.key});
|
||||
const ChatComponent({required this.remoteConversationRecordKey, super.key});
|
||||
|
||||
@override
|
||||
ChatComponentState createState() => ChatComponentState();
|
||||
|
||||
final TypedKey remoteConversationRecordKey;
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties.add(DiagnosticsProperty<TypedKey>(
|
||||
'chatRemoteConversationKey', remoteConversationRecordKey));
|
||||
}
|
||||
}
|
||||
|
||||
class ChatComponentState extends State<ChatComponent> {
|
||||
|
@ -113,99 +127,92 @@ class ChatComponentState extends State<ChatComponent> {
|
|||
final textTheme = Theme.of(context).textTheme;
|
||||
final chatTheme = makeChatTheme(scale, textTheme);
|
||||
|
||||
final activeChatCubit = context.watch<ActiveChatCubit>();
|
||||
final contactListCubit = context.watch<ContactListCubit>();
|
||||
final activeAccountInfo = context.watch<ActiveAccountInfo>();
|
||||
|
||||
final activeChatContactKey = activeChatCubit.state;
|
||||
if (activeChatContactKey == null) {
|
||||
return const NoConversationWidget();
|
||||
}
|
||||
return contactListCubit.state.builder((context, contactList) {
|
||||
// Get active chat contact profile
|
||||
final activeChatContactIdx = contactList.indexWhere(
|
||||
(c) => activeChatContactKey == c.remoteConversationRecordKey);
|
||||
final activeChatContactIdx = contactList.indexWhere((c) =>
|
||||
widget.remoteConversationRecordKey == c.remoteConversationRecordKey);
|
||||
late final proto.Contact activeChatContact;
|
||||
if (activeChatContactIdx == -1) {
|
||||
// xxx: error, no contact for conversation...
|
||||
return const NoConversationWidget();
|
||||
} else {
|
||||
activeChatContact = contactList[activeChatContactIdx];
|
||||
}
|
||||
final contactName = 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);
|
||||
// }
|
||||
final messages = context.select<ActiveConversationMessagesCubit,
|
||||
AsyncValue<IList<proto.Message>>?>(
|
||||
(x) => x.state[widget.remoteConversationRecordKey]);
|
||||
if (messages == null) {
|
||||
// xxx: error, no messages for conversation...
|
||||
return const NoConversationWidget();
|
||||
}
|
||||
return messages.builder((context, protoMessages) {
|
||||
final messages = <types.Message>[];
|
||||
for (final protoMessage in protoMessages) {
|
||||
final message = protoMessageToMessage(protoMessage);
|
||||
messages.insert(0, message);
|
||||
}
|
||||
return DefaultTextStyle(
|
||||
style: textTheme.bodySmall!,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: scale.primaryScale.subtleBorder,
|
||||
),
|
||||
child: Row(children: [
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
16, 0, 16, 0),
|
||||
child: Text(contactName,
|
||||
textAlign: TextAlign.start,
|
||||
style: textTheme.titleMedium),
|
||||
)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () async {
|
||||
context
|
||||
.read<ActiveChatCubit>()
|
||||
.setActiveChat(null);
|
||||
}).paddingLTRB(16, 0, 16, 0)
|
||||
]),
|
||||
),
|
||||
Expanded(
|
||||
child: DecoratedBox(
|
||||
decoration: const BoxDecoration(),
|
||||
child: Chat(
|
||||
theme: chatTheme,
|
||||
messages: messages,
|
||||
//onAttachmentPressed: _handleAttachmentPressed,
|
||||
//onMessageTap: _handleMessageTap,
|
||||
//onPreviewDataFetched: _handlePreviewDataFetched,
|
||||
|
||||
return BlocProvider(
|
||||
create: (context) => MessagesCubit(
|
||||
activeAccountInfo: activeAccountInfo,
|
||||
remoteIdentityPublicKey: activeChatContact.identityPublicKey, localConversationRecordKey: activeChatContact.localConversationRecordKey, localMessagesRecordKey: activeChatContact.,
|
||||
onSendPressed: (message) {
|
||||
unawaited(_handleSendPressed(message));
|
||||
},
|
||||
//showUserAvatars: false,
|
||||
//showUserNames: true,
|
||||
user: _localUser,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: textTheme.bodySmall!,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: scale.primaryScale.subtleBorder,
|
||||
),
|
||||
child: Row(children: [
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
16, 0, 16, 0),
|
||||
child: Text(contactName,
|
||||
textAlign: TextAlign.start,
|
||||
style: textTheme.titleMedium),
|
||||
)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () async {
|
||||
context
|
||||
.read<ActiveChatCubit>()
|
||||
.setActiveChat(null);
|
||||
}).paddingLTRB(16, 0, 16, 0)
|
||||
]),
|
||||
),
|
||||
Expanded(
|
||||
child: DecoratedBox(
|
||||
decoration: const BoxDecoration(),
|
||||
child: Chat(
|
||||
theme: chatTheme,
|
||||
messages: messages,
|
||||
//onAttachmentPressed: _handleAttachmentPressed,
|
||||
//onMessageTap: _handleMessageTap,
|
||||
//onPreviewDataFetched: _handlePreviewDataFetched,
|
||||
|
||||
onSendPressed: (message) {
|
||||
unawaited(_handleSendPressed(message));
|
||||
},
|
||||
//showUserAvatars: false,
|
||||
//showUserNames: true,
|
||||
user: _localUser,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
)));
|
||||
));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue