mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-06-06 21:58:49 -04:00
checkpoint
This commit is contained in:
parent
09ae8ff6bb
commit
aa376a449d
3 changed files with 95 additions and 67 deletions
|
@ -4,7 +4,7 @@ import 'package:veilid_support/veilid_support.dart';
|
||||||
class ActiveChatCubit extends Cubit<TypedKey?> {
|
class ActiveChatCubit extends Cubit<TypedKey?> {
|
||||||
ActiveChatCubit(super.initialState);
|
ActiveChatCubit(super.initialState);
|
||||||
|
|
||||||
void setActiveChat(TypedKey? activeChat) {
|
void setActiveChat(TypedKey? activeChatRemoteConversationRecordKey) {
|
||||||
emit(activeChat);
|
emit(activeChatRemoteConversationRecordKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,11 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
|
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
|
||||||
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
|
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
|
||||||
|
|
||||||
|
import '../../account_manager/account_manager.dart';
|
||||||
|
import '../../contacts/contacts.dart';
|
||||||
import '../../proto/proto.dart' as proto;
|
import '../../proto/proto.dart' as proto;
|
||||||
import '../../theme/theme.dart';
|
import '../../theme/theme.dart';
|
||||||
|
import '../../tools/tools.dart';
|
||||||
import '../chat.dart';
|
import '../chat.dart';
|
||||||
|
|
||||||
class ChatComponent extends StatefulWidget {
|
class ChatComponent extends StatefulWidget {
|
||||||
|
@ -109,73 +112,99 @@ class ChatComponentState extends State<ChatComponent> {
|
||||||
final scale = theme.extension<ScaleScheme>()!;
|
final scale = theme.extension<ScaleScheme>()!;
|
||||||
final textTheme = Theme.of(context).textTheme;
|
final textTheme = Theme.of(context).textTheme;
|
||||||
final chatTheme = makeChatTheme(scale, textTheme);
|
final chatTheme = makeChatTheme(scale, textTheme);
|
||||||
final contactName = widget.activeChatContact.editedProfile.name;
|
|
||||||
|
|
||||||
final protoMessages =
|
final activeChatCubit = context.watch<ActiveChatCubit>();
|
||||||
ref.watch(activeConversationMessagesProvider).asData?.value;
|
final contactListCubit = context.watch<ContactListCubit>();
|
||||||
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(
|
final activeChatContactKey = activeChatCubit.state;
|
||||||
style: textTheme.bodySmall!,
|
if (activeChatContactKey == null) {
|
||||||
child: Align(
|
return const NoConversationWidget();
|
||||||
alignment: AlignmentDirectional.centerEnd,
|
}
|
||||||
child: Stack(
|
return contactListCubit.state.builder((context, contactList) {
|
||||||
children: [
|
|
||||||
Column(
|
// Get active chat contact profile
|
||||||
children: [
|
final activeChatContactIdx = contactList.indexWhere(
|
||||||
Container(
|
(c) => activeChatContactKey == c.remoteConversationRecordKey);
|
||||||
height: 48,
|
late final proto.Contact activeChatContact;
|
||||||
decoration: BoxDecoration(
|
if (activeChatContactIdx == -1) {
|
||||||
color: scale.primaryScale.subtleBorder,
|
activeChatCubit.setActiveChat(null);
|
||||||
|
return const NoConversationWidget();
|
||||||
|
} else {
|
||||||
|
activeChatContact = contactList[activeChatContactIdx];
|
||||||
|
}
|
||||||
|
final contactName = activeChatContact.editedProfile.name;
|
||||||
|
|
||||||
|
// Make a messages cubit for this conversation
|
||||||
|
xxx
|
||||||
|
|
||||||
|
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(
|
||||||
|
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)
|
||||||
|
]),
|
||||||
),
|
),
|
||||||
child: Row(children: [
|
Expanded(
|
||||||
Align(
|
child: DecoratedBox(
|
||||||
alignment: AlignmentDirectional.centerStart,
|
decoration: const BoxDecoration(),
|
||||||
child: Padding(
|
child: Chat(
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
theme: chatTheme,
|
||||||
16, 0, 16, 0),
|
messages: messages,
|
||||||
child: Text(contactName,
|
//onAttachmentPressed: _handleAttachmentPressed,
|
||||||
textAlign: TextAlign.start,
|
//onMessageTap: _handleMessageTap,
|
||||||
style: textTheme.titleMedium),
|
//onPreviewDataFetched: _handlePreviewDataFetched,
|
||||||
)),
|
|
||||||
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) {
|
onSendPressed: (message) {
|
||||||
unawaited(_handleSendPressed(message));
|
unawaited(_handleSendPressed(message));
|
||||||
},
|
},
|
||||||
//showUserAvatars: false,
|
//showUserAvatars: false,
|
||||||
//showUserNames: true,
|
//showUserNames: true,
|
||||||
user: _localUser,
|
user: _localUser,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
));
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
//XXX should rename this
|
class NoConversationWidget extends StatelessWidget {
|
||||||
class NoContactWidget extends StatelessWidget {
|
const NoConversationWidget({super.key});
|
||||||
const NoContactWidget({super.key});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// ignore: prefer_expression_function_bodies
|
// ignore: prefer_expression_function_bodies
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue