checkpoint

This commit is contained in:
Christien Rioux 2024-02-08 21:05:59 -05:00
parent 09ae8ff6bb
commit aa376a449d
3 changed files with 95 additions and 67 deletions

View file

@ -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);
} }
} }

View file

@ -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,7 +112,30 @@ 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 activeChatCubit = context.watch<ActiveChatCubit>();
final contactListCubit = context.watch<ContactListCubit>();
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);
late final proto.Contact activeChatContact;
if (activeChatContactIdx == -1) {
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 = final protoMessages =
ref.watch(activeConversationMessagesProvider).asData?.value; ref.watch(activeConversationMessagesProvider).asData?.value;
@ -149,7 +175,9 @@ class ChatComponentState extends State<ChatComponent> {
IconButton( IconButton(
icon: const Icon(Icons.close), icon: const Icon(Icons.close),
onPressed: () async { onPressed: () async {
context.read<ActiveChatCubit>().setActiveChat(null); context
.read<ActiveChatCubit>()
.setActiveChat(null);
}).paddingLTRB(16, 0, 16, 0) }).paddingLTRB(16, 0, 16, 0)
]), ]),
), ),
@ -177,5 +205,6 @@ class ChatComponentState extends State<ChatComponent> {
], ],
), ),
)); ));
});
} }
} }

View file

@ -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